Add some flags to 'apply-include-cleaner'.

-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 <jleconte@google.com>
Reviewed-by: Björn Terelius <terelius@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#42897}
This commit is contained in:
Jeremy Leconte 2024-08-30 14:30:03 +02:00 committed by WebRTC LUCI CQ
parent d385af56c3
commit c4d749304d

View File

@ -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 <n> : Set debug level to <n>"
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