-
Notifications
You must be signed in to change notification settings - Fork 6
/
build-all.py
executable file
·184 lines (154 loc) · 5 KB
/
build-all.py
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env python3
"""Bootstrap the virtual environment and run a full build"""
import argparse
from pathlib import Path
from platform import system
import subprocess
import sys
# Paths to the vcvars*.bat files, used to set up the dev tools environment
# variables on Windows
VCVARS_MSBUILD = Path(
'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\'
'BuildTools\\VC\\Auxiliary\\Build\\vcvars32.bat')
VCVARS_VS = Path(
'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\'
'Community\\VC\\Auxiliary\\Build\\vcvars32.bat')
GENERATED_BUILD_BATCH = 'build-all.bat' # NOTE: Synch with .gitignore
VENV = Path('.venv') # matches .envrc
verbose = False # set via command-line switch
WHOAMI = Path(__file__).name
#
# Main stages
#
def main():
print(BANNER)
print()
if sys.prefix == sys.base_prefix:
stage_1_create_venv()
else:
stage_2_bootstrap_venv()
stage_3_build_everything()
print()
print('Remember to deactivate the virtual environment when finished with:')
print(' deactivate')
def stage_1_create_venv():
print('Stage 1 of 3: Creating and entering the virtual Python environment')
print()
if not VENV.is_dir():
print('Creating the environment in:', VENV)
if system() == 'Darwin':
python = 'python3'
elif system() == 'Windows':
python = 'python'
else:
raise NotImplementedError
try_to_run([python, '-m', 'venv', VENV])
else:
print('The environment already exists.')
print()
print('Please enter the virtual environment and run ' + WHOAMI + ' again:')
if system() == 'Darwin':
print(' source ' + VENV + '/bin/activate && ./' + WHOAMI)
elif system() == 'Windows':
print(' ' + str(VENV) + '\\Scripts\\activate.bat && python ' + WHOAMI)
else:
raise NotImplementedError
def stage_2_bootstrap_venv():
try:
import buildlib # noqa 401
import ldllib # noqa 401
except ImportError:
print('Stage 2 of 3: Installing required packages and shared code')
print()
install_deps_and_shared_code()
def install_deps_and_shared_code():
print(
'This will call pip to update itself, then install the required '
'packages and code shared between AudioQuake and Level Description '
'Language.')
print()
print(
'Normally this produces a lot of output; it will be kept quiet unless '
"there is an error, or you've used the -v/--verbose switch.")
print()
try:
input('Press Enter to continue, or interrupt to abort. ')
except KeyboardInterrupt:
print()
sys.exit(0)
print('Updating pip')
try_to_run(['pip3', 'install', '--upgrade', 'pip'])
print('Installing required packages (may take some time)')
try_to_run(['pip3', 'install', '--requirement', 'requirements.txt'])
print('Installing shared code as packages')
try_to_run(['pip3', 'install', '--editable', Path('lib') / 'buildlib'])
try_to_run(['pip3', 'install', '--editable', Path('lib') / 'ldllib'])
print()
def stage_3_build_everything():
print('Stage 3 of 3: Running a build')
print()
print('Now to build everything:')
print('a. compile the engine, gamecod and map tools')
print('b. assemble an AQ & LDL release')
print('Any building work done so far will be re-used.')
print()
try:
input('Run these build steps? (Enter to run; interrupt to abort) ')
print()
if system() == 'Darwin':
build_everything_core_mac()
elif system() == 'Windows':
build_everything_core_windows()
else:
raise NotImplementedError
except KeyboardInterrupt:
print()
def build_everything_core_mac():
try_to_run(['python', 'build-giants.py'], force_verbose=True)
print()
try_to_run(
['python', Path('audioquake') / 'build-audioquake.py'],
force_verbose=True)
def build_everything_core_windows():
with open(GENERATED_BUILD_BATCH, 'w') as batch:
batch.write('@echo off\r\n')
if VCVARS_MSBUILD.is_file():
print('Found the Microsoft build tools environment batch file')
batch.write('call "' + str(VCVARS_MSBUILD) + '"')
elif VCVARS_VS.is_file():
print('Found Visual Studio environment batch file')
batch.write('call "' + str(VCVARS_VS) + '"')
else:
raise Exception(
"Can't find the MS Build tools nor "
'the Visual Studio build tools.')
batch.write(
' && python build-giants.py'
' && echo. && python audioquake\\build-audioquake.py\r\n')
try_to_run([GENERATED_BUILD_BATCH], force_verbose=True)
#
# Support
#
def try_to_run(args, force_verbose=False):
sink = None if verbose or force_verbose else subprocess.DEVNULL
try:
subprocess.check_call(args, stdout=sink, stderr=sink)
except subprocess.CalledProcessError:
if verbose or force_verbose:
sys.exit(42)
else:
print('Error encountered; trying again...')
try:
subprocess.check_call(args)
except subprocess.CalledProcessError:
sys.exit(42)
if __name__ == '__main__':
BANNER = 'Build AudioQuake & Level Descripton Languge'
parser = argparse.ArgumentParser(description=BANNER)
parser.add_argument(
'-v', '--verbose', action='store_true',
help='always show full output when trying to run commands')
args = parser.parse_args()
if args.verbose:
verbose = True
main()