7
7
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
8
8
9
9
10
- import argparse
11
10
import multiprocessing
12
11
13
12
import android .adb .commands
18
17
from swift_build_support .swift_build_support .targets import \
19
18
StdlibDeploymentTarget
20
19
20
+ from . import argparse
21
21
from . import defaults
22
22
23
23
@@ -224,22 +224,39 @@ def _apply_default_arguments(args):
224
224
def create_argument_parser ():
225
225
"""Return a configured argument parser."""
226
226
227
+ # NOTE: USAGE, DESCRIPTION and EPILOG are defined at the bottom of the file
227
228
parser = _ApplyDefaultsArgumentParser (
228
229
apply_defaults = _apply_default_arguments ,
229
230
formatter_class = argparse .RawDescriptionHelpFormatter ,
230
231
usage = USAGE ,
231
232
description = DESCRIPTION ,
232
233
epilog = EPILOG )
233
234
235
+ builder = parser .to_builder ()
236
+
237
+ # Prepare DSL functions
238
+ option = builder .add_option
239
+ set_defaults = builder .set_defaults
240
+ in_group = builder .in_group
241
+ mutually_exclusive_group = builder .mutually_exclusive_group
242
+
243
+ # Prepare DSL actions
244
+ store = builder .actions .store
245
+ store_path = builder .actions .store_path
246
+
247
+ # -------------------------------------------------------------------------
248
+ # Top-level options
249
+
234
250
parser .add_argument (
235
251
'-n' , '--dry-run' ,
236
252
action = 'store_true' ,
237
253
default = False ,
238
254
help = 'print the commands that would be executed, but do not execute '
239
255
'them' )
240
256
parser .add_argument (
241
- '--no-legacy-impl' , dest = 'legacy_impl' ,
257
+ '--no-legacy-impl' ,
242
258
action = 'store_false' ,
259
+ dest = 'legacy_impl' ,
243
260
default = True ,
244
261
help = 'avoid legacy implementation' )
245
262
@@ -541,6 +558,7 @@ def create_argument_parser():
541
558
'--skip-test-optimized' ,
542
559
action = arguments .action .unavailable )
543
560
561
+ # -------------------------------------------------------------------------
544
562
targets_group = parser .add_argument_group (
545
563
title = 'Host and cross-compilation targets' )
546
564
targets_group .add_argument (
@@ -570,6 +588,7 @@ def create_argument_parser():
570
588
help = 'A space-separated list that filters which of the configured '
571
589
'targets to build the Swift standard library for, or "all".' )
572
590
591
+ # -------------------------------------------------------------------------
573
592
projects_group = parser .add_argument_group (
574
593
title = 'Options to select projects' )
575
594
projects_group .add_argument (
@@ -622,6 +641,7 @@ def create_argument_parser():
622
641
action = arguments .action .enable ,
623
642
help = 'build the Ninja tool' )
624
643
644
+ # -------------------------------------------------------------------------
625
645
extra_actions_group = parser .add_argument_group (
626
646
title = 'Extra actions to perform before or in addition to building' )
627
647
extra_actions_group .add_argument (
@@ -638,6 +658,7 @@ def create_argument_parser():
638
658
help = 'if provided, an archive of the symbols directory will be '
639
659
'generated at this path' )
640
660
661
+ # -------------------------------------------------------------------------
641
662
build_variant_group = parser .add_mutually_exclusive_group (required = False )
642
663
build_variant_group .add_argument (
643
664
'-d' , '--debug' ,
@@ -661,6 +682,7 @@ def create_argument_parser():
661
682
dest = 'build_variant' ,
662
683
help = 'build the Release variant of everything (default is Debug)' )
663
684
685
+ # -------------------------------------------------------------------------
664
686
build_variant_override_group = parser .add_argument_group (
665
687
title = 'Override build variant for a specific project' )
666
688
build_variant_override_group .add_argument (
@@ -713,99 +735,73 @@ def create_argument_parser():
713
735
dest = 'libicu_build_variant' ,
714
736
help = 'build the Debug variant of libicu' )
715
737
716
- assertions_group = parser .add_mutually_exclusive_group (required = False )
717
- assertions_group .add_argument (
718
- '--assertions' ,
719
- action = 'store_const' ,
720
- const = True ,
721
- dest = 'assertions' ,
722
- help = 'enable assertions in all projects' )
723
- assertions_group .add_argument (
724
- '--no-assertions' ,
725
- action = 'store_const' ,
726
- const = False ,
727
- dest = 'assertions' ,
728
- help = 'disable assertions in all projects' )
729
-
730
- assertions_override_group = parser .add_argument_group (
731
- title = 'Control assertions in a specific project' )
732
- assertions_override_group .add_argument (
733
- '--cmark-assertions' ,
734
- action = 'store_const' ,
735
- const = True ,
736
- dest = 'cmark_assertions' ,
737
- help = 'enable assertions in CommonMark' )
738
- assertions_override_group .add_argument (
739
- '--llvm-assertions' ,
740
- action = 'store_const' ,
741
- const = True ,
742
- dest = 'llvm_assertions' ,
743
- help = 'enable assertions in LLVM' )
744
- assertions_override_group .add_argument (
745
- '--no-llvm-assertions' ,
746
- action = 'store_const' ,
747
- const = False ,
748
- dest = 'llvm_assertions' ,
749
- help = 'disable assertions in LLVM' )
750
- assertions_override_group .add_argument (
751
- '--swift-assertions' ,
752
- action = 'store_const' ,
753
- const = True ,
754
- dest = 'swift_assertions' ,
755
- help = 'enable assertions in Swift' )
756
- assertions_override_group .add_argument (
757
- '--no-swift-assertions' ,
758
- action = 'store_const' ,
759
- const = False ,
760
- dest = 'swift_assertions' ,
761
- help = 'disable assertions in Swift' )
762
- assertions_override_group .add_argument (
763
- '--swift-stdlib-assertions' ,
764
- action = 'store_const' ,
765
- const = True ,
766
- dest = 'swift_stdlib_assertions' ,
767
- help = 'enable assertions in the Swift standard library' )
768
- assertions_override_group .add_argument (
769
- '--no-swift-stdlib-assertions' ,
770
- action = 'store_const' ,
771
- const = False ,
772
- dest = 'swift_stdlib_assertions' ,
773
- help = 'disable assertions in the Swift standard library' )
774
- assertions_override_group .add_argument (
775
- '--lldb-assertions' ,
776
- action = 'store_const' ,
777
- const = True ,
778
- dest = 'lldb_assertions' ,
779
- help = 'enable assertions in LLDB' )
780
- assertions_override_group .add_argument (
781
- '--no-lldb-assertions' ,
782
- action = 'store_const' ,
783
- const = False ,
784
- dest = 'lldb_assertions' ,
785
- help = 'disable assertions in LLDB' )
786
-
787
- # FIXME: This should be one option using choices=[...]
788
- cmake_generator_group = parser .add_argument_group (
789
- title = 'Select the CMake generator' )
790
- cmake_generator_group .add_argument (
791
- '-x' , '--xcode' ,
792
- action = 'store_const' ,
793
- const = 'Xcode' ,
794
- dest = 'cmake_generator' ,
795
- help = "use CMake's Xcode generator (default is Ninja)" )
796
- cmake_generator_group .add_argument (
797
- '-m' , '--make' ,
798
- action = 'store_const' ,
799
- const = 'Unix Makefiles' ,
800
- dest = 'cmake_generator' ,
801
- help = "use CMake's Makefile generator (default is Ninja)" )
802
- cmake_generator_group .add_argument (
803
- '-e' , '--eclipse' ,
804
- action = 'store_const' ,
805
- const = 'Eclipse CDT4 - Ninja' ,
806
- dest = 'cmake_generator' ,
807
- help = "use CMake's Eclipse generator (default is Ninja)" )
808
-
738
+ # -------------------------------------------------------------------------
739
+ # Assertions group
740
+
741
+ with mutually_exclusive_group ():
742
+ set_defaults (assertions = True )
743
+
744
+ # TODO: Convert to store_true
745
+ option ('--assertions' , store ,
746
+ const = True ,
747
+ help = 'enable assertions in all projects' )
748
+
749
+ # TODO: Convert to store_false
750
+ option ('--no-assertions' , store ('assertions' ),
751
+ const = False ,
752
+ help = 'disable assertions in all projects' )
753
+
754
+ # -------------------------------------------------------------------------
755
+ in_group ('Control assertions in a specific project' )
756
+
757
+ option ('--cmark-assertions' , store ,
758
+ const = True ,
759
+ help = 'enable assertions in CommonMark' )
760
+
761
+ option ('--llvm-assertions' , store ,
762
+ const = True ,
763
+ help = 'enable assertions in LLVM' )
764
+ option ('--no-llvm-assertions' , store ('llvm_assertions' ),
765
+ const = False ,
766
+ help = 'disable assertions in LLVM' )
767
+
768
+ option ('--swift-assertions' , store ,
769
+ const = True ,
770
+ help = 'enable assertions in Swift' )
771
+ option ('--no-swift-assertions' , store ('swift_assertions' ),
772
+ const = False ,
773
+ help = 'disable assertions in Swift' )
774
+
775
+ option ('--swift-stdlib-assertions' , store ,
776
+ const = True ,
777
+ help = 'enable assertions in the Swift standard library' )
778
+ option ('--no-swift-stdlib-assertions' , store ('swift_stdlib_assertions' ),
779
+ const = False ,
780
+ help = 'disable assertions in the Swift standard library' )
781
+
782
+ option ('--lldb-assertions' , store ,
783
+ const = True ,
784
+ help = 'enable assertions in LLDB' )
785
+ option ('--no-lldb-assertions' , store ('lldb_assertions' ),
786
+ const = False ,
787
+ help = 'disable assertions in LLDB' )
788
+
789
+ # -------------------------------------------------------------------------
790
+ in_group ('Select the CMake generator' )
791
+
792
+ set_defaults (cmake_generator = defaults .CMAKE_GENERATOR )
793
+
794
+ option (['-e' , '--eclipse' ], store ('cmake_generator' ),
795
+ const = 'Eclipse CDT4 - Ninja' ,
796
+ help = "use CMake's Eclipse generator (%(default)s by default)" )
797
+ option (['-m' , '--make' ], store ('cmake_generator' ),
798
+ const = 'Unix Makefiles' ,
799
+ help = "use CMake's Makefile generator (%(default)s by default)" )
800
+ option (['-x' , '--xcode' ], store ('cmake_generator' ),
801
+ const = 'Xcode' ,
802
+ help = "use CMake's Xcode generator (%(default)s by default)" )
803
+
804
+ # -------------------------------------------------------------------------
809
805
run_tests_group = parser .add_argument_group (
810
806
title = 'Run tests' )
811
807
@@ -907,6 +903,7 @@ def create_argument_parser():
907
903
dest = 'test_cygwin' ,
908
904
help = 'skip testing Swift stdlibs for Cygwin' )
909
905
906
+ # -------------------------------------------------------------------------
910
907
run_build_group = parser .add_argument_group (
911
908
title = 'Run build' )
912
909
run_build_group .add_argument (
@@ -1028,6 +1025,7 @@ def create_argument_parser():
1028
1025
dest = 'build_external_benchmarks' ,
1029
1026
help = 'skip building Swift Benchmark Suite' )
1030
1027
1028
+ # -------------------------------------------------------------------------
1031
1029
skip_test_group = parser .add_argument_group (
1032
1030
title = 'Skip testing specified targets' )
1033
1031
skip_test_group .add_argument (
@@ -1093,58 +1091,51 @@ def create_argument_parser():
1093
1091
help = 'skip testing Android device targets on the host machine (the '
1094
1092
'phone itself)' )
1095
1093
1096
- llvm_group = parser .add_argument_group (
1097
- title = 'Build settings specific for LLVM' )
1098
- llvm_group .add_argument (
1099
- '--llvm-targets-to-build' ,
1100
- default = 'X86;ARM;AArch64;PowerPC;SystemZ;Mips' ,
1101
- help = 'LLVM target generators to build' )
1102
-
1103
- android_group = parser .add_argument_group (
1104
- title = 'Build settings for Android' )
1105
- android_group .add_argument (
1106
- '--android-ndk' ,
1107
- metavar = 'PATH' ,
1108
- help = 'An absolute path to the NDK that will be used as a libc '
1109
- 'implementation for Android builds' )
1110
- android_group .add_argument (
1111
- '--android-api-level' ,
1112
- default = '21' ,
1113
- help = 'The Android API level to target when building for Android. '
1114
- 'Currently only 21 or above is supported' )
1115
- android_group .add_argument (
1116
- '--android-ndk-gcc-version' ,
1117
- choices = ['4.8' , '4.9' ],
1118
- default = '4.9' ,
1119
- help = 'The GCC version to use when building for Android. Currently '
1120
- 'only 4.9 is supported. %(default)s is also the default value. '
1121
- 'This option may be used when experimenting with versions '
1122
- 'of the Android NDK not officially supported by Swift' )
1123
- android_group .add_argument (
1124
- '--android-icu-uc' ,
1125
- metavar = 'PATH' ,
1126
- help = 'Path to a directory containing libicuuc.so' )
1127
- android_group .add_argument (
1128
- '--android-icu-uc-include' ,
1129
- metavar = 'PATH' ,
1130
- help = 'Path to a directory containing headers for libicuuc' )
1131
- android_group .add_argument (
1132
- '--android-icu-i18n' ,
1133
- metavar = 'PATH' ,
1134
- help = 'Path to a directory containing libicui18n.so' )
1135
- android_group .add_argument (
1136
- '--android-icu-i18n-include' ,
1137
- metavar = 'PATH' ,
1138
- help = 'Path to a directory containing headers libicui18n' )
1139
- android_group .add_argument (
1140
- '--android-deploy-device-path' ,
1141
- default = android .adb .commands .DEVICE_TEMP_DIR ,
1142
- metavar = 'PATH' ,
1143
- help = 'Path on an Android device to which built Swift stdlib products '
1144
- 'will be deployed. If running host tests, specify the "{}" '
1145
- 'directory.' .format (android .adb .commands .DEVICE_TEMP_DIR ))
1146
-
1147
- return parser
1094
+ # -------------------------------------------------------------------------
1095
+ in_group ('Build settings specific for LLVM' )
1096
+
1097
+ option ('--llvm-targets-to-build' , store ,
1098
+ default = 'X86;ARM;AArch64;PowerPC;SystemZ;Mips' ,
1099
+ help = 'LLVM target generators to build' )
1100
+
1101
+ # -------------------------------------------------------------------------
1102
+ in_group ('Build settings for Android' )
1103
+
1104
+ option ('--android-ndk' , store_path ,
1105
+ help = 'An absolute path to the NDK that will be used as a libc '
1106
+ 'implementation for Android builds' )
1107
+
1108
+ option ('--android-api-level' , store ,
1109
+ default = '21' ,
1110
+ help = 'The Android API level to target when building for Android. '
1111
+ 'Currently only 21 or above is supported' )
1112
+
1113
+ option ('--android-ndk-gcc-version' , store ,
1114
+ choices = ['4.8' , '4.9' ],
1115
+ default = '4.9' ,
1116
+ help = 'The GCC version to use when building for Android. Currently '
1117
+ 'only 4.9 is supported. %(default)s is also the default '
1118
+ 'value. This option may be used when experimenting with '
1119
+ 'versions of the Android NDK not officially supported by '
1120
+ 'Swift' )
1121
+
1122
+ option ('--android-icu-uc' , store_path ,
1123
+ help = 'Path to a directory containing libicuuc.so' )
1124
+ option ('--android-icu-uc-include' , store_path ,
1125
+ help = 'Path to a directory containing headers for libicuuc' )
1126
+ option ('--android-icu-i18n' , store_path ,
1127
+ help = 'Path to a directory containing libicui18n.so' )
1128
+ option ('--android-icu-i18n-include' , store_path ,
1129
+ help = 'Path to a directory containing headers libicui18n' )
1130
+ option ('--android-deploy-device-path' , store_path ,
1131
+ default = android .adb .commands .DEVICE_TEMP_DIR ,
1132
+ help = 'Path on an Android device to which built Swift stdlib '
1133
+ 'products will be deployed. If running host tests, specify '
1134
+ 'the "{}" directory.' .format (
1135
+ android .adb .commands .DEVICE_TEMP_DIR ))
1136
+
1137
+ # -------------------------------------------------------------------------
1138
+ return builder .build ()
1148
1139
1149
1140
1150
1141
# ----------------------------------------------------------------------------
0 commit comments