-
Notifications
You must be signed in to change notification settings - Fork 565
Expand file tree
/
Copy pathsystem-dependencies.sh
More file actions
executable file
·997 lines (866 loc) · 31.4 KB
/
system-dependencies.sh
File metadata and controls
executable file
·997 lines (866 loc) · 31.4 KB
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
#!/bin/bash -e
set -o pipefail
cd $(dirname $0)
# Detect if we're running on Linux
if [[ "$(uname -s)" == "Linux" ]]; then
IS_LINUX=1
# On Linux, ignore all macOS-specific dependencies
IGNORE_OSX=1
IGNORE_XCODE=1
IGNORE_XCODE_COMPONENTS=1
IGNORE_VISUAL_STUDIO=1
IGNORE_SIMULATORS=1
IGNORE_OLD_SIMULATORS=1
IGNORE_7Z=1
IGNORE_HOMEBREW=1
IGNORE_SHELLCHECK=1
IGNORE_YAMLLINT=1
IGNORE_PYTHON3=1
else
IS_LINUX=
fi
FAIL=
PROVISION_DOWNLOAD_DIR=/tmp/x-provisioning
SUDO=sudo
VERBOSE=
OPTIONAL_SIMULATORS=1
OPTIONAL_OLD_SIMULATORS=1
# parse command-line arguments
while ! test -z $1; do
case $1 in
--no-sudo)
SUDO=
shift
;;
--provision-xcode)
PROVISION_XCODE=1
unset IGNORE_XCODE
shift
;;
--provision-xcode-components)
PROVISION_XCODE_COMPONENTS=1
unset IGNORE_XCODE_COMPONENTS
shift
;;
--provision)
# historical reasons :(
PROVISION_XCODE=1
PROVISION_VS=1
unset IGNORE_XCODE
unset IGNORE_VISUAL_STUDIO
shift
;;
--provision-*-studio)
PROVISION_VS=1
unset IGNORE_VISUAL_STUDIO
shift
;;
--provision-7z)
PROVISION_7Z=1
unset IGNORE_7Z
shift
;;
--provision-autotools)
# this is an old argument, just ignore it
shift
;;
--provision-python3)
# building mono from source requires having python3 installed
PROVISION_PYTHON3=1
unset IGNORE_PYTHON3
shift
;;
--provision-simulators)
PROVISION_SIMULATORS=1
unset OPTIONAL_SIMULATORS
unset IGNORE_SIMULATORS
shift
;;
--provision-old-simulators)
PROVISION_OLD_SIMULATORS=1
unset OPTIONAL_OLD_SIMULATORS
unset IGNORE_OLD_SIMULATORS
shift
;;
--provision-dotnet)
PROVISION_DOTNET=1
unset IGNORE_DOTNET
shift
;;
--provision-shellcheck)
PROVISION_SHELLCHECK=1
unset IGNORE_SHELLCHECK
shift
;;
--provision-yamllint)
PROVISION_YAMLLINT=1
unset IGNORE_YAMLLINT
shift
;;
--provision-all)
PROVISION_VS=1
unset IGNORE_VISUAL_STUDIO
PROVISION_XCODE=1
unset IGNORE_XCODE
PROVISION_7Z=1
unset IGNORE_7Z
PROVISION_HOMEBREW=1
unset IGNORE_HOMEBREW
PROVISION_SIMULATORS=1
unset IGNORE_SIMULATORS
PROVISION_OLD_SIMULATORS=1
unset IGNORE_OLD_SIMULATORS
PROVISION_PYTHON3=1
unset IGNORE_PYTHON3
PROVISION_DOTNET=1
unset IGNORE_DOTNET
PROVISION_SHELLCHECK=1
unset IGNORE_SHELLCHECK
PROVISION_YAMLLINT=1
unset IGNORE_YAMLLINT
PROVISION_XCODE_COMPONENTS=1
unset IGNORE_XCODE_COMPONENTS
shift
;;
--ignore-all)
IGNORE_OSX=1
IGNORE_VISUAL_STUDIO=1
IGNORE_XCODE=1
IGNORE_7Z=1
IGNORE_HOMEBREW=1
IGNORE_SIMULATORS=1
IGNORE_PYTHON3=1
IGNORE_DOTNET=1
IGNORE_SHELLCHECK=1
IGNORE_YAMLLINT=1
IGNORE_XCODE_COMPONENTS=1
shift
;;
--ignore-osx)
IGNORE_OSX=1
shift
;;
--ignore-xcode)
IGNORE_XCODE=1
shift
;;
--ignore-xcode-components)
IGNORE_XCODE_COMPONENTS=1
shift
;;
--ignore-*-studio)
IGNORE_VISUAL_STUDIO=1
shift
;;
--ignore-autotools)
# this is an old argument, just ignore it
shift
;;
--ignore-python3)
IGNORE_PYTHON3=1
shift
;;
--ignore-7z)
IGNORE_7Z=1
shift
;;
--ignore-simulators)
IGNORE_SIMULATORS=1
shift
;;
--ignore-old-simulators)
IGNORE_OLD_SIMULATORS=1
shift
;;
--enforce-simulators)
unset IGNORE_SIMULATORS
unset OPTIONAL_SIMULATORS
shift
;;
--ignore-dotnet)
IGNORE_DOTNET=1
shift
;;
--ignore-shellcheck)
IGNORE_SHELLCHECK=1
shift
;;
--ignore-yamllint)
IGNORE_YAMLLINT=1
shift
;;
-v | --verbose)
set -x
shift
VERBOSE=1
;;
*)
echo "Unknown argument: $1"
exit 1
;;
esac
done
# reporting functions
COLOR_RED=$(tput setaf 1 2>/dev/null || true)
COLOR_ORANGE=$(tput setaf 3 2>/dev/null || true)
COLOR_MAGENTA=$(tput setaf 5 2>/dev/null || true)
COLOR_BLUE=$(tput setaf 6 2>/dev/null || true)
COLOR_CLEAR=$(tput sgr0 2>/dev/null || true)
COLOR_RESET=uniquesearchablestring
FAILURE_PREFIX=
if test -z "$COLOR_RED"; then FAILURE_PREFIX="** failure ** "; fi
function fail () {
echo " $FAILURE_PREFIX${COLOR_RED}${1//${COLOR_RESET}/${COLOR_RED}}${COLOR_CLEAR}"
FAIL=1
}
function warn () {
echo " ${COLOR_ORANGE}${1//${COLOR_RESET}/${COLOR_ORANGE}}${COLOR_CLEAR}"
}
function ok () {
echo " ${1//${COLOR_RESET}/${COLOR_CLEAR}}"
}
function log () {
echo " ${1//${COLOR_RESET}/${COLOR_CLEAR}}"
}
# $1: the version to check
# $2: the minimum version to check against
function is_at_least_version () {
ACT_V=$1
MIN_V=$2
if [[ "$ACT_V" == "$MIN_V" ]]; then
return 0
fi
IFS=. read -a V_ACT <<< "$ACT_V"
IFS=. read -a V_MIN <<< "$MIN_V"
# get the minimum # of elements
AC=${#V_ACT[@]}
MC=${#V_MIN[@]}
COUNT=$(($AC>$MC?$MC:$AC))
C=0
while (( $C < $COUNT )); do
ACT=${V_ACT[$C]}
MIN=${V_MIN[$C]}
if (( $ACT > $MIN )); then
return 0
elif (( "$MIN" > "$ACT" )); then
return 1
fi
let C++
done
if (( $AC == $MC )); then
# identical?
return 0
fi
if (( $AC > $MC )); then
# more version fields in actual than min: OK
return 0
elif (( $AC == $MC )); then
# entire strings aren't equal (first check in function), but each individual field is?
return 0
else
# more version fields in min than actual (1.0 vs 1.0.1 for instance): not OK
return 1
fi
}
function delete_all_simulator_runtimes ()
{
log "Executing 'xcrun simctl runtime delete all'..."
xcrun simctl runtime delete all
local TMPFILE
TMPFILE=$(mktemp)
local COUNT
# sadly simulator deletion is done asynchronously, so we have to wait until they're all gone
log "Waiting for the simulator runtimes to be deleted..."
printf " "
for i in $(seq 1 60); do
sleep 1
xcrun simctl runtime list -j --json-output="$TMPFILE"
COUNT=$(jq "length" -r "$TMPFILE")
if [[ "$COUNT" == "0" ]]; then
break
fi
printf "$COUNT"
done
printf "\n"
if [[ "$COUNT" != "0" ]]; then
warn "Waited for 60 seconds, but there are still $COUNT simulators waiting to deleted."
fi
rm -rf "$TMPFILE"
}
SIMULATORS_WITHOUT_X64=()
SIMULATORS_WITHOUT_X64_COUNT=0
function get_non_universal_simulator_runtimes ()
{
local TMPFILE
TMPFILE=$(mktemp)
xcrun simctl runtime list -j --json-output="$TMPFILE"
# this json query filters the json to simulator runtimes where iOS/tvOS >= 26.0 and where x64 is *not* supported (which we need to run x64 apps in the simulator on arm64)
JQ_QUERY='map({identifier: .identifier, version: .version, supportedArchitectures: .supportedArchitectures | join("|"), majorVersion: .version | split(".")[0] | tonumber }) | map(select(.majorVersion>=26) ) | map(select(.supportedArchitectures | contains("x86_64") | not)) | .[].identifier'
SIMULATORS_WITHOUT_X64=($(jq "$JQ_QUERY" -r "$TMPFILE"))
SIMULATORS_WITHOUT_X64_COUNT="${#SIMULATORS_WITHOUT_X64[@]}"
rm -f "$TMPFILE"
}
function xcodebuild_download_selected_platforms ()
{
local XCODE_DEVELOPER_ROOT
local XCODE_NAME
local XCODE_IS_STABLE
local XCODE_VERSION
local IOS_NUGET_OS_VERSION
local IOS_BUILD_VERSION
local TVOS_NUGET_OS_VERSION
local TVOS_BUILD_VERSION
XCODE_DEVELOPER_ROOT=$(grep XCODE_DEVELOPER_ROOT= Make.config | sed 's/.*=//')
XCODE_NAME=$(basename "$(dirname "$(dirname "$XCODE_DEVELOPER_ROOT")")")
# we use the same logic here as in Make.config to determine whether we're using a stable version of Xcode or not (search for XCODE_IS_STABLE/XCODE_IS_PREVIEW)
XCODE_IS_STABLE=$(echo "$XCODE_NAME" | sed -e 's@^Xcode[_0-9.]*[.]app$@YES@')
XCODE_VERSION=$(grep ^XCODE_VERSION= Make.config | sed 's/.*=//')
IOS_BUILD_VERSION=
TVOS_BUILD_VERSION=
if is_at_least_version "$XCODE_VERSION" 26.0; then
# we always want the universal variant, so that we can run x64 test apps on arm64
IOS_BUILD_VERSION=" -architectureVariant universal"
TVOS_BUILD_VERSION=" -architectureVariant universal"
fi
local TMPFILE
TMPFILE=$(mktemp)
log "Checking if there are any simulator runtimes that aren't ready..."
xcrun simctl runtime list --json "--json-output=$TMPFILE"
NOT_READY_COUNT=$(jq 'map({identifier: .identifier, state: .state}) | map(select(.state != "Ready")) | length' "$TMPFILE")
if [[ "$NOT_READY_COUNT" != "0" ]]; then
log "Found simulator runtimes that aren't ready, will proceed to delete all simulator runtimes:"
(
export IFS=$'\n'
for line in $(jq 'map({identifier: .identifier, state: .state}) | map(select(.state != "Ready"))[] | "\(.identifier): \(.state)"' -r "$TMPFILE"); do
log " $line"
done
)
delete_all_simulator_runtimes
else
log " none found."
fi
# If we're executing on arm64, we need simulator runtimes that support x64 in order to run
# x64 apps in the simulator (aka the universal architecture variant). If we have any simulator
# runtimes that don't support x64, then delete those, so that we can re-install the universal
# variant.
local DOTNET_ARCH
if [[ "$(arch)" == "arm64" ]]; then
DOTNET_ARCH=arm64
elif [[ "$(sysctl -n sysctl.proc_translated 2>/dev/null)" == "1" ]]; then
DOTNET_ARCH=arm64
fi
if [[ "$DOTNET_ARCH" == "arm64" ]]; then
log "Looking for iOS/tvOS 26+ simulator runtimes that don't support x64..."
get_non_universal_simulator_runtimes
if [[ "$SIMULATORS_WITHOUT_X64_COUNT" -gt 0 ]]; then
log "Found ${SIMULATORS_WITHOUT_X64_COUNT} simulator runtimes that don't support x64, which will now be deleted: ${SIMULATORS_WITHOUT_X64[@]}"
for sim in "${SIMULATORS_WITHOUT_X64[@]}"; do
log "Executing 'xcrun simctl runtime delete $sim'"
xcrun simctl runtime delete "$sim"
done
# sadly simulator deletion is done asynchronously, so we have to wait until they're all gone
log "Waiting for the simulators to be deleted..."
printf " "
for i in $(seq 1 60); do
sleep 1
get_non_universal_simulator_runtimes
if [[ "$SIMULATORS_WITHOUT_X64_COUNT" == "0" ]]; then
break
fi
printf "$SIMULATORS_WITHOUT_X64_COUNT"
done
printf "\n"
if [[ "$SIMULATORS_WITHOUT_X64_COUNT" != "0" ]]; then
warn "Waited for 60 seconds, but there are still $SIMULATORS_WITHOUT_X64_COUNT simulators waiting to deleted."
fi
else
log "All installed iOS/tvOS 26+ simulators support x64"
fi
fi
log "Executing '$XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild -downloadPlatform iOS$IOS_BUILD_VERSION' $1"
"$XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild" -downloadPlatform iOS $IOS_BUILD_VERSION 2>&1 | sed 's/^/ /'
log "Executing '$XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild -downloadPlatform tvOS$TVOS_BUILD_VERSION' $1"
"$XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild" -downloadPlatform tvOS $TVOS_BUILD_VERSION 2>&1 | sed 's/^/ /'
return 0
}
function download_xcode_platforms ()
{
if test -n "$IGNORE_SIMULATORS"; then return; fi
local XCODE_VERSION
local XCODE_DEVELOPER_ROOT="$1"
XCODE_VERSION=$(grep ^XCODE_VERSION= Make.config | sed 's/.*=//')
if ! is_at_least_version "$XCODE_VERSION" 14.0; then
# Nothing to do here
log "This version of Xcode ($XCODE_VERSION) does not have any additional platforms to download"
return
fi
if test -z "$PROVISION_SIMULATORS"; then
warn " Xcode may have additional platforms that must be downloaded. Execute './system-dependencies.sh --provision-simulators' to install those platforms (or alternatively ${COLOR_MAGENTA}export IGNORE_SIMULATORS=1${COLOR_RESET} to skip this check)"
return
fi
log "Xcode has additional platforms that must be downloaded ($MUST_INSTALL_RUNTIMES), so installing those."
log "Executing '$SUDO pkill -9 -f CoreSimulator.framework'"
$SUDO pkill -9 -f "CoreSimulator.framework" || true
if ! xcodebuild_download_selected_platforms; then
log "Executing '$XCODE_DEVELOPER_ROOT/usr/bin/simctl runtime list -v"
"$XCODE_DEVELOPER_ROOT/usr/bin/simctl" runtime list -v 2>&1 | sed 's/^/ /'
# Don't exit here, just hope for the best instead.
(
set +x
echo "##vso[task.logissue type=warning;sourcepath=system-dependencies.sh]Failed to download all simulator platforms, this may result in problems executing tests in the simulator."
set -x
)
else
log "Executing '$XCODE_DEVELOPER_ROOT/usr/bin/simctl runtime list -v"
"$XCODE_DEVELOPER_ROOT/usr/bin/simctl" runtime list -v 2>&1 | sed 's/^/ /'
log "Executing '$XCODE_DEVELOPER_ROOT/usr/bin/simctl list -v"
"$XCODE_DEVELOPER_ROOT/usr/bin/simctl" list -v 2>&1 | sed 's/^/ /'
fi
log "Executing '$SUDO $XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild -runFirstLaunch'"
$SUDO "$XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild" -runFirstLaunch
log "Executed '$SUDO $XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild -runFirstLaunch'"
log "Finished installing Xcode platforms"
}
function run_xcode_first_launch ()
{
local XCODE_VERSION="$1"
local XCODE_DEVELOPER_ROOT="$2"
# xcodebuild -runFirstLaunch seems to have been introduced in Xcode 9
if ! is_at_least_version "$XCODE_VERSION" 9.0; then
return
fi
if ! "$XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild" -checkFirstLaunchStatus; then
if ! test -z "$PROVISION_XCODE"; then
# Run the first launch tasks
log "Executing '$SUDO $XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild -runFirstLaunch'"
$SUDO "$XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild" -runFirstLaunch
log "Executed '$SUDO $XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild -runFirstLaunch'"
else
fail "Xcode has pending first launch tasks. Execute 'make fix-xcode-first-run' to execute those tasks."
return
fi
fi
}
function install_specific_xcode () {
local XCODE_URL=`grep XCODE$1_URL= Make.config | sed 's/.*=//'`
local XCODE_VERSION=`grep XCODE$1_VERSION= Make.config | sed 's/.*=//'`
local XCODE_DEVELOPER_ROOT="$2"
local XCODE_ROOT="$(dirname "$(dirname "$XCODE_DEVELOPER_ROOT")")"
if test -z $XCODE_URL; then
fail "No XCODE$1_URL set in Make.config, cannot provision"
return
fi
mkdir -p $PROVISION_DOWNLOAD_DIR
log "Downloading Xcode $XCODE_VERSION from $XCODE_URL to $PROVISION_DOWNLOAD_DIR..."
local XCODE_NAME=`basename $XCODE_URL`
local XCODE_DMG=$PROVISION_DOWNLOAD_DIR/$XCODE_NAME
# To test this script with new Xcode versions, copy the downloaded file to $XCODE_DMG,
# uncomment the following curl line, and run ./system-dependencies.sh --provision-xcode
if test -f "$HOME/Downloads/$XCODE_NAME"; then
log "Found $XCODE_NAME in your ~/Downloads folder, copying that version to $XCODE_DMG instead of re-downloading it."
cp "$HOME/Downloads/$XCODE_NAME" "$XCODE_DMG"
else
curl -L $XCODE_URL > $XCODE_DMG
fi
if [[ ${XCODE_DMG: -4} == ".dmg" ]]; then
local XCODE_MOUNTPOINT=$PROVISION_DOWNLOAD_DIR/$XCODE_NAME-mount
log "Mounting $XCODE_DMG into $XCODE_MOUNTPOINT..."
hdiutil attach $XCODE_DMG -mountpoint $XCODE_MOUNTPOINT -quiet -nobrowse
log "Removing previous Xcode from $XCODE_ROOT"
rm -Rf $XCODE_ROOT
log "Installing Xcode $XCODE_VERSION to $XCODE_ROOT..."
cp -R $XCODE_MOUNTPOINT/*.app $XCODE_ROOT
log "Unmounting $XCODE_DMG..."
hdiutil detach $XCODE_MOUNTPOINT -quiet
elif [[ ${XCODE_DMG: -4} == ".xip" ]]; then
log "Extracting $XCODE_DMG..."
pushd . > /dev/null
cd $PROVISION_DOWNLOAD_DIR
# make sure there's nothing interfering
rm -Rf *.app
rm -Rf $XCODE_ROOT
# extract
xip --expand "$XCODE_DMG"
log "Installing Xcode $XCODE_VERSION to $XCODE_ROOT..."
mv *.app $XCODE_ROOT
popd > /dev/null
else
fail "Don't know how to install $XCODE_DMG"
fi
rm -f $XCODE_DMG
log "Removing any com.apple.quarantine attributes from the installed Xcode"
$SUDO xattr -s -d -r com.apple.quarantine $XCODE_ROOT
if is_at_least_version $XCODE_VERSION 5.0; then
log "Accepting Xcode license"
$SUDO $XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild -license accept
fi
if is_at_least_version "$XCODE_VERSION" 9.0; then
run_xcode_first_launch "$XCODE_VERSION" "$XCODE_DEVELOPER_ROOT"
elif is_at_least_version $XCODE_VERSION 8.0; then
PKGS="MobileDevice.pkg MobileDeviceDevelopment.pkg XcodeSystemResources.pkg"
for pkg in $PKGS; do
if test -f "$XCODE_DEVELOPER_ROOT/../Resources/Packages/$pkg"; then
log "Installing $pkg"
$SUDO /usr/sbin/installer -dumplog -verbose -pkg "$XCODE_DEVELOPER_ROOT/../Resources/Packages/$pkg" -target /
log "Installed $pkg"
else
log "Not installing $pkg because it doesn't exist."
fi
done
fi
log "Clearing xcrun cache..."
xcrun -k
ok "Xcode $XCODE_VERSION provisioned"
}
function install_coresimulator ()
{
local XCODE_DEVELOPER_ROOT
local CORESIMULATOR_PKG
local CORESIMULATOR_PKG_DIR
local XCODE_ROOT
local TARGET_CORESIMULATOR_VERSION
local CURRENT_CORESIMULATOR_VERSION
XCODE_DEVELOPER_ROOT=$(grep XCODE_DEVELOPER_ROOT= Make.config | sed 's/.*=//')
XCODE_ROOT=$(dirname "$(dirname "$XCODE_DEVELOPER_ROOT")")
CORESIMULATOR_PKG=$XCODE_ROOT/Contents/Resources/Packages/XcodeSystemResources.pkg
if ! test -f "$CORESIMULATOR_PKG"; then
warn "Could not find XcodeSystemResources.pkg (which contains CoreSimulator.framework) in $XCODE_DEVELOPER_ROOT ($CORESIMULATOR_PKG doesn't exist)."
return
fi
# Get the CoreSimulator.framework version from our Xcode
# Extract the .pkg to get the pkg's PackageInfo file, which contains the CoreSimulator.framework version.
CORESIMULATOR_PKG_DIR=$(mktemp -d)
pkgutil --expand "$CORESIMULATOR_PKG" "$CORESIMULATOR_PKG_DIR/extracted"
if ! TARGET_CORESIMULATOR_VERSION=$(xmllint --xpath 'string(/pkg-info/bundle-version/bundle[@id="com.apple.CoreSimulator"]/@CFBundleShortVersionString)' "$CORESIMULATOR_PKG_DIR/extracted/PackageInfo"); then
rm -rf "$CORESIMULATOR_PKG_DIR"
warn "Failed to look up the CoreSimulator version of $XCODE_DEVELOPER_ROOT"
return
fi
rm -rf "$CORESIMULATOR_PKG_DIR"
# Get the CoreSimulator.framework currently installed
local CURRENT_CORESIMULATOR_PATH=/Library/Developer/PrivateFrameworks/CoreSimulator.framework/Versions/A/CoreSimulator
local CURRENT_CORESIMULATOR_VERSION=0.0
if test -f "$CURRENT_CORESIMULATOR_PATH"; then
CURRENT_CORESIMULATOR_VERSION=$(otool -L $CURRENT_CORESIMULATOR_PATH | grep "$CURRENT_CORESIMULATOR_PATH.*current version" | sed -e 's/.*current version//' -e 's/)//' -e 's/[[:space:]]//g' | uniq)
fi
# Either version may be composed of either 1, 2 or 3 numbers.
# We only care about the first two, so strip off the 3rd number if it exists.
# shellcheck disable=SC2001
CURRENT_CORESIMULATOR_VERSION=$(echo "$CURRENT_CORESIMULATOR_VERSION" | sed 's/\([0-9]*[.][0-9]*\).*/\1/')
# shellcheck disable=SC2001
TARGET_CORESIMULATOR_VERSION=$(echo "$TARGET_CORESIMULATOR_VERSION" | sed 's/\([0-9]*[.][0-9]*\).*/\1/')
# Add a .0 if we only got one number
if [[ "${CURRENT_CORESIMULATOR_VERSION/./}" == "${CURRENT_CORESIMULATOR_VERSION}" ]]; then
CURRENT_CORESIMULATOR_VERSION=$CURRENT_CORESIMULATOR_VERSION.0
fi
if [[ "${TARGET_CORESIMULATOR_VERSION/./}" == "${TARGET_CORESIMULATOR_VERSION}" ]]; then
TARGET_CORESIMULATOR_VERSION=$TARGET_CORESIMULATOR_VERSION.0
fi
# Compare versions to see if we got what we need
if [[ x"$TARGET_CORESIMULATOR_VERSION" == x"$CURRENT_CORESIMULATOR_VERSION" ]]; then
log "Found CoreSimulator.framework $CURRENT_CORESIMULATOR_VERSION (exactly $TARGET_CORESIMULATOR_VERSION is recommended)"
return
fi
if test -z $PROVISION_XCODE; then
# This is not a failure for now, until this logic has been tested thoroughly
warn "You should have exactly CoreSimulator.framework version $TARGET_CORESIMULATOR_VERSION (found $CURRENT_CORESIMULATOR_VERSION). Execute './system-dependencies.sh --provision-xcode' to install the expected version."
return
fi
# Just installing the package won't work, because there's a version check somewhere
# that prevents the macOS installer from downgrading, so remove the existing
# CoreSimulator.framework manually first.
log "Installing CoreSimulator.framework $CURRENT_CORESIMULATOR_VERSION..."
$SUDO rm -Rf /Library/Developer/PrivateFrameworks/CoreSimulator.framework
$SUDO installer -pkg "$CORESIMULATOR_PKG" -target /
CURRENT_CORESIMULATOR_VERSION=$(otool -L $CURRENT_CORESIMULATOR_PATH | grep "$CURRENT_CORESIMULATOR_PATH.*current version" | sed -e 's/.*current version//' -e 's/)//' -e 's/[[:space:]]//g')
log "Installed CoreSimulator.framework $CURRENT_CORESIMULATOR_VERSION successfully."
}
function check_specific_xcode () {
local XCODE_DEVELOPER_ROOT=`grep XCODE$1_DEVELOPER_ROOT= Make.config | sed 's/.*=//'`
local XCODE_VERSION=`grep XCODE$1_VERSION= Make.config | sed 's/.*=//'`
local XCODE_ROOT=$(dirname `dirname $XCODE_DEVELOPER_ROOT`)
if ! test -d $XCODE_DEVELOPER_ROOT; then
if ! test -z $PROVISION_XCODE; then
install_specific_xcode "$1" "$XCODE_DEVELOPER_ROOT"
else
fail "You must install Xcode ($XCODE_VERSION) in $XCODE_ROOT. You can download Xcode $XCODE_VERSION here: https://developer.apple.com/downloads/index.action?name=Xcode"
fi
return
else
if is_at_least_version $XCODE_VERSION 5.0; then
if ! $XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild -license check >/dev/null 2>&1; then
if ! test -z $PROVISION_XCODE; then
$SUDO $XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild -license accept
else
fail "The license for Xcode $XCODE_VERSION has not been accepted. Execute '$SUDO $XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild' to review the license and accept it."
return
fi
fi
fi
run_xcode_first_launch "$XCODE_VERSION" "$XCODE_DEVELOPER_ROOT"
fi
local XCODE_ACTUAL_VERSION=`/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "$XCODE_DEVELOPER_ROOT/../version.plist"`
# this is a hard match, having 4.5 when requesting 4.4 is not OK (but 4.4.1 is OK)
if [[ ! "x$XCODE_ACTUAL_VERSION" =~ "x$XCODE_VERSION" ]]; then
fail "You must install Xcode $XCODE_VERSION in $XCODE_ROOT (found $XCODE_ACTUAL_VERSION). You can download Xcode $XCODE_VERSION here: https://developer.apple.com/downloads/index.action?name=Xcode";
return
fi
ok "Found Xcode $XCODE_ACTUAL_VERSION in $XCODE_ROOT"
}
function check_xcode () {
if ! test -z $IGNORE_XCODE; then return; fi
# must have latest Xcode in /Applications/Xcode<version>.app
check_specific_xcode
install_coresimulator
local IOS_SDK_VERSION MACOS_SDK_VERSION TVOS_SDK_VERSION
local XCODE_DEVELOPER_ROOT=`grep ^XCODE_DEVELOPER_ROOT= Make.config | sed 's/.*=//'`
IOS_SDK_VERSION=$(grep ^IOS_NUGET_OS_VERSION= Make.versions | sed -e 's/.*=//')
MACOS_SDK_VERSION=$(grep ^MACOS_NUGET_OS_VERSION= Make.versions | sed -e 's/.*=//')
TVOS_SDK_VERSION=$(grep ^TVOS_NUGET_OS_VERSION= Make.versions | sed -e 's/.*=//')
download_xcode_platforms "$XCODE_DEVELOPER_ROOT" "$TVOS_SDK_VERSION"
local D=$XCODE_DEVELOPER_ROOT/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator${IOS_SDK_VERSION}.sdk
if test ! -d $D -a -z "$FAIL"; then
fail "The directory $D does not exist. If you've updated the Xcode location it means you also need to update IOS_SDK_VERSION in Make.config."
fi
local D=$XCODE_DEVELOPER_ROOT/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${MACOS_SDK_VERSION}.sdk
if test ! -d $D -a -z "$FAIL"; then
fail "The directory $D does not exist. If you've updated the Xcode location it means you also need to update MACOS_SDK_VERSION in Make.config."
fi
local D=$XCODE_DEVELOPER_ROOT/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS${TVOS_SDK_VERSION}.sdk
if test ! -d $D -a -z "$FAIL"; then
fail "The directory $D does not exist. If you've updated the Xcode location it means you also need to update TVOS_SDK_VERSION in Make.config."
fi
}
function check_xcode_components ()
{
if ! test -z "$IGNORE_XCODE_COMPONENTS"; then return; fi
local COMPONENTS=(MetalToolchain)
for comp in "${COMPONENTS[@]}"; do
componentInfo=$(xcrun xcodebuild -showComponent "$comp")
local NEEDS_INSTALL=
local NEEDS_UPDATE=
if [[ "$componentInfo" =~ .*Status:" "installedUpdateAvailable.* ]]; then
NEEDS_UPDATE=1
elif [[ "$componentInfo" =~ .*Status:" "installed.* ]]; then
NEEDS_INSTALL=
else
NEEDS_INSTALL=1
fi
if test -z "$NEEDS_INSTALL$NEEDS_UPDATE"; then
ok "The Xcode component ${COLOR_BLUE}$comp${COLOR_CLEAR} is installed."
elif test -z "$PROVISION_XCODE_COMPONENTS"; then
if test -n "$NEEDS_UPDATE"; then
fail "The Xcode component ${COLOR_BLUE}$comp${COLOR_RESET} is installed, but an update is available. Execute ${COLOR_MAGENTA}xcrun xcodebuild -downloadComponent $comp${COLOR_RESET} or ${COLOR_MAGENTA}./system-dependencies.sh --provision-xcode-components${COLOR_RESET} to install."
else
fail "The Xcode component ${COLOR_BLUE}$comp${COLOR_RESET} is not installed. Execute ${COLOR_MAGENTA}xcrun xcodebuild -downloadComponent $comp${COLOR_RESET} or ${COLOR_MAGENTA}./system-dependencies.sh --provision-xcode-components${COLOR_RESET} to install."
fi
fail "Alternatively you can ${COLOR_MAGENTA}export IGNORE_XCODE_COMPONENTS=1${COLOR_RED} to skip this check."
elif test -n "$PROVISION_XCODE_COMPONENTS"; then
log "Installing the Xcode component ${COLOR_BLUE}$comp${COLOR_CLEAR} by executing ${COLOR_BLUE}xcrun xcodebuild -downloadComponent $comp${COLOR_CLEAR}..."
xcrun xcodebuild -downloadComponent "$comp"
ok "Successfully installed the Xcode component ${COLOR_BLUE}$comp${COLOR_CLEAR}."
fi
done
log "Clearing xcrun cache..."
xcrun -k
}
function install_shellcheck () {
if ! brew --version >& /dev/null; then
fail "Asked to install shellcheck, but brew is not installed."
return
fi
ok "Installing ${COLOR_BLUE}shellcheck${COLOR_RESET}..."
brew install shellcheck
}
function install_yamllint () {
if ! brew --version >& /dev/null; then
fail "Asked to install yamllint, but brew is not installed."
return
fi
ok "Installing ${COLOR_BLUE}yamllint${COLOR_RESET}..."
brew install yamllint
}
function install_python3 () {
if ! brew --version >& /dev/null; then
fail "Asked to install python3, but brew is not installed."
return
fi
ok "Installing ${COLOR_BLUE}python3${COLOR_RESET}..."
brew install python3
}
function check_shellcheck () {
if ! test -z $IGNORE_SHELLCHECK; then return; fi
IFStmp=$IFS
IFS='
'
if SHELLCHECK_VERSION=($(shellcheck --version 2>/dev/null)); then
ok "Found shellcheck ${SHELLCHECK_VERSION[1]} (no specific version is required)"
elif ! test -z $PROVISION_SHELLCHECK; then
install_shellcheck
else
fail "You must install shellcheck. The easiest way is to use homebrew, and execute ${COLOR_MAGENTA}brew install shellcheck${COLOR_RESET}."
fi
IFS=$IFS_tmp
}
function check_yamllint () {
if ! test -z $IGNORE_YAMLLINT; then return; fi
IFStmp=$IFS
IFS='
'
if YAMLLINT_VERSION=($(yamllint --version 2>/dev/null)); then
ok "Found ${YAMLLINT_VERSION[0]} (no specific version is required)"
elif ! test -z $PROVISION_YAMLLINT; then
install_yamllint
else
fail "You must install yamllint. The easiest way is to use homebrew, and execute ${COLOR_MAGENTA}brew install yamllint${COLOR_RESET}."
fi
IFS=$IFS_tmp
}
function check_python3 () {
if ! test -z $IGNORE_PYTHON3; then return; fi
IFStmp=$IFS
IFS='
'
if PYTHON3_VERSION=$(python3 --version 2>/dev/null); then
ok "Found $PYTHON3_VERSION (no specific version is required)"
elif ! test -z $PROVISION_PYTHON3; then
install_python3
else
fail "You must install python3. The easiest way is to use homebrew, and execute ${COLOR_MAGENTA}brew install python3${COLOR_RESET}."
fi
IFS=$IFS_tmp
}
function check_osx_version () {
if ! test -z $IGNORE_OSX; then return; fi
MIN_OSX_BUILD_VERSION=`grep MIN_OSX_BUILD_VERSION= Make.config | sed 's/.*=//'`
ACTUAL_OSX_VERSION=$(sw_vers -productVersion)
if ! is_at_least_version $ACTUAL_OSX_VERSION $MIN_OSX_BUILD_VERSION; then
fail "You must have at least OSX $MIN_OSX_BUILD_VERSION (found $ACTUAL_OSX_VERSION)"
return
fi
ok "Found OSX $ACTUAL_OSX_VERSION (at least $MIN_OSX_BUILD_VERSION is required)"
}
function check_checkout_dir () {
# Skip on Linux - this check is macOS-specific
if test -n "$IS_LINUX"; then
return
fi
# use apple script to get the possibly translated special folders and check that we are not a subdir
for special in documents downloads desktop; do
path=$(osascript -e "set result to POSIX path of (path to $special folder as string)")
if [[ $PWD == $path* ]]; then
fail "Your checkout is under $path which is a special path. This can result in problems running the tests."
fi
done
ok "Checkout location will not result in test problems."
}
function install_7z () {
if ! brew --version >& /dev/null; then
fail "Asked to install 7z, but brew is not installed."
return
fi
brew install p7zip
}
function check_7z () {
if ! test -z $IGNORE_7Z; then return; fi
if ! 7z &> /dev/null; then
if ! test -z $PROVISION_7Z; then
install_7z
else
fail "You must install 7z (no specific version is required)"
fi
return
fi
ok "Found 7z (no specific version is required)"
}
function check_homebrew ()
{
if ! test -z $IGNORE_HOMEBREW; then return; fi
IFStmp=$IFS
IFS='
'
if HOMEBREW_VERSION=($(brew --version 2>/dev/null)); then
ok "Found Homebrew ($HOMEBREW_VERSION)"
elif ! test -z $PROVISION_HOMEBREW; then
log "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
HOMEBREW_VERSION=($(brew --version 2>/dev/null))
log "Installed Homebrew ($HOMEBREW_VERSION)"
else
warn "Could not find Homebrew. Homebrew is required to auto-provision some dependencies (p7zip), but not required otherwise."
fi
IFS=$IFS_tmp
}
function check_old_simulators ()
{
if test -n "$IGNORE_OLD_SIMULATORS"; then return; fi
local EXTRA_SIMULATORS
local XCODE
local XCODE_DEVELOPER_ROOT
XCODE_DEVELOPER_ROOT=$(grep XCODE$1_DEVELOPER_ROOT= Make.config | sed 's/.*=//')
IFS=' ' read -r -a EXTRA_SIMULATORS <<< "$(grep ^EXTRA_SIMULATORS= Make.config | sed 's/.*=//')"
XCODE=$(dirname "$(dirname "$XCODE_DEVELOPER_ROOT")")
if ! test -d "$XCODE"; then
# can't test unless Xcode is present
warn "Can't check if simulators are available unless Xcode is already installed."
return
fi
SD_TMP_DIR=$(mktemp -d /tmp/system-dependencies.XXXXXX)
trap 'rm -rf -- "$SD_TMP_DIR"' EXIT
TMP_FILE=$SD_TMP_DIR/simulator-runtimes.json
xcrun simctl list runtimes --json --json-output "$TMP_FILE"
local action=warn
if test -z $OPTIONAL_OLD_SIMULATORS; then
action=fail
fi
local os
local versionName
local version
for spec in "${EXTRA_SIMULATORS[@]}"; do
os=${spec/:*/}
versionName=${spec/*:/}
version=$(grep "^${versionName}=" Make.config | sed 's/.*=//')
OS_TMP_FILE=$SD_TMP_DIR/$os-$version.json
jq ".runtimes[] | select(.platform == \"$os\" and .version == \"$version\" and .isAvailable == true and .isInternal == false) | [ { \"version\":.version, \"name\":.name, \"identifier\":.identifier } ]" < "$TMP_FILE" > "$OS_TMP_FILE"
#echo $OS_TMP_FILE
LENGTH=$(jq length < "$OS_TMP_FILE")
if [[ "$LENGTH" != "" && "$LENGTH" -gt 0 ]]; then
ok "Found the $os $version simulator."
elif test -z "$PROVISION_OLD_SIMULATORS"; then
$action "The $os $version simulator is not installed. Execute ${COLOR_MAGENTA}xcodebuild -downloadPlatform $os -buildVersion $version${COLOR_RESET} to install."
else
warn "The $os $version simulator is not installed. Now executing ${COLOR_BLUE}"$XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild" -downloadPlatform $os -buildVersion $version${COLOR_RESET} to install..."
"$XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild" -downloadPlatform "$os" -buildVersion "$version" 2>&1 | sed 's/^/ /'
warn "Successfully executed ${COLOR_BLUE}"$XCODE_DEVELOPER_ROOT/usr/bin/xcodebuild" -downloadPlatform $os -buildVersion $version${COLOR_RESET}."
fi
done
}
echo "Checking system..."
if test -n "$IS_LINUX"; then
ok "Running on ${COLOR_BLUE}Linux${COLOR_CLEAR} - skipping macOS-specific checks"
ok "Only .NET download and managed code builds will be available"
fi
check_osx_version
check_checkout_dir
check_xcode
check_xcode_components
check_homebrew
check_shellcheck
check_yamllint
check_python3
check_7z
check_old_simulators
if test -z "$IGNORE_DOTNET"; then
if test -f /usr/local/share/dotnet/dotnet; then
ok "Installed .NET SDKs:"
(IFS=$'\n'; for i in $(/usr/local/share/dotnet/dotnet --list-sdks); do log "$i"; done)
else
warn ".NET is not installed"
fi
fi
if test -z $FAIL; then
echo "System check succeeded"
else
echo "System check failed"
exit 1
fi