From 3d60f2560e68829eefbd60153d7510d0a1a72cd9 Mon Sep 17 00:00:00 2001 From: Jeremy Leconte Date: Tue, 3 Sep 2024 11:20:55 +0200 Subject: [PATCH] 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 Commit-Queue: Jeremy Leconte Cr-Commit-Position: refs/heads/main@{#42927} --- tools_webrtc/iwyu/apply-include-cleaner | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tools_webrtc/iwyu/apply-include-cleaner b/tools_webrtc/iwyu/apply-include-cleaner index 789e1202dc..06c108ddb7 100755 --- a/tools_webrtc/iwyu/apply-include-cleaner +++ b/tools_webrtc/iwyu/apply-include-cleaner @@ -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."