Create a script to automatically update libcxx_headers.gni
We frequently get breakages after autorolls of libc++ from missing headers.
Once this script is landed, we will then modify the autoroller to run
this script.
Bug: 432582032
Change-Id: I6a6a6964a2791cbaa1253c8b091d7c0dc3ad69fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6768392
Commit-Queue: Matt Stark <msta@google.com>
Reviewed-by: Takuto Ikuta <tikuta@chromium.org>
Reviewed-by: Junji Watanabe <jwata@google.com>
Cr-Commit-Position: refs/heads/main@{#1488652}
NOKEYCHECK=True
GitOrigin-RevId: 552967c8f87e862d7d6e5ce52b911dfc2246b03d
diff --git a/third_party/libc++/generate_libcxx_headers.py b/third_party/libc++/generate_libcxx_headers.py
new file mode 100755
index 0000000..82fff30
--- /dev/null
+++ b/third_party/libc++/generate_libcxx_headers.py
@@ -0,0 +1,43 @@
+#!/usr/bin/env python
+
+# Copyright 2025 The Chromium Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import pathlib
+
+_CURRENT_DIR = pathlib.Path(__file__).parent
+
+
+def _get_headers(include_dir: pathlib.Path) -> list[str]:
+ headers = []
+ for (dirpath, _, filenames) in include_dir.walk():
+ dirpath = dirpath.relative_to(include_dir)
+ for f in filenames:
+ path = dirpath / f
+ if f != 'CMakeLists.txt' and '__cxx03' not in path.parts:
+ headers.append(str(path))
+ headers.sort()
+ return headers
+
+
+def _write_headers(path: pathlib.Path, headers: list[str]):
+ lines = [f' "//third_party/libc++/src/include/{hdr}",' for hdr in headers]
+ path.write_text(f"""# Copyright 2025 The Chromium Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# DO NOT EDIT. This file is generated.
+# To regenerate, run buildtools/third_party/libc++/generate_libcxx_headers.py
+
+libcxx_headers = [
+{'\n'.join(lines)}
+]
+""")
+
+
+if __name__ == '__main__':
+ _write_headers(
+ _CURRENT_DIR / 'libcxx_headers.gni',
+ _get_headers(_CURRENT_DIR / '../../../third_party/libc++/src/include'),
+ )
diff --git a/third_party/libc++/libcxx_headers.gni b/third_party/libc++/libcxx_headers.gni
index 514924c..925ac24 100644
--- a/third_party/libc++/libcxx_headers.gni
+++ b/third_party/libc++/libcxx_headers.gni
@@ -2,12 +2,10 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-# Generate the list via
-# $ find third_party/libc++/src/include/ -type f | fgrep -v "cxx03" | sed -E 's:(.*):" //\1",:g' | LANG=C sort
+# DO NOT EDIT. This file is generated.
+# To regenerate, run buildtools/third_party/libc++/generate_libcxx_headers.py
libcxx_headers = [
- # go/keep-sorted start
- "//third_party/libc++/src/include/CMakeLists.txt",
"//third_party/libc++/src/include/__algorithm/adjacent_find.h",
"//third_party/libc++/src/include/__algorithm/all_of.h",
"//third_party/libc++/src/include/__algorithm/any_of.h",
@@ -1099,6 +1097,4 @@
"//third_party/libc++/src/include/version",
"//third_party/libc++/src/include/wchar.h",
"//third_party/libc++/src/include/wctype.h",
-
- # go/keep-sorted end
]