forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstd_modulemap_darwin_fix.py
More file actions
46 lines (37 loc) · 1.85 KB
/
Copy pathstd_modulemap_darwin_fix.py
File metadata and controls
46 lines (37 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
import os
import re
import subprocess
import sys
def resolve_cyclic_module_dependencies(content):
for h in ["ctype.h", "stdint.h"]:
content = re.sub(f' header "{h}"', f' textual header "{h}"', content)
return content
def main():
if len(sys.argv) < 3:
raise ValueError("Usage: std_modulemap_darwin_fix.py <sdk_path> <output_path>")
sdk_path = sys.argv[1]
output_path = sys.argv[2]
cpp_modulemap = os.path.join(sdk_path, "usr/include/c++/v1/module.modulemap")
if not os.path.exists(cpp_modulemap):
# Try again if we are running a conda build. conda-forge ships the MacOS SDK stripped of libc++.
# Instead, the standard libraries are shipped as a separate package which must be declared as a build
# dependency and thus ends up in the $BUILD_PREFIX path. For explanation, see
# https://conda-forge.zulipchat.com/#narrow/channel/516932-compilers/topic/Organisation.20of.20libc.2B.2B.20and.20SDKs.20on.20MacOS
if (os.environ.get("CONDA_BUILD", "0") == "1") and (os.environ.get("BUILD_PREFIX", None) is not None):
cpp_modulemap = os.path.join(os.environ["BUILD_PREFIX"], "include/c++/v1/module.modulemap")
if not os.path.exists(cpp_modulemap):
raise FileNotFoundError(f"Cannot find libc++ modulemap at {cpp_modulemap}")
with open(cpp_modulemap, "r") as f:
original_content = f.read()
cleaned_content = resolve_cyclic_module_dependencies(original_content)
os.makedirs(os.path.dirname(output_path), exist_ok=True)
with open(output_path, "w") as f:
f.write("// Auto-generated flat modulemap for Cling\n")
f.write("module std [system] {\n")
f.write("export *\n\n")
f.write("// Entire modulemap wrapped\n")
f.write(cleaned_content)
f.write("\n}\n")
if __name__ == "__main__":
main()