[libcxx-commits] [libcxx] [libc++] Rewrite the IWYU generation (PR #78295)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jan 16 08:58:50 PST 2024


================
@@ -1,116 +1,72 @@
 #!/usr/bin/env python
 
-import os, pathlib, sys
-
-
-def generate(private, public):
-    return f'{{ include: [ "{private}", "private", "<{public}>", "public" ] }}'
-
-
-def panic(file):
-    print(f"========== {__file__} error ==========", file=sys.stderr)
-    print(
-        f"\tFile '{file}' is a top-level detail header without a mapping",
-        file=sys.stderr,
-    )
-    sys.exit(1)
-
-
-def generate_map(include):
-    detail_files = []
-    detail_directories = []
-    c_headers = []
-
-    for i in include.iterdir():
-        if i.is_dir() and i.name.startswith("__"):
-            detail_directories.append(f"{i.name}")
-            continue
-
-        if i.name.startswith("__"):
-            detail_files.append(i.name)
-            continue
-
-        if i.name.endswith(".h"):
-            c_headers.append(i.name)
-
-    result = []
-    temporary_mappings = {"__locale_dir": "locale"}
-    for i in detail_directories:
-        public_header = temporary_mappings.get(i, i.lstrip("_"))
-        result.append(f'{generate(f"@<{i}/.*>", public_header)},')
-
-    for i in detail_files:
-        public = []
-        if i == "__assert":
-            continue
-        elif i == "__availability":
-            continue
-        elif i == "__bit_reference":
-            continue
-        elif i == "__bits":
-            public = ["bits"]
-        elif i == "__config_site.in":
-            continue
-        elif i == "__config":
-            continue
-        elif i == "__errc":
-            continue
-        elif i == "__hash_table":
-            public = ["unordered_map", "unordered_set"]
-        elif i == "__locale":
-            public = ["locale"]
-        elif i == "__mbstate_t.h":
-            continue
-        elif i == "__mutex_base":
-            continue
-        elif i == "__node_handle":
-            public = ["map", "set", "unordered_map", "unordered_set"]
-        elif i == "__pstl_algorithm":
-            continue
-        elif i == "__pstl_config_site.in":
-            continue
-        elif i == "__pstl_execution":
-            continue
-        elif i == "__pstl_memory":
-            continue
-        elif i == "__pstl_numeric":
-            continue
-        elif i == "__split_buffer":
-            public = ["deque", "vector"]
-        elif i == "__std_clang_module":
-            continue
-        elif i == "__std_mbstate_t.h":
-            continue
-        elif i == "__threading_support":
-            public = ["atomic", "mutex", "semaphore", "thread"]
-        elif i == "__tree":
-            public = ["map", "set"]
-        elif i == "__undef_macros":
-            continue
-        elif i == "__verbose_abort":
-            continue
-        else:
-            panic(i)
-
-        for p in public:
-            result.append(f'{generate(f"<{i}>", p)},')
-
-    result.sort()
-    return result
-
+import libcxx.header_information
+import os
+import pathlib
+import re
+import typing
+
+def IWYU_mapping(header: str) -> typing.Optional[typing.List[str]]:
+    ignore = [
+        "__debug_utils/.+",
+        "__fwd/get[.]h",
+        "__support/.+",
+    ]
+    if any(re.match(pattern, header) for pattern in ignore):
+        return None
+    elif header == "__bits":
+        return ["bits"]
+    elif header in ("__bit_reference", "__fwd/bit_reference.h"):
+        return ["bitset", "vector"]
+    elif header == "__hash_table":
+        return ["unordered_map", "unordered_set"]
+    elif header == "__locale":
+        return ["locale"]
+    elif re.match("__locale_dir/.+", header):
+        return ["locale"]
+    elif re.match("__math/.+", header):
+        return ["cmath"]
+    elif header == "__node_handle":
+        return ["map", "set", "unordered_map", "unordered_set"]
+    elif header == "__split_buffer":
+        return ["deque", "vector"]
+    elif header == "__threading_support":
+        return ["atomic", "mutex", "semaphore", "thread"]
+    elif header == "__tree":
+        return ["map", "set"]
+    elif header == "__fwd/hash.h":
+        return ["functional"]
+    elif header == "__fwd/pair.h":
+        return ["utility"]
+    elif header == "__fwd/subrange.h":
+        return ["ranges"]
----------------
philnik777 wrote:

These headers should really just be renamed to their corresponding top level headers.

https://github.com/llvm/llvm-project/pull/78295


More information about the libcxx-commits mailing list