-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
build-script-impl
executable file
·3474 lines (3064 loc) · 161 KB
/
build-script-impl
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 bash
#===--- build-script-impl - Implementation details of build-script ---------===#
#
## This source file is part of the Swift.org open source project
##
## Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
## Licensed under Apache License v2.0 with Runtime Library Exception
##
## See https://swift.org/LICENSE.txt for license information
## See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
#===------------------------------------------------------------------------===#
#
# This script is an implementation detail of other build scripts and should not
# be called directly.
#
# Note: This script will NOT auto-clean before building.
#
set -o pipefail
set -e
umask 0022
# Declare the set of known settings along with each one's description
#
# If you add a user-settable variable, add it to this list.
#
# A default value of "" indicates that the corresponding variable
# will remain unset unless set explicitly.
#
# The --skip-build parameter, with no product name, does not affect the
# configuration (CMake parameters). You can turn this option on and
# off in different invocations of the script for the same build
# directory without affecting configuration.
#
# skip-build-* and build-* parameters affect the CMake configuration
# (enable/disable those components).
#
# Each variable name is re-exported into this script in uppercase, where dashes
# are substituted by underscores. For example, `swift-install-components` is
# referred to as `SWIFT_INSTALL_COMPONENTS` in the remainder of this script.
# name default description
KNOWN_SETTINGS=(
## Debugging Options
dry-run "" "print the commands that would be executed, but do not execute them"
verbose-build "" "print the commands executed during the build"
check-args-only "" "set to check all arguments are known. Exit with status 0 if success, non zero otherwise"
only-execute "all" "Only execute the named action (see implementation)"
check-incremental-compilation "0" "set to 1 to compile swift libraries multiple times to check if incremental compilation works"
enable-array-cow-checks "0" "set tp 1 compile the stdlib with Array COW checks enabled (only relevant for assert builds)"
## Build Mode Options
enable-asan "" "enable Address Sanitizer"
enable-ubsan "" "enable Undefined Behavior Sanitizer"
clang-profile-instr-use "" "If set, profile file to use for clang PGO while building llvm/clang"
swift-profile-instr-use "" "If set, profile file to use for clang PGO while building swift"
## Build Tool Settings
build-args "" "arguments to the build tool; defaults to -j8 when CMake generator is \"Unix Makefiles\""
build-dir "" "out-of-tree build directory; default is in-tree. **This argument is required**"
build-jobs "" "The number of parallel build jobs to use"
lit-jobs "" "The number of workers to use when testing with lit"
build-runtime-with-host-compiler "" "use the host c++ compiler to build everything"
build-stdlib-deployment-targets "all" "space-separated list that filters which of the configured targets to build the Swift standard library for, or 'all'"
build-toolchain-only "" "If set, only build the necessary tools to build an external toolchain"
bootstrapping "" "the bootstrapping build mode for the swift compiler modules"
cmake-generator "Unix Makefiles" "kind of build system to generate; see output of 'cmake --help' for choices"
llvm-num-parallel-lto-link-jobs "" "The number of parallel link jobs to use when compiling llvm"
reconfigure "" "force a CMake configuration run even if CMakeCache.txt already exists"
skip-reconfigure "" "set to skip reconfigure"
swift-tools-num-parallel-lto-link-jobs "" "The number of parallel link jobs to use when compiling swift tools"
use-gold-linker "" "Enable using the gold linker"
workspace "${HOME}/src" "source directory containing llvm, clang, swift"
dsymutil-jobs "1" "number of parallel invocations of dsymutil"
## Build Tools
host-cc "" "the path to CC, the 'clang' compiler for the host platform. **This argument is required**"
host-cxx "" "the path to CXX, the 'clang++' compiler for the host platform. **This argument is required**"
host-libtool "" "the path to libtool"
host-lipo "" "the path to lipo for creating universal binaries on Darwin"
cmake "" "path to the cmake binary"
distcc "" "use distcc in pump mode"
distcc-pump "" "the path to distcc pump executable. This argument is required if distcc is set."
ninja-bin "" "the path to Ninja tool"
## Android Options
android-api-level "" "The Android API level to target when building for Android. Currently only 21 or above is supported"
android-arch "armv7" "The Android target architecture when building for Android"
android-deploy-device-path "" "Path on an Android device to which built Swift stdlib products will be deployed"
android-ndk "" "An absolute path to the NDK that will be used as a libc implementation for Android builds"
## Darwin Options
darwin-crash-reporter-client "" "whether to enable CrashReporter integration, default is 1 on Darwin platforms, 0 otherwise"
darwin-deployment-version-ios "11.0" "minimum deployment target version for iOS"
darwin-deployment-version-osx "10.13" "minimum deployment target version for OS X"
darwin-deployment-version-tvos "11.0" "minimum deployment target version for tvOS"
darwin-deployment-version-watchos "4.0" "minimum deployment target version for watchOS"
darwin-install-extract-symbols "" "whether to extract symbols with dsymutil during installations"
darwin-install-extract-symbols-use-just-built-dsymutil "1" "whether we should extract symbols using the just built dsymutil"
darwin-symroot-path-filters "" "space-separated list of path patterns to consider for symbol generation"
darwin-overlay-target "" "single overlay target to build, dependencies are computed later"
darwin-sdk-deployment-targets "xctest-ios-8.0" "semicolon-separated list of triples like 'fookit-ios-9.0;barkit-watchos-9.0'"
darwin-stdlib-install-name-dir "" "the directory of the install_name for standard library dylibs"
darwin-toolchain-alias "" "Swift alias for toolchain"
darwin-toolchain-application-cert "" "Application Cert name to codesign xctoolchain"
darwin-toolchain-bundle-identifier "" "CFBundleIdentifier for xctoolchain info plist"
darwin-toolchain-display-name "" "Display Name for xctoolcain info plist"
darwin-toolchain-display-name-short "" "Display Name with out date for xctoolchain info plist"
darwin-toolchain-installer-cert "" "Installer Cert name to create installer pkg"
darwin-toolchain-installer-package "" "The path to installer pkg"
darwin-toolchain-name "" "Directory name for xctoolchain"
darwin-toolchain-version "" "Version for xctoolchain info plist and installer pkg"
darwin-toolchain-require-use-os-runtime "0" "When setting up a plist for a toolchain, require the users of the toolchain to link against the OS instead of the packaged toolchain runtime. 0 for false, 1 for true"
darwin-xcrun-toolchain "default" "the name of the toolchain to use on Darwin"
## WebAssembly/WASI Options
wasi-sysroot "" "An absolute path to the wasi-sysroot that will be used as a libc implementation for Wasm builds"
## Build Types for Components
swift-stdlib-build-type "Debug" "the CMake build variant for Swift"
## Skip Build ...
skip-build "" "set to configure as usual while skipping the build step"
skip-build-android "" "set to skip building Swift stdlibs for Android"
skip-build-wasm "" "set to skip building Swift stdlibs for WebAssembly"
skip-build-benchmarks "" "set to skip building Swift Benchmark Suite"
skip-build-clang-tools-extra "" "set to skip building clang-tools-extra as part of llvm"
skip-build-compiler-rt "" "set to skip building Compiler-RT"
skip-build-lld "" "set to skip building lld as part of llvm (linux only)"
## Skip Test ...
skip-test-benchmarks "" "set to skip running Swift Benchmark Suite"
skip-test-sourcekit "" "set to skip testing SourceKit"
## Extra ... CMake Options
common-cmake-options "" "CMake options used for all targets, including LLVM/Clang"
extra-cmake-options "" "Extra options to pass to CMake for all targets"
ninja-cmake-options "" "CMake options used for all ninja targets"
## Build ...
build-llvm "1" "set to 1 to build LLVM and Clang"
build-sil-debugging-stdlib "0" "set to 1 to build the Swift standard library with -sil-based-debuginfo to enable debugging and profiling on SIL level"
build-swift-dynamic-sdk-overlay "" "set to 1 to build dynamic variants of the Swift SDK overlay"
build-swift-dynamic-stdlib "" "set to 1 to build dynamic variants of the Swift standard library"
build-swift-examples "1" "set to 1 to build examples"
build-swift-remote-mirror "1" "set to 1 to build the Swift Remote Mirror library"
build-swift-static-sdk-overlay "" "set to 1 to build static variants of the Swift SDK overlay"
build-swift-static-stdlib "" "set to 1 to build static variants of the Swift standard library"
build-swift-stdlib-unittest-extra "0" "set to 1 to build optional StdlibUnittest components"
build-swift-tools "1" "set to 1 to build Swift host tools"
build-swift-libexec "1" "set to 1 to build auxiliary executables"
## Skip cleaning build directories ...
skip-clean-libdispatch "0" "skip cleaning the libdispatch build"
skip-clean-foundation "0" "skip cleaning the foundation build"
skip-clean-xctest "0" "skip cleaning the xctest build"
## Test Options
llvm-include-tests "1" "Set to true to generate testing targets for LLVM. Set to true by default."
long-test "0" "set to run the long test suite"
only-executable-test "" "only run the executable variant of the swift lit tests"
stress-test "0" "set to run the stress test suite"
stress-test-sourcekit "" "set to run the stress-SourceKit target"
swift-include-tests "1" "Set to true to generate testing targets for Swift. This allows the build to proceed when 'test' directory is missing (required for B&I builds)"
validation-test "0" "set to run the validation test suite"
## llbuild Options
llbuild-enable-assertions "1" "enable assertions in llbuild"
skip-clean-llbuild "0" "skip cleaning up llbuild"
## LLDB Options
lldb-assertions "1" "build lldb with assertions enabled"
lldb-extra-cmake-args "" "extra command line args to pass to lldb cmake"
lldb-test-cc "" "CC to use for building LLDB testsuite test inferiors. Defaults to just-built, in-tree clang. If set to 'host-toolchain', sets it to same as host-cc."
lldb-test-swift-compatibility "" "specify additional Swift compilers to test lldb with"
lldb-test-swift-only "0" "when running lldb tests, only include Swift-specific tests"
lldb-use-system-debugserver "" "don't try to codesign debugserver, and use the system's debugserver instead"
lldb-configure-tests "1" "if set, will make sure we configure LLDB's test target without running the tests"
## LLVM Options
llvm-enable-lto "" "Must be set to one of 'thin' or 'full'"
llvm-enable-modules "0" "enable building llvm using modules"
llvm-install-components "" "a semicolon-separated list of LLVM components to install"
llvm-lit-args "" "If set, override the lit args passed to LLVM"
enable-llvm-assertions "1" "set to enable llvm assertions"
llvm-ninja-targets "" "list of ninja targets to build for LLVM"
llvm-ninja-targets-for-cross-compile-hosts "" "list of ninja targets to build for LLVM for hosts that are cross-compiled"
## Swift Options
swift-analyze-code-coverage "not-merged" "Code coverage analysis mode for Swift (false, not-merged, merged). Defaults to false if the argument is not present, and not-merged if the argument is present without a modifier."
swift-enable-assertions "1" "enable assertions in Swift"
swift-enable-ast-verifier "1" "If enabled, and the assertions are enabled, the built Swift compiler will run the AST verifier every time it is invoked"
swift-install-components "" "a semicolon-separated list of Swift components to install"
swift-primary-variant-arch "" "default arch for target binaries"
swift-primary-variant-sdk "" "default SDK for target binaries"
swift-runtime-enable-leak-checker "0" "Enable leaks checking routines in the runtime"
swift-stdlib-enable-assertions "1" "enable assertions in Swift"
swift-stdlib-enable-debug-preconditions-in-release "0" "Enable _debugPrecondition checks in the stdlib in Release configurations"
swift-tools-enable-lto "" "enable LTO compilation of Swift tools. *NOTE* This does not include the swift standard library and runtime. Must be set to one of 'thin' or 'full'"
extra-swift-args "" "Extra arguments to pass to swift modules which match regex. Assumed to be a flattened cmake list consisting of [module_regexp, args, module_regexp, args, ...]"
report-statistics "0" "set to 1 to generate compilation statistics files for swift libraries"
sil-verify-all "0" "If enabled, run the SIL verifier after each transform when building Swift files during this build process"
sil-verify-all-macos-only "0" "If enabled, run the SIL verifier after each transform when building Swift files during this build process when building a macos stdlib"
stdlib-deployment-targets "" "space-separated list of targets to configure the Swift standard library to be compiled or cross-compiled for"
swift-objc-interop "" "whether to enable interoperability with Objective-C, default is 1 on Darwin platforms, 0 otherwise"
swift-enable-dispatch "1" "whether to enable use of libdispatch"
swift-implicit-concurrency-import "1" "whether to implicitly import the Swift concurrency module"
swift-stdlib-support-back-deployment "1" "whether to support back-deployment of built binaries to older OS versions"
swift-enable-reflection "1" "whether to support reflection and mirrors"
swift-stdlib-reflection-metadata "enabled" "whether to build stdlib with runtime metadata (valid options are 'enabled', 'disabled' and 'debugger-only')"
swift-stdlib-has-dladdr "1" "whether to build stdlib assuming the runtime environment provides dladdr API"
swift-stdlib-has-dlsym "1" "whether to build stdlib assuming the runtime environment provides the dlsym API"
swift-stdlib-has-filesystem "1" "whether to build stdlib assuming the runtime environment provides a filesystem"
swift-stdlib-supports-backtrace-reporting "" "whether to build stdlib assuming the runtime environment provides the backtrace(3) API, if not set defaults to true on all platforms except for Cygwin, Haiku and wasm"
swift-runtime-static-image-inspection "0" "whether to build stdlib assuming the runtime environment only supports a single runtime image with Swift code"
swift-threading-package "" "override the threading package for the host build; this is either a single package or a semicolon-separated list of sdk:package pairs. Valid packages are empty string (no override), 'pthreads', 'darwin', 'linux', 'win32', 'c11', 'none'"
swift-stdlib-single-threaded-concurrency "0" "build Swift concurrency in single-threaded mode"
swift-stdlib-tracing "" "whether to enable tracing signposts for the stdlib; default is 1 on Darwin platforms, 0 otherwise"
swift-stdlib-concurrency-tracing "" "whether to enable tracing signposts for concurrency; default is 1 on Darwin platforms, 0 otherwise"
swift-stdlib-use-relative-protocol-witness-tables "0" "whether to use relative protocol witness table"
swift-enable-runtime-function-counters "" "whether to enable runtime function counters"
swift-stdlib-os-versioning "1" "whether to build stdlib with availability based on OS versions (Darwin only)"
swift-stdlib-has-commandline "1" "whether to build stdlib with the CommandLine enum and support for argv/argc"
swift-stdlib-stable-abi "" "should stdlib be built with stable ABI, if not set defaults to true on Darwin, false otherwise"
swift-stdlib-has-darwin-libmalloc "1" "whether the Darwin build of stdlib can use extended libmalloc APIs"
swift-stdlib-has-asl "" "whether the stdlib can use the asl_log API, defaults to true on Darwin, false otherwise"
swift-stdlib-has-stdin "1" "whether to build stdlib assuming the platform supports stdin and getline API"
swift-stdlib-has-environ "1" "whether to build stdlib assuming the platform supports environment variables"
swift-stdlib-has-locale "" "whether to build stdlib assuming the platform has locale support"
swift-stdlib-lto "" "enable LLVM LTO on the stdlib, valid values are empty string (no LTO), 'full' and 'thin'"
swift-stdlib-enable-prespecialization "" "whether stdlib should be built with generic metadata prespecialization enabled, defaults to true on Darwin and Linux, false otherwise"
swift-stdlib-passthrough-metadata-allocator "0" "whether stdlib should be built without a custom implementation of MetadataAllocator, relying on malloc+free instead"
swift-stdlib-short-mangling-lookups "1" "whether to build stdlib with fast-path context descriptor lookups based on well-known short manglings"
swift-stdlib-enable-vector-types "1" "whether to build stdlib with support for SIMD and vector types"
swift-stdlib-experimental-hermetic-seal-at-link "0" "whether stdlib should be built with -experimental-hermetic-seal-at-link"
swift-stdlib-disable-instantiation-caches "0" "whether to build stdlib with -disable-preallocated-instantiation-caches"
swift-stdlib-has-type-printing "1" "whether stdlib should support printing user-friendly type name as strings at runtime"
swift-stdlib-trap-function "" "Name of function to call instead of emitting a trap instruction"
swift-disable-dead-stripping "0" "turns off Darwin-specific dead stripping for Swift host tools"
common-swift-flags "" "Flags used for Swift targets other than the stdlib, like the corelibs"
swift-enable-experimental-string-processing "1" "whether to build experimental string processing feature"
swift-earlyswiftsyntax "0" "use the early SwiftSyntax"
swift-enable-backtracing "1" "whether to build the backtracing support"
swift-runtime-fixed-backtracer-path "" "if set, use a fixed path for the backtracer"
## FREESTANDING Stdlib Options
swift-freestanding-flavor "" "when building the FREESTANDING stdlib, which build style to use (options: apple, linux)"
swift-freestanding-sdk "" "which SDK to use when building the FREESTANDING stdlib"
swift-freestanding-triple-name "" "which triple name (e.g. 'none-macho') to use when building the FREESTANDING stdlib"
swift-freestanding-module-name "" "which .swiftmodule name (e.g. 'freestanding') to use when building the FREESTANDING stdlib"
swift-freestanding-archs "" "space-separated list of which architectures to build when building the FREESTANDING stdlib"
## Uncategorised
install-prefix "" "installation prefix"
toolchain-prefix "" "the path to the .xctoolchain directory that houses the install prefix path"
install-destdir "" "the path to use as the filesystem root for the installation"
install-symroot "" "the path to install debug symbols into"
installable-package "" "the path to the archive of the installation directory"
test-installable-package "" "whether to run post-packaging tests on the produced package"
skip-local-build "" "set to skip building for the current host (useful when crosscompiling)"
test-paths "" "run tests located in specific directories and/or files"
native-llvm-tools-path "" "directory that contains LLVM tools that are executable on the build machine"
native-clang-tools-path "" "directory that contains Clang tools that are executable on the build machine"
native-swift-tools-path "" "directory that contains Swift tools that are executable on the build machine"
embed-bitcode-section "0" "embed an LLVM bitcode section in stdlib/overlay binaries for supported platforms"
host-target "" "The host target. LLVM, Clang, and Swift will be built for this target. The built LLVM and Clang will be used to compile Swift for the cross-compilation targets. **This argument is required**"
cross-compile-hosts "" "space-separated list of targets to cross-compile host Swift tools for"
cross-compile-with-host-tools "" "set to use the clang we build for the host to then build the cross-compile hosts"
cross-compile-install-prefixes "" "semicolon-separated list of install prefixes to use for the cross-compiled hosts. The list expands, so if there are more cross-compile hosts than prefixes, unmatched hosts use the last prefix in the list"
cross-compile-deps-path "" "path for CMake to look for cross-compiled library dependencies, such as libXML2"
cross-compile-append-host-target-to-destdir "1" "turns on appending the host target name of each cross-compiled toolchain to its install-destdir, to keep them separate from the natively-built toolchain"
skip-merge-lipo-cross-compile-tools "" "set to skip running merge-lipo after installing cross-compiled host Swift tools"
coverage-db "" "If set, coverage database to use when prioritizing testing"
skip-local-host-install "" "If we are cross-compiling multiple targets, skip an install pass locally if the hosts match"
enable-extract-symbol-dry-run-test "" "If we are dry-running, still run the extract symbol phase so that we can test it"
)
components=(
foundation
libcxx
libdispatch
libicu
libxml2
zlib
curl
llbuild
lldb
llvm
static-foundation
static-libdispatch
swift
xctest
)
for component in ${components[@]} ; do
component_skip_test_default=""
KNOWN_SETTINGS+=(
${component}-build-type "Debug" "the build variant for ${component}"
${component}-cmake-options "" "CMake options used for ${component}"
skip-build-${component} "" "set to skip building ${component}"
skip-test-${component} "${component_skip_test_default}" "set to skip testing ${component}"
install-${component} "" "whether to install ${component}"
)
done
# Centralized access point for traced command invocation.
# Every operation that might mutates file system should be called via
# these functions.
function call() {
if [[ ${DRY_RUN} ]] || [[ "${VERBOSE_BUILD}" ]]; then
echo "${PS4}"$(quoted_print "$@")
fi
SECONDS=0
if [[ ! ${DRY_RUN} ]]; then
{ set -x; } 2>/dev/null
"$@"
{ set +x; } 2>/dev/null
fi
}
function with_pushd() {
local dir=$1
shift
if [[ "$1" == "call" ]]; then
shift
fi
if [[ ${DRY_RUN} ]]; then
echo ${PS4}pushd "${dir}"
echo "${PS4}"$(quoted_print "$@")
echo ${PS4}popd
else
set -x
pushd "${dir}"
"$@"
{ set -x; } 2>/dev/null # because $@ might includes { set +x; }
popd
{ set +x; } 2>/dev/null
fi
}
function quoted_print() {
python3 -c 'import shlex; import sys; print(" ".join(shlex.quote(arg) for arg in sys.argv[1:]))' "$@"
}
function toupper() {
echo "$@" | tr '[:lower:]' '[:upper:]'
}
function tolower() {
echo "$@" | tr '[:upper:]' '[:lower:]'
}
function true_false() {
case "$1" in
false | FALSE | 0 | "")
echo "FALSE"
;;
true | TRUE | 1)
echo "TRUE"
;;
*)
echo "true_false: unknown value: $1" >&2
exit 1
;;
esac
}
function to_bootstrapping_mode() {
case "$1" in
false | FALSE | 0)
echo "OFF"
;;
true | TRUE | 1 | "")
if [[ "$(uname -s)" == "Darwin" ]] ; then
echo "BOOTSTRAPPING-WITH-HOSTLIBS"
else
echo "BOOTSTRAPPING"
fi
;;
*)
echo `toupper $1`
;;
esac
}
function to_varname() {
# Uses `tr` because it is orders of magnitude faster than ${1//-/_} on long
# strings, which happens when translating KNOWN_SETTINGS.
toupper "$(echo $1 | tr '-' '_')"
}
function is_llvm_lto_enabled() {
if [[ "${LLVM_ENABLE_LTO}" == "thin" ]] ||
[[ "${LLVM_ENABLE_LTO}" == "full" ]]; then
echo "TRUE"
else
echo "FALSE"
fi
}
function is_swift_lto_enabled() {
if [[ "${SWIFT_TOOLS_ENABLE_LTO}" == "thin" ]] ||
[[ "${SWIFT_TOOLS_ENABLE_LTO}" == "full" ]]; then
echo "TRUE"
else
echo "FALSE"
fi
}
# Support for performing isolated actions.
#
# This is part of refactoring more work to be done or controllable via
# `build-script` itself. For additional information, see:
# https://github.com/apple/swift/issues/42859
#
# To use this functionality, the script is invoked with:
# ONLY_EXECUTE=<action name>
# where <action name> is one of:
# all -- execute all actions
# ${host}-${product}-build -- the build of the product
# ${host}-${product}-test -- the test of the product
# ${host}-${product}-install -- the install of the product
# ${host}-package -- the package construction and test
# merged-hosts-lipo -- the lipo step, if used
# and if used, only the one individual action will be performed.
#
# If not set, the default is `all`.
# should_execute_action(name) -> 1 or nil
#
# Check if the named action should be run in the given script invocation.
function should_execute_action() {
local name="$1"
if [[ "${ONLY_EXECUTE}" = "all" ]] ||
[[ "${ONLY_EXECUTE}" = "${name}" ]]; then
echo 1
fi
}
# should_execute_host_actions_for_phase(host, phase-name) -> 1 or nil
#
# Check if the there are any actions to execute for this host and phase (i.e.,
# "build", "test", or "install")
function should_execute_host_actions_for_phase() {
local host="$1"
local phase_name="$2"
if [[ "${ONLY_EXECUTE}" = "all" ]] ||
[[ "${ONLY_EXECUTE}" == ${host}-*-${phase_name} ]]; then
echo 1
fi
}
function verify_host_is_supported() {
local host="$1"
case ${host} in
freebsd-arm64 \
| freebsd-x86_64 \
| openbsd-amd64 \
| cygwin-x86_64 \
| haiku-x86_64 \
| linux-x86_64 \
| linux-i686 \
| linux-armv5 \
| linux-armv6 \
| linux-armv7 \
| linux-aarch64 \
| linux-powerpc \
| linux-powerpc64 \
| linux-powerpc64le \
| linux-riscv64 \
| linux-s390x \
| macosx-x86_64 \
| macosx-arm64 \
| macosx-arm64e \
| iphonesimulator-x86_64 \
| iphonesimulator-arm64 \
| iphoneos-arm64 \
| iphoneos-arm64e \
| appletvsimulator-x86_64 \
| appletvsimulator-arm64 \
| appletvos-arm64 \
| watchsimulator-i386 \
| watchsimulator-x86_64 \
| watchsimulator-arm64 \
| watchos-armv7k \
| watchos-arm64_32 \
| wasi-wasm32 \
| android-armv7 \
| android-aarch64 \
| android-x86_64)
;;
*)
echo "Unknown host tools target: ${host}"
exit 1
;;
esac
}
function set_build_options_for_host() {
llvm_cmake_options=()
swift_cmake_options=()
lldb_cmake_options=()
llbuild_cmake_options=()
SWIFT_HOST_VARIANT=
SWIFT_HOST_VARIANT_SDK=
SWIFT_HOST_VARIANT_ARCH=
SWIFT_HOST_TRIPLE=
local host="$1"
# Hosts which can be cross-compiled must specify:
# SWIFT_HOST_TRIPLE and llvm_target_arch.
# Hosts which have differing platform names from their
# SWIFT_HOST_VARIANT_* values should change them here as well.
verify_host_is_supported $host
local platform=${host%%-*}
local architecture=${host##*-}
SWIFT_HOST_VARIANT=$platform
SWIFT_HOST_VARIANT_SDK=$(toupper $platform)
SWIFT_HOST_VARIANT_ARCH=$architecture
case ${host} in
android-*)
# Clang uses a different sysroot natively on Android in the Termux
# app, which the Termux build scripts pass in through a $PREFIX
# variable.
if [[ "${PREFIX}" ]] ; then
llvm_cmake_options+=(
-DCLANG_DEFAULT_LINKER:STRING="lld"
-DDEFAULT_SYSROOT:STRING="$(dirname ${PREFIX})"
)
fi
# Android doesn't support building all of compiler-rt yet.
if [[ ! $(is_cross_tools_host "${host}") ]] ; then
llvm_cmake_options+=(
-DCOMPILER_RT_INCLUDE_TESTS:BOOL=FALSE
)
fi
case ${host} in
android-aarch64)
SWIFT_HOST_TRIPLE="aarch64-unknown-linux-android${ANDROID_API_LEVEL}"
llvm_target_arch="AArch64"
;;
android-armv7)
SWIFT_HOST_TRIPLE="armv7-unknown-linux-androideabi${ANDROID_API_LEVEL}"
llvm_target_arch="ARM"
;;
android-x86_64)
SWIFT_HOST_TRIPLE="x86_64-unknown-linux-android${ANDROID_API_LEVEL}"
llvm_target_arch="X86"
;;
esac
;;
linux-armv5)
SWIFT_HOST_TRIPLE="armv5-unknown-linux-gnueabi"
llvm_target_arch="ARM"
;;
linux-armv6)
SWIFT_HOST_TRIPLE="armv6-unknown-linux-gnueabihf"
llvm_target_arch="ARM"
;;
linux-armv7)
SWIFT_HOST_TRIPLE="armv7-unknown-linux-gnueabihf"
llvm_target_arch="ARM"
;;
macosx-* | \
iphoneos-* | \
iphonesimulator-* | \
appletvos-* | \
appletvsimulator-* | \
watchos-* | \
watchsimulator-*)
swift_cmake_options+=(
-DPython3_EXECUTABLE="$(xcrun -f python3)"
)
case ${host} in
macosx-x86_64)
SWIFT_HOST_TRIPLE="x86_64-apple-macosx${DARWIN_DEPLOYMENT_VERSION_OSX}"
llvm_target_arch=""
SWIFT_HOST_VARIANT_SDK="OSX"
cmake_osx_deployment_target="${DARWIN_DEPLOYMENT_VERSION_OSX}"
;;
macosx-arm64)
xcrun_sdk_name="macosx"
llvm_target_arch="AArch64"
SWIFT_HOST_TRIPLE="arm64-apple-macosx${DARWIN_DEPLOYMENT_VERSION_OSX}"
SWIFT_HOST_VARIANT="macosx"
SWIFT_HOST_VARIANT_SDK="OSX"
SWIFT_HOST_VARIANT_ARCH="arm64"
cmake_osx_deployment_target="${DARWIN_DEPLOYMENT_VERSION_OSX}"
;;
macosx-arm64e)
xcrun_sdk_name="macosx"
llvm_target_arch="AArch64"
SWIFT_HOST_TRIPLE="arm64e-apple-macosx${DARWIN_DEPLOYMENT_VERSION_OSX}"
SWIFT_HOST_VARIANT="macosx"
SWIFT_HOST_VARIANT_SDK="OSX"
SWIFT_HOST_VARIANT_ARCH="arm64e"
cmake_osx_deployment_target="${DARWIN_DEPLOYMENT_VERSION_OSX}"
;;
iphonesimulator-x86_64)
SWIFT_HOST_TRIPLE="x86_64-apple-ios${DARWIN_DEPLOYMENT_VERSION_IOS}-simulator"
llvm_target_arch="X86"
SWIFT_HOST_VARIANT_SDK="IOS_SIMULATOR"
cmake_osx_deployment_target=""
;;
iphonesimulator-arm64)
xcrun_sdk_name="iphonesimulator"
llvm_target_arch="AArch64"
SWIFT_HOST_TRIPLE="arm64-apple-ios${DARWIN_DEPLOYMENT_VERSION_IOS}-simulator"
SWIFT_HOST_VARIANT="iphonesimulator"
SWIFT_HOST_VARIANT_SDK="IOS_SIMULATOR"
SWIFT_HOST_VARIANT_ARCH="arm64"
cmake_osx_deployment_target=""
;;
iphoneos-arm64)
SWIFT_HOST_TRIPLE="arm64-apple-ios${DARWIN_DEPLOYMENT_VERSION_IOS}"
llvm_target_arch="AArch64"
SWIFT_HOST_VARIANT_SDK="IOS"
cmake_osx_deployment_target=""
;;
iphoneos-arm64e)
SWIFT_HOST_TRIPLE="arm64e-apple-ios${DARWIN_DEPLOYMENT_VERSION_IOS}"
llvm_target_arch="AArch64"
SWIFT_HOST_VARIANT_SDK="IOS"
cmake_osx_deployment_target=""
;;
appletvsimulator-x86_64)
SWIFT_HOST_TRIPLE="x86_64-apple-tvos${DARWIN_DEPLOYMENT_VERSION_TVOS}-simulator"
llvm_target_arch="X86"
SWIFT_HOST_VARIANT_SDK="TVOS_SIMULATOR"
cmake_osx_deployment_target=""
;;
appletvsimulator-arm64)
xcrun_sdk_name="appletvsimulator"
llvm_target_arch="AArch64"
SWIFT_HOST_TRIPLE="arm64-apple-tvos${DARWIN_DEPLOYMENT_VERSION_IOS}-simulator"
SWIFT_HOST_VARIANT="appletvsimulator"
SWIFT_HOST_VARIANT_SDK="TVOS_SIMULATOR"
SWIFT_HOST_VARIANT_ARCH="arm64"
cmake_osx_deployment_target=""
;;
appletvos-arm64)
SWIFT_HOST_TRIPLE="arm64-apple-tvos${DARWIN_DEPLOYMENT_VERSION_TVOS}"
llvm_target_arch="AArch64"
SWIFT_HOST_VARIANT_SDK="TVOS"
cmake_osx_deployment_target=""
;;
watchsimulator-i386)
SWIFT_HOST_TRIPLE="i386-apple-watchos${DARWIN_DEPLOYMENT_VERSION_WATCHOS}-simulator"
llvm_target_arch="X86"
SWIFT_HOST_VARIANT_SDK="WATCHOS_SIMULATOR"
cmake_osx_deployment_target=""
;;
watchsimulator-x86_64)
SWIFT_HOST_TRIPLE="x86_64-apple-watchos${DARWIN_DEPLOYMENT_VERSION_WATCHOS}-simulator"
llvm_target_arch="X86"
SWIFT_HOST_VARIANT_SDK="WATCHOS_SIMULATOR"
cmake_osx_deployment_target=""
;;
watchsimulator-arm64)
xcrun_sdk_name="watchsimulator"
llvm_target_arch="AArch64"
SWIFT_HOST_TRIPLE="arm64-apple-watchos${DARWIN_DEPLOYMENT_VERSION_IOS}-simulator"
SWIFT_HOST_VARIANT="watchsimulator"
SWIFT_HOST_VARIANT_SDK="WATCHOS_SIMULATOR"
SWIFT_HOST_VARIANT_ARCH="arm64"
cmake_osx_deployment_target=""
;;
watchos-armv7k)
SWIFT_HOST_TRIPLE="armv7k-apple-watchos${DARWIN_DEPLOYMENT_VERSION_WATCHOS}"
llvm_target_arch="ARM"
SWIFT_HOST_VARIANT_SDK="WATCHOS"
cmake_osx_deployment_target=""
;;
watchos-arm64_32)
SWIFT_HOST_TRIPLE="arm64_32-apple-watchos${DARWIN_DEPLOYMENT_VERSION_WATCHOS}"
llvm_target_arch="AArch64"
SWIFT_HOST_VARIANT_SDK="WATCHOS"
cmake_osx_deployment_target=""
;;
esac
if [[ "${DARWIN_SDK_DEPLOYMENT_TARGETS}" != "" ]]; then
# IFS is immediately unset after its use to avoid unwanted
# replacement of characters in subsequent lines.
local IFS=";"; DARWIN_SDK_DEPLOYMENT_TARGETS=($DARWIN_SDK_DEPLOYMENT_TARGETS); unset IFS
for target in "${DARWIN_SDK_DEPLOYMENT_TARGETS[@]}"; do
# IFS is immediately unset after its use to avoid unwanted
# replacement of characters in subsequent lines.
local IFS="-"; triple=($target); unset IFS
sdk_target=$(toupper ${triple[0]}_${triple[1]})
swift_cmake_options+=(
"-DSWIFTLIB_DEPLOYMENT_VERSION_${sdk_target}=${triple[2]}"
)
done
fi
cmake_os_sysroot="$(xcrun --sdk ${platform} --show-sdk-path)"
llvm_cmake_options=(
-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING="${cmake_osx_deployment_target}"
-DCMAKE_OSX_SYSROOT:PATH="${cmake_os_sysroot}"
-DCOMPILER_RT_ENABLE_IOS:BOOL=FALSE
-DCOMPILER_RT_ENABLE_WATCHOS:BOOL=FALSE
-DCOMPILER_RT_ENABLE_TVOS:BOOL=FALSE
-DLLVM_ENABLE_MODULES:BOOL="$(true_false ${LLVM_ENABLE_MODULES})"
-DCMAKE_OSX_ARCHITECTURES="${architecture}"
)
if [[ $(is_llvm_lto_enabled) == "TRUE" ]]; then
llvm_cmake_options+=(
"-DLLVM_PARALLEL_LINK_JOBS=${LLVM_NUM_PARALLEL_LTO_LINK_JOBS}"
)
fi
if [[ $(is_swift_lto_enabled) == "TRUE" ]]; then
llvm_cmake_options+=(
-DLLVM_ENABLE_MODULE_DEBUGGING:BOOL=NO
)
swift_cmake_options+=(
-DLLVM_ENABLE_MODULE_DEBUGGING:BOOL=NO
"-DSWIFT_PARALLEL_LINK_JOBS=${SWIFT_TOOLS_NUM_PARALLEL_LTO_LINK_JOBS}"
)
fi
swift_cmake_options+=(
-DSWIFT_DARWIN_DEPLOYMENT_VERSION_OSX="${DARWIN_DEPLOYMENT_VERSION_OSX}"
-DSWIFT_DARWIN_DEPLOYMENT_VERSION_IOS="${DARWIN_DEPLOYMENT_VERSION_IOS}"
-DSWIFT_DARWIN_DEPLOYMENT_VERSION_TVOS="${DARWIN_DEPLOYMENT_VERSION_TVOS}"
-DSWIFT_DARWIN_DEPLOYMENT_VERSION_WATCHOS="${DARWIN_DEPLOYMENT_VERSION_WATCHOS}"
-DCMAKE_OSX_SYSROOT:PATH="${cmake_os_sysroot}"
# This is needed to make sure to avoid using the wrong architecture
# in the compiler checks CMake performs
-DCMAKE_OSX_ARCHITECTURES="${architecture}"
)
lldb_cmake_options+=(
-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING="${cmake_osx_deployment_target}"
-DCMAKE_OSX_SYSROOT:PATH="${cmake_os_sysroot}"
-DCMAKE_OSX_ARCHITECTURES="${architecture}"
)
llbuild_cmake_options+=(
-DCMAKE_OSX_ARCHITECTURES="${architecture}"
)
;;
esac
# We don't currently support building compiler-rt for cross-compile targets.
# It's not clear that's useful anyway.
if [[ $(is_cross_tools_host "${host}") ]] ; then
llvm_cmake_options+=(
-DLLVM_TOOL_COMPILER_RT_BUILD:BOOL=FALSE
-DLLVM_BUILD_EXTERNAL_COMPILER_RT:BOOL=FALSE
)
else
llvm_cmake_options+=(
-DLLVM_TOOL_COMPILER_RT_BUILD:BOOL="$(false_true ${SKIP_BUILD_COMPILER_RT})"
-DLLVM_BUILD_EXTERNAL_COMPILER_RT:BOOL="$(false_true ${SKIP_BUILD_COMPILER_RT})"
)
fi
# If we are asked to not generate test targets for LLVM and or Swift,
# disable as many LLVM tools as we can. This improves compile time when
# compiling with LTO.
#
# *NOTE* Currently we do not support testing LLVM via build-script. But in a
# future commit we will.
#for arg in "$(compute_cmake_llvm_tool_disable_flags)"; do
# llvm_cmake_options+=( ${arg} )
#done
if [[ "${llvm_target_arch}" ]] ; then
llvm_cmake_options+=(
-DLLVM_TARGET_ARCH="${llvm_target_arch}"
)
fi
# For cross-compilable hosts, we need to know the triple
# and it must be the same for both LLVM and Swift
if [[ "${SWIFT_HOST_TRIPLE}" ]] ; then
llvm_cmake_options+=(
-DLLVM_HOST_TRIPLE:STRING="${SWIFT_HOST_TRIPLE}"
)
swift_cmake_options+=(
-DSWIFT_HOST_TRIPLE:STRING="${SWIFT_HOST_TRIPLE}"
)
lldb_cmake_options+=(
-DLLVM_HOST_TRIPLE:STRING="${SWIFT_HOST_TRIPLE}"
)
fi
swift_cmake_options+=(
-DSWIFT_HOST_VARIANT="${SWIFT_HOST_VARIANT}"
-DSWIFT_HOST_VARIANT_SDK="${SWIFT_HOST_VARIANT_SDK}"
-DSWIFT_HOST_VARIANT_ARCH="${SWIFT_HOST_VARIANT_ARCH}"
)
llvm_cmake_options+=(
-DLLVM_LIT_ARGS="${LLVM_LIT_ARGS} -j ${LIT_JOBS}"
)
swift_cmake_options+=(
-DLLVM_LIT_ARGS="${LLVM_LIT_ARGS} -j ${LIT_JOBS}"
)
lldb_cmake_options+=(
-DLLVM_LIT_ARGS="${LLVM_LIT_ARGS} -j ${LIT_JOBS}"
)
if [[ "${CLANG_PROFILE_INSTR_USE}" ]]; then
llvm_cmake_options+=(
-DLLVM_PROFDATA_FILE="${CLANG_PROFILE_INSTR_USE}"
)
fi
if [[ "${SWIFT_PROFILE_INSTR_USE}" ]]; then
swift_cmake_options+=(
-DSWIFT_PROFDATA_FILE="${SWIFT_PROFILE_INSTR_USE}"
)
fi
swift_cmake_options+=(
-DCOVERAGE_DB="${COVERAGE_DB}"
)
if [[ "$(true_false ${SWIFT_EARLYSWIFTSYNTAX})" == "TRUE" ]]; then
early_swiftsyntax_build_dir="$(build_directory ${host} earlyswiftsyntax)"
swift_cmake_options+=(
-DSWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR:PATH="${early_swiftsyntax_build_dir}"
)
lldb_cmake_options+=(
-DSWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR:PATH="${early_swiftsyntax_build_dir}"
)
fi
}
function configure_default_options() {
# Build a table of all of the known setting variables names.
#
# This is an optimization to do the argument to variable conversion (which is
# slow) in a single pass.
local all_settings=()
for ((i = 0; i < ${#KNOWN_SETTINGS[@]}; i += 3)); do
all_settings+=("${KNOWN_SETTINGS[i]}")
done
local known_setting_varnames=($(to_varname "${all_settings[*]}"))
# Build up an "associative array" mapping setting names to variable names
# (we use this for error checking to identify "known options", and as a fast
# way to map the setting name to a variable name). See the code for scanning
# command line arguments.
#
# This loop also sets (or unsets) each corresponding variable to its default
# value.
#
# NOTE: If the Mac's bash were not stuck in the past, we could "declare -A"
# an associative array, but instead we have to hack it by defining variables.
for ((i = 0; i < ${#KNOWN_SETTINGS[@]}; i += 3)); do
local setting="${KNOWN_SETTINGS[i]}"
local default_value="${KNOWN_SETTINGS[$((i+1))]}"
# Find the variable name in our lookup table.
local varname="${known_setting_varnames[$((i/3))]}"
# Establish the associative array mapping.
eval "${setting//-/_}_VARNAME=${varname}"
if [[ "${default_value}" ]] ; then
# For an explanation of the backslash see http://stackoverflow.com/a/9715377
eval ${varname}=$\default_value
else
unset ${varname}
fi
done
}
configure_default_options
COMMAND_NAME="$(basename "$0")"
# Print instructions for using this script to stdout
usage() {
echo "Usage: ${COMMAND_NAME} [--help|-h] [ --SETTING=VALUE | --SETTING VALUE | --SETTING ]*"
echo
echo " Available settings. Each setting corresponds to a variable,"
echo " obtained by upcasing its name, in this script. A variable"
echo " with no default listed here will be unset in the script if"
echo " not explicitly specified. A setting passed in the 3rd form"
echo " will set its corresponding variable to \"1\"."
echo
setting_list="
| |Setting| Default|Description
| |-------| -------|-----------
"
for ((i = 0; i < ${#KNOWN_SETTINGS[@]}; i += 3)); do
setting_list+="\
| |--${KNOWN_SETTINGS[i]}| ${KNOWN_SETTINGS[$((i+1))]}|${KNOWN_SETTINGS[$((i+2))]}
"
done
echo "${setting_list}" | column -x -s'|' -t
echo
echo "Note: when using the form --SETTING VALUE, VALUE must not begin "
echo " with a hyphen."
echo "Note: the \"--release\" option creates a pre-packaged combination"
echo " of settings used by the buildbot."
echo
echo "Cross-compiling Swift host tools"
echo " When building cross-compiled tools, it first builds for the native"
echo " build host machine. Then it proceeds to build the specified cross-compile"
echo " targets. It currently builds the requested variants of stdlib each"
echo " time around, so once for the native build, then again each time for"
echo " the cross-compile tool targets."
echo
echo " When installing cross-compiled tools, it first installs each target"
echo " arch into a separate subdirectory under install-destdir, since you"
echo " can cross-compile for multiple targets at the same time. It then runs"
echo " recursive-lipo to produce fat binaries by merging the cross-compiled"
echo " targets, installing the merged result into the expected location of"
echo " install-destdir. After that, any remaining steps to extract dsyms and"
echo " create an installable package operates on install-destdir as normal."
}
# Scan all command-line arguments
while [[ "$1" ]] ; do
case "$1" in
-h | --help )
usage
exit
;;
--* )
dashless="${1:2}"
# drop suffix beginning with the first "="
setting="${dashless%%=*}"
# compute the variable to set, using the cached map set up by
# configure_default_options().
varname_var="${setting//-/_}_VARNAME"
varname=${!varname_var}
# check to see if this is a known option
if [[ "${varname}" = "" ]] ; then
echo "error: unknown setting: ${setting}" 1>&2
usage 1>&2
exit 1
fi
# find the intended value
if [[ "${dashless}" == *=* ]] ; then # if there's an '=', the value
value="${dashless#*=}" # is everything after the first '='
elif [[ "$2" ]] && [[ "${2:0:1}" != "-" ]] ; then # else if the next parameter exists
value="$2" # but isn't an option, use that
shift
else # otherwise, the value is 1
value=1
fi
# For explanation of backslash see http://stackoverflow.com/a/9715377
eval ${varname}=$\value
;;
*)
echo "Error: Invalid argument: $1" 1>&2
usage 1>&2
exit 1
esac
shift
done
# TODO: Rename this argument
LOCAL_HOST=$HOST_TARGET
if [[ "${CHECK_ARGS_ONLY}" ]]; then
exit 0
fi