[NFC][Coroutines] Use structured binding with llvm::enumerate in CoroSplit (#116879)
[llvm-project.git] / libcxx / utils / generate_libcxx_cppm_in.py
blob39076a61b55b845e7c4d14f41f96ffffaa2c3349
1 # ===----------------------------------------------------------------------===##
3 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 # See https://llvm.org/LICENSE.txt for license information.
5 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 # ===----------------------------------------------------------------------===##
9 import os.path
10 import sys
12 from libcxx.header_information import module_c_headers, module_headers, header_restrictions, headers_not_available, libcxx_root
15 def write_file(module):
16 with open(libcxx_root / "modules" / f"{module}.cppm.in", "w") as module_cpp_in:
17 module_cpp_in.write(
18 """\
19 // -*- C++ -*-
20 //===----------------------------------------------------------------------===//
22 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
23 // See https://llvm.org/LICENSE.txt for license information.
24 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
26 //===----------------------------------------------------------------------===//
28 // WARNING, this entire header is generated by
29 // utils/generate_libcxx_cppm_in.py
30 // DO NOT MODIFY!
32 module;
34 #include <__config>
36 // The headers of Table 24: C++ library headers [tab:headers.cpp]
37 // and the headers of Table 25: C++ headers for C library facilities [tab:headers.cpp.c]
38 """
40 for header in sorted(module_headers if module == "std" else module_c_headers):
41 if header in header_restrictions:
42 module_cpp_in.write(
43 f"""\
44 #if {header_restrictions[header]}
45 # include <{header}>
46 #endif
47 """
49 else:
50 module_cpp_in.write(f"#include <{header}>\n")
52 module_cpp_in.write(
53 """
54 // *** Headers not yet available ***
56 // This validation is mainly to catch when a new header is added but adding the
57 // corresponding .inc file is forgotten. However, the check based on __has_include
58 // alone doesn't work on Windows because the Windows SDK is on the include path,
59 // and that means the MSVC STL headers can be found as well, tricking __has_include
60 // into thinking that libc++ provides the header.
62 #ifndef _WIN32
63 """
65 for header in sorted(headers_not_available):
66 module_cpp_in.write(
67 f"""\
68 # if __has_include(<{header}>)
69 # error "please update the header information for <{header}> in headers_not_available in utils/libcxx/header_information.py"
70 # endif // __has_include(<{header}>)
71 """
74 module_cpp_in.write(
75 f"""#endif // _WIN32
77 export module {module};
78 {'export import std;' if module == 'std.compat' else ''}
80 {'@LIBCXX_MODULE_STD_INCLUDE_SOURCES@' if module == 'std' else ''}
81 {'@LIBCXX_MODULE_STD_COMPAT_INCLUDE_SOURCES@' if module == 'std.compat' else ''}"""
85 if __name__ == "__main__":
86 if len(sys.argv) != 2 or (sys.argv[1] != "std" and sys.argv[1] != "std.compat"):
87 sys.stderr.write(
88 f"""\
89 Usage:
90 {os.path.basename(__file__)} (std|std.compat)
91 """
93 sys.exit(1)
95 write_file(sys.argv[1])