Skip to content

Commit be42a57

Browse files
authored
Merge pull request #2983 from apple/build-script-boolean-argument
[build-script] Add optional boolean action
2 parents 4ad30b6 + 3a945c4 commit be42a57

File tree

3 files changed

+117
-71
lines changed

3 files changed

+117
-71
lines changed

utils/build-script

Lines changed: 51 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -824,11 +824,11 @@ def main_preset():
824824
parser.add_argument(
825825
"--show-presets",
826826
help="list all presets and exit",
827-
action="store_true")
827+
action=arguments.action.optional_bool)
828828
parser.add_argument(
829829
"--distcc",
830830
help="use distcc",
831-
action="store_true")
831+
action=arguments.action.optional_bool)
832832
parser.add_argument(
833833
"preset_substitutions_raw",
834834
help="'name=value' pairs that are substituted in the preset",
@@ -1116,22 +1116,22 @@ details of the setups of other systems or automated environments.""")
11161116
projects_group.add_argument(
11171117
"--xctest",
11181118
help="build xctest",
1119-
action="store_true",
1119+
action=arguments.action.optional_bool,
11201120
dest="build_xctest")
11211121
projects_group.add_argument(
11221122
"--foundation",
11231123
help="build foundation",
1124-
action="store_true",
1124+
action=arguments.action.optional_bool,
11251125
dest="build_foundation")
11261126
projects_group.add_argument(
11271127
"--libdispatch",
11281128
help="build libdispatch",
1129-
action="store_true",
1129+
action=arguments.action.optional_bool,
11301130
dest="build_libdispatch")
11311131
projects_group.add_argument(
11321132
"--build-ninja",
11331133
help="build the Ninja tool",
1134-
action="store_true")
1134+
action=arguments.action.optional_bool)
11351135

11361136
extra_actions_group = parser.add_argument_group(
11371137
title="Extra actions to perform before or in addition to building")
@@ -1142,7 +1142,7 @@ details of the setups of other systems or automated environments.""")
11421142
extra_actions_group.add_argument(
11431143
"--export-compile-commands",
11441144
help="generate compilation databases in addition to building",
1145-
action="store_true")
1145+
action=arguments.action.optional_bool)
11461146
extra_actions_group.add_argument(
11471147
"--symbols-package",
11481148
metavar="PATH",
@@ -1324,11 +1324,7 @@ details of the setups of other systems or automated environments.""")
13241324
run_tests_group.add_argument(
13251325
"--test",
13261326
help="test Swift after building",
1327-
metavar="BOOL",
1328-
nargs='?',
1329-
type=arguments.type.bool,
1330-
default=False,
1331-
const=True)
1327+
action=arguments.action.optional_bool)
13321328
run_tests_group.add_argument(
13331329
"-T",
13341330
help="run the validation test suite (implies --test)",
@@ -1338,11 +1334,7 @@ details of the setups of other systems or automated environments.""")
13381334
run_tests_group.add_argument(
13391335
"--validation-test",
13401336
help="run the validation test suite (implies --test)",
1341-
metavar="BOOL",
1342-
nargs='?',
1343-
type=arguments.type.bool,
1344-
default=False,
1345-
const=True)
1337+
action=arguments.action.optional_bool)
13461338
run_tests_group.add_argument(
13471339
"-o",
13481340
help="run the test suite in optimized mode too (implies --test)",
@@ -1352,52 +1344,44 @@ details of the setups of other systems or automated environments.""")
13521344
run_tests_group.add_argument(
13531345
"--test-optimized",
13541346
help="run the test suite in optimized mode too (implies --test)",
1355-
metavar="BOOL",
1356-
nargs='?',
1357-
type=arguments.type.bool,
1358-
default=False,
1359-
const=True)
1347+
action=arguments.action.optional_bool)
13601348
run_tests_group.add_argument(
13611349
"--long-test",
13621350
help="run the long test suite",
1363-
metavar="BOOL",
1364-
nargs='?',
1365-
type=arguments.type.bool,
1366-
default=False,
1367-
const=True)
1351+
action=arguments.action.optional_bool)
13681352
run_tests_group.add_argument(
13691353
"--host-test",
13701354
help="run executable tests on host devices (such as iOS or tvOS)",
1371-
action="store_true")
1355+
action=arguments.action.optional_bool)
13721356
run_tests_group.add_argument(
13731357
"-B", "--benchmark",
13741358
help="run the Swift Benchmark Suite after building",
13751359
action="store_true")
13761360
run_tests_group.add_argument(
13771361
"--skip-test-osx",
13781362
help="skip testing Swift stdlibs for Mac OS X",
1379-
action="store_true")
1363+
action=arguments.action.optional_bool)
13801364
run_tests_group.add_argument(
13811365
"--skip-test-linux",
13821366
help="skip testing Swift stdlibs for Linux",
1383-
action="store_true")
1367+
action=arguments.action.optional_bool)
13841368
run_tests_group.add_argument(
13851369
"--skip-test-freebsd",
13861370
help="skip testing Swift stdlibs for FreeBSD",
1387-
action="store_true")
1371+
action=arguments.action.optional_bool)
13881372
run_tests_group.add_argument(
13891373
"--skip-test-cygwin",
13901374
help="skip testing Swift stdlibs for Cygwin",
1391-
action="store_true")
1375+
action=arguments.action.optional_bool)
13921376
parser.add_argument(
13931377
"--build-runtime-with-host-compiler",
13941378
help="Use the host compiler, not the self-built one to compile the "
13951379
"Swift runtime",
1396-
action="store_true")
1380+
action=arguments.action.optional_bool)
13971381
parser.add_argument(
13981382
"--build-swift-stdlib-unittest-extra",
13991383
help="Build optional StdlibUnittest components",
1400-
action="store_true")
1384+
action=arguments.action.optional_bool)
14011385

14021386
run_build_group = parser.add_argument_group(
14031387
title="Run build")
@@ -1408,124 +1392,124 @@ details of the setups of other systems or automated environments.""")
14081392
run_build_group.add_argument(
14091393
"--skip-build-linux",
14101394
help="skip building Swift stdlibs for Linux",
1411-
action="store_true")
1395+
action=arguments.action.optional_bool)
14121396
run_build_group.add_argument(
14131397
"--skip-build-freebsd",
14141398
help="skip building Swift stdlibs for FreeBSD",
1415-
action="store_true")
1399+
action=arguments.action.optional_bool)
14161400
run_build_group.add_argument(
14171401
"--skip-build-cygwin",
14181402
help="skip building Swift stdlibs for Cygwin",
1419-
action="store_true")
1403+
action=arguments.action.optional_bool)
14201404
run_build_group.add_argument(
14211405
"--skip-build-osx",
14221406
help="skip building Swift stdlibs for MacOSX",
1423-
action="store_true")
1407+
action=arguments.action.optional_bool)
14241408

