Skip to content

Commit

Permalink
Fix standard headers list
Browse files Browse the repository at this point in the history
Due to an error in the regex parsing the webpage content, all headers
using `_` were missing.
  • Loading branch information
martis42 committed Jun 20, 2024
1 parent ee7e037 commit 0ca6260
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 6 deletions.
7 changes: 7 additions & 0 deletions scripts/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
load("@rules_python//python:defs.bzl", "py_binary")

py_binary(
name = "extract_std_headers",
srcs = ["extract_std_headers.py"],
visibility = [":__subpackages__"],
)
23 changes: 19 additions & 4 deletions scripts/extract_std_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,26 @@
python file containing the standard header list for DWYU to lookup.
"""

from __future__ import annotations

import re
from pathlib import Path

with Path("input.txt").open(encoding="utf-8") as fin:
INPUT = Path("input.txt")


def extract_header(text: str) -> list[str]:
headers = []
for line in fin.readlines():
headers.extend(re.findall(r"<([a-z/.]+)>", line))
print("\n".join(f'"{h}",' for h in sorted(set(headers)))) # noqa: T201
for line in text.split("\n"):
headers.extend(re.findall(r"<([a-z_/.]+)>", line))
return headers


def main() -> None:
with INPUT.open(encoding="utf-8") as fin:
headers = extract_header(fin.read())
print("\n".join(f'"{h}",' for h in sorted(set(headers)))) # noqa: T201


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion scripts/mypy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

set -o errexit

bazel build --config=mypy -- //src/... //examples:all //test/aspect:all //test/apply_fixes:all
bazel build --config=mypy -- //src/... //scripts/... //examples:all //test/aspect:all //test/apply_fixes:all
7 changes: 7 additions & 0 deletions scripts/test/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
load("@rules_python//python:defs.bzl", "py_test")

py_test(
name = "extract_std_headers_test",
srcs = ["extract_std_headers_test.py"],
deps = ["//scripts:extract_std_headers"],
)
27 changes: 27 additions & 0 deletions scripts/test/extract_std_headers_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from __future__ import annotations

import unittest

from scripts.extract_std_headers import extract_header


class TestExtractHeader(unittest.TestCase):
def test_empty_input_yields_empty_list(self) -> None:
self.assertEqual(extract_header(""), [])

def test_extracting_headers(self) -> None:
headers = extract_header(
"""
unrelated_stuff
<foo>
ignore this
<bar.h>
<multiple_header><in_one_line>
""".strip()
)

self.assertEqual(headers, ["foo", "bar.h", "multiple_header", "in_one_line"])


if __name__ == "__main__":
unittest.main()
2 changes: 1 addition & 1 deletion scripts/unit_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

set -o errexit

bazel test -- //src/... //test/aspect:all //third_party/...
bazel test -- //src/... //scripts/... //test/aspect:all //third_party/...
18 changes: 18 additions & 0 deletions src/analyze_includes/std_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"complex",
"complex.h",
"concepts",
"condition_variable",
"coroutine",
"cpio.h",
"csetjmp",
Expand Down Expand Up @@ -68,18 +69,23 @@
"fcntl.h",
"fenv.h",
"filesystem",
"flat_map",
"flat_set",
"float.h",
"fmtmsg.h",
"fnmatch.h",
"format",
"forward_list",
"fstream",
"ftw.h",
"functional",
"future",
"generator",
"glob.h",
"grp.h",
"hazard_pointer",
"iconv.h",
"initializer_list",
"inttypes.h",
"iomanip",
"ios",
Expand All @@ -100,6 +106,7 @@
"math.h",
"mdspan",
"memory",
"memory_resource",
"monetary.h",
"mqueue.h",
"mutex",
Expand All @@ -109,6 +116,7 @@
"netinet/in.h",
"netinet/tcp.h",
"new",
"nl_types.h",
"numbers",
"numeric",
"optional",
Expand All @@ -125,12 +133,15 @@
"regex",
"regex.h",
"sched.h",
"scoped_allocator",
"search.h",
"semaphore",
"semaphore.h",
"set",
"setjmp.h",
"shared_mutex",
"signal.h",
"source_location",
"span",
"spanstream",
"spawn.h",
Expand All @@ -150,9 +161,11 @@
"stdio.h",
"stdlib.h",
"stdnoreturn.h",
"stop_token",
"streambuf",
"string",
"string.h",
"string_view",
"strings.h",
"stropts.h",
"strstream",
Expand All @@ -175,19 +188,24 @@
"sys/utsname.h",
"sys/wait.h",
"syslog.h",
"system_error",
"tar.h",
"termios.h",
"text_encoding",
"tgmath.h",
"thread",
"threads.h",
"time.h",
"trace.h",
"tuple",
"type_traits",
"typeindex",
"typeinfo",
"uchar.h",
"ulimit.h",
"unistd.h",
"unordered_map",
"unordered_set",
"utility",
"utime.h",
"utmpx.h",
Expand Down

0 comments on commit 0ca6260

Please sign in to comment.