@@ -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" ,
@@ -897,6 +908,35 @@ details of the setups of other systems or automated environments.""")
897
908
if '--check-args-only' in args .build_script_impl_args :
898
909
return 0
899
910
911
+ # Prepare and validate toolchain
912
+ toolchain = host_toolchain (xcrun_toolchain = args .darwin_xcrun_toolchain )
913
+
914
+ if args .host_cc is not None :
915
+ toolchain .cc = args .host_cc
916
+ if args .host_cxx is not None :
917
+ toolchain .cxx = args .host_cxx
918
+ if args .cmake is not None :
919
+ toolchain .cmake = args .cmake
920
+
921
+ if toolchain .cc is None or toolchain .cxx is None :
922
+ print_with_argv0 (
923
+ "Can't find clang. Please install clang-3.5 or a later version." )
924
+ return 1
925
+
926
+ if toolchain .cmake is None :
927
+ print_with_argv0 ("Can't find CMake. Please install CMake." )
928
+ return 1
929
+
930
+ if args .distcc :
931
+ if toolchain .distcc is None :
932
+ print_with_argv0 (
933
+ "Can't find distcc. Please install distcc" )
934
+ return 1
935
+ if toolchain .distcc_pump is None :
936
+ print_with_argv0 (
937
+ "Can't find distcc-pump. Please install distcc-pump" )
938
+ return 1
939
+
900
940
if args .host_target is None or args .stdlib_deployment_targets is None :
901
941
print_with_argv0 ("Unknown operating system." )
902
942
return 1
@@ -1221,61 +1261,19 @@ details of the setups of other systems or automated environments.""")
1221
1261
if args .clean and os .path .isdir (build_dir ):
1222
1262
shutil .rmtree (build_dir )
1223
1263
1224
- host_clang = swift_build_support .toolchain .host_clang (
1225
- xcrun_toolchain = args .darwin_xcrun_toolchain )
1226
- if args .host_cc is None and host_clang is not None :
1227
- args .host_cc = str (host_clang .cc )
1228
- if args .host_cxx is None and host_clang is not None :
1229
- args .host_cxx = str (host_clang .cxx )
1230
- is_host_clang_ok = (
1231
- args .host_cc is not None and os .access (args .host_cc , os .X_OK ) and
1232
- args .host_cxx is not None and os .access (args .host_cxx , os .X_OK ))
1233
- if not is_host_clang_ok :
1234
- print_with_argv0 (
1235
- "Can't find clang. Please install clang-3.5 or a later version." )
1236
- return 1
1237
-
1238
- host_cmake = args .cmake
1239
- if not host_cmake :
1240
- host_cmake = swift_build_support .cmake .host_cmake (
1241
- args .darwin_xcrun_toolchain )
1242
- if not host_cmake :
1243
- print_with_argv0 ("Can't find CMake. Please install CMake." )
1244
- return 1
1245
-
1246
- # distcc usage.
1247
- host_distcc = None
1248
- host_distcc_pump = None
1249
- if args .distcc :
1250
- host_distcc = swift_build_support .which ('distcc' )
1251
- # On some platforms, 'pump' may be unrelated to distcc, in which case
1252
- # it's called 'distcc-pump'.
1253
- host_distcc_pump = swift_build_support .which ('distcc-pump' )
1254
- if host_distcc_pump is None :
1255
- host_distcc_pump = swift_build_support .which ('pump' )
1256
-
1257
- if host_distcc is None or host_distcc_pump is None :
1258
- print_with_argv0 (
1259
- "Can't find distcc. Please install distcc" )
1260
-
1261
- host_distcc = str (host_distcc )
1262
- host_distcc_pump = str (host_distcc_pump )
1263
-
1264
1264
cmake = CMake (args = args ,
1265
- host_cc = args .host_cc ,
1266
- host_cxx = args .host_cxx ,
1267
- host_distcc = host_distcc )
1265
+ toolchain = toolchain )
1268
1266
1269
1267
build_script_impl_args = [
1270
1268
"--build-dir" , build_dir ,
1271
1269
"--install-prefix" , os .path .abspath (args .install_prefix ),
1272
1270
"--host-target" , args .host_target ,
1273
1271
"--stdlib-deployment-targets" ,
1274
1272
" " .join (args .stdlib_deployment_targets ),
1275
- "--host-cc" , args . host_cc ,
1276
- "--host-cxx" , args . host_cxx ,
1273
+ "--host-cc" , toolchain . cc ,
1274
+ "--host-cxx" , toolchain . cxx ,
1277
1275
"--darwin-xcrun-toolchain" , args .darwin_xcrun_toolchain ,
1278
- "--cmake" , host_cmake ,
1276
+ "--cmake" , toolchain . cmake ,
1279
1277
"--cmark-build-type" , args .cmark_build_variant ,
1280
1278
"--llvm-build-type" , args .llvm_build_variant ,
1281
1279
"--swift-build-type" , args .swift_build_variant ,
@@ -1299,7 +1297,7 @@ details of the setups of other systems or automated environments.""")
1299
1297
if args .distcc :
1300
1298
build_script_impl_args += [
1301
1299
"--distcc" ,
1302
- "--distcc-pump=%s" % host_distcc_pump
1300
+ "--distcc-pump=%s" % toolchain . distcc_pump
1303
1301
]
1304
1302
if args .enable_asan :
1305
1303
build_script_impl_args += ["--enable-asan" ]
@@ -1319,8 +1317,7 @@ details of the setups of other systems or automated environments.""")
1319
1317
build_script_impl_args += [
1320
1318
"--foundation-build-type" , args .foundation_build_variant
1321
1319
]
1322
- if args .cmake_generator == 'Ninja' and \
1323
- not swift_build_support .ninja .is_ninja_installed ():
1320
+ if args .cmake_generator == 'Ninja' and toolchain .ninja is None :
1324
1321
build_script_impl_args += ["--build-ninja" ]
1325
1322
1326
1323
if args .skip_build_linux :
0 commit comments