Fix up IWYU output to refer to the complete third_party/ path.
Bug: webrtc:42226242
Change-Id: Ice01e2a821deeeb4b6d9e20a9805c8968addbb26
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/394580
Reviewed-by: Philipp Hancke <phancke@meta.com>
Commit-Queue: Jeremy Leconte <jleconte@google.com>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#44814}
diff --git a/tools_webrtc/iwyu/apply_include_cleaner.py b/tools_webrtc/iwyu/apply_include_cleaner.py
index 3723649..adb7fe2 100755
--- a/tools_webrtc/iwyu/apply_include_cleaner.py
+++ b/tools_webrtc/iwyu/apply_include_cleaner.py
@@ -54,7 +54,12 @@
 _IWYU_MAPPING = {
     '"gmock/gmock.h"': '"test/gmock.h"',
     '"gtest/gtest.h"': '"test/gtest.h"',
-    "<sys/socket.h>": '"rtc_base/net_helpers.h"',
+    '<sys/socket.h>': '"rtc_base/net_helpers.h"',
+
+    # IWYU does not refer to the complete third_party/ path.
+    '"libyuv/': '"third_party/libyuv/include/libyuv/',
+    '"aom/': '"third_party/libaom/source/libaom/',
+    '"vpx/': '"third_party/libvpx/source/libvpx/',
 }
 
 
@@ -182,20 +187,18 @@
         if value in modified_content:
             # If the required include is already in the file, clear it from the
             # cleaner output and remove what the cleaner added to the file
-            output = output.replace(f'+ {key.replace("#include ", "")}', "")
-            if should_modify:
-                modified_content = re.sub(rf"^#include {re.escape(key)}.*\n?",
-                                          "",
-                                          modified_content,
-                                          flags=re.MULTILINE)
-
-        elif should_modify:
-            # Otherwise, change what the cleaner added to the correct include
+            output = re.sub(rf"^\+ {re.escape(key)}$",
+                            "",
+                            output,
+                            flags=re.MULTILINE)
+        if should_modify:
+            # Change what the cleaner added to the correct include
             # from _IWYU_MAPPING
             modified_content = re.sub(rf"^#include {re.escape(key)}",
                                       f"#include {value}",
                                       modified_content,
                                       flags=re.MULTILINE)
+
     if should_modify and content != modified_content:
         file_path.write_text(modified_content)