File
Blob: build/tools/clang_tidy/clang_tidy_wrapper.sh
| 1 | #! /bin/bash |
| 2 | # simple wrapper script to execute clang-tidy |
| 3 | |
| 4 | set -euo pipefail |
| 5 | |
| 6 | CLANG_TIDY_BIN=$1 |
| 7 | shift |
| 8 | |
| 9 | OUTPUT=$1 |
| 10 | shift |
| 11 | |
| 12 | PWD=$(pwd)/ |
| 13 | ESCAPED_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. |
| 18 | CLANG_TIDY_STDERR=$(mktemp) |
| 19 | |
| 20 | set +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" |
| 24 | CLANG_TIDY_EXIT_CODE=$? |
| 25 | set -e |
| 26 | |
| 27 | if [[ $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 |
| 31 | fi |
| 32 | |
| 33 | rm -f "$CLANG_TIDY_STDERR" |
| 34 | |
| 35 | # bazel needs run action to produce some output, touch the file |
| 36 | touch "$OUTPUT" |