@@ -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 (
@@ -591,7 +546,7 @@ details of the setups of other systems or automated environments.""")
591
546
help = "test Swift after building" ,
592
547
metavar = "BOOL" ,
593
548
nargs = '?' ,
594
- type = argparse_bool ,
549
+ type = arguments . type . bool ,
595
550
default = False ,
596
551
const = True )
597
552
run_tests_group .add_argument (
@@ -605,7 +560,7 @@ details of the setups of other systems or automated environments.""")
605
560
help = "run the validation test suite (implies --test)" ,
606
561
metavar = "BOOL" ,
607
562
nargs = '?' ,
608
- type = argparse_bool ,
563
+ type = arguments . type . bool ,
609
564
default = False ,
610
565
const = True )
611
566
run_tests_group .add_argument (
@@ -619,15 +574,15 @@ details of the setups of other systems or automated environments.""")
619
574
help = "run the test suite in optimized mode too (implies --test)" ,
620
575
metavar = "BOOL" ,
621
576
nargs = '?' ,
622
- type = argparse_bool ,
577
+ type = arguments . type . bool ,
623
578
default = False ,
624
579
const = True )
625
580
run_tests_group .add_argument (
626
581
"--long-test" ,
627
582
help = "run the long test suite" ,
628
583
metavar = "BOOL" ,
629
584
nargs = '?' ,
630
- type = argparse_bool ,
585
+ type = arguments . type . bool ,
631
586
default = False ,
632
587
const = True )
633
588
run_tests_group .add_argument (
@@ -860,7 +815,7 @@ details of the setups of other systems or automated environments.""")
860
815
"--cmake" ,
861
816
help = "the path to a CMake executable that will be used to build "
862
817
"Swift" ,
863
- type = argparse_executable ,
818
+ type = arguments . type . executable ,
864
819
metavar = "PATH" )
865
820
parser .add_argument (
866
821
"--show-sdks" ,
@@ -916,13 +871,13 @@ details of the setups of other systems or automated environments.""")
916
871
"--host-cc" ,
917
872
help = "the absolute path to CC, the 'clang' compiler for the host "
918
873
"platform. Default is auto detected." ,
919
- type = argparse_executable ,
874
+ type = arguments . type . executable ,
920
875
metavar = "PATH" )
921
876
parser .add_argument (
922
877
"--host-cxx" ,
923
878
help = "the absolute path to CXX, the 'clang++' compiler for the host "
924
879
"platform. Default is auto detected." ,
925
- type = argparse_executable ,
880
+ type = arguments . type . executable ,
926
881
metavar = "PATH" )
927
882
parser .add_argument (
928
883
"--distcc" ,
@@ -939,7 +894,7 @@ details of the setups of other systems or automated environments.""")
939
894
parser .add_argument (
940
895
"--clang-compiler-version" ,
941
896
help = "string that indicates a compiler version for Clang" ,
942
- type = argparse_clang_compiler_version ,
897
+ type = arguments . type . clang_compiler_version ,
943
898
metavar = "MAJOR.MINOR.PATCH" )
944
899
945
900
parser .add_argument (
@@ -969,23 +924,23 @@ details of the setups of other systems or automated environments.""")
969
924
"separated options '-DCMAKE_VAR1=YES,-DCMAKE_VAR2=/tmp'. Can be "
970
925
"called multiple times to add multiple such options." ,
971
926
action = "append" ,
972
- type = argparse_shell_split ,
927
+ type = arguments . type . shell_split ,
973
928
default = [])
974
929
975
930
parser .add_argument (
976
931
"--build-args" ,
977
932
help = "arguments to the build tool. This would be prepended to the "
978
933
"default argument that is '-j8' when CMake generator is "
979
934
"\" Ninja\" ." ,
980
- type = argparse_shell_split ,
935
+ type = arguments . type . shell_split ,
981
936
default = [])
982
937
983
938
parser .add_argument (
984
939
"--verbose-build" ,
985
940
help = "print the commands executed during the build" ,
986
941
metavar = "BOOL" ,
987
942
nargs = '?' ,
988
- type = argparse_bool ,
943
+ type = arguments . type . bool ,
989
944
default = False ,
990
945
const = True )
991
946
0 commit comments