104 lines · python
1# ===----------------------------------------------------------------------===##2#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-exception6#7# ===----------------------------------------------------------------------===##8 9import os.path10import sys11 12from libcxx.header_information import (13 module_c_headers,14 module_headers,15 header_restrictions,16 headers_not_available,17 libcxx_root,18)19 20 21def write_file(module):22 with open(23 libcxx_root / "modules" / f"{module}.cppm.in", "w", encoding="utf-8"24 ) as module_cpp_in:25 module_cpp_in.write(26 """\27// -*- C++ -*-28//===----------------------------------------------------------------------===//29//30// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.31// See https://llvm.org/LICENSE.txt for license information.32// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception33//34//===----------------------------------------------------------------------===//35 36// WARNING, this entire header is generated by37// utils/generate_libcxx_cppm_in.py38// DO NOT MODIFY!39 40module;41 42#include <__config>43 44// The headers of Table 24: C++ library headers [tab:headers.cpp]45// and the headers of Table 25: C++ headers for C library facilities [tab:headers.cpp.c]46"""47 )48 for header in sorted(module_headers if module == "std" else module_c_headers):49 if header in header_restrictions:50 module_cpp_in.write(51 f"""\52#if {header_restrictions[header]}53# include <{header}>54#endif55"""56 )57 else:58 module_cpp_in.write(f"#include <{header}>\n")59 60 module_cpp_in.write(61 """62// *** Headers not yet available ***63//64// This validation is mainly to catch when a new header is added but adding the65// corresponding .inc file is forgotten. However, the check based on __has_include66// alone doesn't work on Windows because the Windows SDK is on the include path,67// and that means the MSVC STL headers can be found as well, tricking __has_include68// into thinking that libc++ provides the header.69//70#ifndef _WIN3271"""72 )73 for header in sorted(headers_not_available):74 module_cpp_in.write(75 f"""\76# if __has_include(<{header}>)77# error "please update the header information for <{header}> in headers_not_available in utils/libcxx/header_information.py"78# endif // __has_include(<{header}>)79"""80 )81 82 module_cpp_in.write(83 f"""#endif // _WIN3284 85export module {module};86{'export import std;' if module == 'std.compat' else ''}87 88{'@LIBCXX_MODULE_STD_INCLUDE_SOURCES@' if module == 'std' else ''}89{'@LIBCXX_MODULE_STD_COMPAT_INCLUDE_SOURCES@' if module == 'std.compat' else ''}"""90 )91 92 93if __name__ == "__main__":94 if len(sys.argv) != 2 or (sys.argv[1] != "std" and sys.argv[1] != "std.compat"):95 sys.stderr.write(96 f"""\97Usage:98{os.path.basename(__file__)} (std|std.compat)99"""100 )101 sys.exit(1)102 103 write_file(sys.argv[1])104