-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_all.py
344 lines (286 loc) · 10.9 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
#!/usr/bin/env python
#-*- coding:utf-8 -#-
import os, sys, re, atexit, getopt, subprocess, multiprocessing
from functools import *
from blibs import *
from blibs.copy import *
from blibs.env import *
from blibs.util import *
from blibs.project import *
def guarded_rmtree(path):
if os.path.isdir(path):
shutil.rmtree(path)
log_f = None
def close_log():
global log_f
if not log_f is None:
log_f.close()
def make_bjam(prj):
assert isinstance(prj, project)
old_dir = os.curdir
src = prj.boost_root()
os.chdir(src)
bjam_file_name = executable_file_name("bjam", systems.current())
if os.path.exists(bjam_file_name):
report_info('Bjam is existed.')
os.chdir(old_dir)
return True
customized_toolset_dir = prj.customized_toolset_dir()
env = os.environ.copy()
envvar_separator = None
bootstrap_script = None
if systems.current() == systems.win32:
envvar_separator = ';'
bootstrap_script = "bootstrap.bat"
else:
envvar_separator = ':'
bootstrap_script = "./bootstrap.sh"
if customized_toolset_dir:
env['PATH'] = "%s%s%s" % (env['PATH'], envvar_separator, customized_toolset_dir)
try:
subprocess.call(bootstrap_script, env=env)
except:
os.chdir(old_dir)
report_error("Unknown error occurred when building bjam.")
if not os.path.exists(bjam_file_name):
os.chdir(old_dir)
report_error("Bjam wasn't built.")
os.chdir(old_dir)
return True
def clean_boost(proj):
src = proj.boost_root()
stage = proj.boost_stage()
os.chdir(src)
if systems.current() == systems.win32:
boost_cmd = "bjam --clean"
print( 'Executing: %s' % boost_cmd )
os.system(boost_cmd)
else:
return False
os.chdir(proj.source_root())
guarded_rmtree(proj.boost_stage())
def make_boost(proj):
src = proj.boost_root()
stage = proj.boost_stage()
#Get boost build command
# Add configs
libs = ["atomic", "chrono", "thread", "system", "filesystem", "date_time", "test", "wave", "program_options",
"serialization", "locale"]
address_model = 'address-model=%d' % proj.arch().bits()
options = ["--build-dir=./", "link=shared", "runtime-link=shared", "threading=multi", "stage"]
toolset = proj.toolset()
defs = []
cxxflags = []
if toolset.short_compiler_name() == 'vc':
defs = ["_CRT_SECURE_NO_DEPRECATE", "_SCL_SECURE_NO_DEPRECATE"]
cxxflags = ["-wd4819", "-wd4910"]
#bjam toolset stagedir address-model defs cxxflags libs options
bjam_executable = None
if systems.current() == systems.win32:
bjam_executable = 'bjam'
elif systems.current() == systems.linux:
bjam_executable = './bjam'
else:
report_error("Unsupported OS.")
#configs to cmd
libs_cmd = ["--with-%s" % lib for lib in libs]
defs_cmd = []
if len(defs) > 0:
defs_cmd = ["define=%s" % dfn for dfn in defs]
cxxflags_cmd = []
if len(cxxflags) > 0:
cxxflags_cmd = ["cxxflags=%s" % flag for flag in cxxflags]
toolset_cmd = "--toolset=%s" % toolset.boost_name()
stage_cmd = '--stagedir=%s' % stage
boost_cmd = [bjam_executable, toolset_cmd, stage_cmd, address_model] \
+ defs_cmd + cxxflags_cmd + libs_cmd + options + proj.boost_configs()
report_info( 'Executing: %s' % boost_cmd )
env = os.environ
if not proj.customized_toolset_dir() is None:
env = add_binpath(os.environ, [proj.customized_toolset_dir()])
os.chdir(src)
if subprocess.call(boost_cmd, env=env, stdout = sys.stdout) != 0:
report_error("Boost build failed.")
os.chdir(proj.source_root())
report_info("Boost build done.")
return True
def clean_llvm(proj):
guarded_rmtree(proj.llvm_build())
guarded_rmtree(proj.llvm_install())
def config_and_make_cmake_project(project_name, additional_params, source_dir, build_dir, install_dir, proj):
if additional_params is None:
conf_params = dict()
else:
conf_params = additional_params.copy()
if not proj.toolset().short_compiler_name() == "vc":
conf_params["CMAKE_BUILD_TYPE"] = ("STRING", proj.config_name())
conf_params["CMAKE_INFO_ARCH_NAME"] = ("STRING", str(proj.arch()))
if not install_dir is None:
conf_params["CMAKE_INSTALL_PREFIX"] = ("PATH", install_dir)
params_cmd = reduce(lambda cmd, lib: cmd + lib, [' -D %s:%s="%s"' % (k, v[0], v[1]) for (k, v) in conf_params.items()])
report_info("Configuring %s ..." % project_name)
if not os.path.exists(build_dir):
os.makedirs(build_dir)
conf_cmd = batch_command(build_dir)
if proj.customized_toolset_dir():
if systems.current() == systems.win32:
conf_cmd.add_native_command('@set PATH=%s;%%PATH%%' % proj.customized_toolset_dir())
elif systems.current() == systems.linux:
conf_cmd.add_native_command('PATH=%s:$PATH' % proj.customized_toolset_dir())
else:
report_error("Unsupported OS.")
conf_cmd.add_execmd_with_error_exit('"%s" -G "%s" %s %s' % (proj.cmake_exe(), proj.generator(), params_cmd, source_dir))
if conf_cmd.execute() != 0:
report_error("%s configure failed." % project_name)
report_info("Making %s on %s ..." % (project_name, proj.config_name()))
if proj.toolset().short_compiler_name() == "vc":
make_cmd = batch_command(build_dir)
make_cmd.add_native_command('@call "%s"' % proj.env_setup_commands())
make_cmd.add_native_command('@set VisualStudioVersion=%s' % proj.toolset().vs_version_string())
make_cmd.add_execmd_with_error_exit('%s ALL_BUILD.%s /m /v:m /p:Configuration=%s'
% (proj.maker_name(), proj.project_file_ext(), proj.config_name()))
if not install_dir is None:
make_cmd.add_execmd_with_error_exit(
'%s INSTALL.%s /m /v:m /p:Configuration=%s' % (proj.maker_name(), proj.project_file_ext(), proj.config_name()))
if make_cmd.execute() != 0:
report_error("%s make failed." % project_name)
elif proj.toolset().short_compiler_name() in ["mgw", "gcc"]:
make_cmd = batch_command(build_dir)
make_cmd.add_execmd_with_error_exit('%s' % proj.env_setup_commands())
make_cmd.add_execmd_with_error_exit('%s -j%d' % (proj.maker_name(), multiprocessing.cpu_count()))
if not install_dir is None:
make_cmd.add_execmd_with_error_exit('%s install' % proj.maker_name())
if make_cmd.execute() != 0:
report_error("%s make failed." % project_name)
else:
report_error("Unsupported toolset or OS.")
def config_and_make_llvm(proj):
# Add definitions here
defs = dict()
defs["PYTHON_EXECUTABLE"] = ("PATH", sys.executable)
defs["LLVM_BOOST_DIR"] = ("PATH", proj.boost_root())
defs["LLVM_BOOST_STDINT"] = ("BOOL", "TRUE")
config_and_make_cmake_project('LLVM', defs, proj.llvm_root(), proj.llvm_build(), proj.llvm_install(), proj)
def config_and_make_freeimage(proj):
config_and_make_cmake_project('FreeImage', None, proj.freeimage_root(), proj.freeimage_build(), proj.freeimage_install(), proj)
def config_and_make_freetype(proj):
config_and_make_cmake_project('FreeType', None, proj.freetype_root(), proj.freetype_build(), proj.freetype_install(), proj)
def clean_salvia(proj):
guarded_rmtree(proj.salvia_build())
guarded_rmtree(proj.salvia_lib())
guarded_rmtree(proj.salvia_bin())
def config_and_make_salvia(proj):
defs = dict()
defs["SALVIA_BOOST_DIR"] = ("PATH", proj.boost_root())
defs["PYTHON_EXECUTABLE"] = ("PATH", sys.executable)
if proj.toolset().short_compiler_name() == 'vc':
defs["SALVIA_BOOST_LIB_DIR"] = ("PATH", proj.boost_lib_dir_in_msvc())
else:
defs["SALVIA_BOOST_LIB_DIR"] = ("PATH", proj.boost_lib_dir())
if proj.toolset().short_compiler_name() == "vc":
defs["SALVIA_FREEIMAGE_DIR"] = ( "PATH", proj.freeimage_install_in_msvc() )
defs["SALVIA_LLVM_INSTALL_DIR"] = ("PATH", proj.llvm_install_in_msvc() )
defs["SALVIA_FREETYPE_DIR"] = ( "PATH", proj.freetype_install_in_msvc() )
else:
defs["SALVIA_FREEIMAGE_DIR"] = ( "PATH", proj.freeimage_install() )
defs["SALVIA_LLVM_INSTALL_DIR"] = ("PATH", proj.llvm_install() )
defs["SALVIA_FREETYPE_DIR"] = ( "PATH", proj.freetype_install() )
defs["SALVIA_BUILD_WITH_DIRECTX"] = ("BOOL", "TRUE" if proj.directx() else "FALSE")
config_and_make_cmake_project('SALVIA', defs, proj.source_root(), proj.salvia_build(), None, proj)
def install_prebuild_binaries(proj):
report_info( "Installing dependencies ..." )
dynamic_lib_ext = None
if proj.os() == systems.win32:
dynamic_lib_ext = ".dll"
elif proj.os() == systems.linux:
dynamic_lib_ext = ".so"
else:
report_error("Target OS cannot be supported.")
# Copy mingw runtime
if proj.toolset().short_compiler_name() == "mgw":
mgw_dir = proj.customized_toolset_dir()
libs = ["stdc++", "sjlj", "seh"]
for f in os.listdir(mgw_dir):
if os.path.splitext(f)[1] != dynamic_lib_ext:
continue
for lib_name in libs:
if lib_name in f:
copy_newer(os.path.join(mgw_dir, f), proj.salvia_bin())
# Copy FreeImage dlls
freeimage_dist_dir = os.path.join(proj.freeimage_install(), "Dist")
files = os.listdir(freeimage_dist_dir)
for f in files:
name, ext = os.path.splitext(f)
if ext != dynamic_lib_ext:
continue
src = os.path.join(freeimage_dist_dir, f)
copy_newer(src, proj.salvia_bin())
# Copy d3dcompile_xx.dll
if proj.dx_dlls_dirs():
for d in proj.dx_dlls_dirs():
for f in os.listdir(d):
copy_newer( os.path.join(d, f), proj.salvia_bin())
# Copy boost dlls
files = os.listdir(proj.boost_lib_dir())
need_copy = []
for f in files:
name, ext = os.path.splitext(f)
if ext != dynamic_lib_ext:
continue
if not proj.toolset().boost_lib_name() in name:
continue
need_copy.append(os.path.join(proj.boost_lib_dir(), f))
for f in need_copy:
copy_newer(f, proj.salvia_bin())
def clean_all(proj):
print('clean Boost ...')
clean_boost(proj)
print('clean LLVM ...')
clean_llvm(proj)
print('clean SALVIA ...')
clean_salvia(proj)
pass
def build(proj_props, cleanBuild):
log_f = open("build.log", "w")
atexit.register(close_log)
proj = project(proj_props, os.getcwd())
proj.print_props()
proj.check()
make_bjam(proj)
if cleanBuild: clean_all(proj)
make_boost(proj)
config_and_make_freetype(proj)
config_and_make_freeimage(proj)
config_and_make_llvm(proj)
config_and_make_salvia(proj)
install_prebuild_binaries(proj)
if __name__ == "__main__":
try:
opts, args = getopt.getopt(sys.argv[1:], "c", ['clean'])
except getopt.GetoptError:
print("Option parsed error.")
os.system("pause")
sys.exit(1)
if copy_newer("build_conf.tmpl", "proj.py"):
print( "Project file was generated.\nPlease edit proj.py and run build_all.py again." )
os.system('pause')
sys.exit(1)
report_info("Salvia building start.")
# Load Project
prj_props = __import__("proj")
for opt, arg in opts:
if opt == "-c" or opt == "--clean":
proj = project(prj_props, os.getcwd())
proj.print_props()
clean_all(proj)
os.system("pause")
sys.exit(0)
try:
build(prj_props, False)
except building_error as err:
print("[E] " + err.message())
print("[E] Salvia built failed.")
os.system("pause")
sys.exit(1)
report_info("Salvia building done.")
os.system("pause")