Skip to content

Commit 0ca6260

Browse files
committed
Fix standard headers list
Due to an error in the regex parsing the webpage content, all headers using `_` were missing.
1 parent ee7e037 commit 0ca6260

File tree

7 files changed

+80
-6
lines changed

7 files changed

+80
-6
lines changed

scripts/BUILD

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
load("@rules_python//python:defs.bzl", "py_binary")
2+
3+
py_binary(
4+
name = "extract_std_headers",
5+
srcs = ["extract_std_headers.py"],
6+
visibility = [":__subpackages__"],
7+
)

scripts/extract_std_headers.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,26 @@
1010
python file containing the standard header list for DWYU to lookup.
1111
"""
1212

13+
from __future__ import annotations
14+
1315
import re
1416
from pathlib import Path
1517

16-
with Path("input.txt").open(encoding="utf-8") as fin:
18+
INPUT = Path("input.txt")
19+
20+
21+
def extract_header(text: str) -> list[str]:
1722
headers = []
18-
for line in fin.readlines():
19-
headers.extend(re.findall(r"<([a-z/.]+)>", line))
20-
print("\n".join(f'"{h}",' for h in sorted(set(headers)))) # noqa: T201
23+
for line in text.split("\n"):
24+
headers.extend(re.findall(r"<([a-z_/.]+)>", line))
25+
return headers
26+
27+
28+
def main() -> None:
29+
with INPUT.open(encoding="utf-8") as fin:
30+
headers = extract_header(fin.read())
31+
print("\n".join(f'"{h}",' for h in sorted(set(headers)))) # noqa: T201
32+
33+
34+
if __name__ == "__main__":
35+
main()

scripts/mypy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
set -o errexit
44

5-
bazel build --config=mypy -- //src/... //examples:all //test/aspect:all //test/apply_fixes:all
5+
bazel build --config=mypy -- //src/... //scripts/... //examples:all //test/aspect:all //test/apply_fixes:all

scripts/test/BUILD

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
load("@rules_python//python:defs.bzl", "py_test")
2+
3+
py_test(
4+
name = "extract_std_headers_test",
5+
srcs = ["extract_std_headers_test.py"],
6+
deps = ["//scripts:extract_std_headers"],
7+
)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from __future__ import annotations
2+
3+
import unittest
4+
5+
from scripts.extract_std_headers import extract_header
6+
7+
8+
class TestExtractHeader(unittest.TestCase):
9+
def test_empty_input_yields_empty_list(self) -> None:
10+
self.assertEqual(extract_header(""), [])
11+
12+
def test_extracting_headers(self) -> None:
13+
headers = extract_header(
14+
"""
15+
unrelated_stuff
16+
<foo>
17+
ignore this
18+
<bar.h>
19+
<multiple_header><in_one_line>
20+
""".strip()
21+
)
22+
23+
self.assertEqual(headers, ["foo", "bar.h", "multiple_header", "in_one_line"])
24+
25+
26+
if __name__ == "__main__":
27+
unittest.main()

scripts/unit_tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
set -o errexit
44

5-
bazel test -- //src/... //test/aspect:all //third_party/...
5+
bazel test -- //src/... //scripts/... //test/aspect:all //third_party/...

src/analyze_includes/std_header.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"complex",
3939
"complex.h",
4040
"concepts",
41+
"condition_variable",
4142
"coroutine",
4243
"cpio.h",
4344
"csetjmp",
@@ -68,18 +69,23 @@
6869
"fcntl.h",
6970
"fenv.h",
7071
"filesystem",
72+
"flat_map",
73+
"flat_set",
7174
"float.h",
7275
"fmtmsg.h",
7376
"fnmatch.h",
7477
"format",
78+
"forward_list",
7579
"fstream",
7680
"ftw.h",
7781
"functional",
7882
"future",
7983
"generator",
8084
"glob.h",
8185
"grp.h",
86+
"hazard_pointer",
8287
"iconv.h",
88+
"initializer_list",
8389
"inttypes.h",
8490
"iomanip",
8591
"ios",
@@ -100,6 +106,7 @@
100106
"math.h",
101107
"mdspan",
102108
"memory",
109+
"memory_resource",
103110
"monetary.h",
104111
"mqueue.h",
105112
"mutex",
@@ -109,6 +116,7 @@
109116
"netinet/in.h",
110117
"netinet/tcp.h",
111118
"new",
119+
"nl_types.h",
112120
"numbers",
113121
"numeric",
114122
"optional",
@@ -125,12 +133,15 @@
125133
"regex",
126134
"regex.h",
127135
"sched.h",
136+
"scoped_allocator",
128137
"search.h",
129138
"semaphore",
130139
"semaphore.h",
131140
"set",
132141
"setjmp.h",
142+
"shared_mutex",
133143
"signal.h",
144+
"source_location",
134145
"span",
135146
"spanstream",
136147
"spawn.h",
@@ -150,9 +161,11 @@
150161
"stdio.h",
151162
"stdlib.h",
152163
"stdnoreturn.h",
164+
"stop_token",
153165
"streambuf",
154166
"string",
155167
"string.h",
168+
"string_view",
156169
"strings.h",
157170
"stropts.h",
158171
"strstream",
@@ -175,19 +188,24 @@
175188
"sys/utsname.h",
176189
"sys/wait.h",
177190
"syslog.h",
191+
"system_error",
178192
"tar.h",
179193
"termios.h",
194+
"text_encoding",
180195
"tgmath.h",
181196
"thread",
182197
"threads.h",
183198
"time.h",
184199
"trace.h",
185200
"tuple",
201+
"type_traits",
186202
"typeindex",
187203
"typeinfo",
188204
"uchar.h",
189205
"ulimit.h",
190206
"unistd.h",
207+
"unordered_map",
208+
"unordered_set",
191209
"utility",
192210
"utime.h",
193211
"utmpx.h",

0 commit comments

Comments
 (0)