diff --git a/tools_webrtc/iwyu/apply-include-cleaner b/tools_webrtc/iwyu/apply-include-cleaner index 164c33a3bc..789e1202dc 100755 --- a/tools_webrtc/iwyu/apply-include-cleaner +++ b/tools_webrtc/iwyu/apply-include-cleaner @@ -58,20 +58,25 @@ usage() { echo "Usage: $0 [ -c compile-commands-file.json ] [-r] file.cc" echo "Runs the include-cleaner tool on a file" echo "Arguments:" - echo " -n : just print changes, don't do them" + 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" echo " -r : Remove non-required includes from .h file" echo " -d : Set debug level to " + echo " -w : Specify the workdir (out/Default if not specified)" echo " -h : Print this help message" } COMMAND=" --edit" INCLUDE_ARGS="" +CHECK_MODE=false -while getopts 'd:rnh' opts; do +while getopts 'd:rncw:h' opts; do case "${opts}" in n) COMMAND=" --print=changes" ;; + c) COMMAND=" --print=changes" ; CHECK_MODE=true ;; r) INCLUDE_ARGS=" --remove" ;; d) DEBUG=${OPTARG};if [ $DEBUG -gt 0 ]; then set -x; fi ;; + w) WORKDIR=${OPTARG} ;; h) usage; exit 1 ;; *) error "Unexpected option ${opts}" ;; esac @@ -96,7 +101,8 @@ if [ ! -f $FILE ]; then error "File $FILE is not found" fi -$CLEANER -p $WORKDIR $INCLUDE_ARGS $COMMAND $FILE +OUTPUT=$($CLEANER -p $WORKDIR $INCLUDE_ARGS $COMMAND $FILE) +echo "${OUTPUT}" # include-cleaner does not support custom mappings for certain deps # this ensures that the gtest/gmock deps it inserts are replaced @@ -113,3 +119,9 @@ git diff-index -U -G "^#include \"gmock\/gmock\.h" HEAD --name-only | xargs -I { echo "Finished. Check diff, compile, gn gen --check and git cl format" echo "before uploading." + +# Return a non-zero exit code if running with "CHECK_MODE" +# and there are changes to apply. +if $CHECK_MODE && [[ ! -z $OUTPUT ]]; then + exit 1 +fi