14251409
run_build_group.add_argument(
14261410
"--skip-build-ios",
14271411
help="skip building Swift stdlibs for iOS",
1428-
action="store_true")
1412+
action=arguments.action.optional_bool)
14291413
run_build_group.add_argument(
14301414
"--skip-build-ios-device",
14311415
help="skip building Swift stdlibs for iOS devices "
14321416
"(i.e. build simulators only)",
1433-
action="store_true")
1417+
action=arguments.action.optional_bool)
14341418
run_build_group.add_argument(
14351419
"--skip-build-ios-simulator",
14361420
help="skip building Swift stdlibs for iOS simulator "
14371421
"(i.e. build devices only)",
1438-
action="store_true")
1422+
action=arguments.action.optional_bool)
14391423

14401424
run_build_group.add_argument(
14411425
"--skip-build-tvos",
14421426
help="skip building Swift stdlibs for tvOS",
1443-
action="store_true")
1427+
action=arguments.action.optional_bool)
14441428
run_build_group.add_argument(
14451429
"--skip-build-tvos-device",
14461430
help="skip building Swift stdlibs for tvOS devices "
14471431
"(i.e. build simulators only)",
1448-
action="store_true")
1432+
action=arguments.action.optional_bool)
14491433
run_build_group.add_argument(
14501434
"--skip-build-tvos-simulator",
14511435
help="skip building Swift stdlibs for tvOS simulator "
14521436
"(i.e. build devices only)",
1453-
action="store_true")
1437+
action=arguments.action.optional_bool)
14541438

