Stop the kernel header scrubber from duplicating includes.
We'll probably never hit this (because the case I hit it with, struct
sigaction, isn't amenable to the "replace with #include <bits/STRUCT.h>"
trick), but in case we do, and because a set expresses our intent better
than a list, keep the list^Wset of generated includes in a set.
Bug: http://b/236042740
Test: treehugger
Change-Id: I21f5c08515eab1b28e6a36fc00149b6bc7740b7e
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'))