-
Notifications
You must be signed in to change notification settings - Fork 328
Expand file tree
/
Copy pathall_builds.py
More file actions
99 lines (72 loc) · 2.82 KB
/
all_builds.py
File metadata and controls
99 lines (72 loc) · 2.82 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
#!/usr/bin/env python3
import subprocess
import shutil
import os
import sys
# -------------------------------------------------------------------
# CONFIGURATION - Easily add new build directories and options.
# -------------------------------------------------------------------
BUILD_CONFIGS = {
"build_python": ["cmake", "-DBASISU_SSE=1 -DBASISU_BUILD_PYTHON=ON", ".."],
"build_wasm_mt": ["cmake", "-DCMAKE_TOOLCHAIN_FILE=$WASI_SDK_PATH/share/cmake/wasi-sdk-pthread.cmake -DCMAKE_BUILD_TYPE=Release -DBASISU_WASM_THREADING=ON", ".."],
"build_wasm_st": ["cmake", "-DCMAKE_TOOLCHAIN_FILE=$WASI_SDK_PATH/share/cmake/wasi-sdk.cmake -DCMAKE_BUILD_TYPE=Release -DBASISU_WASM_THREADING=OFF", ".."],
"build_native": ["cmake", "-DBASISU_SSE=1", ".."]
}
# -------------------------------------------------------------------
def log(msg):
print(f"[INFO] {msg}")
def run(cmd, work_dir):
"""
Execute a shell command after changing the working directory.
Always restore the original directory, even on exceptions.
"""
if isinstance(cmd, list):
cmd = " ".join(cmd)
original_dir = os.getcwd()
log(f"Preparing to run command:\n CMD: {cmd}\n IN: {work_dir}")
print(f"[INFO] Current working directory before change: {original_dir}")
try:
os.chdir(work_dir)
print(f"[INFO] Changed working directory to: {os.getcwd()}")
log(f"Running command: {cmd}")
subprocess.check_call(cmd, shell=True)
except subprocess.CalledProcessError:
log(f"ERROR: Command failed: {cmd}")
raise
finally:
# Always restore the directory
os.chdir(original_dir)
print(f"[INFO] Restored working directory to: {original_dir}")
def clean_build_dirs():
log("Cleaning all build directories...")
for build_dir in BUILD_CONFIGS:
if os.path.isdir(build_dir):
log(f"Deleting directory: {build_dir}")
shutil.rmtree(build_dir)
else:
log(f"Directory not found, skipping: {build_dir}")
log("Clean complete.\n")
def create_dir(path):
if not os.path.isdir(path):
log(f"Creating directory: {path}")
os.makedirs(path)
else:
log(f"Directory already exists: {path}")
def perform_builds():
for build_dir, cmake_cmd in BUILD_CONFIGS.items():
log(f"Starting build in: {build_dir}")
create_dir(build_dir)
# Run CMake inside the directory
log(f"Executing CMake for {build_dir}")
run(cmake_cmd, work_dir=build_dir)
# Run Make inside the directory
log(f"Running make for {build_dir}")
run("make", work_dir=build_dir)
log(f"Finished build for {build_dir}\n")
def main():
if "--clean" in sys.argv:
clean_build_dirs()
perform_builds()
log("SUCCESS\n")
if __name__ == "__main__":
main()