@@ -47,8 +47,7 @@ import swift_build_support.tar # noqa (E402)
47
47
import swift_build_support .targets # noqa (E402)
48
48
from swift_build_support .targets import StdlibDeploymentTarget # noqa (E402)
49
49
from swift_build_support .cmake import CMake # noqa (E402)
50
- from swift_build_support .workspace import Workspace # noqa(E402)
51
- from swift_build_support .workspace import compute_build_subdir # noqa(E402)
50
+ import swift_build_support .workspace # noqa (E402)
52
51
53
52
54
53
def call_without_sleeping (command , dry_run = False ):
@@ -66,6 +65,48 @@ def call_without_sleeping(command, dry_run=False):
66
65
shell .call (command , dry_run = dry_run , echo = False )
67
66
68
67
68
+ class BuildScriptInvocation (object ):
69
+ """Represent a single build script invocation."""
70
+
71
+ def __init__ (self , toolchain , args ):
72
+ self .toolchain = toolchain
73
+ self .args = args
74
+
75
+ self .workspace = swift_build_support .workspace .Workspace (
76
+ source_root = SWIFT_SOURCE_ROOT ,
77
+ build_root = os .path .join (SWIFT_BUILD_ROOT , args .build_subdir ))
78
+
79
+ def initialize_runtime_environment (self ):
80
+ """Change the program environment for building."""
81
+
82
+ # Set an appropriate default umask.
83
+ os .umask (0o022 )
84
+
85
+ # Unset environment variables that might affect how tools behave.
86
+ for v in [
87
+ 'MAKEFLAGS' ,
88
+ 'SDKROOT' ,
89
+ 'MACOSX_DEPLOYMENT_TARGET' ,
90
+ 'IPHONEOS_DEPLOYMENT_TARGET' ,
91
+ 'TVOS_DEPLOYMENT_TARGET' ,
92
+ 'WATCHOS_DEPLOYMENT_TARGET' ]:
93
+ os .environ .pop (v , None )
94
+
95
+ def build_ninja (self ):
96
+ if not os .path .exists (self .workspace .source_dir ("ninja" )):
97
+ diagnostics .fatal (
98
+ "can't find source directory for ninja "
99
+ "(tried %s)" % (self .workspace .source_dir ("ninja" )))
100
+
101
+ ninja_build = products .Ninja (
102
+ args = self .args ,
103
+ toolchain = self .toolchain ,
104
+ source_dir = self .workspace .source_dir ("ninja" ),
105
+ build_dir = self .workspace .build_dir ("build" , "ninja" ))
106
+ ninja_build .do_build ()
107
+ self .toolchain .ninja = ninja_build .ninja_bin_path
108
+
109
+
69
110
# Main entry point for the preset mode.
70
111
def main_preset ():
71
112
parser = argparse .ArgumentParser (
@@ -1239,60 +1280,41 @@ details of the setups of other systems or automated environments.""")
1239
1280
args .skip_test_watchos_host = True
1240
1281
1241
1282
if args .build_subdir is None :
1242
- args .build_subdir = compute_build_subdir (args )
1283
+ args .build_subdir = swift_build_support .workspace .compute_build_subdir (
1284
+ args )
1243
1285
1244
1286
# Add optional stdlib-deployment-targets
1245
1287
if args .android :
1246
1288
args .stdlib_deployment_targets .append (
1247
1289
StdlibDeploymentTarget .Android .armv7 )
1248
1290
1249
- workspace = Workspace (
1250
- source_root = SWIFT_SOURCE_ROOT ,
1251
- build_root = os .path .join (SWIFT_BUILD_ROOT , args .build_subdir ))
1291
+ # Create the build script invocation.
1292
+ invocation = BuildScriptInvocation (toolchain , args )
1252
1293
1253
- if args .build_ninja :
1254
- if not os .path .exists (workspace .source_dir ("ninja" )):
1255
- diagnostics .fatal ("can't find source directory for ninja "
1256
- "(tried %s)" % (workspace .source_dir ("ninja" )))
1257
-
1258
- os .umask (0o022 )
1259
-
1260
- # Unset environment variables that might affect how tools behave.
1261
- for v in [
1262
- 'MAKEFLAGS' ,
1263
- 'SDKROOT' ,
1264
- 'MACOSX_DEPLOYMENT_TARGET' ,
1265
- 'IPHONEOS_DEPLOYMENT_TARGET' ,
1266
- 'TVOS_DEPLOYMENT_TARGET' ,
1267
- 'WATCHOS_DEPLOYMENT_TARGET' ]:
1268
- os .environ .pop (v , None )
1294
+ # Sanitize the runtime environment.
1295
+ invocation .initialize_runtime_environment ()
1269
1296
1297
+ # Show SDKs, if requested.
1270
1298
if args .show_sdks :
1271
1299
swift_build_support .debug .print_xcodebuild_versions ()
1272
1300
1273
1301
# Clean build directory if requested.
1274
1302
if args .clean :
1275
- shell .rmtree (workspace .build_root )
1303
+ shell .rmtree (invocation . workspace .build_root )
1276
1304
1277
1305
# Create build directory.
1278
- shell .makedirs (workspace .build_root )
1306
+ shell .makedirs (invocation . workspace .build_root )
1279
1307
1280
- # Build ninja if required.
1308
+ # Build ninja if required, which will update the toolchain .
1281
1309
if args .build_ninja :
1282
- ninja_build = products .Ninja (
1283
- args = args ,
1284
- toolchain = toolchain ,
1285
- source_dir = workspace .source_dir ("ninja" ),
1286
- build_dir = workspace .build_dir ("build" , "ninja" ))
1287
- ninja_build .do_build ()
1288
- toolchain .ninja = ninja_build .ninja_bin_path
1310
+ invocation .build_ninja ()
1289
1311
1290
1312
cmake = CMake (args = args ,
1291
1313
toolchain = toolchain )
1292
1314
1293
1315
build_script_impl_args = [
1294
- "--workspace" , workspace .source_root ,
1295
- "--build-dir" , workspace .build_root ,
1316
+ "--workspace" , invocation . workspace .source_root ,
1317
+ "--build-dir" , invocation . workspace .build_root ,
1296
1318
"--install-prefix" , args .install_prefix ,
1297
1319
"--host-target" , args .host_target ,
1298
1320
"--stdlib-deployment-targets" ,
0 commit comments