[iwyu] Add postprocessing to handle gtest/gmock include paths

Unfortunately, clangd's include-cleaner has a smaller set of
customization features and does not allow us to set custom mappings for
certain include paths. Instead, add some postprocessing to our internal
wrapper on top of it (`apply-include-cleaner`) to handle gtest/gmock
include paths

Bug: webrtc:42226242
Change-Id: I65e4f73bb1b762bf2da1fb0f9a520bdd980b64bd
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/359161
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Dor Hen <dorhen@meta.com>
Cr-Commit-Position: refs/heads/main@{#42774}
This commit is contained in:
Dor Hen 2024-08-13 11:05:16 +03:00 committed by WebRTC LUCI CQ
parent 1921fa5ea1
commit 9c1ad5f8c0

View File

@ -98,5 +98,18 @@ fi
$CLEANER -p $WORKDIR $INCLUDE_ARGS $COMMAND $FILE
# 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
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' {}
echo "Finished. Check diff, compile, gn gen --check and git cl format"
echo "before uploading."