-
Notifications
You must be signed in to change notification settings - Fork 139
/
bootstrap.py
1094 lines (900 loc) · 44.2 KB
/
bootstrap.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
# bootstrap.py
# created: January 8, 2020
#
# This script checks for the necessary tools to construct and build the rhino3dm native and wrapper libraries
# for all supported platforms. See related scripts in this folder for other steps in the process.
#
# This script is inspired by - but deviates from - the "Scripts To Rule Them All" pattern:
# https://github.com/github/scripts-to-rule-them-all
# ---------------------------------------------------- Imports ---------------------------------------------------------
from __future__ import (division, absolute_import, print_function, unicode_literals)
import subprocess
import sys
import os
from os import listdir
from os.path import isfile, isdir, join
import argparse
import ssl
import re
import glob
import platform
if sys.version_info >= (3,):
import urllib.request as urllib2
import urllib.parse as urlparse
else:
import urllib2
import urlparse
import urllib
from subprocess import Popen, PIPE
from sys import platform as _platform
# ---------------------------------------------------- Globals ---------------------------------------------------------
xcode_logging = False
valid_platform_args = ["windows", "linux", "macos", "ios", "android", "js", "python"]
submodules = ["opennurbs", "draco", "pybind11"]
script_folder = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
src_folder = os.path.abspath(os.path.join(script_folder, "..", "src"))
lib_folder = os.path.abspath(os.path.join(src_folder, "lib"))
class BuildTool:
def __init__(self, name, abbr, currently_using, archive_url, install_notes):
self.name = name
self.abbr = abbr
self.currently_using = currently_using
self.archive_url = archive_url
self.install_notes = install_notes
# ---------------------------------------------------- Logging ---------------------------------------------------------
# colors for terminal reporting
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def print_warning_message(warning_message):
warning_prefix = " warning: "
if xcode_logging:
print(warning_prefix + warning_message)
else:
print(bcolors.BOLD + bcolors.WARNING + warning_prefix.upper() + bcolors.ENDC + bcolors.WARNING + warning_message +
bcolors.ENDC)
def print_error_message(error_message):
error_prefix = " error: "
if xcode_logging:
print(error_prefix + error_message)
else:
print(f"{bcolors.BOLD}{bcolors.FAIL}{error_prefix.upper()}{bcolors.ENDC}{bcolors.FAIL}{error_message}{bcolors.ENDC}")
def print_ok_message(ok_message):
ok_prefix = " ok: "
if xcode_logging:
print(ok_prefix + ok_message)
else:
print(bcolors.BOLD + bcolors.OKBLUE + ok_prefix.upper() + bcolors.ENDC + bcolors.OKBLUE + ok_message +
bcolors.ENDC)
# ------------------------------------------------- Versions -----------------------------------------------------------
def split_by_numbers(x):
r = re.compile('(\\d+)')
l = r.split(x)
return [int(y) if y.isdigit() else y for y in l]
def normalize_version(v):
parts = [int(x) for x in v.split(".")]
while parts[-1] == 0:
parts.pop()
return parts
def compare_versions(v1, v2):
a = normalize_version(v1)
b = normalize_version(v2)
return (a > b) - (a < b)
def read_required_versions():
# check to make sure that the Current Development Tools.md file exists, exit with error if not
current_development_tools_file_path = os.path.join(script_folder, '..', 'Current_Development_Tools.md')
if not os.path.exists(current_development_tools_file_path):
print_error_message("Could not find the Current_Development_Tools.md (rhino3dm) file listing our "
"current development tools.\n This file should be in: " +
current_development_tools_file_path + "\n Exiting script.")
sys.exit(1)
# Windows
msbuild = BuildTool("msbuild", "msbuild", "", "", "")
# Linux
dotnet = BuildTool("dotnet Core SDK", "dotnet", "", "", "")
# iOS
xamios = BuildTool("Xamarin.iOS", "xamios", "", "", "")
# Android
ndk = BuildTool("Android NDK", "ndk", "", "", "")
xamandroid = BuildTool("Xamarin.Android", "xamandroid", "", "", "")
# Javascript
emscripten = BuildTool("Emscripten", "emscripten", "", "", "")
# Shared
git = BuildTool("Git", "git", "", "", "")
python = BuildTool("Python", "python", "", "", "")
cmake = BuildTool("CMake", "cmake", "", "", "")
mdk = BuildTool("Mono MDK", "mdk", "", "", "")
macos = BuildTool("macOS", "macos", "", "", "")
xcode = BuildTool("Xcode", "xcode", "", "", "")
# create the build tools dictionary
build_tools = dict(msbuild=msbuild,
dotnet=dotnet,
macos=macos,
xamios=xamios,
ndk=ndk,
xamandroid=xamandroid,
emscripten=emscripten,
git=git,
python=python,
cmake=cmake,
mdk=mdk,
xcode=xcode)
# open and read Current Development Tools.md and load required versions
current_development_tools_file = open(current_development_tools_file_path, "r")
for line in current_development_tools_file:
for tool in build_tools:
tool_prefix = tool
if tool == "python":
if sys.version_info[0] < 3:
tool_prefix = tool + "2"
else:
tool_prefix = tool + "3"
ver_prefix = tool_prefix + "_currently_using = "
archive_prefix = tool_prefix + "_archive_url"
archive_suffix = ''
if _platform == "win32":
archive_suffix = "_windows = "
if _platform == "darwin":
archive_suffix = "_macos = "
if _platform == "linux" or _platform == "linux2":
archive_suffix = "_linux = "
archive_string = archive_prefix + " = "
archive_string_with_platform = archive_prefix + archive_suffix
install_notes_prefix = tool_prefix + "_install_notes"
install_notes_suffix = ''
if _platform == "win32":
install_notes_suffix = "_windows = "
if _platform == "darwin":
install_notes_suffix = "_macos = "
if _platform == "linux" or _platform == "linux2":
install_notes_suffix = "_linux = "
install_notes_string = install_notes_prefix + " = "
install_notes_string_with_platform = install_notes_prefix + install_notes_suffix
if ver_prefix in line:
build_tools[str(tool)].currently_using = line.split('= ', 1)[1].split('`', 1)[0]
if archive_string in line:
build_tools[str(tool)].archive_url = line.split('= ', 1)[1].split('`', 1)[0]
if archive_string_with_platform in line:
build_tools[str(tool)].archive_url = line.split('= ', 1)[1].split('`', 1)[0]
if install_notes_string in line:
build_tools[str(tool)].install_notes = line.split('= ', 1)[1].split('`', 1)[0]
if install_notes_string_with_platform in line:
build_tools[str(tool)].install_notes = line.split('= ', 1)[1].split('`', 1)[0]
return build_tools
# -------------------------------------------------- Checks ------------------------------------------------------------
def print_platform_preamble(platform_target_name):
print("")
if xcode_logging:
print("Checking " + platform_target_name + " Dependencies...")
else:
print(bcolors.BOLD + "Checking " + platform_target_name + " Dependencies..." + bcolors.ENDC)
def print_check_preamble(build_tool):
print("")
if xcode_logging:
print("Checking " + build_tool.name + "...")
else:
print(bcolors.BOLD + "Checking " + build_tool.name + "..." + bcolors.ENDC)
def format_install_instructions(build_tool):
install_instructions = ''
if build_tool.archive_url:
install_instructions = install_instructions + "You can download " + build_tool.name + " from: " \
+ build_tool.archive_url
if build_tool.install_notes:
install_instructions = install_instructions + " " + build_tool.install_notes
return install_instructions
def print_version_comparison(build_tool, running_version):
print(" This system is running " + build_tool.name + " " + running_version)
print(" We are currently using " + build_tool.name + " " + build_tool.currently_using)
version_alignment = compare_versions(running_version, build_tool.currently_using)
if version_alignment == 0:
print_ok_message(build_tool.name + " version " + running_version + " found.")
elif version_alignment > 0:
print_warning_message(
build_tool.name + " version " + running_version + " found, a newer version. We are currently using "
+ build_tool.currently_using + ". ")
elif version_alignment < 0:
print_warning_message(
build_tool.name + " version " + running_version + " found, an older version. We are currently using "
+ build_tool.currently_using + ". " + format_install_instructions(build_tool))
return version_alignment
def check_submodules():
for submodule in submodules:
path_to_submodule = os.path.abspath(os.path.join(lib_folder, submodule))
path_to_git = os.path.abspath(os.path.join(path_to_submodule, '.git'))
if not os.path.exists(path_to_git):
print_error_message("submodule at: " + path_to_submodule + " does not appear to be initialized. Please run: git submodule update --init")
return False
return True
def check_macos(build_tool):
if _platform != 'darwin':
print_warning_message("macOS is only supported on macOS...duh.")
return False
print_check_preamble(build_tool)
running_version = ''
if sys.version_info >= (3,):
running_version = platform.mac_ver()[0]
else:
p = subprocess.Popen(['sw_vers'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
sw_vers_output = p.communicate()
running_version = sw_vers_output[0].split('\n')[1].split('\t')[1]
print_version_comparison(build_tool, running_version)
return
def check_git(build_tool):
print_check_preamble(build_tool)
try:
p = subprocess.Popen(['git', '--version'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
except OSError:
print_error_message(build_tool.name + " not found. " + format_install_instructions(build_tool))
return False
if sys.version_info[0] < 3:
running_version = p.communicate()[0].splitlines()[0].split('git version ', 1)[1]
#version_output = (p.communicate()[0].splitlines()[0]).decode("utf-8")
#running_version = re.sub(r'git version\s(\d{0,5}.\d{0,5}.\d{0,5}).*', r'\1', version_output, re.MULTILINE)
else:
running_version, err = p.communicate()
if err:
print_warning_message(err)
return False
running_version = running_version.decode('utf-8').splitlines()[0].split('git version ', 1)[1]
#version_output = (p.communicate()[0].splitlines()[0]).decode("utf-8")
#running_version = re.sub(r'git version\s(\d{0,5}.\d{0,5}.\d{0,5}).*', r'\1', version_output, re.MULTILINE)
if _platform == "darwin":
running_version = running_version.split()[0]
if _platform == "win32":
running_version = running_version.split(".windows")[0]
print_version_comparison(build_tool, running_version)
return True
def check_python(build_tool):
print_check_preamble(build_tool)
running_version = ".".join([str(sys.version_info.major), str(sys.version_info.minor), str(sys.version_info.micro)])
print_version_comparison(build_tool, running_version)
return True
def check_xcode(build_tool):
if _platform != 'darwin':
print_warning_message("Xcode is only supported on macOS.")
return False
print_check_preamble(build_tool)
try:
p = subprocess.Popen(['xcodebuild', '-version'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
except OSError:
print_error_message("Error running xcodebuild -version. Do you have Xcode installed? "
+ format_install_instructions(build_tool))
return False
warning_message_one = "Xcode appears to be in the Applications folder, but Xcode does not know which build " \
"tools to use. Please launch Xcode and navigate to Xcode > Preferences > Locations and " \
"verify that the Command Line Tools are set to the proper version."
warning_message_two = "Xcode (or xcodebuild) does not seem to be in the Applications folder. If you believe " \
"this is an error, please launch Xcode and navigate to Xcode > Preferences > Locations " \
"and verify that the Command Line Tools are set to the proper version."
if sys.version_info[0] < 3:
running_version = p.communicate()[0]
if "Build version " not in running_version:
if os.path.exists("/Applications/Xcode.app"):
print_warning_message(warning_message_one)
return False
else:
print_warning_message(warning_message_two)
return False
running_version = running_version.split('Build version', 1)[0].split('Xcode ', 1)[1].split('\n', 1)[0]
else:
running_version, err = p.communicate()
if err:
print_warning_message(err)
return False
if "Build version " not in running_version.decode('utf-8'):
if os.path.exists("/Applications/Xcode.app"):
print_warning_message(warning_message_one)
return False
else:
print_warning_message(warning_message_two)
return False
running_version = running_version.decode('utf-8')
running_version = running_version.splitlines()[0].strip().split('Xcode ', 1)[1].split('\n', 1)[0]
print_version_comparison(build_tool, running_version)
return True
def check_emscripten(build_tool):
def version_from_emscripten_output (output):
first_line = output.splitlines()[0]
return re.match (r".*([0-9]+\.[0-9]+\.[0-9]+).*", first_line).group (1)
print_check_preamble(build_tool)
# check to make sure that the $EMSDK path variable has been set
if _platform != "win32" and _platform != "win64":
emsdk_path = ''
cmd = 'echo $EMSDK'
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
if sys.version_info[0] < 3:
emsdk_path = p.communicate()[0].strip()
else:
emsdk_path, err = p.communicate()
emsdk_path = emsdk_path.strip()
if not emsdk_path:
print_error_message(build_tool.name + " EMSDK path not set." + format_install_instructions(build_tool))
return False
emcc = 'emcc.bat' if _platform == 'win32' else 'emcc'
try:
p = subprocess.Popen([emcc, '--version'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
except OSError:
print_error_message(build_tool.name + " not found. " + format_install_instructions(build_tool))
return False
if sys.version_info[0] < 3:
running_version = version_from_emscripten_output (p.communicate()[0])
if not running_version:
print_error_message(build_tool.name + " not found." + format_install_instructions(build_tool))
return False
else:
running_version, err = p.communicate()
if err:
print_error_message(err)
return False
running_version = version_from_emscripten_output (running_version.decode('utf-8'))
print_version_comparison(build_tool, running_version)
return True
def check_cmake(build_tool):
print_check_preamble(build_tool)
try:
p = subprocess.Popen(['cmake', '--version'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
except OSError:
print_error_message(build_tool.name + " not found. " + format_install_instructions(build_tool))
return False
if sys.version_info[0] < 3:
running_version = p.communicate()[0].splitlines()[0].split('cmake version ', 1)[1]
else:
running_version, err = p.communicate()
if err:
print_warning_message(err)
return
running_version = re.split(r'cmake3? version ', running_version.decode('utf-8').splitlines()[0].strip())[1]
print_version_comparison(build_tool, running_version)
return True
def check_mdk(build_tool):
print_check_preamble(build_tool)
# check to see if the Mono.framework exists at all...
running_mono_framework_version_file_path = '/Library/Frameworks/Mono.framework/Versions/Current/VERSION'
if not os.path.exists(running_mono_framework_version_file_path):
print_error_message(build_tool.name + " not found. " + format_install_instructions(build_tool))
return False
# read in the contents of /Library/Frameworks/Mono.framework/Versions/Current/VERSION
running_mono_framework_version_file = open(running_mono_framework_version_file_path, "r")
running_version = ''
for line in running_mono_framework_version_file:
running_version = line.split('\n', 1)[0]
print_version_comparison(build_tool, running_version)
return True
def check_xamios(build_tool):
print_check_preamble(build_tool)
# check to see if the Xamarin.iOS.framework exists at all...
running_xamios_framework_version_file_path = os.path.join('/', 'Library', 'Frameworks',
'Xamarin.iOS.Framework', "Versions",
"Current", "Version")
if not os.path.exists(running_xamios_framework_version_file_path):
print_error_message(build_tool.name + " not found. " + format_install_instructions(build_tool))
return False
# read in the contents of /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/VERSION
running_xamios_framework_version_file = open(running_xamios_framework_version_file_path, "r")
running_version = ''
for line in running_xamios_framework_version_file:
running_version = line.split('\n', 1)[0]
print_version_comparison(build_tool, running_version)
return True
def check_ndk(build_tool):
print_check_preamble(build_tool)
# figure out where the NDK might be installed - multiple versions are
# frequently installed, so we need to figure out which is the root folder
# containing these versions...
ndk_root_path = ''
ndk_root_path_spaceless = ''
drive_prefix = ''
android_ndk_path = ''
if _platform == "win32":
program_files = os.environ["ProgramW6432"]
ndk_root_path = os.path.join(program_files, "Android", "ndk")
drive_prefix = os.path.splitdrive(sys.executable)[0]
ndk_root_path_spaceless = drive_prefix + '\\' + 'Android\\' + 'ndk\\'
if _platform == "darwin":
home = os.path.expanduser("~")
ndk_root_path = os.path.join(home, "Library", "Android", "sdk", "ndk")
print(ndk_root_path)
print(os.environ.get('ANDROID_NDK_ROOT'))
if not os.path.exists(ndk_root_path):
print_error_message(build_tool.name + " not found. " + format_install_instructions(build_tool))
return False
# we are going to search the root folder for valid ndk versions, so we need to set up
# a search pattern that is per-platform
ndk_build_sub_search = ''
if _platform == "win32":
ndk_build_sub_search = "\\android-ndk-r??\\ndk-build"
versions_found = dict()
print(ndk_root_path + ndk_build_sub_search)
if glob.glob(ndk_root_path + ndk_build_sub_search):
ndk_build_sub_search = ''
has_ndk = True
path_to_search = ndk_root_path
only_folders = [d for d in listdir(path_to_search) if isdir(join(path_to_search, d))]
for folder in only_folders:
version_id = folder
# create a path to source.properites
ver_info_file = os.path.join(ndk_root_path, folder, "source.properties")
if os.path.exists(ver_info_file):
src_props_file = open(ver_info_file, "r")
for line in src_props_file:
if "Pkg.Revision =" in line:
build_number = line.strip().split('= ')[1]
versions_found[version_id] = build_number
src_props_file.close()
print(versions_found)
if not versions_found:
print_error_message(build_tool.name + " not found. " + format_install_instructions(build_tool))
return False
# check to see if we have the current NDK version in the list
running_version = ''
for version_id, build_number in versions_found.items():
if build_number == build_tool.currently_using:
running_version = build_number
# check which path actually exists
android_ndk_path = os.path.join(ndk_root_path, "android-ndk-" + version_id, '')
if os.path.exists(android_ndk_path) == False:
android_ndk_path = os.path.join(ndk_root_path, version_id, '')
# if we don't find a match, get the highest version we can find...
if not running_version:
sorted_versions_found = sorted(versions_found, key=split_by_numbers)
if sorted_versions_found:
version_id = sorted_versions_found[-1]
running_version = versions_found[version_id]
android_ndk_path = os.path.join(ndk_root_path, "android-ndk-" + version_id, '')
print_version_comparison(build_tool, running_version)
android_env_variable = os.environ.get('ANDROID_NDK') #
if not android_env_variable or os.environ.get('ANDROID_NDK') != android_ndk_path:
print_warning_message('The NDK was found but the ANDROID_NDK variable is not properly set. Setting to ' + android_ndk_path + ' now.')
os.environ["ANDROID_NDK"] = android_ndk_path
return android_ndk_path
def check_xamandroid(build_tool):
print_check_preamble(build_tool)
# check to see if the Xamarin.Android.framework exists at all...
running_xamandroid_framework_version_file_path = os.path.join('/', 'Library', 'Frameworks',
'Xamarin.Android.Framework', "Versions",
"Current", "Version")
if not os.path.exists(running_xamandroid_framework_version_file_path):
print_error_message(build_tool.name + " not found. " + format_install_instructions(build_tool))
return False
# read in the contents of /Library/Frameworks/Xamarin.Android.framework/Versions/Current/VERSION
running_xamandroid_framework_version_file = open(running_xamandroid_framework_version_file_path, "r")
running_version = ''
for line in running_xamandroid_framework_version_file:
running_version = line.split('\n', 1)[0]
print_version_comparison(build_tool, running_version)
return True
def check_msbuild(build_tool):
print_check_preamble(build_tool)
# msbuild ships with the mdk on macOS and Linux, so that check should suffice there.
if _platform != "win32" and _platform != "win64":
print_warning_message("Checking for " + build_tool.name + " requires that you run this script on Windows.")
return False
# prepare to do some searching
drive_prefix = os.path.splitdrive(sys.executable)[0]
program_files = os.environ.get("PROGRAMFILES")
running_version = ''
msbuild_path = ''
# Check for the Visual Studio MSBuild
if not msbuild_path:
visual_studio_path = os.path.join(drive_prefix, program_files, "Microsoft Visual Studio")
if os.path.exists(visual_studio_path):
versions_found = []
vs_ver_subsearch = "\\20??\\*"
if glob.glob(visual_studio_path + vs_ver_subsearch):
path_to_search = visual_studio_path
only_folders = [d for d in listdir(path_to_search) if isdir(join(path_to_search, d))]
for folder in only_folders:
if folder.startswith("20"):
versions_found.append(folder)
if versions_found:
latest_version = str(max(versions_found))
vs_path_version = os.path.join(visual_studio_path, latest_version)
vs_editions = os.listdir(vs_path_version)
vs_edition = vs_editions[0]
if len(vs_editions) > 1:
if "Enterprise" in vs_editions:
vs_edition = "Enterprise"
elif "Professional" in vs_editions:
vs_edition = "Professional"
elif "Community" in vs_editions:
vs_edition = "Community"
path_to_search = os.path.join(vs_path_version, vs_edition, "MSBuild", "Current", "Bin", "MSBuild.exe")
if os.path.exists(path_to_search):
msbuild_path = path_to_search
#Check if msbuild is in the path
if not msbuild_path:
try:
p = subprocess.Popen(['where', 'msbuild'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
if sys.version_info[0] < 3:
response = p.communicate()
if "Could not find files" not in response:
if "MSBuild.exe" in response:
msbuild_path = response
else:
err, response = p.communicate()
if "Could not find files" not in response:
if "MSBuild.exe" in response:
msbuild_path = response
except:
msbuild_path = ''
# Check for the .NET Framework MSBuild (probably not the wisest to use though)
if not msbuild_path:
dotnet_framework_path = os.path.join(drive_prefix, "\\", "Windows", "Microsoft.NET", "Framework")
if os.path.exists(dotnet_framework_path):
versions_found = dict()
dotnet_ver_subsearch = "\\v*\\MSBuild.exe"
if glob.glob(dotnet_framework_path + dotnet_ver_subsearch):
path_to_search = dotnet_framework_path
only_folders = [d for d in listdir(path_to_search) if isdir(join(path_to_search, d))]
for folder in only_folders:
if folder.startswith("v"):
version_id = folder.split("v")[1]
versions_found[version_id] = folder
if versions_found:
#debug
print(versions_found)
sorted_versions_found = sorted(versions_found, key=split_by_numbers)
if sorted_versions_found:
version_id = sorted_versions_found[-1]
path_to_search = os.path.join(dotnet_framework_path, versions_found[version_id], "MSBuild.exe")
if os.path.exists(path_to_search):
msbuild_path = path_to_search
if not msbuild_path:
print_error_message(build_tool.name + " not found. " + format_install_instructions(build_tool))
return False
# Check the msbuild version
try:
p = subprocess.Popen([msbuild_path, '/Version'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
if sys.version_info[0] < 3:
running_version = p.communicate()[0].splitlines()[-1].strip()
else:
running_version, err = p.communicate()
if err:
print_warning_message(err)
return
running_version = running_version.decode('utf-8').splitlines()[-1].strip()
except:
running_version = ''
if not running_version:
print_error_message("unable to determine the version of " + build_tool.name)
return False
print_version_comparison(build_tool, running_version)
return msbuild_path
def check_dotnet(build_tool):
print_check_preamble(build_tool)
try:
p = subprocess.Popen(['which', 'dotnet'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
if sys.version_info[0] < 3:
output = p.communicate()
if not output[0] and not output[1]:
print_error_message(build_tool.name + " not found. " + format_install_instructions(build_tool))
return False
else:
output, err = p.communicate()
if not output and not err:
print_error_message(build_tool.name + " not found. " + format_install_instructions(build_tool))
return False
except OSError:
print_error_message(build_tool.name + " not found. " + format_install_instructions(build_tool))
return False
running_version = ''
# check to see if there are any sdks in the list that match the currently used one
dotnet_sdks = []
dotnet_listsdks_process = subprocess.Popen(['dotnet', '--list-sdks'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
if sys.version_info[0] < 3:
dotnet_sdks = dotnet_listsdks_process.communicate()[0].splitlines()
else:
dotnet_listsdks_output, err = dotnet_listsdks_process.communicate()
if err:
print_error_message(err)
return False
dotnet_sdks = dotnet_listsdks_output.decode('utf').splitlines()
for sdk in dotnet_sdks:
version_number = sdk.split(' [')[0]
if build_tool.currently_using in str(sdk):
running_version = build_tool.currently_using
# fall-back: check the version on the system...
if not running_version:
dotnet_version_process = subprocess.Popen(['dotnet', '--version'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
if sys.version_info[0] < 3:
running_version = dotnet_version_process.communicate()[0].strip()
else:
dotnet_version_output, err = dotnet_version_process.communicate()
running_version = dotnet_version_output.decode('utf-8').strip()
if not running_version:
print_error_message(build_tool.name + " not found. " + format_install_instructions(build_tool))
return False
print_version_comparison(build_tool, running_version)
return True
def check_handler(check, build_tools):
if check == "windows":
print_platform_preamble("Windows")
if _platform != "win32" and _platform != "win64":
print_error_message("Checking dependencies for Windows requires that you run this script on Windows")
return False
check_git(build_tools["git"])
check_python(build_tools["python"])
check_cmake(build_tools["cmake"])
check_msbuild(build_tools["msbuild"])
if check == "linux":
print_platform_preamble("Linux")
if _platform != "linux" and _platform != "linux2":
print_error_message("Checking dependencies for Linux requires that you run this script on Linux.")
return False
check_git(build_tools["git"])
check_python(build_tools["python"])
check_cmake(build_tools["cmake"])
check_dotnet(build_tools["dotnet"])
if check == "macos":
print_platform_preamble("macOS")
if _platform != "darwin":
print_error_message("Checking dependencies for macOS requires that you run this script on macOS")
return False
check_macos(build_tools["macos"])
check_xcode(build_tools["xcode"])
check_git(build_tools["git"])
check_python(build_tools["python"])
check_cmake(build_tools["cmake"])
check_mdk(build_tools["mdk"])
if check == "ios":
print_platform_preamble("iOS")
if _platform != "darwin":
print_error_message("Checking dependencies for iOS requires that you run this script on macOS")
return False
check_macos(build_tools["macos"])
check_xcode(build_tools["xcode"])
check_git(build_tools["git"])
check_python(build_tools["python"])
check_cmake(build_tools["cmake"])
check_mdk(build_tools["mdk"])
check_xamios(build_tools["xamios"])
if check == "android":
print_platform_preamble("Android")
if _platform != "darwin":
print_error_message("Checking dependencies for Android requires that you run this script on macOS")
return False
check_macos(build_tools["macos"])
check_xcode(build_tools["xcode"])
check_git(build_tools["git"])
check_python(build_tools["python"])
check_cmake(build_tools["cmake"])
check_mdk(build_tools["mdk"])
check_ndk(build_tools["ndk"])
check_xamandroid(build_tools["xamandroid"])
if check == "js":
print_platform_preamble("JavaScript")
if _platform == "darwin":
check_macos(build_tools["macos"])
check_xcode(build_tools["xcode"])
check_git(build_tools["git"])
check_python(build_tools["python"])
check_emscripten(build_tools["emscripten"])
check_cmake(build_tools["cmake"])
if check == "python":
print_platform_preamble("Python")
if _platform == "darwin":
check_macos(build_tools["macos"])
check_xcode(build_tools["xcode"])
check_git(build_tools["git"])
check_python(build_tools["python"])
check_emscripten(build_tools["emscripten"])
check_cmake(build_tools["cmake"])
if check not in valid_platform_args:
if check == "all":
for tool in build_tools:
getattr(sys.modules[__name__], 'check_' + tool)(build_tools[tool])
else:
getattr(sys.modules[__name__], 'check_' + check)(build_tools[check])
# ------------------------------------------------- Downloads ----------------------------------------------------------
def print_platform_download_preamble(platform_target_name):
print("")
if xcode_logging:
print("Download all tools for " + platform_target_name + "...")
else:
print(bcolors.BOLD + "Download all tools for " + platform_target_name + "..." + bcolors.ENDC)
def connected_to_internet(host='http://google.com'):
try:
urllib.urlopen(host)
return True
except:
print_error_message("No internet connection available.")
return False
def download_file(url, dest=None):
if not os.environ.get('PYTHONHTTPSVERIFY', '') and getattr(ssl, '_create_unverified_context', None):
ssl._create_default_https_context = ssl._create_unverified_context
u = urllib2.urlopen(url)
scheme, netloc, path, query, fragment = urlparse.urlsplit(url)
filename = os.path.basename(path)
if not filename:
filename = 'downloaded.file'
if dest:
filename = os.path.join(dest, filename)
with open(filename, 'wb') as f:
meta = u.info()
meta_func = meta.getheaders if hasattr(meta, 'getheaders') else meta.get_all
meta_length = meta_func("Content-Length")
file_size = None
if meta_length:
file_size = int(meta_length[0])
print("URL: {0} Bytes: {1}".format(url, file_size))
file_size_dl = 0
block_sz = 8192
while True:
buffer = u.read(block_sz)
if not buffer:
break
file_size_dl += len(buffer)
f.write(buffer)
status = "{0:16}".format(file_size_dl)
if file_size:
status += " [{0:6.2f}%]".format(file_size_dl * 100 / file_size)
status += chr(13)
print(status, end="")
print()
return filename
def download_dependency(build_tool):
print("")
if xcode_logging:
print("Downloading " + build_tool.name + "...")
else:
print(bcolors.BOLD + "Downloading " + build_tool.name + "..." + bcolors.ENDC)
downloads_folder = '/Downloads/'
if _platform == "win32" or _platform == "win64":
downloads_folder = '\\Downloads\\'
destination_folder = os.path.expanduser("~") + downloads_folder
if build_tool.archive_url:
download_file(build_tool.archive_url, destination_folder)
print_ok_message('Downloaded to ' + destination_folder + build_tool.archive_url.split('/')[-1])
else:
print_warning_message(build_tool.name + ' does not have a url on file. ' + build_tool.install_notes)
def download_handler(download, build_tools):
if download == "windows":
print_platform_download_preamble("Windows")
if _platform != "win32" and _platform != "win64":
print_error_message("Downloading dependencies for Windows requires that you run this script on Windows")
return False
download_dependency(build_tools["git"])
download_dependency(build_tools["python"])
download_dependency(build_tools["cmake"])
download_dependency(build_tools["msbuild"])
if download == "linux":
print_platform_download_preamble("Linux")
if _platform != "linux" and _platform != "linux2":
print_error_message("Downloading dependencies for Linux requires that you run this script on Linux")
return False
download_dependency(build_tools["git"])
download_dependency(build_tools["python"])
download_dependency(build_tools["cmake"])
download_dependency(build_tools["dotnet"])
if download == "macos":
print_platform_download_preamble("macOS")
if _platform != "darwin":
print_error_message("Downloading dependencies for macOS requires that you run this script on macOS")
return False
download_dependency(build_tools["macos"])
download_dependency(build_tools["xcode"])
download_dependency(build_tools["git"])
download_dependency(build_tools["python"])
download_dependency(build_tools["cmake"])
download_dependency(build_tools["mdk"])
if download == "ios":
print_platform_download_preamble("iOS")
if _platform != "darwin":
print_error_message("Downloading dependencies for iOS requires that you run this script on macOS")
return False
download_dependency(build_tools["macos"])
download_dependency(build_tools["xcode"])
download_dependency(build_tools["git"])
download_dependency(build_tools["python"])
download_dependency(build_tools["cmake"])
download_dependency(build_tools["mdk"])
download_dependency(build_tools["xamios"])
if download == "android":
print_platform_download_preamble("Android")
if _platform == "darwin":
download_dependency(build_tools["macos"])
download_dependency(build_tools["xcode"])
download_dependency(build_tools["git"])
download_dependency(build_tools["python"])
download_dependency(build_tools["cmake"])
download_dependency(build_tools["mdk"])
download_dependency(build_tools["ndk"])
download_dependency(build_tools["xamandroid"])
if download == "js":
print_platform_download_preamble("JavaScript")
if _platform == "darwin":
download_dependency(build_tools["macos"])
download_dependency(build_tools["xcode"])
download_dependency(build_tools["git"])
download_dependency(build_tools["python"])
download_dependency(build_tools["emscripten"])
download_dependency(build_tools["cmake"])
if download == "python":
print_platform_download_preamble("Python")
if _platform == "darwin":