From c4d749304ddcf63c9c0f60813fc81d71e7976fae Mon Sep 17 00:00:00 2001 From: Jeremy Leconte Date: Fri, 30 Aug 2024 14:30:03 +0200 Subject: [PATCH] Add some flags to 'apply-include-cleaner'. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -w allow to specify the working directory. -c sets the exit code to 1 if there are changes to apply. This flags are added so that the script can be running from a CQ bot. Change-Id: I725a530b4dbbff26d4060435e90aaa66a75e572f Bug: b/236227627 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/360980 Commit-Queue: Jeremy Leconte Reviewed-by: Björn Terelius Cr-Commit-Position: refs/heads/main@{#42897} --- tools_webrtc/iwyu/apply-include-cleaner | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) 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