@@ -15,6 +15,7 @@ import argparse
15
15
import multiprocessing
16
16
import os
17
17
import platform
18
+ import re
18
19
import shutil
19
20
import sys
20
21
import pipes
@@ -48,6 +49,7 @@ from swift_build_support import migration # noqa (E402)
48
49
import swift_build_support .ninja # noqa (E402)
49
50
import swift_build_support .tar # noqa (E402)
50
51
import swift_build_support .targets # noqa (E402)
52
+ from swift_build_support .cmake import CMake # noqa (E402)
51
53
52
54
53
55
# A strict parser for bools (unlike Python's `bool()`, where
@@ -75,6 +77,16 @@ def argparse_shell_split(string):
75
77
return list (lex )
76
78
77
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
+
78
90
# Main entry point for the preset mode.
79
91
def main_preset ():
80
92
parser = argparse .ArgumentParser (
@@ -812,6 +824,34 @@ details of the setups of other systems or automated environments.""")
812
824
help = "Path to a directory containing headers libicui18n" ,
813
825
metavar = "PATH" )
814
826
827
+ parser .add_argument (
828
+ "--host-cc" ,
829
+ help = "the absolute path to CC, the 'clang' compiler for the host "
830
+ "platform. Default is auto detected." ,
831
+ metavar = "PATH" )
832
+ parser .add_argument (
833
+ "--host-cxx" ,
834
+ help = "the absolute path to CXX, the 'clang++' compiler for the host "
835
+ "platform. Default is auto detected." ,
836
+ metavar = "PATH" )
837
+ parser .add_argument (
838
+ "--distcc" ,
839
+ help = "use distcc in pump mode" ,
840
+ action = "store_true" )
841
+ parser .add_argument (
842
+ "--enable-asan" ,
843
+ help = "enable Address Sanitizer" ,
844
+ action = "store_true" )
845
+ parser .add_argument (
846
+ "--enable-ubsan" ,
847
+ help = "enable Undefined Behavior Sanitizer" ,
848
+ action = "store_true" )
849
+ parser .add_argument (
850
+ "--clang-compiler-version" ,
851
+ help = "string that indicates a compiler version for Clang" ,
852
+ type = argparse_clang_compiler_version ,
853
+ metavar = "MAJOR.MINOR.PATCH" )
854
+
815
855
parser .add_argument (
816
856
"--extra-cmake-options" ,
817
857
help = "Pass through extra options to CMake in the form of comma "
@@ -821,6 +861,19 @@ details of the setups of other systems or automated environments.""")
821
861
type = argparse_shell_split ,
822
862
default = [])
823
863
864
+ parser .add_argument (
865
+ "--build-args" ,
866
+ help = "arguments to the build tool. This would be prepended to the "
867
+ "default argument that is '-j8' when CMake generator is "
868
+ "\" Ninja\" ." ,
869
+ type = argparse_shell_split ,
870
+ default = [])
871
+
872
+ parser .add_argument (
873
+ "--verbose-build" ,
874
+ help = "print the commands executed during the build" ,
875
+ action = "store_true" )
876
+
824
877
args = migration .parse_args (parser , sys .argv [1 :])
825
878
826
879
build_script_impl = os .path .join (
@@ -955,11 +1008,6 @@ details of the setups of other systems or automated environments.""")
955
1008
956
1009
build_script_impl_inferred_args = []
957
1010
958
- if args .export_compile_commands :
959
- build_script_impl_inferred_args += [
960
- "--export-compile-commands"
961
- ]
962
-
963
1011
if not args .test and not args .validation_test and not args .long_test :
964
1012
build_script_impl_inferred_args += [
965
1013
"--skip-test-cmark" ,
@@ -1166,9 +1214,16 @@ details of the setups of other systems or automated environments.""")
1166
1214
1167
1215
host_clang = swift_build_support .toolchain .host_clang (
1168
1216
xcrun_toolchain = args .darwin_xcrun_toolchain )
1169
- if not host_clang :
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 :
1170
1225
print_with_argv0 (
1171
- "Can't find clang. Please install clang-3.5 or a later version." )
1226
+ "Can't find clang. Please install clang-3.5 or a later version." )
1172
1227
return 1
1173
1228
1174
1229
host_cmake = args .cmake
@@ -1178,14 +1233,38 @@ details of the setups of other systems or automated environments.""")
1178
1233
if not host_cmake :
1179
1234
print_with_argv0 ("Can't find CMake. Please install CMake." )
1180
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
+ cmake = CMake (args = args ,
1256
+ host_cc = args .host_cc ,
1257
+ host_cxx = args .host_cxx ,
1258
+ host_distcc = host_distcc )
1259
+
1181
1260
build_script_impl_args = [
1182
1261
"--build-dir" , build_dir ,
1183
1262
"--install-prefix" , os .path .abspath (args .install_prefix ),
1184
1263
"--host-target" , args .host_target ,
1185
1264
"--stdlib-deployment-targets" ,
1186
1265
" " .join (args .stdlib_deployment_targets ),
1187
- "--host-cc" , host_clang . cc ,
1188
- "--host-cxx" , host_clang . cxx ,
1266
+ "--host-cc" , args . host_cc ,
1267
+ "--host-cxx" , args . host_cxx ,
1189
1268
"--darwin-xcrun-toolchain" , args .darwin_xcrun_toolchain ,
1190
1269
"--cmake" , host_cmake ,
1191
1270
"--cmark-build-type" , args .cmark_build_variant ,
@@ -1201,8 +1280,28 @@ details of the setups of other systems or automated environments.""")
1201
1280
args .swift_analyze_code_coverage ).lower (),
1202
1281
"--cmake-generator" , args .cmake_generator ,
1203
1282
"--build-jobs" , str (args .build_jobs ),
1204
- "--workspace" , SWIFT_SOURCE_ROOT
1283
+ "--workspace" , SWIFT_SOURCE_ROOT ,
1284
+ "--common-cmake-options=%s" % ' ' .join (
1285
+ pipes .quote (opt ) for opt in cmake .common_options ()),
1286
+ "--build-args=%s" % ' ' .join (
1287
+ pipes .quote (arg ) for arg in cmake .build_args ()),
1205
1288
]
1289
+
1290
+ if args .distcc :
1291
+ build_script_impl_args += [
1292
+ "--distcc" ,
1293
+ "--distcc-pump=%s" % host_distcc_pump
1294
+ ]
1295
+ if args .enable_asan :
1296
+ build_script_impl_args += ["--enable-asan" ]
1297
+ if args .enable_ubsan :
1298
+ build_script_impl_args += ["--enable-ubsan" ]
1299
+ if args .clang_compiler_version :
1300
+ build_script_impl_args += [
1301
+ "--clang-compiler-version=%s.%s.%s" % args .clang_compiler_version
1302
+ ]
1303
+ if args .verbose_build :
1304
+ build_script_impl_args += ["--verbose-build" ]
1206
1305
if args .install_symroot :
1207
1306
build_script_impl_args += [
1208
1307
"--install-symroot" , os .path .abspath (args .install_symroot )
0 commit comments