Skip to content
File

Blob: build/tools/clang_tidy/clang_tidy_wrapper.sh

bash37 lines
1#! /bin/bash
2# simple wrapper script to execute clang-tidy
3 
4set -euo pipefail
5 
6CLANG_TIDY_BIN=$1
7shift
8 
9OUTPUT=$1
10shift
11 
12PWD=$(pwd)/
13ESCAPED_PWD=$(sed 's/[\*\.&/]/\\&/g' <<< "$PWD")
14 
15# Interestingly clang-tidy prints real errors to stdout, but system message like
16# `4 warnings generated` when they are filtered out, to stderr.
17# Save stderr and print only on errors to reduce the clutter.
18CLANG_TIDY_STDERR=$(mktemp)
19 
20set +e
21"${CLANG_TIDY_BIN}" "$@" 2>"$CLANG_TIDY_STDERR" | \
22 # clang-tidy insists on printing absolute file paths, chop current dir off
23 sed "s/$ESCAPED_PWD//g"
24CLANG_TIDY_EXIT_CODE=$?
25set -e
26 
27if [[ $CLANG_TIDY_EXIT_CODE -ne 0 ]]; then
28 cat "$CLANG_TIDY_STDERR" >&2
29 rm -f "$CLANG_TIDY_STDERR"
30 exit $CLANG_TIDY_EXIT_CODE
31fi
32 
33rm -f "$CLANG_TIDY_STDERR"
34 
35# bazel needs run action to produce some output, touch the file
36touch "$OUTPUT"