14551439
run_build_group.add_argument(
14561440
"--skip-build-watchos",
14571441
help="skip building Swift stdlibs for watchOS",
1458-
action="store_true")
1442+
action=arguments.action.optional_bool)
14591443
run_build_group.add_argument(
14601444
"--skip-build-watchos-device",
14611445
help="skip building Swift stdlibs for watchOS devices "
14621446
"(i.e. build simulators only)",
1463-
action="store_true")
1447+
action=arguments.action.optional_bool)
14641448
run_build_group.add_argument(
14651449
"--skip-build-watchos-simulator",
14661450
help="skip building Swift stdlibs for watchOS simulator "
14671451
"(i.e. build devices only)",
1468-
action="store_true")
1452+
action=arguments.action.optional_bool)
14691453

14701454
run_build_group.add_argument(
14711455
"--skip-build-android",
14721456
help="skip building Swift stdlibs for Android",
1473-
action="store_true")
1457+
action=arguments.action.optional_bool)
14741458

14751459
run_build_group.add_argument(
14761460
"--skip-build-benchmarks",
14771461
help="skip building Swift Benchmark Suite",
1478-
action="store_true")
1462+
action=arguments.action.optional_bool)
14791463

14801464
skip_test_group = parser.add_argument_group(
14811465
title="Skip testing specified targets")
14821466
skip_test_group.add_argument(
14831467
"--skip-test-ios",
14841468
help="skip testing all iOS targets. Equivalent to specifying both "
14851469
"--skip-test-ios-simulator and --skip-test-ios-host",
1486-
action="store_true")
1470+
action=arguments.action.optional_bool)
14871471
skip_test_group.add_argument(
14881472
"--skip-test-ios-simulator",
14891473
help="skip testing iOS simulator targets",
1490-
action="store_true")
1474+
action=arguments.action.optional_bool)
14911475
skip_test_group.add_argument(
14921476
"--skip-test-ios-host",
14931477
help="skip testing iOS device targets on the host machine (the phone "
14941478
"itself)",
1495-
action="store_true")
1479+
action=arguments.action.optional_bool)
14961480
skip_test_group.add_argument(
14971481
"--skip-test-tvos",
14981482
help="skip testing all tvOS targets. Equivalent to specifying both "
14991483
"--skip-test-tvos-simulator and --skip-test-tvos-host",
1500-
action="store_true")
1484+
action=arguments.action.optional_bool)
15011485
skip_test_group.add_argument(
15021486
"--skip-test-tvos-simulator",
15031487
help="skip testing tvOS simulator targets",
1504-
action="store_true")
1488+
action=arguments.action.optional_bool)
15051489
skip_test_group.add_argument(
15061490
"--skip-test-tvos-host",
15071491
help="skip testing tvOS device targets on the host machine (the TV "
15081492
"itself)",
1509-
action="store_true")
1493+
action=arguments.action.optional_bool)
15101494
skip_test_group.add_argument(
15111495
"--skip-test-watchos",
15121496
help="skip testing all tvOS targets. Equivalent to specifying both "
15131497
"--skip-test-watchos-simulator and --skip-test-watchos-host",
1514-
action="store_true")
1498+
action=arguments.action.optional_bool)
15151499
skip_test_group.add_argument(
15161500
"--skip-test-watchos-simulator",
15171501
help="skip testing watchOS simulator targets",
1518-
action="store_true")
1502+
action=arguments.action.optional_bool)
15191503
skip_test_group.add_argument(
15201504
"--skip-test-watchos-host",
15211505
help="skip testing watchOS device targets on the host machine (the "
15221506
"watch itself)",
1523-
action="store_true")
1507+
action=arguments.action.optional_bool)
15241508
skip_test_group.add_argument(
15251509
"--skip-test-android-host",
15261510
help="skip testing Android device targets on the host machine (the "
15271511
"phone itself)",
1528-
action="store_true")
1512+
action=arguments.action.optional_bool)
15291513

