clang_tidy_code.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/bash
  2. # Copyright 2015 gRPC authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. echo "NOTE: to automagically apply fixes, invoke with --fix"
  16. set -ex
  17. # change to root directory
  18. cd $(dirname $0)/../..
  19. REPO_ROOT=$(pwd)
  20. # grep targets with manual tag, which is not included in a result of bazel build using ...
  21. # let's get a list of them using query command and pass it to gen_compilation_database.py
  22. export MANUAL_TARGETS=$(bazel query 'attr("tags", "manual", tests(//test/cpp/...))' | grep -v _on_ios)
  23. # generate a clang compilation database for all C/C++ sources in the repo.
  24. tools/distrib/gen_compilation_database.py \
  25. --include_headers \
  26. --ignore_system_headers \
  27. --dedup_targets \
  28. "//:*" \
  29. "//src/core/..." \
  30. "//src/compiler/..." \
  31. "//test/core/..." \
  32. "//test/cpp/..." \
  33. $MANUAL_TARGETS
  34. if [ "$CLANG_TIDY_SKIP_DOCKER" == "" ]
  35. then
  36. # build clang-tidy docker image
  37. docker build -t grpc_clang_tidy tools/dockerfile/grpc_clang_tidy
  38. # run clang-tidy against the checked out codebase
  39. # when modifying the checked-out files, the current user will be impersonated
  40. # so that the updated files don't end up being owned by "root".
  41. docker run \
  42. -e TEST="$TEST" \
  43. -e CHANGED_FILES="$CHANGED_FILES" \
  44. -e CLANG_TIDY_ROOT="/local-code" \
  45. --rm=true \
  46. -v "${REPO_ROOT}":/local-code \
  47. -v "${HOME/.cache/bazel}":"${HOME/.cache/bazel}" \
  48. --user "$(id -u):$(id -g)" \
  49. -t grpc_clang_tidy /clang_tidy_all_the_things.sh "$@"
  50. else
  51. CLANG_TIDY_ROOT="${REPO_ROOT}" tools/dockerfile/grpc_clang_tidy/clang_tidy_all_the_things.sh "$@"
  52. fi