-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
executable file
·111 lines (94 loc) · 4.14 KB
/
Copy pathbuild.py
File metadata and controls
executable file
·111 lines (94 loc) · 4.14 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env python3
import os
import sys
import subprocess
from pathlib import Path
def main():
if len(sys.argv) < 2:
print(f"Usage: {sys.argv[0]} <pxr_install_dir>", file=sys.stderr)
sys.exit(1)
pxr_dir = sys.argv[1]
conda_prefix = os.environ.get("CONDA_PREFIX", "")
build_dir = Path("build")
build_dir.mkdir(exist_ok=True)
cmake_args = [
"cmake", "..",
"-G", "Ninja",
"-DCMAKE_BUILD_TYPE=Debug",
f"-DCMAKE_PREFIX_PATH={conda_prefix};{pxr_dir}",
f"-DCPLUS_INCLUDE_PATH={conda_prefix}/include/",
f"-DUSD_INSTALL_DIR={pxr_dir}",
]
# conda-forge clang on macOS uses a target-triple prefix, which Qt's cmake
# config mistakes for cross-compilation. Tell Qt the host Qt == target Qt.
if sys.platform == "darwin" and conda_prefix:
cmake_args += [f"-DQT_HOST_PATH={conda_prefix}"]
subprocess.run(cmake_args, cwd=build_dir, check=True)
subprocess.run(["cmake", "--build", "."], cwd=build_dir, check=True)
# Generate env.py — cross-platform environment setup script
env_py = build_dir / "usdsim_env.py"
conda_lib = str(Path(conda_prefix) / "lib") if conda_prefix else ""
pxr_lib = str(Path(pxr_dir) / "lib")
pxr_python = str(Path(pxr_dir) / "lib" / "python")
build_lib = str(build_dir.resolve() / "lib")
conda_python = str(Path(conda_prefix) / "bin" / "python3") if conda_prefix else ""
qt_plugin_path = str(Path(conda_prefix) / "lib" / "qt6" / "plugins") if conda_prefix else ""
qml_import_path = str(Path(conda_prefix) / "lib" / "qt6" / "qml") if conda_prefix else ""
env_py.write_text('''\
#!/usr/bin/env python3
"""Auto-generated by build.py.
Usage:
1. As a launcher: python build/env.py your_script.py [args...]
2. As an import: import env (with build/ on sys.path or PYTHONPATH)
On Linux/macOS, the dynamic library path must be set before the process loads
shared libs, so this module re-execs the current process with the correct env.
"""
import os, sys
_PATHS = ''' + repr([build_lib, pxr_python]) + '''
_LD_PATHS = ''' + repr([p for p in [conda_lib, pxr_lib, build_lib] if p]) + '''
_CONDA_PYTHON = ''' + repr(conda_python) + '''
_QT_PLUGIN_PATH = ''' + repr(qt_plugin_path) + '''
_QML_IMPORT_PATH = ''' + repr(qml_import_path) + '''
# 0. Set Qt environment variables if needed
if _QT_PLUGIN_PATH and os.path.isdir(_QT_PLUGIN_PATH):
os.environ.setdefault("QT_PLUGIN_PATH", _QT_PLUGIN_PATH)
if _QML_IMPORT_PATH and os.path.isdir(_QML_IMPORT_PATH):
os.environ.setdefault("QML2_IMPORT_PATH", _QML_IMPORT_PATH)
_FONTCONFIG_PATH = os.path.join(os.path.dirname(_QT_PLUGIN_PATH), '..', 'etc', 'fonts') if _QT_PLUGIN_PATH else ''
if _FONTCONFIG_PATH and os.path.isdir(_FONTCONFIG_PATH):
os.environ.setdefault("FONTCONFIG_PATH", _FONTCONFIG_PATH)
# 0b. Re-exec with the build-time Python if running a different interpreter
if _CONDA_PYTHON and os.path.exists(_CONDA_PYTHON) and os.path.realpath(sys.executable) != os.path.realpath(_CONDA_PYTHON):
os.execv(_CONDA_PYTHON, [_CONDA_PYTHON] + sys.argv)
# 1. Fix sys.path
for p in reversed(_PATHS):
if p not in sys.path:
sys.path.insert(0, p)
# 2. Fix dynamic library path — re-exec if not already set
if sys.platform == "win32":
for p in _LD_PATHS:
os.add_dll_directory(p)
else:
_lib_var = "DYLD_LIBRARY_PATH" if sys.platform == "darwin" else "LD_LIBRARY_PATH"
_ld = os.environ.get(_lib_var, "")
_missing = [p for p in _LD_PATHS if p not in _ld]
if _missing:
os.environ[_lib_var] = os.pathsep.join(
_LD_PATHS + ([_ld] if _ld else [])
)
os.execv(sys.executable, [sys.executable] + sys.argv)
# 3. If run as a script, exec the target
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python build/env.py <script.py> [args...]")
sys.exit(1)
script = sys.argv[1]
sys.argv = sys.argv[1:] # shift so script sees correct argv
with open(script) as f:
code = compile(f.read(), script, "exec")
exec(code, {"__name__": "__main__", "__file__": os.path.abspath(script)})
''')
env_py.chmod(0o755)
print(f"Generated {env_py}")
if __name__ == "__main__":
main()