15301514
parser.add_argument(
15311515
"-i", "--ios",
@@ -1542,7 +1526,7 @@ details of the setups of other systems or automated environments.""")
15421526
"--tvos",
15431527
help="also build for tvOS, but disallow tests that require a tvos "
15441528
"device",
1545-
action="store_true")
1529+
action=arguments.action.optional_bool)
15461530
parser.add_argument(
15471531
"--skip-tvos",
15481532
help="set to skip everything tvOS-related",
@@ -1553,7 +1537,7 @@ details of the setups of other systems or automated environments.""")
15531537
"--watchos",
15541538
help="also build for watchOS, but disallow tests that require an "
15551539
"watchOS device",
1556-
action="store_true")
1540+
action=arguments.action.optional_bool)
15571541
parser.add_argument(
15581542
"--skip-watchos",
15591543
help="set to skip everything watchOS-related",
@@ -1563,7 +1547,7 @@ details of the setups of other systems or automated environments.""")
15631547
parser.add_argument(
15641548
"--android",
15651549
help="also build for Android",
1566-
action="store_true")
1550+
action=arguments.action.optional_bool)
15671551

15681552
parser.add_argument(
15691553
"--swift-analyze-code-coverage",
@@ -1609,7 +1593,7 @@ details of the setups of other systems or automated environments.""")
16091593
parser.add_argument(
16101594
"--show-sdks",
16111595
help="print installed Xcode and SDK versions",
1612-
action="store_true")
1596+
action=arguments.action.optional_bool)
16131597

16141598
parser.add_argument(
16151599
"--extra-swift-args",
@@ -1677,15 +1661,15 @@ details of the setups of other systems or automated environments.""")
16771661
parser.add_argument(
16781662
"--distcc",
16791663
help="use distcc in pump mode",
1680-
action="store_true")
1664+
action=arguments.action.optional_bool)
16811665
parser.add_argument(
16821666
"--enable-asan",
16831667
help="enable Address Sanitizer",
1684-
action="store_true")
1668+
action=arguments.action.optional_bool)
16851669
parser.add_argument(
16861670
"--enable-ubsan",
16871671
help="enable Undefined Behavior Sanitizer",
1688-
action="store_true")
1672+
action=arguments.action.optional_bool)
16891673
parser.add_argument(
16901674
"--clang-compiler-version",
16911675
help="string that indicates a compiler version for Clang",
@@ -1733,11 +1717,7 @@ details of the setups of other systems or automated environments.""")
17331717
parser.add_argument(
17341718
"--verbose-build",
17351719
help="print the commands executed during the build",
1736-
metavar="BOOL",
1737-
nargs='?',
1738-
type=arguments.type.bool,
1739-
default=False,
1740-
const=True)
1720+
action=arguments.action.optional_bool)
17411721

17421722
parser.add_argument(
17431723
"--lto",

utils/swift_build_support/swift_build_support/arguments.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,26 @@ def __call__(self, parser, namespace, values, option_string=None):
141141
setattr(namespace, self.dest, val)
142142

143143
_register(action, 'concat', _ConcatAction)
144+
145+
146+
class _OptionalBoolAction(argparse.Action):
147+
def __init__(self,
148+
option_strings,
149+
dest,
150+
default=False,
151+
metavar="BOOL",
152+
help=None):
153+
super(_OptionalBoolAction, self).__init__(
154+
option_strings=option_strings,
155+
dest=dest,
156+
default=default,
157+
metavar=metavar,
158+
nargs="?",
159+
type=type.bool,
160+
help=help,
161+
const=True)
162+
163+
def __call__(self, parser, namespace, values, option_string=None):
164+
setattr(namespace, self.dest, values)
165+
166+
_register(action, 'optional_bool', _OptionalBoolAction)

0 commit comments

Comments
 (0)