forked from defold/defold
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
executable file
·2228 lines (1860 loc) · 97.5 KB
/
build.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
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
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
# Copyright 2020-2022 The Defold Foundation
# Copyright 2014-2020 King
# Copyright 2009-2014 Ragnar Svensson, Christian Murray
# Licensed under the Defold License version 1.0 (the "License"); you may not use
# this file except in compliance with the License.
#
# You may obtain a copy of the License, together with FAQs at
# https://www.defold.com/license
#
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
# add build_tools folder to the import search path
import sys, os, platform
from os.path import join, dirname, basename, relpath, expanduser, normpath, abspath
sys.path.append(os.path.join(normpath(join(dirname(abspath(__file__)), '..')), "build_tools"))
import shutil, zipfile, re, itertools, json, platform, math, mimetypes
import optparse, subprocess, urllib, urllib.parse, tempfile, time
import github
import run
import s3
import sdk
import release_to_github
import BuildUtility
import http_cache
from urllib.parse import urlparse
from tarfile import TarFile
from glob import glob
from threading import Thread, Event
from queue import Queue
from configparser import ConfigParser
BASE_PLATFORMS = [ 'x86_64-linux',
'x86_64-darwin',
'win32', 'x86_64-win32',
'x86_64-ios', 'arm64-darwin',
'armv7-android', 'arm64-android',
'js-web', 'wasm-web']
sys.dont_write_bytecode = True
try:
import build_nx64
sys.modules['build_private'] = build_nx64
except Exception:
pass
sys.dont_write_bytecode = False
try:
import build_private
except Exception:
pass
if 'build_private' not in sys.modules:
class build_private(object):
@classmethod
def get_target_platforms(cls):
return []
@classmethod
def get_install_host_packages(cls, platform): # Returns the packages that should be installed for the host
return []
@classmethod
def get_install_target_packages(cls, platform): # Returns the packages that should be installed for the target
return []
@classmethod
def install_sdk(cls, configuration, platform): # Installs the sdk for the private platform
pass
@classmethod
def is_library_supported(cls, platform, library):
return True
@classmethod
def is_repo_private(self):
return False
@classmethod
def get_tag_suffix(self):
return ''
def get_target_platforms():
return BASE_PLATFORMS + build_private.get_target_platforms()
PACKAGES_ALL="protobuf-3.20.1 waf-2.0.3 junit-4.6 protobuf-java-3.20.1 openal-1.1 maven-3.0.1 ant-1.9.3 vecmath vpx-1.7.0 luajit-2.1.0-beta3 tremolo-0.0.8 defold-robot-0.7.0 bullet-2.77 libunwind-395b27b68c5453222378bc5fe4dab4c6db89816a jctest-0.8 vulkan-1.1.108".split()
PACKAGES_HOST="cg-3.1 vpx-1.7.0 luajit-2.1.0-beta3 tremolo-0.0.8".split()
PACKAGES_IOS_X86_64="protobuf-3.20.1 luajit-2.1.0-beta3 tremolo-0.0.8 bullet-2.77".split()
PACKAGES_IOS_64="protobuf-3.20.1 luajit-2.1.0-beta3 tremolo-0.0.8 bullet-2.77 MoltenVK-1.0.41".split()
PACKAGES_DARWIN="vpx-1.7.0".split()
PACKAGES_DARWIN_64="protobuf-3.20.1 luajit-2.1.0-beta3 vpx-1.7.0 tremolo-0.0.8 sassc-5472db213ec223a67482df2226622be372921847 bullet-2.77 spirv-cross-2018-08-07 glslc-v2018.0 MoltenVK-1.0.41 luac-32-5.1.5".split()
PACKAGES_WIN32="protobuf-3.20.1 luajit-2.1.0-beta3 openal-1.1 glut-3.7.6 bullet-2.77 vulkan-1.1.108".split()
PACKAGES_WIN32_64="protobuf-3.20.1 luajit-2.1.0-beta3 openal-1.1 glut-3.7.6 sassc-5472db213ec223a67482df2226622be372921847 bullet-2.77 spirv-cross-2018-08-07 glslc-v2018.0 vulkan-1.1.108 luac-32-5.1.5".split()
PACKAGES_LINUX_64="protobuf-3.20.1 luajit-2.1.0-beta3 sassc-5472db213ec223a67482df2226622be372921847 bullet-2.77 spirv-cross-2018-08-07 glslc-v2018.0 vulkan-1.1.108 luac-32-5.1.5".split()
PACKAGES_ANDROID="protobuf-3.20.1 android-support-multidex androidx-multidex android-31 luajit-2.1.0-beta3 tremolo-0.0.8 bullet-2.77 libunwind-8ba86320a71bcdc7b411070c0c0f101cf2131cf2".split()
PACKAGES_ANDROID_64="protobuf-3.20.1 android-support-multidex androidx-multidex android-31 luajit-2.1.0-beta3 tremolo-0.0.8 bullet-2.77 libunwind-8ba86320a71bcdc7b411070c0c0f101cf2131cf2".split()
PACKAGES_EMSCRIPTEN="protobuf-3.20.1 bullet-2.77".split()
PACKAGES_NODE_MODULES="xhr2-0.1.0".split()
DMSDK_PACKAGES_ALL="vectormathlibrary-r1649".split()
CDN_PACKAGES_URL=os.environ.get("DM_PACKAGES_URL", None)
DEFAULT_ARCHIVE_DOMAIN=os.environ.get("DM_ARCHIVE_DOMAIN", "d.defold.com")
DEFAULT_RELEASE_REPOSITORY=os.environ.get("DM_RELEASE_REPOSITORY") if os.environ.get("DM_RELEASE_REPOSITORY") else release_to_github.get_current_repo()
PACKAGES_TAPI_VERSION="tapi1.6"
PACKAGES_NODE_MODULE_XHR2="xhr2-v0.1.0"
PACKAGES_ANDROID_NDK="android-ndk-r20"
PACKAGES_ANDROID_SDK="android-sdk"
ANDROID_TARGET_API_LEVEL=31
ANDROID_BUILD_TOOLS_VERSION="32.0.0"
PACKAGES_CCTOOLS_PORT="cctools-port-darwin19-6c438753d2252274678d3e0839270045698c159b-linux"
NODE_MODULE_LIB_DIR = os.path.join("ext", "lib", "node_modules")
EMSCRIPTEN_VERSION_STR = "2.0.11"
EMSCRIPTEN_SDK = "sdk-{0}-64bit".format(EMSCRIPTEN_VERSION_STR)
PACKAGES_EMSCRIPTEN_SDK="emsdk-{0}".format(EMSCRIPTEN_VERSION_STR)
SHELL = os.environ.get('SHELL', 'bash')
# Don't use WSL from the msys/cygwin terminal
if os.environ.get('TERM','') in ('cygwin',):
if 'WD' in os.environ:
SHELL= '%s\\bash.exe' % os.environ['WD'] # the binary directory
ENGINE_LIBS = "testmain ddf particle glfw graphics lua hid input physics resource extension script render rig gameobject gui sound liveupdate crash gamesys tools record iap push iac webview profiler facebook engine sdk".split()
EXTERNAL_LIBS = "bullet3d".split()
def is_64bit_machine():
return platform.machine().endswith('64')
# Legacy format, should be removed eventually
# Returns: [linux|x86_64-linux|win32|x86_64-win32|darwin]
def get_host_platform():
if sys.platform == 'linux':
arch = platform.architecture()[0]
if arch == '64bit':
return 'x86_64-linux'
else:
return 'linux'
elif sys.platform == 'win32' and is_64bit_machine():
return 'x86_64-win32'
else:
return sys.platform
# The difference from get_host_platform is that it returns the correct platform
# Returns: [x86|x86_64][win32|linux|darwin]
def get_host_platform2():
if sys.platform == 'linux':
arch = platform.architecture()[0]
if arch == '64bit':
return 'x86_64-linux'
else:
return 'x86-linux'
elif sys.platform == 'win32':
if is_64bit_machine():
return 'x86_64-win32'
else:
return 'x86-win32'
elif sys.platform == 'darwin':
if is_64bit_machine():
return 'x86_64-darwin'
else:
return 'x86-darwin'
else:
raise Exception("Unknown host platform: %s" % sys.platform)
def format_exes(name, platform):
prefix = ''
suffix = ['']
if 'win32' in platform:
suffix = ['.exe']
elif 'android' in platform:
prefix = 'lib'
suffix = ['.so']
elif 'js-web' in platform:
prefix = ''
suffix = ['.js']
elif 'wasm-web' in platform:
prefix = ''
suffix = ['.js', '.wasm']
elif platform in ['arm64-nx64']:
prefix = ''
suffix = ['.nss', '.nso']
else:
suffix = ['']
exes = []
for suff in suffix:
exes.append('%s%s%s' % (prefix, name, suff))
return exes
def format_lib(name, platform):
prefix = 'lib'
suffix = ''
if 'darwin' in platform or 'ios' in platform:
suffix = '.dylib'
elif 'win32' in platform:
prefix = ''
suffix = '.dll'
else:
suffix = '.so'
return '%s%s%s' % (prefix, name, suffix)
class ThreadPool(object):
def __init__(self, worker_count):
self.workers = []
self.work_queue = Queue()
for i in range(worker_count):
w = Thread(target = self.worker)
w.setDaemon(True)
w.start()
self.workers.append(w)
def worker(self):
func, args, future = self.work_queue.get()
while func:
try:
result = func(*args)
future.result = result
except Exception as e:
future.result = e
future.event.set()
func, args, future = self.work_queue.get()
class Future(object):
def __init__(self, pool, f, *args):
self.result = None
self.event = Event()
pool.work_queue.put([f, args, self])
def __call__(self):
try:
# In order to respond to ctrl+c wait with timeout...
while not self.event.is_set():
self.event.wait(0.1)
except KeyboardInterrupt as e:
sys.exit(0)
if isinstance(self.result, Exception):
raise self.result
else:
return self.result
def download_sdk(conf, url, targetfolder, strip_components=1, force_extract=False, format='z'):
if not os.path.exists(targetfolder) or force_extract:
if not os.path.exists(os.path.dirname(targetfolder)):
os.makedirs(os.path.dirname(targetfolder))
path = conf.get_local_or_remote_file(url)
conf._extract_tgz_rename_folder(path, targetfolder, strip_components, format=format)
else:
print ("SDK already installed:", targetfolder)
class Configuration(object):
def __init__(self, dynamo_home = None,
target_platform = None,
skip_tests = False,
skip_codesign = False,
skip_docs = False,
skip_builtins = False,
skip_bob_light = False,
disable_ccache = False,
no_colors = False,
archive_domain = None,
package_path = None,
set_version = None,
channel = None,
engine_artifacts = None,
waf_options = [],
save_env_path = None,
notarization_username = None,
notarization_password = None,
notarization_itc_provider = None,
github_token = None,
github_target_repo = None,
github_sha1 = None,
version = None,
codesigning_identity = None,
windows_cert = None,
windows_cert_pass = None,
verbose = False):
if sys.platform == 'win32':
home = os.environ['USERPROFILE']
else:
home = os.environ['HOME']
self.dynamo_home = dynamo_home if dynamo_home else join(os.getcwd(), 'tmp', 'dynamo_home')
self.ext = join(self.dynamo_home, 'ext')
self.dmsdk = join(self.dynamo_home, 'sdk')
self.defold = normpath(join(dirname(abspath(__file__)), '..'))
self.defold_root = os.getcwd()
self.host = get_host_platform()
self.host2 = get_host_platform2()
self.target_platform = target_platform
self.build_utility = BuildUtility.BuildUtility(self.target_platform, self.host, self.dynamo_home)
self.skip_tests = skip_tests
self.skip_codesign = skip_codesign
self.skip_docs = skip_docs
self.skip_builtins = skip_builtins
self.skip_bob_light = skip_bob_light
self.disable_ccache = disable_ccache
self.no_colors = no_colors
self.archive_path = "s3://%s/archive" % (archive_domain)
self.archive_domain = archive_domain
self.package_path = package_path
self.set_version = set_version
self.channel = channel
self.engine_artifacts = engine_artifacts
self.waf_options = waf_options
self.save_env_path = save_env_path
self.notarization_username = notarization_username
self.notarization_password = notarization_password
self.notarization_itc_provider = notarization_itc_provider
self.github_token = github_token
self.github_target_repo = github_target_repo
self.github_sha1 = github_sha1
self.version = version
self.codesigning_identity = codesigning_identity
self.windows_cert = windows_cert
self.windows_cert_pass = windows_cert_pass
self.verbose = verbose
if self.github_token is None:
self.github_token = os.environ.get("GITHUB_TOKEN")
self.thread_pool = None
self.futures = []
if version is None:
with open('VERSION', 'r') as f:
self.version = f.readlines()[0].strip()
self._create_common_dirs()
def __del__(self):
if len(self.futures) > 0:
print('ERROR: Pending futures (%d)' % len(self.futures))
os._exit(5)
def _create_common_dirs(self):
for p in ['ext/lib/python', 'share', 'lib/js-web/js', 'lib/wasm-web/js']:
self._mkdirs(join(self.dynamo_home, p))
def _mkdirs(self, path):
if not os.path.exists(path):
os.makedirs(path)
def _log(self, msg):
print(str(msg))
sys.stdout.flush()
sys.stderr.flush()
def distclean(self):
if os.path.exists(self.dynamo_home):
self._log('Removing %s' % self.dynamo_home)
shutil.rmtree(self.dynamo_home)
for lib in ['dlib','texc']+ENGINE_LIBS:
builddir = join(self.defold_root, 'engine/%s/build' % lib)
if os.path.exists(builddir):
self._log('Removing %s' % builddir)
shutil.rmtree(builddir)
# Recreate dirs
self._create_common_dirs()
self._log('distclean done.')
def _extract_tgz(self, file, path):
self._log('Extracting %s to %s' % (file, path))
version = sys.version_info
suffix = os.path.splitext(file)[1]
# Avoid a bug in python 2.7 (fixed in 2.7.2) related to not being able to remove symlinks: http://bugs.python.org/issue10761
if self.host == 'x86_64-linux' and version[0] == 2 and version[1] == 7 and version[2] < 2:
fmts = {'.gz': 'z', '.xz': 'J', '.bzip2': 'j'}
run.env_command(self._form_env(), ['tar', 'xf%s' % fmts.get(suffix, 'z'), file], cwd = path)
else:
fmts = {'.gz': 'gz', '.xz': 'xz', '.bzip2': 'bz2'}
tf = TarFile.open(file, 'r:%s' % fmts.get(suffix, 'gz'))
tf.extractall(path)
tf.close()
def _extract_tgz_rename_folder(self, src, target_folder, strip_components=1, format=None):
src = src.replace('\\', '/')
force_local = ''
if os.environ.get('GITHUB_SHA', None) is not None and os.environ.get('TERM', '') == 'cygwin':
force_local = '--force-local' # to make tar not try to "connect" because it found a colon in the source file
self._log('Extracting %s to %s/' % (src, target_folder))
parentdir, dirname = os.path.split(target_folder)
old_dir = os.getcwd()
os.chdir(parentdir)
if not os.path.exists(dirname):
os.makedirs(dirname)
if format is None:
suffix = os.path.splitext(src)[1]
fmts = {'.gz': 'z', '.xz': 'J', '.bzip2': 'j'}
format = fmts.get(suffix, 'z')
cmd = ['tar', 'xf%s' % format, src, '-C', dirname]
if strip_components:
cmd.extend(['--strip-components', '%d' % strip_components])
if force_local:
cmd.append(force_local)
run.env_command(self._form_env(), cmd)
os.chdir(old_dir)
def _extract_zip(self, file, path):
self._log('Extracting %s to %s' % (file, path))
def _extract_zip_entry( zf, info, extract_dir ):
zf.extract( info.filename, path=extract_dir )
out_path = os.path.join( extract_dir, info.filename )
perm = info.external_attr >> 16
os.chmod( out_path, perm )
with zipfile.ZipFile(file, 'r') as zf:
for info in zf.infolist():
_extract_zip_entry( zf, info, path )
def _extract(self, file, path):
if os.path.splitext(file)[1] == '.zip':
self._extract_zip(file, path)
else:
self._extract_tgz(file, path)
def _copy(self, src, dst):
self._log('Copying %s -> %s' % (src, dst))
shutil.copy(src, dst)
def _copy_tree(self, src, dst):
self._log('Copying %s -> %s' % (src, dst))
shutil.copytree(src, dst)
def _download(self, url):
self._log('Downloading %s' % (url))
path = http_cache.download(url, lambda count, total: self._log('Downloading %s %.2f%%' % (url, 100 * count / float(total))))
if not path:
self._log('Downloading %s failed' % (url))
return path
def _check_package_path(self):
if self.package_path is None:
print("No package path provided. Use either --package-path option or DM_PACKAGES_URL environment variable")
sys.exit(1)
def install_ext(self):
def make_package_path(root, platform, package):
return join(root, 'packages', package) + '-%s.tar.gz' % platform
def make_package_paths(root, platform, packages):
return [make_package_path(root, platform, package) for package in packages]
self._check_package_path()
print("Installing common packages")
for p in PACKAGES_ALL:
self._extract_tgz(make_package_path(self.defold_root, 'common', p), self.ext)
for p in DMSDK_PACKAGES_ALL:
self._extract_tgz(make_package_path(self.defold_root, 'common', p), self.dmsdk)
# TODO: Make sure the order of install does not affect the outcome!
platform_packages = {
'win32': PACKAGES_WIN32,
'x86_64-win32': PACKAGES_WIN32_64,
'x86_64-linux': PACKAGES_LINUX_64,
'darwin': PACKAGES_DARWIN, # ?? Still used by bob-light?
'x86_64-darwin': PACKAGES_DARWIN_64,
'arm64-darwin': PACKAGES_IOS_64,
'x86_64-ios': PACKAGES_IOS_X86_64,
'armv7-android': PACKAGES_ANDROID,
'arm64-android': PACKAGES_ANDROID_64,
'js-web': PACKAGES_EMSCRIPTEN,
'wasm-web': PACKAGES_EMSCRIPTEN
}
base_platforms = self.get_base_platforms()
target_platform = self.target_platform
other_platforms = set(platform_packages.keys()).difference(set(base_platforms), set([target_platform, self.host]))
if target_platform in ['js-web', 'wasm-web']:
node_modules_dir = os.path.join(self.dynamo_home, NODE_MODULE_LIB_DIR)
for package in PACKAGES_NODE_MODULES:
path = join(self.defold_root, 'packages', package + '.tar.gz')
name = package.split('-')[0]
self._extract_tgz(path, join(node_modules_dir, name))
installed_packages = set()
for platform in other_platforms:
packages = platform_packages.get(platform, [])
package_paths = make_package_paths(self.defold_root, platform, packages)
print("Installing %s packages " % platform)
for path in package_paths:
self._extract_tgz(path, self.ext)
installed_packages.update(package_paths)
for base_platform in self.get_base_platforms():
packages = list(PACKAGES_HOST) + build_private.get_install_host_packages(base_platform)
packages.extend(platform_packages.get(base_platform, []))
package_paths = make_package_paths(self.defold_root, base_platform, packages)
package_paths = [path for path in package_paths if path not in installed_packages]
if len(package_paths) != 0:
print("Installing %s packages" % base_platform)
for path in package_paths:
self._extract_tgz(path, self.ext)
installed_packages.update(package_paths)
# For easier usage with the extender server, we want the linux protoc tool available
if target_platform in ('x86_64-darwin', 'x86_64-win32', 'x86_64-linux'):
protobuf_packages = filter(lambda x: "protobuf" in x, PACKAGES_HOST)
package_paths = make_package_paths(self.defold_root, 'x86_64-linux', protobuf_packages)
print("Installing %s packages " % 'x86_64-linux')
for path in package_paths:
self._extract_tgz(path, self.ext)
installed_packages.update(package_paths)
target_packages = platform_packages.get(self.target_platform, []) + build_private.get_install_target_packages(self.target_platform)
target_package_paths = make_package_paths(self.defold_root, self.target_platform, target_packages)
target_package_paths = [path for path in target_package_paths if path not in installed_packages]
if len(target_package_paths) != 0:
print("Installing %s packages" % self.target_platform)
for path in target_package_paths:
self._extract_tgz(path, self.ext)
installed_packages.update(target_package_paths)
print("Installing python wheels")
run.env_command(self._form_env(), ['python', './packages/get-pip.py', 'pip==20.3.4', '--user'])
run.env_command(self._form_env(), ['python', '-m', 'pip', '-q', '-q', 'install', '-t', join(self.ext, 'lib', 'python'), 'requests', 'pyaml'])
for whl in glob(join(self.defold_root, 'packages', '*.whl')):
self._log('Installing %s' % basename(whl))
run.env_command(self._form_env(), ['python', '-m', 'pip', '-q', '-q', 'install', '--upgrade', '-t', join(self.ext, 'lib', 'python'), whl])
print("Installing javascripts")
for n in 'js-web-pre.js'.split():
self._copy(join(self.defold_root, 'share', n), join(self.dynamo_home, 'share'))
for n in 'js-web-pre-engine.js'.split():
self._copy(join(self.defold_root, 'share', n), join(self.dynamo_home, 'share'))
print("Installing profiles etc")
for n in itertools.chain(*[ glob('share/*%s' % ext) for ext in ['.mobileprovision', '.xcent', '.supp']]):
self._copy(join(self.defold_root, n), join(self.dynamo_home, 'share'))
# Simple way to reduce number of warnings in the build
proto_path = os.path.join(self.dynamo_home, 'share', 'proto')
if not os.path.exists(proto_path):
os.makedirs(proto_path)
def get_local_or_remote_file(self, path):
if os.path.isdir(self.package_path): # is is a local path?
if os.path.exists(path):
return os.path.normpath(os.path.abspath(path))
print("Could not find local file:", path)
sys.exit(1)
dirname, basename = os.path.split(path)
path = dirname + "/" + urllib.parse.quote(basename)
path = self._download(path) # it should be an url
if path is None:
print("Error. Could not download %s" % path)
sys.exit(1)
return path
def check_sdk(self):
sdkfolder = join(self.ext, 'SDKs')
self.sdk_info = sdk.get_sdk_info(sdkfolder, target_platform)
# We currently only support a subset of platforms using this mechanic
if platform in ('x86_64-darwin','x86_64-ios','arm64-darwin'):
if not self.sdk_info:
print("Couldn't find any sdks")
print("We recommend you follow the packaging steps found here: %s" % "https://github.com/defold/defold/blob/dev/scripts/package/README.md#packaging-the-sdks")
print("Then run './scripts/build.py --package-path=<local_folder_or_url> install_ext --platform=<platform>=%s'" % self.target_platform)
sys.exit(1)
print("Using SDKS:", self.sdk_info)
def install_sdk(self):
sdkfolder = join(self.ext, 'SDKs')
target_platform = self.target_platform
if target_platform in ('x86_64-darwin', 'arm64-darwin', 'x86_64-ios'):
# macOS SDK
download_sdk(self,'%s/%s.tar.gz' % (self.package_path, sdk.PACKAGES_MACOS_SDK), join(sdkfolder, sdk.PACKAGES_MACOS_SDK))
download_sdk(self,'%s/%s.darwin.tar.gz' % (self.package_path, sdk.PACKAGES_XCODE_TOOLCHAIN), join(sdkfolder, sdk.PACKAGES_XCODE_TOOLCHAIN))
if target_platform in ('arm64-darwin', 'x86_64-ios'):
# iOS SDK
download_sdk(self,'%s/%s.tar.gz' % (self.package_path, sdk.PACKAGES_IOS_SDK), join(sdkfolder, sdk.PACKAGES_IOS_SDK))
download_sdk(self,'%s/%s.tar.gz' % (self.package_path, sdk.PACKAGES_IOS_SIMULATOR_SDK), join(sdkfolder, sdk.PACKAGES_IOS_SIMULATOR_SDK))
if 'win32' in target_platform or ('win32' in self.host2):
win32_sdk_folder = join(self.ext, 'SDKs', 'Win32')
download_sdk(self,'%s/%s.tar.gz' % (self.package_path, sdk.PACKAGES_WIN32_SDK_10), join(win32_sdk_folder, 'WindowsKits', '10') )
download_sdk(self,'%s/%s.tar.gz' % (self.package_path, sdk.PACKAGES_WIN32_TOOLCHAIN), join(win32_sdk_folder, 'MicrosoftVisualStudio14.0'), strip_components=0 )
# On OSX, the file system is already case insensitive, so no need to duplicate the files as we do on the extender server
if target_platform in ('armv7-android', 'arm64-android'):
host = self.host
if 'win32' in host:
host = 'windows'
elif 'linux' in host:
host = 'linux'
# Android NDK
download_sdk(self, '%s/%s-%s-x86_64.tar.gz' % (self.package_path, PACKAGES_ANDROID_NDK, host), join(sdkfolder, PACKAGES_ANDROID_NDK))
# Android SDK
download_sdk(self, '%s/%s-%s-android-%s-%s.tar.gz' % (self.package_path, PACKAGES_ANDROID_SDK, host, ANDROID_TARGET_API_LEVEL, ANDROID_BUILD_TOOLS_VERSION), join(sdkfolder, PACKAGES_ANDROID_SDK))
if 'linux' in self.host2:
download_sdk(self, '%s/%s.tar.xz' % (self.package_path, sdk.PACKAGES_LINUX_TOOLCHAIN), join(sdkfolder, 'linux', sdk.PACKAGES_LINUX_CLANG), format='J')
if target_platform in ('x86_64-darwin', 'arm64-darwin', 'x86_64-ios') and 'linux' in self.host2:
if not os.path.exists(join(sdkfolder, 'linux', sdk.PACKAGES_LINUX_CLANG, 'cctools')):
download_sdk(self, '%s/%s.tar.gz' % (self.package_path, PACKAGES_CCTOOLS_PORT), join(sdkfolder, 'linux', sdk.PACKAGES_LINUX_CLANG), force_extract=True)
build_private.install_sdk(self, target_platform)
def get_ems_dir(self):
return join(self.ext, 'SDKs', 'emsdk-' + EMSCRIPTEN_VERSION_STR)
def _form_ems_path(self):
upstream = join(self.get_ems_dir(), 'upstream', 'emscripten')
if os.path.exists(upstream):
return upstream
return join(self.get_ems_dir(), 'fastcomp', 'emscripten')
def install_ems(self):
# TODO: should eventually be moved to install_sdk
emsDir = self.get_ems_dir()
os.environ['EMSCRIPTEN'] = self._form_ems_path()
os.environ['EM_CONFIG'] = join(self.get_ems_dir(), '.emscripten')
os.environ['EM_CACHE'] = join(self.get_ems_dir(), 'emscripten_cache')
if os.path.isdir(emsDir):
print("Emscripten is already installed:", emsDir)
else:
self._check_package_path()
platform_map = {'x86_64-linux':'linux','x86_64-darwin':'darwin','x86_64-win32':'win32'}
path = join(self.package_path, '%s-%s.tar.gz' % (PACKAGES_EMSCRIPTEN_SDK, platform_map.get(self.host, self.host)))
path = self.get_local_or_remote_file(path)
self._extract(path, join(self.ext, 'SDKs'))
config = os.environ['EM_CONFIG']
if not os.path.isfile(config):
self.activate_ems()
def activate_ems(self):
version = EMSCRIPTEN_VERSION_STR
if 'fastcomp' in self._form_ems_path():
version += "-fastcomp"
run.env_command(self._form_env(), [join(self.get_ems_dir(), 'emsdk'), 'activate', version, '--embedded'])
# prewarm the cache
# Although this method might be more "correct", it also takes 10 minutes more than we'd like on CI
#run.env_command(self._form_env(), ['%s/embuilder.py' % self._form_ems_path(), 'build', 'SYSTEM', 'MINIMAL'])
# .. so we stick with the old version of prewarming
# Compile a file warm up the emscripten caches (libc etc)
c_file = tempfile.mktemp(suffix='.c')
exe_file = tempfile.mktemp(suffix='.js')
with open(c_file, 'w') as f:
f.write('int main() { return 0; }')
run.env_command(self._form_env(), ['%s/emcc' % self._form_ems_path(), c_file, '-o', '%s' % exe_file])
def check_ems(self):
config = join(self.get_ems_dir(), '.emscripten')
err = False
if not os.path.isfile(config):
print('No .emscripten file.')
err = True
emsDir = self.get_ems_dir()
if not os.path.isdir(emsDir):
print('Emscripten tools not installed.')
err = True
if err:
print('Consider running install_ems')
def _git_sha1(self, ref = None):
return self.build_utility.git_sha1(ref)
def _ziptree(self, path, outfile = None, directory = None):
# Directory is similar to -C in tar
if not outfile:
outfile = tempfile.NamedTemporaryFile(delete = False)
zip = zipfile.ZipFile(outfile, 'w', zipfile.ZIP_DEFLATED)
for root, dirs, files in os.walk(path):
for f in files:
p = os.path.join(root, f)
an = p
if directory:
an = os.path.relpath(p, directory)
zip.write(p, an)
zip.close()
return outfile.name
def _add_files_to_zip(self, zip, paths, directory=None, topfolder=None):
for p in paths:
if not os.path.isfile(p):
continue
an = p
if directory:
an = os.path.relpath(p, directory)
if topfolder:
an = os.path.join(topfolder, an)
zip.write(p, an)
def is_cross_platform(self):
return self.host != self.target_platform
def is_desktop_target(self):
return self.target_platform in ['x86_64-linux', 'x86_64-darwin', 'x86_64-win32']
# package the native SDK, return the path to the zip file
def _package_platform_sdk(self, platform):
with open(join(self.dynamo_home, 'defoldsdk.zip'), 'wb') as outfile:
zip = zipfile.ZipFile(outfile, 'w', zipfile.ZIP_DEFLATED)
topfolder = 'defoldsdk'
defold_home = os.path.normpath(os.path.join(self.dynamo_home, '..', '..'))
# Includes
includes = []
for root, dirs, files in os.walk(os.path.join(self.dynamo_home, "sdk/include")):
for file in files:
if file.endswith('.h'):
includes.append(os.path.join(root, file))
# proto _ddf.h + "res_*.h"
for root, dirs, files in os.walk(os.path.join(self.dynamo_home, "include")):
for file in files:
if file.endswith('.h') and ('ddf' in file or file.startswith('res_')):
includes.append(os.path.join(root, file))
self._add_files_to_zip(zip, includes, self.dynamo_home, topfolder)
# Configs
configs = ['extender/build.yml']
configs = [os.path.join(self.dynamo_home, x) for x in configs]
self._add_files_to_zip(zip, configs, self.dynamo_home, topfolder)
# Variants
variants = []
for root, dirs, files in os.walk(os.path.join(self.dynamo_home, "extender/variants")):
for file in files:
if file.endswith('.appmanifest'):
variants.append(os.path.join(root, file))
self._add_files_to_zip(zip, variants, self.dynamo_home, topfolder)
def _findlibs(libdir):
paths = os.listdir(libdir)
paths = [os.path.join(libdir, x) for x in paths if os.path.splitext(x)[1] in ('.a', '.dylib', '.so', '.lib', '.dll')]
return paths
def _findjars(jardir, ends_with):
paths = os.listdir(jardir)
paths = [os.path.join(jardir, x) for x in paths if x.endswith(ends_with)]
return paths
def _findjslibs(libdir):
paths = os.listdir(libdir)
paths = [os.path.join(libdir, x) for x in paths if os.path.splitext(x)[1] in ('.js',)]
return paths
def _findfiles(directory, exts):
paths = []
for root, dirs, files in os.walk(directory):
for f in files:
if os.path.splitext(f)[1] in exts:
paths.append(os.path.join(root, f))
return paths
# Dynamo libs
libdir = os.path.join(self.dynamo_home, 'lib/%s' % platform)
paths = _findlibs(libdir)
self._add_files_to_zip(zip, paths, self.dynamo_home, topfolder)
# External libs
libdir = os.path.join(self.dynamo_home, 'ext/lib/%s' % platform)
paths = _findlibs(libdir)
self._add_files_to_zip(zip, paths, self.dynamo_home, topfolder)
# Android Jars (Dynamo)
jardir = os.path.join(self.dynamo_home, 'share/java')
paths = _findjars(jardir, ('android.jar', 'dlib.jar', 'r.jar'))
self._add_files_to_zip(zip, paths, self.dynamo_home, topfolder)
# Android Jars (external)
external_jars = ("android-support-multidex.jar",
"androidx-multidex.jar",
"android.jar")
jardir = os.path.join(self.dynamo_home, 'ext/share/java')
paths = _findjars(jardir, external_jars)
self._add_files_to_zip(zip, paths, self.dynamo_home, topfolder)
# Win32 resource files
engine_rc = os.path.join(self.dynamo_home, 'lib/%s/defold.ico' % platform)
defold_ico = os.path.join(self.dynamo_home, 'lib/%s/engine.rc' % platform)
self._add_files_to_zip(zip, [engine_rc, defold_ico], self.dynamo_home, topfolder)
# JavaScript files
# js-web-pre-x files
jsdir = os.path.join(self.dynamo_home, 'share')
paths = _findjslibs(jsdir)
self._add_files_to_zip(zip, paths, self.dynamo_home, topfolder)
# libraries for js-web
jsdir = os.path.join(self.dynamo_home, 'lib/js-web/js/')
paths = _findjslibs(jsdir)
self._add_files_to_zip(zip, paths, self.dynamo_home, topfolder)
# libraries for wasm-web
jsdir = os.path.join(self.dynamo_home, 'lib/wasm-web/js/')
paths = _findjslibs(jsdir)
self._add_files_to_zip(zip, paths, self.dynamo_home, topfolder)
# .proto files
for d in ['share/proto/', 'ext/include/google/protobuf']:
protodir = os.path.join(self.dynamo_home, d)
paths = _findfiles(protodir, ('.proto',))
self._add_files_to_zip(zip, paths, self.dynamo_home, topfolder)
# pipeline tools
if platform in ('x86_64-darwin','x86_64-linux','x86_64-win32'): # needed for the linux build server
# protoc
protoc = os.path.join(self.dynamo_home, 'ext/bin/%s/protoc' % platform)
ddfc_py = os.path.join(self.dynamo_home, 'bin/ddfc.py')
ddfc_cxx = os.path.join(self.dynamo_home, 'bin/ddfc_cxx')
ddfc_cxx_bat = os.path.join(self.dynamo_home, 'bin/ddfc_cxx.bat')
ddfc_java = os.path.join(self.dynamo_home, 'bin/ddfc_java')
# protoc plugin (ddfc.py) needs our dlib_shared too
plugin_pb2 = os.path.join(self.dynamo_home, 'lib/python/plugin_pb2.py')
ddf_init = os.path.join(self.dynamo_home, 'lib/python/ddf/__init__.py')
ddf_extensions_pb2 = os.path.join(self.dynamo_home, 'lib/python/ddf/ddf_extensions_pb2.py')
ddf_math_pb2 = os.path.join(self.dynamo_home, 'lib/python/ddf/ddf_math_pb2.py')
dlib_init = os.path.join(self.dynamo_home, 'lib/python/dlib/__init__.py')
self._add_files_to_zip(zip, [protoc, ddfc_py, ddfc_java, ddfc_cxx, ddfc_cxx_bat, plugin_pb2, ddf_init, ddf_extensions_pb2, ddf_math_pb2, dlib_init], self.dynamo_home, topfolder)
# we don't want to run "pip install" on individual sdk files., so we copy the python files as-is
protobuf_files = []
for root, dirs, files in os.walk(os.path.join(self.dynamo_home, 'ext/lib/python/google')):
for f in files:
_, ext = os.path.splitext(f)
print (root, f)
if ext in ('.pyc',):
continue
path = os.path.join(root, f)
protobuf_files.append(path)
if not protobuf_files:
raise Exception("Failed to find python protobuf folder")
self._add_files_to_zip(zip, protobuf_files, self.dynamo_home, topfolder)
# bob pipeline classes
bob_light = os.path.join(self.dynamo_home, 'share/java/bob-light.jar')
self._add_files_to_zip(zip, [bob_light], self.dynamo_home, topfolder)
# For logging, print all paths in zip:
for x in zip.namelist():
print(x)
zip.close()
return outfile.name
return None
def build_platform_sdk(self):
# Helper function to make it easier to build a platform sdk locally
try:
path = self._package_platform_sdk(self.target_platform)
except Exception as e:
print ("Failed to package sdk for platform %s: %s" % (self.target_platform, e))
else:
print ("Wrote %s" % path)
def build_builtins(self):
with open(join(self.dynamo_home, 'share', 'builtins.zip'), 'wb') as f:
self._ziptree(join(self.dynamo_home, 'content', 'builtins'), outfile = f, directory = join(self.dynamo_home, 'content'))
def _strip_engine(self, path):
""" Strips the debug symbols from an executable """
if self.target_platform not in ['x86_64-linux','x86_64-darwin','arm64-darwin','x86_64-ios','armv7-android','arm64-android']:
return False
sdkfolder = join(self.ext, 'SDKs')
strip = "strip"
if 'android' in self.target_platform:
ANDROID_NDK_VERSION = '20'
ANDROID_NDK_ROOT = os.path.join(sdkfolder,'android-ndk-r%s' % ANDROID_NDK_VERSION)
ANDROID_GCC_VERSION = '4.9'
if target_platform == 'armv7-android':
ANDROID_PLATFORM = 'arm-linux-androideabi'
elif target_platform == 'arm64-android':
ANDROID_PLATFORM = 'aarch64-linux-android'
ANDROID_HOST = 'linux' if sys.platform == 'linux' else 'darwin'
strip = "%s/toolchains/%s-%s/prebuilt/%s-x86_64/bin/%s-strip" % (ANDROID_NDK_ROOT, ANDROID_PLATFORM, ANDROID_GCC_VERSION, ANDROID_HOST, ANDROID_PLATFORM)
if self.target_platform in ('x86_64-darwin','arm64-darwin','x86_64-ios') and 'linux' == sys.platform:
strip = os.path.join(sdkfolder, 'linux', sdk.PACKAGES_LINUX_CLANG, 'bin', 'x86_64-apple-darwin19-strip')
run.shell_command("%s %s" % (strip, path))
return True
def archive_engine(self):
sha1 = self._git_sha1()
full_archive_path = join(sha1, 'engine', self.target_platform).replace('\\', '/')
share_archive_path = join(sha1, 'engine', 'share').replace('\\', '/')
java_archive_path = join(sha1, 'engine', 'share', 'java').replace('\\', '/')
dynamo_home = self.dynamo_home
self.full_archive_path = full_archive_path
bin_dir = self.build_utility.get_binary_path()
lib_dir = self.target_platform
# upload editor 2.0 launcher
if self.target_platform in ['x86_64-linux', 'x86_64-darwin', 'x86_64-win32']:
launcher_name = format_exes("launcher", self.target_platform)[0]
launcherbin = join(bin_dir, launcher_name)
self.upload_to_archive(launcherbin, '%s/%s' % (full_archive_path, launcher_name))
# upload gdc tool on desktop platforms
if self.is_desktop_target():
gdc_name = format_exes("gdc", self.target_platform)[0]
gdc_bin = join(bin_dir, gdc_name)
self.upload_to_archive(gdc_bin, '%s/%s' % (full_archive_path, gdc_name))
for n in ['dmengine', 'dmengine_release', 'dmengine_headless']:
for engine_name in format_exes(n, self.target_platform):
engine = join(bin_dir, engine_name)
self.upload_to_archive(engine, '%s/%s' % (full_archive_path, engine_name))
engine_stripped = join(bin_dir, engine_name + "_stripped")
shutil.copy2(engine, engine_stripped)
if self._strip_engine(engine_stripped):
self.upload_to_archive(engine_stripped, '%s/stripped/%s' % (full_archive_path, engine_name))
if 'win32' in self.target_platform:
pdb = join(bin_dir, os.path.splitext(engine_name)[0] + '.pdb')
self.upload_to_archive(pdb, '%s/%s' % (full_archive_path, os.path.basename(pdb)))
if 'web' in self.target_platform:
engine_mem = join(bin_dir, engine_name + '.mem')
if os.path.exists(engine_mem):
self.upload_to_archive(engine_mem, '%s/%s.mem' % (full_archive_path, engine_name))
engine_symbols = join(bin_dir, engine_name + '.symbols')
if os.path.exists(engine_symbols):
self.upload_to_archive(engine_symbols, '%s/%s.symbols' % (full_archive_path, engine_name))
elif 'darwin' in self.target_platform:
engine_symbols = join(bin_dir, engine_name + '.dSYM.zip')
if os.path.exists(engine_symbols):
self.upload_to_archive(engine_symbols, '%s/%s' % (full_archive_path, os.path.basename(engine_symbols)))
zip_archs = []
if not self.skip_docs:
zip_archs.append('ref-doc.zip')
if not self.skip_builtins:
zip_archs.append('builtins.zip')
for zip_arch in zip_archs:
self.upload_to_archive(join(dynamo_home, 'share', zip_arch), '%s/%s' % (share_archive_path, zip_arch))
if self.target_platform == 'x86_64-linux':
# NOTE: It's arbitrary for which platform we archive dlib.jar. Currently set to linux 64-bit
self.upload_to_archive(join(dynamo_home, 'share', 'java', 'dlib.jar'), '%s/dlib.jar' % (java_archive_path))
if 'android' in self.target_platform:
files = [
('share/java', 'classes.dex'),
('ext/share/java', 'android.jar'),
]
for f in files:
src = join(dynamo_home, f[0], f[1])
self.upload_to_archive(src, '%s/%s' % (full_archive_path, f[1]))
resources = self._ziptree(join(dynamo_home, 'ext', 'share', 'java', 'res'), directory = join(dynamo_home, 'ext', 'share', 'java'))
self.upload_to_archive(resources, '%s/android-resources.zip' % (full_archive_path))
if self.is_desktop_target():
libs = ['dlib', 'texc', 'particle']
for lib in libs:
lib_name = format_lib('%s_shared' % (lib), self.target_platform)
lib_path = join(dynamo_home, 'lib', lib_dir, lib_name)
self.upload_to_archive(lib_path, '%s/%s' % (full_archive_path, lib_name))
sdkpath = self._package_platform_sdk(self.target_platform)
self.upload_to_archive(sdkpath, '%s/defoldsdk.zip' % full_archive_path)
def _get_build_flags(self):
supported_tests = {}