@@ -42,11 +42,9 @@ from SwiftBuildSupport import (
42
42
sys .path .append (os .path .join (os .path .dirname (__file__ ), 'swift_build_support' ))
43
43
44
44
# E402 means module level import not at top of file
45
- import swift_build_support .toolchain # noqa (E402)
46
- import swift_build_support .cmake # noqa (E402)
45
+ from swift_build_support .toolchain import host_toolchain # noqa (E402)
47
46
import swift_build_support .debug # noqa (E402)
48
47
from swift_build_support import migration # noqa (E402)
49
- import swift_build_support .ninja # noqa (E402)
50
48
import swift_build_support .tar # noqa (E402)
51
49
import swift_build_support .targets # noqa (E402)
52
50
from swift_build_support .cmake import CMake # noqa (E402)
@@ -87,6 +85,15 @@ def argparse_clang_compiler_version(string):
87
85
"%r is invalid version value. must be 'MAJOR.MINOR.PATCH'" % string )
88
86
89
87
88
+ # Check the string is executable path string.
89
+ # Convert it to absolute path.
90
+ def argparse_executable (string ):
91
+ if os .access (string , os .X_OK ):
92
+ return os .path .abspath (string )
93
+ raise argparse .ArgumentTypeError (
94
+ "%r is not execuable" % string )
95
+
96
+
90
97
# Main entry point for the preset mode.
91
98
def main_preset ():
92
99
parser = argparse .ArgumentParser (
@@ -773,7 +780,9 @@ details of the setups of other systems or automated environments.""")
773
780
parser .add_argument (
774
781
"--cmake" ,
775
782
help = "the path to a CMake executable that will be used to build "
776
- "Swift" )
783
+ "Swift" ,
784
+ type = argparse_executable ,
785
+ metavar = "PATH" )
777
786
parser .add_argument (
778
787
"--show-sdks" ,
779
788
help = "print installed Xcode and SDK versions" ,
@@ -828,11 +837,13 @@ details of the setups of other systems or automated environments.""")
828
837
"--host-cc" ,
829
838
help = "the absolute path to CC, the 'clang' compiler for the host "
830
839
"platform. Default is auto detected." ,
840
+ type = argparse_executable ,
831
841
metavar = "PATH" )
832
842
parser .add_argument (
833
843
"--host-cxx" ,
834
844
help = "the absolute path to CXX, the 'clang++' compiler for the host "
835
845
"platform. Default is auto detected." ,
846
+ type = argparse_executable ,
836
847
metavar = "PATH" )
837
848
parser .add_argument (
838
849
"--distcc" ,
@@ -893,6 +904,35 @@ details of the setups of other systems or automated environments.""")
893
904
if '--check-args-only' in args .build_script_impl_args :
894
905
return 0
895
906
907
+ # Prepare and validate toolchain
908
+ toolchain = host_toolchain (xcrun_toolchain = args .darwin_xcrun_toolchain )
909
+
910
+ if args .host_cc is not None :
911
+ toolchain .cc = args .host_cc
912
+ if args .host_cxx is not None :
913
+ toolchain .cxx = args .host_cxx
914
+ if args .cmake is not None :
915
+ toolchain .cmake = args .cmake
916
+
917
+ if toolchain .cc is None or toolchain .cxx is None :
918
+ print_with_argv0 (
919
+ "Can't find clang. Please install clang-3.5 or a later version." )
920
+ return 1
921
+
922
+ if toolchain .cmake is None :
923
+ print_with_argv0 ("Can't find CMake. Please install CMake." )
924
+ return 1
925
+
926
+ if args .distcc :
927
+ if toolchain .distcc is None :
928
+ print_with_argv0 (
929
+ "Can't find distcc. Please install distcc" )
930
+ return 1
931
+ if toolchain .distcc_pump is None :
932
+ print_with_argv0 (
933
+ "Can't find distcc-pump. Please install distcc-pump" )
934
+ return 1
935
+
896
936
if args .host_target is None or args .stdlib_deployment_targets is None :
897
937
print_with_argv0 ("Unknown operating system." )
898
938
return 1
@@ -1212,61 +1252,19 @@ details of the setups of other systems or automated environments.""")
1212
1252
if args .clean and os .path .isdir (build_dir ):
1213
1253
shutil .rmtree (build_dir )
1214
1254
1215
- host_clang = swift_build_support .toolchain .host_clang (
1216
- xcrun_toolchain = args .darwin_xcrun_toolchain )
1217
- if args .host_cc is None and host_clang is not None :
1218
- args .host_cc = str (host_clang .cc )
1219
- if args .host_cxx is None and host_clang is not None :
1220
- args .host_cxx = str (host_clang .cxx )
1221
- is_host_clang_ok = (
1222
- args .host_cc is not None and os .access (args .host_cc , os .X_OK ) and
1223
- args .host_cxx is not None and os .access (args .host_cxx , os .X_OK ))
1224
- if not is_host_clang_ok :
1225
- print_with_argv0 (
1226
- "Can't find clang. Please install clang-3.5 or a later version." )
1227
- return 1
1228
-
1229
- host_cmake = args .cmake
1230
- if not host_cmake :
1231
- host_cmake = swift_build_support .cmake .host_cmake (
1232
- args .darwin_xcrun_toolchain )
1233
- if not host_cmake :
1234
- print_with_argv0 ("Can't find CMake. Please install CMake." )
1235
- return 1
1236
-
1237
- # distcc usage.
1238
- host_distcc = None
1239
- host_distcc_pump = None
1240
- if args .distcc :
1241
- host_distcc = swift_build_support .which ('distcc' )
1242
- # On some platforms, 'pump' may be unrelated to distcc, in which case
1243
- # it's called 'distcc-pump'.
1244
- host_distcc_pump = swift_build_support .which ('distcc-pump' )
1245
- if host_distcc_pump is None :
1246
- host_distcc_pump = swift_build_support .which ('pump' )
1247
-
1248
- if host_distcc is None or host_distcc_pump is None :
1249
- print_with_argv0 (
1250
- "Can't find distcc. Please install distcc" )
1251
-
1252
- host_distcc = str (host_distcc )
1253
- host_distcc_pump = str (host_distcc_pump )
1254
-
1255
1255
cmake = CMake (args = args ,
1256
- host_cc = args .host_cc ,
1257
- host_cxx = args .host_cxx ,
1258
- host_distcc = host_distcc )
1256
+ toolchain = toolchain )
1259
1257
1260
1258
build_script_impl_args = [
1261
1259
"--build-dir" , build_dir ,
1262
1260
"--install-prefix" , os .path .abspath (args .install_prefix ),
1263
1261
"--host-target" , args .host_target ,
1264
1262
"--stdlib-deployment-targets" ,
1265
1263
" " .join (args .stdlib_deployment_targets ),
1266
- "--host-cc" , args . host_cc ,
1267
- "--host-cxx" , args . host_cxx ,
1264
+ "--host-cc" , toolchain . cc ,
1265
+ "--host-cxx" , toolchain . cxx ,
1268
1266
"--darwin-xcrun-toolchain" , args .darwin_xcrun_toolchain ,
1269
- "--cmake" , host_cmake ,
1267
+ "--cmake" , toolchain . cmake ,
1270
1268
"--cmark-build-type" , args .cmark_build_variant ,
1271
1269
"--llvm-build-type" , args .llvm_build_variant ,
1272
1270
"--swift-build-type" , args .swift_build_variant ,
@@ -1290,7 +1288,7 @@ details of the setups of other systems or automated environments.""")
1290
1288
if args .distcc :
1291
1289
build_script_impl_args += [
1292
1290
"--distcc" ,
1293
- "--distcc-pump=%s" % host_distcc_pump
1291
+ "--distcc-pump=%s" % toolchain . distcc_pump
1294
1292
]
1295
1293
if args .enable_asan :
1296
1294
build_script_impl_args += ["--enable-asan" ]
@@ -1310,8 +1308,8 @@ details of the setups of other systems or automated environments.""")
1310
1308
build_script_impl_args += [
1311
1309
"--foundation-build-type" , args .foundation_build_variant
1312
1310
]
1313
- if args .cmake_generator == 'Ninja' and \
1314
- not swift_build_support .ninja . is_ninja_installed ( ):
1311
+ if ( args .cmake_generator == 'Ninja' and
1312
+ toolchain .ninja is None ):
1315
1313
build_script_impl_args += ["--build-ninja" ]
1316
1314
1317
1315
if args .skip_build_linux :
0 commit comments