diff --git a/tools_webrtc/iwyu/apply-include-cleaner b/tools_webrtc/iwyu/apply-include-cleaner index c96bf35a5e..262b6019e3 100755 --- a/tools_webrtc/iwyu/apply-include-cleaner +++ b/tools_webrtc/iwyu/apply-include-cleaner @@ -55,8 +55,8 @@ error() { WORKDIR=out/Default usage() { - echo "Usage: $0 [-r] file.cc" - echo "Runs the include-cleaner tool on a file" + echo "Usage: $0 [-r] file.cc [file2.cc ...]" + echo "Runs the include-cleaner tool on a list of files" echo "Arguments:" echo " -n : Just print changes, don't do them" echo " -c : Just return non-zero exit code if there are changes, don't do them" @@ -95,39 +95,47 @@ if [[ -z "$COMPILE_COMMANDS" ]]; then fi fi -FILE="$1" - -if [ -z $FILE ] || [ ! -f $FILE ]; then - usage - error "File $FILE is not found" -fi - -# Run the command in $WORKDIR because of this reported issue: -# https://github.com/llvm/llvm-project/issues/110843 -cd $WORKDIR -OUTPUT=$(../../$CLEANER $INCLUDE_ARGS $COMMAND ../../$FILE) -cd - - -# include-cleaner does not support custom mappings for certain deps -# this ensures that the gtest/gmock deps it inserts are replaced -# with the right paths for those includes. -# Since sed inplace argument acts differently between GNU/BSD based systems -# we handle this here. -case "$(uname -s)" in - Linux*) INPLACE_ARG=( -i );; - Darwin*) INPLACE_ARG=( -i '' );; - *) INPLACE_ARG=( -i ) -esac -for INCLUDE in "gtest" "gmock"; do - if grep -q "#include \"test\/${INCLUDE}\.h\"" $FILE; then - OUTPUT=${OUTPUT//"+ \"${INCLUDE}"\/"${INCLUDE}.h\""/} - sed "${INPLACE_ARG[@]}" -e "/#include \"${INCLUDE}\/${INCLUDE}\.h\"/d" $FILE - else - sed "${INPLACE_ARG[@]}" -e "s@^#include \"${INCLUDE}\/${INCLUDE}\.h@#include \"test\/${INCLUDE}\.h@g" $FILE +# To get a list of files in a commit: git diff-tree --no-commit-id --name-only -r HEAD +for FILE in "$@" +do + if [ -z $FILE ] || [ ! -f $FILE ]; then + usage + error "File $FILE is not found" fi done -echo "${OUTPUT}" +HAS_OUTPUT=false +for FILE in "$@" +do + # Run the command in $WORKDIR because of this reported issue: + # https://github.com/llvm/llvm-project/issues/110843 + cd $WORKDIR + OUTPUT=$(../../$CLEANER $INCLUDE_ARGS $COMMAND ../../$FILE) + cd - + + # include-cleaner does not support custom mappings for certain deps + # this ensures that the gtest/gmock deps it inserts are replaced + # with the right paths for those includes. + # Since sed inplace argument acts differently between GNU/BSD based systems + # we handle this here. + case "$(uname -s)" in + Linux*) INPLACE_ARG=( -i );; + Darwin*) INPLACE_ARG=( -i '' );; + *) INPLACE_ARG=( -i ) + esac + for INCLUDE in "gtest" "gmock"; do + if grep -q "#include \"test\/${INCLUDE}\.h\"" $FILE; then + OUTPUT=${OUTPUT//"+ \"${INCLUDE}"\/"${INCLUDE}.h\""/} + sed "${INPLACE_ARG[@]}" -e "/#include \"${INCLUDE}\/${INCLUDE}\.h\"/d" $FILE + else + sed "${INPLACE_ARG[@]}" -e "s@^#include \"${INCLUDE}\/${INCLUDE}\.h@#include \"test\/${INCLUDE}\.h@g" $FILE + fi + done + + echo "${OUTPUT}" + HAS_OUTPUT=$HAS_OUTPUT || [[ ! -z $OUTPUT ]] +done + echo "Finished. Check diff, compile, gn gen --check and git cl format" echo "before uploading."