Merge "Stop the kernel header scrubber from duplicating includes." into main
diff --git a/libc/kernel/tools/cpp.py b/libc/kernel/tools/cpp.py
index c0b379b..6939bda 100755
--- a/libc/kernel/tools/cpp.py
+++ b/libc/kernel/tools/cpp.py
@@ -1202,7 +1202,7 @@
 
     def removeStructs(self, structs):
         """Remove structs."""
-        extra_includes = []
+        extra_includes = set()
         block_num = 0
         num_blocks = len(self.blocks)
         while block_num < num_blocks:
@@ -1248,7 +1248,7 @@
                     #  #include <bits/STRUCT_NAME.h>
                     struct_token = b.tokens[i + 1]
                     if not structs[struct_token.id]:
-                        extra_includes.append("<bits/%s.h>" % struct_token.id)
+                        extra_includes.add("<bits/%s.h>" % struct_token.id)
 
                     # Search forward for the end of the structure.
                     # Very simple search, look for } and ; tokens.
@@ -1292,7 +1292,7 @@
                     continue
                 i += 1
 
-        for extra_include in extra_includes:
+        for extra_include in sorted(extra_includes):
             replacement = CppStringTokenizer(extra_include)
             self.blocks.insert(2, Block(replacement.tokens, directive='include'))