-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
155 lines (128 loc) · 4.96 KB
/
build.py
File metadata and controls
155 lines (128 loc) · 4.96 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import argparse
import os
import subprocess
import sys
import shutil
import stat
import time
from datetime import datetime, timezone
dry_run = False
# Self-Script Information
script_name = os.path.basename(sys.argv[0])
script_dir_relative = os.path.dirname(sys.argv[0])
script_dir_absolute = os.path.realpath(script_dir_relative)
def vmec_log(*vargs):
# Convert to nanoseconds
current_time = int(time.time() * 1e9)
display_time = str( current_time )
print( f"[{display_time}][VMEC Build Py]", *vargs)
def vmec_error(*vargs):
print("[VMEC Build Py][ERROR]", *vargs)
def vmec_debug(*vargs):
print("[DEBUG]", *vargs)
# Always start from project root location
os.chdir(script_dir_absolute)
os.system("") # enables ansi escape characters in terminal
vmec_log(f"Changing directory to '{script_dir_absolute}'")
vmec_log(f"Running script {script_name}")
def execute( command ):
global dry_run
if dry_run:
vmec_log( f"(dry run) executing command: \"{command}\"" )
return 0
else:
vmec_log( f"executing command: \"{command}\"" )
completed = subprocess.run( command.split() )
if completed.returncode != 0:
vmec_error( "Failed to execute command" )
return completed.returncode
def execute_list( *command_list ):
global dry_run
commands = [*command_list]
if dry_run:
vmec_log( f"(dry run) executing command: \"{commands}\"" )
return 0
else:
vmec_log( f"executing command: '{commands}'" )
completed = subprocess.run( commands )
if completed.returncode != 0:
vmec_error( "Failed to execute command" )
return completed.returncode
# Hack to fix rmtree failing on read only objects
def rmtree_remove_readonly( func, path, _ ):
os.chmod( path, stat.S_IWRITE )
func( path )
options = argparse.ArgumentParser()
options.add_argument( "--build-dir", action="store" )
options.add_argument( "--build-type", action="store" )
options.add_argument( "--build-label", action="store" )
options.add_argument( "--alt-build", action="store_true",
help="Move build directory to uniquely named transient/build directories" )
options.add_argument( "--dry-run" )
options.add_argument( "--clean", action="store_true")
options.add_argument( "--debug", action="store_true" )
# options.add_argument( "--ninja", action="store_true" )
# options.add_argument( "--nmake", action="store_true" )
# options.add_argument( "--no-submodule-sync", action="store_true" )
options.add_argument( "--no-build", action="store_true" )
# options.add_argument( "--no-configure", action="store_true" )
options.add_argument( "--configure", action="store_true" )
options.add_argument( "--test-no-output", action="store_true" )
# options.add_argument( "--no-package", action="store_true" )
# options.add_argument( "--package-only", action="store_true" )
args = options.parse_args()
vmec_log( "Command Line Arguments: " )
for x_name in vars( args ).items():
vmec_log( f" {x_name[0]} : {x_name[1]}" )
dry_run = args.dry_run
build_label = "shipping"
root_dir = script_dir_absolute
build_dir = f"{root_dir}/build"
install_dir = f"{root_dir}/../tachyon_artifacts/package/{build_label}"
dev_install_dir = f"{root_dir}/../tachyonc_artifacts/dev_package/{build_label}"
extra_install_dir = f"{root_dir}/../tachyonO_artifacts/dev_package/{build_label}_openusd"
extra_build_dir = f"{build_dir}/extra/"
if args.alt_build:
build_dir = f"{root_dir}/transient/build/{build_label}"
# Canonicalize all paths
root_dir = os.path.realpath( root_dir )
build_dir = os.path.realpath( build_dir )
install_dir = os.path.realpath( install_dir )
extra_install_dir = os.path.realpath( extra_install_dir )
extra_build_dir = os.path.realpath( extra_build_dir )
if args.clean:
vmec_log( f"Cleaning build directory {build_dir}" )
try:
if os.path.isdir( build_dir ):
shutil.rmtree( build_dir, onerror = rmtree_remove_readonly )
else:
vmec_log( "Build directory already empty." )
except Exception as err:
vmec_log(f"""Exception occured whilst removing build directory.
Type: {type(err).__name__}
Message: {err}
You should check if you have any files or executables in tbhe directy
'{build_dir}' still open and close them Bailing script.""" )
sys.exit( 1 )
# Main Program
build_dir_empty = not os.path.isdir( build_dir )
configure_fail = 0
build_fail = 0
test_fail = 0
did_configure = False
if args.clean or build_dir_empty:
configure_fail = execute( "meson setup build" )
did_configure = True
if args.configure:
configure_fail = execute( "meson setup build --reconfigure" )
did_configure = True
# Don't try to fail if we didn't do a manual configuration
if did_configure and configure_fail:
sys.exit( 1 )
build_fail = execute( "meson compile -C build" )
if build_fail:
sys.exit( 1)
if args.test_no_output:
test_fail = execute( "meson test -C build" )
else:
test_fail = execute( "meson test -C build --verbose" )