@@ -16,8 +16,6 @@ import multiprocessing
16
16
import os
17
17
import pipes
18
18
import platform
19
- import re
20
- import shlex
21
19
import sys
22
20
23
21
# FIXME: Instead of modifying the system path in order to enable imports from
@@ -40,6 +38,7 @@ from SwiftBuildSupport import (
40
38
sys .path .append (os .path .join (os .path .dirname (__file__ ), 'swift_build_support' ))
41
39
42
40
# E402 means module level import not at top of file
41
+ from swift_build_support import arguments # noqa (E402)
43
42
from swift_build_support .toolchain import host_toolchain # noqa (E402)
44
43
import swift_build_support .debug # noqa (E402)
45
44
from swift_build_support import migration # noqa (E402)
@@ -52,50 +51,6 @@ from swift_build_support.workspace import Workspace # noqa(E402)
52
51
from swift_build_support .workspace import compute_build_subdir # noqa(E402)
53
52
54
53
55
- # A strict parser for bools (unlike Python's `bool()`, where
56
- # `bool('False')` is `True`).
57
- #
58
- # This function can be passed as `type=` argument to argparse to parse values
59
- # passed to command line arguments.
60
- def argparse_bool (string ):
61
- if string in ['0' , 'false' , 'False' ]:
62
- return False
63
- if string in ['1' , 'true' , 'True' ]:
64
- return True
65
- raise argparse .ArgumentTypeError ("%r is not a boolean value" % string )
66
-
67
-
68
- # Parse and split shell arguments string into a list of shell arguments.
69
- # Recognize `,` as a separator as well as white spaces.
70
- # string: -BAR="foo bar" -BAZ='foo,bar',-QUX 42
71
- # into
72
- # ['-BAR=foo bar', '-BAZ=foo,bar', "-QUX", "42"]
73
- def argparse_shell_split (string ):
74
- lex = shlex .shlex (string , posix = True )
75
- lex .whitespace_split = True
76
- lex .whitespace += ','
77
- return list (lex )
78
-
79
-
80
- # Parse version string and split into a tuple of strings (major, minor, patch)
81
- # Support only "MAJOR.MINOR.PATCH" format.
82
- def argparse_clang_compiler_version (string ):
83
- m = re .match (r'([0-9]*)\.([0-9]*)\.([0-9]*)' , string )
84
- if m is not None :
85
- return m .group (1 , 2 , 3 )
86
- raise argparse .ArgumentTypeError (
87
- "%r is invalid version value. must be 'MAJOR.MINOR.PATCH'" % string )
88
-
89
-
90
- # Check the string is executable path string.
91
- # Convert it to absolute path.
92
- def argparse_executable (string ):
93
- if os .access (string , os .X_OK ):
94
- return os .path .abspath (string )
95
- raise argparse .ArgumentTypeError (
96
- "%r is not executable" % string )
97
-
98
-
99
54
# Main entry point for the preset mode.
100
55
def main_preset ():
101
56
parser = argparse .ArgumentParser (
@@ -595,7 +550,7 @@ details of the setups of other systems or automated environments.""")
595
550
help = "test Swift after building" ,
596
551
metavar = "BOOL" ,
597
552
nargs = '?' ,
598
- type = argparse_bool ,
553
+ type = arguments . type . bool ,
599
554
default = False ,
600
555
const = True )
601
556
run_tests_group .add_argument (
@@ -609,7 +564,7 @@ details of the setups of other systems or automated environments.""")
609
564
help = "run the validation test suite (implies --test)" ,
610
565
metavar = "BOOL" ,
611
566
nargs = '?' ,
612
- type = argparse_bool ,
567
+ type = arguments . type . bool ,
613
568
default = False ,
614
569
const = True )
615
570
run_tests_group .add_argument (
@@ -623,15 +578,15 @@ details of the setups of other systems or automated environments.""")
623
578
help = "run the test suite in optimized mode too (implies --test)" ,
624
579
metavar = "BOOL" ,
625
580
nargs = '?' ,
626
- type = argparse_bool ,
581
+ type = arguments . type . bool ,
627
582
default = False ,
628
583
const = True )
629
584
run_tests_group .add_argument (
630
585
"--long-test" ,
631
586
help = "run the long test suite" ,
632
587
metavar = "BOOL" ,
633
588
nargs = '?' ,
634
- type = argparse_bool ,
589
+ type = arguments . type . bool ,
635
590
default = False ,
636
591
const = True )
637
592
run_tests_group .add_argument (
@@ -864,7 +819,7 @@ details of the setups of other systems or automated environments.""")
864
819
"--cmake" ,
865
820
help = "the path to a CMake executable that will be used to build "
866
821
"Swift" ,
867
- type = argparse_executable ,
822
+ type = arguments . type . executable ,
868
823
metavar = "PATH" )
869
824
parser .add_argument (
870
825
"--show-sdks" ,
@@ -920,13 +875,13 @@ details of the setups of other systems or automated environments.""")
920
875
"--host-cc" ,
921
876
help = "the absolute path to CC, the 'clang' compiler for the host "
922
877
"platform. Default is auto detected." ,
923
- type = argparse_executable ,
878
+ type = arguments . type . executable ,
924
879
metavar = "PATH" )
925
880
parser .add_argument (
926
881
"--host-cxx" ,
927
882
help = "the absolute path to CXX, the 'clang++' compiler for the host "
928
883
"platform. Default is auto detected." ,
929
- type = argparse_executable ,
884
+ type = arguments . type . executable ,
930
885
metavar = "PATH" )
931
886
parser .add_argument (
932
887
"--distcc" ,
@@ -943,7 +898,7 @@ details of the setups of other systems or automated environments.""")
943
898
parser .add_argument (
944
899
"--clang-compiler-version" ,
945
900
help = "string that indicates a compiler version for Clang" ,
946
- type = argparse_clang_compiler_version ,
901
+ type = arguments . type . clang_compiler_version ,
947
902
metavar = "MAJOR.MINOR.PATCH" )
948
903
949
904
parser .add_argument (
@@ -973,23 +928,23 @@ details of the setups of other systems or automated environments.""")
973
928
"separated options '-DCMAKE_VAR1=YES,-DCMAKE_VAR2=/tmp'. Can be "
974
929
"called multiple times to add multiple such options." ,
975
930
action = "append" ,
976
- type = argparse_shell_split ,
931
+ type = arguments . type . shell_split ,
977
932
default = [])
978
933
979
934
parser .add_argument (
980
935
"--build-args" ,
981
936
help = "arguments to the build tool. This would be prepended to the "
982
937
"default argument that is '-j8' when CMake generator is "
983
938
"\" Ninja\" ." ,
984
- type = argparse_shell_split ,
939
+ type = arguments . type . shell_split ,
985
940
default = [])
986
941
987
942
parser .add_argument (
988
943
"--verbose-build" ,
989
944
help = "print the commands executed during the build" ,
990
945
metavar = "BOOL" ,
991
946
nargs = '?' ,
992
- type = argparse_bool ,
947
+ type = arguments . type . bool ,
993
948
default = False ,
994
949
const = True )
995
950
0 commit comments