[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}
diff --git a/tools_webrtc/iwyu/apply-include-cleaner b/tools_webrtc/iwyu/apply-include-cleaner
index 7164b35..164c33a 100755
--- a/tools_webrtc/iwyu/apply-include-cleaner
+++ b/tools_webrtc/iwyu/apply-include-cleaner
@@ -98,5 +98,18 @@
 
 $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."