iwyu.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/bin/sh
  2. # Copyright 2017 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. set -ex
  16. cd ${IWYU_ROOT}
  17. export PATH=${PATH}:/iwyu_build/bin
  18. cat compile_commands.json | sed "s,\"file\": \",\"file\": \"${IWYU_ROOT}/,g" > compile_commands_for_iwyu.json
  19. # figure out which files to include
  20. cat compile_commands.json | jq -r '.[].file' \
  21. | grep -E "^src/core/lib/promise/" \
  22. | grep -v -E "/upb-generated/|/upbdefs-generated/" \
  23. | sort \
  24. | tee iwyu_files.txt
  25. # run iwyu, filtering out changes to port_platform.h
  26. xargs -a iwyu_files.txt /iwyu/iwyu_tool.py -p compile_commands_for_iwyu.json -j 16 \
  27. | grep -v -E "port_platform.h" \
  28. | tee iwyu.out
  29. # apply the suggested changes
  30. /iwyu/fix_includes.py --nocomments < iwyu.out || true
  31. # reformat sources, since iwyu gets this wrong
  32. xargs -a iwyu_files.txt ${CLANG_FORMAT:-clang-format} -i
  33. # TODO(ctiller): expand this to match the clang-tidy directories:
  34. # | grep -E "(^include/|^src/core/|^src/cpp/|^test/core/|^test/cpp/)"