-
Notifications
You must be signed in to change notification settings - Fork 2
/
SConstruct
644 lines (487 loc) · 19.9 KB
/
SConstruct
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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2019-2021 Péter Magyar
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
EnsureSConsVersion(0, 98, 1)
import sys
import os
import subprocess
import json
import shutil
import traceback
import module_config
repository_index = 0
module_clone_path = '/modules/'
clone_command = 'git clone {0} {1}'
visual_studio_call_vcvarsall = False
visual_studio_vcvarsall_path = 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Auxiliary\\Build\\vcvarsall.bat'
visual_studio_arch = 'amd64'
exports = {
'global': [],
'linux': [],
'windows': [],
'android': [],
'javascript': [],
'osx': [],
'ios': [],
'server': [],
}
additional_commands = {
'global': [],
'linux': [],
'windows': [],
'android': [],
'javascript': [],
'osx': [],
'ios': [],
'server': [],
}
target_commits = {}
def onerror(func, path, exc_info):
"""
https://stackoverflow.com/questions/2656322/shutil-rmtree-fails-on-windows-with-access-is-denied
Because Windows.
Error handler for ``shutil.rmtree``.
If the error is due to an access error (read only file)
it attempts to add write permission and then retries.
If the error is for another reason it re-raises the error.
Usage : ``shutil.rmtree(path, onerror=onerror)``
"""
import stat
if not os.access(path, os.W_OK):
# Is the error an access error ?
os.chmod(path, stat.S_IWUSR)
func(path)
else:
raise
def load_target_commits_array():
global target_commits
if os.path.isfile('./HEADS'):
with open('./HEADS', 'r') as infile:
target_commits = json.load(infile)
else:
target_commits = {}
def save_target_commits_array():
with open('./HEADS', 'w') as outfile:
json.dump(target_commits, outfile)
def update_repository(data, clone_path, branch = 'master'):
cwd = os.getcwd()
full_path = cwd + clone_path + data[1] + '/'
if not os.path.isdir(full_path):
os.chdir(cwd + clone_path)
subprocess.call(clone_command.format(data[0][repository_index], data[1]), shell=True)
os.chdir(full_path)
subprocess.call('git reset', shell=True)
subprocess.call('git reset --hard', shell=True)
subprocess.call('git clean -f -d', shell=True)
subprocess.call('git checkout -B ' + branch + ' origin/' + branch, shell=True)
subprocess.call('git reset', shell=True)
subprocess.call('git reset --hard', shell=True)
subprocess.call('git clean -f -d', shell=True)
subprocess.call('git pull origin ' + branch, shell=True)
process = subprocess.Popen('git rev-parse HEAD', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output = process.communicate()[0].decode().strip()
if data[1] not in target_commits:
target_commits[data[1]] = {}
target_commits[data[1]][branch] = output
os.chdir(cwd)
def setup_repository(data, clone_path, branch = 'master'):
cwd = os.getcwd()
full_path = cwd + clone_path + data[1] + '/'
if not os.path.isdir(full_path):
os.chdir(cwd + clone_path)
subprocess.call(clone_command.format(data[0][repository_index], data[1]), shell=True)
os.chdir(full_path)
subprocess.call('git reset', shell=True)
subprocess.call('git reset --hard', shell=True)
subprocess.call('git clean -f -d', shell=True)
subprocess.call('git checkout -B ' + branch + ' origin/' + branch, shell=True)
subprocess.call('git pull origin ' + branch, shell=True)
subprocess.call('git reset', shell=True)
subprocess.call('git reset --hard', shell=True)
if data[1] in target_commits:
target = target_commits[data[1]][branch]
subprocess.call('git checkout -B ' + branch + ' ' + target, shell=True)
subprocess.call('git clean -f -d', shell=True)
subprocess.call('git reset', shell=True)
subprocess.call('git reset --hard', shell=True)
os.chdir(cwd)
def copy_repository(data, target_folder, clone_path):
copytree(os.path.abspath(clone_path + data[1] + '/' + data[2]), os.path.abspath(target_folder + data[1]))
def copytree(src, dst):
for item in os.listdir(src):
sp = os.path.join(src, item)
dp = os.path.join(dst, item)
if os.path.isdir(sp):
if os.path.isdir(dp):
shutil.rmtree(dp, onerror=onerror)
shutil.copytree(sp, dp)
else:
if not os.path.isdir(dst):
os.makedirs(dst)
shutil.copy2(sp, dp)
def validate_repository_origin(data, clone_path, branch = 'master'):
full_path = os.path.abspath(clone_path)
if not os.path.isdir(full_path):
return
cwd = os.getcwd()
os.chdir(full_path)
res = subprocess.run('git remote -v', shell=True, capture_output=True)
resstr = res.stdout.decode('ascii')
resarr = resstr.split("\n")
res_orig = []
for l in resarr:
if "origin" in l:
res_orig.append(l)
if len(res_orig) == 0:
print("The repository " + clone_path + " does not seem to have an origin remote. Adding it.")
subprocess.call('git remote add origin ' + data[0][repository_index], shell=True)
os.chdir(cwd)
return
for l in data[0]:
for ll in res_orig:
if l in ll:
os.chdir(cwd)
return
rind = 0
if 'git@' in res_orig[0]:
rind = 1
subprocess.call('git remote remove origin', shell=True)
subprocess.call('git remote add origin ' + data[0][rind], shell=True)
subprocess.call('git pull origin', shell=True)
subprocess.call('git checkout origin/' + branch, shell=True)
print('Updated git remote origin in ' + clone_path)
os.chdir(cwd)
def remove_repository(data, target_folder):
folder = os.path.abspath(target_folder + data[1])
if os.path.isdir(folder):
shutil.rmtree(folder)
def update_engine():
validate_repository_origin(module_config.engine_repository, './engine/', module_config.godot_branch)
update_repository(module_config.engine_repository, '/', module_config.godot_branch)
def update_modules():
for rep in module_config.module_repositories:
update_repository(rep, module_clone_path)
copy_repository(rep, './engine/modules/', '.' + module_clone_path)
def update_addons():
for rep in module_config.addon_repositories:
update_repository(rep, module_clone_path)
copy_repository(rep, './game/addons/', '.' + module_clone_path)
def update_addons_third_party_addons():
for rep in module_config.third_party_addon_repositories:
update_repository(rep, module_clone_path)
copy_repository(rep, './game/addons/', '.' + module_clone_path)
def update_all():
update_engine()
update_modules()
update_addons()
update_addons_third_party_addons()
save_target_commits_array()
def setup_engine():
validate_repository_origin(module_config.engine_repository, './engine/', module_config.godot_branch)
setup_repository(module_config.engine_repository, '/', module_config.godot_branch)
def setup_modules():
for rep in module_config.module_repositories:
setup_repository(rep, module_clone_path)
copy_repository(rep, './engine/modules/', '.' + module_clone_path)
for rep in module_config.removed_modules:
remove_repository(rep, './engine/modules/')
def setup_addons():
for rep in module_config.addon_repositories:
setup_repository(rep, module_clone_path)
copy_repository(rep, './game/addons/', '.' + module_clone_path)
def setup_addons_third_party_addons():
for rep in module_config.third_party_addon_repositories:
setup_repository(rep, module_clone_path)
copy_repository(rep, './game/addons/', '.' + module_clone_path)
def setup_all():
setup_engine()
setup_modules()
setup_addons()
setup_addons_third_party_addons()
def format_path(path):
if 'win' in sys.platform:
path = path.replace('/', '\\')
path = path.replace('~', '%userprofile%')
return path
def get_exports_for(platform):
export_command = 'export '
command_separator = ';'
if 'win' in sys.platform:
command_separator = '&'
export_command = 'set '
command = ''
for p in exports[platform]:
command += export_command + p + command_separator
return command
def get_additional_commands_for(platform):
command_separator = ';'
if 'win' in sys.platform:
command_separator = '&'
command = ''
for p in additional_commands[platform]:
command += p + command_separator
return command
def parse_config():
global visual_studio_vcvarsall_path
global visual_studio_arch
global visual_studio_call_vcvarsall
global exports
if not os.path.isfile('build.config'):
return
with open('build.config', 'r') as f:
for line in f:
ls = line.strip()
if ls == '' or ls.startswith('#'):
continue
words = line.split()
if (len(words) < 2):
print('This build.config line is malformed, and got ignored: ' + ls)
continue
if words[0] == 'visual_studio_vcvarsall_path':
visual_studio_vcvarsall_path = format_path(ls[29:])
elif words[0] == 'visual_studio_arch':
visual_studio_arch = format_path(ls[19:])
elif words[0] == 'visual_studio_call_vcvarsall':
visual_studio_call_vcvarsall = words[1].lower() in [ 'true', '1', 't', 'y', 'yes' ]
elif words[0] == 'export':
if (len(words) < 3) or not words[1] in exports:
print('This build.config line is malformed, and got ignored: ' + ls)
continue
export_path = format_path(ls[8 + len(words[1]):])
exports[words[1]].append(export_path)
elif words[0] == 'run':
if (len(words) < 3) or not words[1] in additional_commands:
print('This build.config line is malformed, and got ignored: ' + ls)
continue
final_cmd = format_path(ls[5 + len(words[1]):])
additional_commands[words[1]].append(final_cmd)
parse_config()
env = Environment()
if len(sys.argv) > 1:
arg = sys.argv[1]
arg_split = arg.split('_')
arg = arg_split[0]
arg_split = arg_split[1:]
if arg[0] == 'b':
build_string = get_exports_for('global') + get_additional_commands_for('global') + 'scons '
build_string += 'tools='
if 'e' in arg:
build_string += 'yes'
else:
build_string += 'no'
build_string += ' '
build_string += 'target='
if 'r' in arg:
build_string += 'release'
elif 'd' in arg:
build_string += 'debug'
else:
build_string += 'release_debug'
build_string += ' '
build_string += 'custom_modules_shared='
if 's' in arg:
build_string += 'yes'
else:
build_string += 'no'
build_string += ' '
if 'm' in arg:
build_string += 'use_mingw=yes'
else:
if 'win' in sys.platform and visual_studio_call_vcvarsall:
build_string = 'call "{0}" {1}&'.format(visual_studio_vcvarsall_path, visual_studio_arch) + build_string
if 'o' in arg:
build_string += 'use_llvm=yes'
if 'v' in arg:
build_string += 'vsproj=yes'
for i in range(2, len(sys.argv)):
build_string += ' ' + sys.argv[i] + ' '
if 'slim' in arg_split:
build_string += module_config.slim_args
build_string += ' '
if 'latomic' in arg_split:
build_string += 'LINKFLAGS="-latomic"'
build_string += ' '
if 'strip' in arg_split:
build_string += 'debug_symbols=no'
build_string += ' '
if 'threads' in arg_split:
build_string += 'threads_enabled=yes'
build_string += ' '
target = ' '
if 'E' in arg:
target += 'bin/libess.x11.opt.tools.64.so'
elif 'T' in arg:
target += 'bin/libtexture_packer.x11.opt.tools.64.so'
elif 'V' in arg:
target += 'bin/libvoxelman.x11.opt.tools.64.so'
elif 'W' in arg:
target += 'bin/libworld_generator.x11.opt.tools.64.so'
elif 'P' in arg:
target += 'bin/libprocedural_animations.x11.opt.tools.64.so'
cwd = os.getcwd()
full_path = cwd + '/engine/'
if not os.path.isdir(full_path):
print('engine directory doesnt exists.')
exit()
os.chdir(full_path)
if 'l' in arg:
build_string += 'platform=x11'
build_string = get_exports_for('linux') + get_additional_commands_for('linux') + build_string + target
print('Running command: ' + build_string)
subprocess.call(build_string, shell=True)
elif 'w' in arg:
build_string += 'platform=windows'
build_string = get_exports_for('windows') + get_additional_commands_for('windows') + build_string
print('Running command: ' + build_string)
subprocess.call(build_string, shell=True)
elif 'a' in arg:
build_string += 'platform=android'
build_string = get_exports_for('android') + get_additional_commands_for('android') + build_string
print('Running command: ' + build_string + ' android_arch=armv7')
subprocess.call(build_string + ' android_arch=armv7', shell=True)
print('Running command: ' + build_string + ' android_arch=arm64v8')
subprocess.call(build_string + ' android_arch=arm64v8', shell=True)
print('Running command: ' + build_string + ' android_arch=x86')
subprocess.call(build_string + ' android_arch=x86', shell=True)
os.chdir(full_path + 'platform/android/java/')
print('Running command: ' + get_exports_for('global') + get_additional_commands_for('global') + get_exports_for('android') + get_additional_commands_for('android') + './gradlew generateGodotTemplates')
subprocess.call(get_exports_for('global') + get_additional_commands_for('global') + get_exports_for('android') + get_additional_commands_for('android') + './gradlew generateGodotTemplates', shell=True)
elif 'j' in arg:
build_string += 'platform=javascript'
build_string = get_exports_for('javascript') + get_additional_commands_for('javascript') + build_string
print('Running command: ' + build_string)
subprocess.call(build_string, shell=True)
elif 'i' in arg:
build_string += 'platform=iphone'
print('Running command: ' + build_string)
subprocess.call(build_string, shell=True)
#print('Running command: ' + build_string + " arch=arm")
#subprocess.call(build_string + ' arch=arm', shell=True)
#print('Running command: ' + build_string + " arch=arm64")
#subprocess.call(build_string + ' arch=arm64', shell=True)
#print('Running command: ' + build_string + " arch=x86_64")
#subprocess.call(build_string + ' arch=x86_64', shell=True)
elif 'x' in arg:
build_string += 'platform=osx'
build_string = get_exports_for('osx') + get_additional_commands_for('osx') + build_string + target
print('Running command: ' + build_string)
subprocess.call(build_string, shell=True)
elif 'h' in arg:
#headless
build_string += 'platform=server'
build_string = get_exports_for('server') + get_additional_commands_for('server') + build_string
print('Running command: ' + build_string)
subprocess.call(build_string, shell=True)
else:
print('No platform specified')
exit()
exit()
# elif arg[0] == 'p':
# if arg == 'p':
# print("Applies a patch. No Patches right now.Append s for the skeleton editor patch. For example: ps ")
# exit()
#
# cwd = os.getcwd()
# full_path = cwd + '/engine/'
#
# if not os.path.isdir(full_path):
# print('engine directory does not exists.')
# exit()
#
# os.chdir(full_path)
#
# #apply the patch to just the working directory, without creating a commit
#
# if 's' in arg:
# subprocess.call('git apply --index ../patches/custom_skeleton_3d_editor_plugin.patch', shell=True)
#
# #unstage all files
# subprocess.call('git reset', shell=True)
#
# vman_full_path = cwd + '/engine/modules/voxelman/'
#
# #also patch voxelman as the plugin changes forward_spatial_gui_input's definition
# if os.path.isdir(vman_full_path):
# os.chdir(vman_full_path)
#
# subprocess.call('git apply --index ../../../patches/fix-voxel-editor-after-the-skeleton-editor-patch.patch', shell=True)
#
# #unstage all files
# subprocess.call('git reset', shell=True)
# else:
# print('Voxelman directory does not exists, skipping patch.')
#
# exit()
opts = Variables(args=ARGUMENTS)
opts.Add('a', 'What to do', '')
opts.Add(EnumVariable('action', 'What to do', 'setup', ('setup', 'update')))
opts.Add('t', 'Action target', '')
opts.Add(EnumVariable('target', 'Action target', 'all', ('all', 'engine', 'modules', 'all_addons', 'addons', 'third_party_addons')))
opts.Add(EnumVariable('repository_type', 'Type of repositories to clone from first', 'http', ('http', 'ssh')))
opts.Update(env)
Help(opts.GenerateHelpText(env))
load_target_commits_array()
rt = env['repository_type']
if rt == 'ssh':
repository_index = 1
action = env['action']
target = env['target']
if env['a']:
action = env['a']
if env['t']:
target = env['t']
if not os.path.isdir('./modules'):
os.mkdir('./modules')
if 'm' in action:
godot_branch = 'master'
if 'setup' in action or action[0] == 's':
if target == 'all':
setup_all()
elif target == 'engine':
setup_engine()
elif target == 'modules':
setup_modules()
elif target == 'all_addons':
setup_addons()
setup_addons_third_party_addons()
elif target == 'addons':
setup_addons()
elif target == 'third_party_addons':
setup_addons_third_party_addons()
elif 'update' in action or action[0] == 'u':
if target == 'all':
update_all()
elif target == 'engine':
update_engine()
save_target_commits_array()
elif target == 'modules':
update_modules()
save_target_commits_array()
elif target == 'all_addons':
update_addons()
update_addons_third_party_addons()
save_target_commits_array()
elif target == 'addons':
update_addons()
save_target_commits_array()
elif target == 'third_party_addons':
update_addons_third_party_addons()
save_target_commits_array()