iwyu.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/bash
  2. # Copyright 2021 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. # build clang-tidy docker image
  35. docker build -t grpc_iwyu tools/dockerfile/grpc_iwyu
  36. # run clang-tidy against the checked out codebase
  37. # when modifying the checked-out files, the current user will be impersonated
  38. # so that the updated files don't end up being owned by "root".
  39. docker run \
  40. -e TEST="$TEST" \
  41. -e CHANGED_FILES="$CHANGED_FILES" \
  42. -e IWYU_ROOT="/local-code" \
  43. --rm=true \
  44. -v "${REPO_ROOT}":/local-code \
  45. -v "${HOME/.cache/bazel}":"${HOME/.cache/bazel}" \
  46. --user "$(id -u):$(id -g)" \
  47. -t grpc_iwyu /iwyu.sh "$@"