IWYU: process a list of files
for easy integration with git diff-tree --no-commit-id --name-only -r HEAD which gets the list of files in a commit BUG=webrtc:42226242 Change-Id: I6e80d0f13e4f182d7c0c9c8ea971f6e48fbaae76 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/370461 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Philipp Hancke <phancke@meta.com> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Cr-Commit-Position: refs/heads/main@{#43589}
This commit is contained in:
parent
0dec0897f1
commit
588dbe6fa7
@ -55,8 +55,8 @@ error() {
|
|||||||
WORKDIR=out/Default
|
WORKDIR=out/Default
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "Usage: $0 [-r] file.cc"
|
echo "Usage: $0 [-r] file.cc [file2.cc ...]"
|
||||||
echo "Runs the include-cleaner tool on a file"
|
echo "Runs the include-cleaner tool on a list of files"
|
||||||
echo "Arguments:"
|
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 " -c : Just return non-zero exit code if there are changes, don't do them"
|
||||||
@ -95,39 +95,47 @@ if [[ -z "$COMPILE_COMMANDS" ]]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
FILE="$1"
|
# To get a list of files in a commit: git diff-tree --no-commit-id --name-only -r HEAD
|
||||||
|
for FILE in "$@"
|
||||||
if [ -z $FILE ] || [ ! -f $FILE ]; then
|
do
|
||||||
usage
|
if [ -z $FILE ] || [ ! -f $FILE ]; then
|
||||||
error "File $FILE is not found"
|
usage
|
||||||
fi
|
error "File $FILE is not found"
|
||||||
|
|
||||||
# Run the command in $WORKDIR because of this reported issue:
|
|
||||||
# https://github.com/llvm/llvm-project/issues/110843
|
|
||||||
cd $WORKDIR
|
|
||||||
OUTPUT=$(../../$CLEANER $INCLUDE_ARGS $COMMAND ../../$FILE)
|
|
||||||
cd -
|
|
||||||
|
|
||||||
# include-cleaner does not support custom mappings for certain deps
|
|
||||||
# this ensures that the gtest/gmock deps it inserts are replaced
|
|
||||||
# with the right paths for those includes.
|
|
||||||
# Since sed inplace argument acts differently between GNU/BSD based systems
|
|
||||||
# we handle this here.
|
|
||||||
case "$(uname -s)" in
|
|
||||||
Linux*) INPLACE_ARG=( -i );;
|
|
||||||
Darwin*) INPLACE_ARG=( -i '' );;
|
|
||||||
*) INPLACE_ARG=( -i )
|
|
||||||
esac
|
|
||||||
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
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "${OUTPUT}"
|
HAS_OUTPUT=false
|
||||||
|
for FILE in "$@"
|
||||||
|
do
|
||||||
|
# Run the command in $WORKDIR because of this reported issue:
|
||||||
|
# https://github.com/llvm/llvm-project/issues/110843
|
||||||
|
cd $WORKDIR
|
||||||
|
OUTPUT=$(../../$CLEANER $INCLUDE_ARGS $COMMAND ../../$FILE)
|
||||||
|
cd -
|
||||||
|
|
||||||
|
# include-cleaner does not support custom mappings for certain deps
|
||||||
|
# this ensures that the gtest/gmock deps it inserts are replaced
|
||||||
|
# with the right paths for those includes.
|
||||||
|
# Since sed inplace argument acts differently between GNU/BSD based systems
|
||||||
|
# we handle this here.
|
||||||
|
case "$(uname -s)" in
|
||||||
|
Linux*) INPLACE_ARG=( -i );;
|
||||||
|
Darwin*) INPLACE_ARG=( -i '' );;
|
||||||
|
*) INPLACE_ARG=( -i )
|
||||||
|
esac
|
||||||
|
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}"
|
||||||
|
HAS_OUTPUT=$HAS_OUTPUT || [[ ! -z $OUTPUT ]]
|
||||||
|
done
|
||||||
|
|
||||||
echo "Finished. Check diff, compile, gn gen --check and git cl format"
|
echo "Finished. Check diff, compile, gn gen --check and git cl format"
|
||||||
echo "before uploading."
|
echo "before uploading."
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user