Fix gtest/gmock includes in apply-include-cleaner script.

gmock and gtest includes are replaced in the script but this wasn't applied to the 'CHECK_MODE' causing false error report.

nit: Usage is printed when no arguments are provided.

Change-Id: I418a17b998934b0079f5bf19513097481f35aa70
Bug: b/236227627
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/361400
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Jeremy Leconte <jleconte@google.com>
Cr-Commit-Position: refs/heads/main@{#42927}
This commit is contained in:
Jeremy Leconte 2024-09-03 11:20:55 +02:00 committed by WebRTC LUCI CQ
parent 3881cb65cf
commit 3d60f2560e

View File

@ -55,7 +55,7 @@ error() {
WORKDIR=out/Default
usage() {
echo "Usage: $0 [ -c compile-commands-file.json ] [-r] file.cc"
echo "Usage: $0 [-r] file.cc"
echo "Runs the include-cleaner tool on a file"
echo "Arguments:"
echo " -n : Just print changes, don't do them"
@ -97,12 +97,12 @@ fi
FILE="$1"
if [ ! -f $FILE ]; then
if [ -z $FILE ] || [ ! -f $FILE ]; then
usage
error "File $FILE is not found"
fi
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
@ -114,9 +114,16 @@ case "$(uname -s)" in
Darwin*) INPLACE_ARG=( -i '' );;
*) INPLACE_ARG=( -i )
esac
git diff-index -U -G "^#include \"gtest\/gtest\.h" HEAD --name-only | xargs -I {} sed "${INPLACE_ARG[@]}" -e 's@^#include "gtest\/gtest\.h@#include "test\/gtest\.h@g' {}
git diff-index -U -G "^#include \"gmock\/gmock\.h" HEAD --name-only | xargs -I {} sed "${INPLACE_ARG[@]}" -e 's@^#include "gmock\/gmock\.h@#include "test\/gmock\.h@g' {}
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}"
echo "Finished. Check diff, compile, gn gen --check and git cl format"
echo "before uploading."