@@ -42,6 +42,8 @@ from swift_build_support.swift_build_support.SwiftBuildSupport import (
42
42
SWIFT_SOURCE_ROOT ,
43
43
)
44
44
from swift_build_support .swift_build_support .cmake import CMake
45
+ from swift_build_support .swift_build_support .host_specific_configuration \
46
+ import HostSpecificConfiguration
45
47
from swift_build_support .swift_build_support .targets import \
46
48
StdlibDeploymentTarget
47
49
from swift_build_support .swift_build_support .toolchain import host_toolchain
@@ -66,239 +68,6 @@ class JSONDumper(json.JSONEncoder):
66
68
return vars (o )
67
69
68
70
69
- class HostSpecificConfiguration (object ):
70
-
71
- """Configuration information for an individual host."""
72
-
73
- def __init__ (self , host_target , args ):
74
- """Initialize for the given `host_target`."""
75
-
76
- # Compute the set of deployment targets to configure/build.
77
- if host_target == args .host_target :
78
- # This host is the user's desired product, so honor the requested
79
- # set of targets to configure/build.
80
- stdlib_targets_to_configure = args .stdlib_deployment_targets
81
- if "all" in args .build_stdlib_deployment_targets :
82
- stdlib_targets_to_build = set (stdlib_targets_to_configure )
83
- else :
84
- stdlib_targets_to_build = set (
85
- args .build_stdlib_deployment_targets ).intersection (
86
- set (args .stdlib_deployment_targets ))
87
- else :
88
- # Otherwise, this is a host we are building as part of
89
- # cross-compiling, so we only need the target itself.
90
- stdlib_targets_to_configure = [host_target ]
91
- stdlib_targets_to_build = set (stdlib_targets_to_configure )
92
-
93
- # Compute derived information from the arguments.
94
- #
95
- # FIXME: We should move the platform-derived arguments to be entirely
96
- # data driven, so that we can eliminate this code duplication and just
97
- # iterate over all supported platforms.
98
- platforms_to_skip_build = self .__platforms_to_skip_build (args )
99
- platforms_to_skip_test = self .__platforms_to_skip_test (args )
100
- platforms_archs_to_skip_test = \
101
- self .__platforms_archs_to_skip_test (args )
102
- platforms_to_skip_test_host = self .__platforms_to_skip_test_host (args )
103
-
104
- # Compute the lists of **CMake** targets for each use case (configure
105
- # vs. build vs. run) and the SDKs to configure with.
106
- self .sdks_to_configure = set ()
107
- self .swift_stdlib_build_targets = []
108
- self .swift_test_run_targets = []
109
- self .swift_benchmark_build_targets = []
110
- self .swift_benchmark_run_targets = []
111
- for deployment_target_name in stdlib_targets_to_configure :
112
- # Get the target object.
113
- deployment_target = StdlibDeploymentTarget .get_target_for_name (
114
- deployment_target_name )
115
- if deployment_target is None :
116
- diagnostics .fatal ("unknown target: %r" % (
117
- deployment_target_name ,))
118
-
119
- # Add the SDK to use.
120
- deployment_platform = deployment_target .platform
121
- self .sdks_to_configure .add (deployment_platform .sdk_name )
122
-
123
- # If we aren't actually building this target (only configuring
124
- # it), do nothing else.
125
- if deployment_target_name not in stdlib_targets_to_build :
126
- continue
127
-
128
- # Compute which actions are desired.
129
- build = (
130
- deployment_platform not in platforms_to_skip_build )
131
- test = (
132
- deployment_platform not in platforms_to_skip_test )
133
- test_host_only = None
134
- dt_supports_benchmark = deployment_target .supports_benchmark
135
- build_benchmarks = build and dt_supports_benchmark
136
- build_external_benchmarks = all ([build , dt_supports_benchmark ,
137
- args .build_external_benchmarks ])
138
-
139
- # FIXME: Note, `build-script-impl` computed a property here
140
- # w.r.t. testing, but it was actually unused.
141
-
142
- # For platforms which normally require a connected device to
143
- # test, the default behavior is to run tests that only require
144
- # the host (i.e., they do not attempt to execute).
145
- if deployment_platform .uses_host_tests and \
146
- deployment_platform not in \
147
- platforms_to_skip_test_host :
148
- test_host_only = True
149
-
150
- name = deployment_target .name
151
-
152
- for skip_test_arch in platforms_archs_to_skip_test :
153
- if deployment_target .name == skip_test_arch .name :
154
- test = False
155
-
156
- if build :
157
- # Validation, long, and stress tests require building the full
158
- # standard library, whereas the other targets can build a
159
- # slightly smaller subset which is faster to build.
160
- if args .build_swift_stdlib_unittest_extra or \
161
- args .validation_test or args .long_test or \
162
- args .stress_test :
163
- self .swift_stdlib_build_targets .append (
164
- "swift-stdlib-" + name )
165
- else :
166
- self .swift_stdlib_build_targets .append (
167
- "swift-test-stdlib-" + name )
168
- if build_benchmarks :
169
- self .swift_benchmark_build_targets .append (
170
- "swift-benchmark-" + name )
171
- if args .benchmark :
172
- self .swift_benchmark_run_targets .append (
173
- "check-swift-benchmark-" + name )
174
-
175
- if build_external_benchmarks :
176
- # Add support for the external benchmarks.
177
- self .swift_benchmark_build_targets .append (
178
- "swift-benchmark-{}-external" .format (name ))
179
- if args .benchmark :
180
- self .swift_benchmark_run_targets .append (
181
- "check-swift-benchmark-{}-external" .format (name ))
182
- if test :
183
- if test_host_only :
184
- suffix = "-only_non_executable"
185
- elif args .only_executable_test :
186
- suffix = "-only_executable"
187
- else :
188
- suffix = ""
189
- subset_suffix = ""
190
- if args .validation_test and args .long_test and \
191
- args .stress_test :
192
- subset_suffix = "-all"
193
- elif args .validation_test :
194
- subset_suffix = "-validation"
195
- elif args .long_test :
196
- subset_suffix = "-only_long"
197
- elif args .stress_test :
198
- subset_suffix = "-only_stress"
199
- else :
200
- subset_suffix = ""
201
- self .swift_test_run_targets .append ("check-swift{}{}-{}" .format (
202
- subset_suffix , suffix , name ))
203
- if args .test_optimized and not test_host_only :
204
- self .swift_test_run_targets .append (
205
- "check-swift{}-optimize-{}" .format (
206
- subset_suffix , name ))
207
- if args .test_optimize_for_size and not test_host_only :
208
- self .swift_test_run_targets .append (
209
- "check-swift{}-optimize_size-{}" .format (
210
- subset_suffix , name ))
211
- if args .test_optimize_none_implicit_dynamic and \
212
- not test_host_only :
213
- self .swift_test_run_targets .append (
214
- "check-swift{}-optimize_none_implicit_dynamic-{}"
215
- .format (subset_suffix , name ))
216
-
217
- def __platforms_to_skip_build (self , args ):
218
- platforms_to_skip_build = set ()
219
- if not args .build_linux :
220
- platforms_to_skip_build .add (StdlibDeploymentTarget .Linux )
221
- if not args .build_freebsd :
222
- platforms_to_skip_build .add (StdlibDeploymentTarget .FreeBSD )
223
- if not args .build_cygwin :
224
- platforms_to_skip_build .add (StdlibDeploymentTarget .Cygwin )
225
- if not args .build_osx :
226
- platforms_to_skip_build .add (StdlibDeploymentTarget .OSX )
227
- if not args .build_ios_device :
228
- platforms_to_skip_build .add (StdlibDeploymentTarget .iOS )
229
- if not args .build_ios_simulator :
230
- platforms_to_skip_build .add (StdlibDeploymentTarget .iOSSimulator )
231
- if not args .build_tvos_device :
232
- platforms_to_skip_build .add (StdlibDeploymentTarget .AppleTV )
233
- if not args .build_tvos_simulator :
234
- platforms_to_skip_build .add (
235
- StdlibDeploymentTarget .AppleTVSimulator )
236
- if not args .build_watchos_device :
237
- platforms_to_skip_build .add (StdlibDeploymentTarget .AppleWatch )
238
- if not args .build_watchos_simulator :
239
- platforms_to_skip_build .add (
240
- StdlibDeploymentTarget .AppleWatchSimulator )
241
- if not args .build_android :
242
- platforms_to_skip_build .add (StdlibDeploymentTarget .Android )
243
- return platforms_to_skip_build
244
-
245
- def __platforms_to_skip_test (self , args ):
246
- platforms_to_skip_test = set ()
247
- if not args .test_linux :
248
- platforms_to_skip_test .add (StdlibDeploymentTarget .Linux )
249
- if not args .test_freebsd :
250
- platforms_to_skip_test .add (StdlibDeploymentTarget .FreeBSD )
251
- if not args .test_cygwin :
252
- platforms_to_skip_test .add (StdlibDeploymentTarget .Cygwin )
253
- if not args .test_osx :
254
- platforms_to_skip_test .add (StdlibDeploymentTarget .OSX )
255
- if not args .test_ios_host :
256
- platforms_to_skip_test .add (StdlibDeploymentTarget .iOS )
257
- else :
258
- exit_rejecting_arguments ("error: iOS device tests are not " +
259
- "supported in open-source Swift." )
260
- if not args .test_ios_simulator :
261
- platforms_to_skip_test .add (StdlibDeploymentTarget .iOSSimulator )
262
- if not args .test_tvos_host :
263
- platforms_to_skip_test .add (StdlibDeploymentTarget .AppleTV )
264
- else :
265
- exit_rejecting_arguments ("error: tvOS device tests are not " +
266
- "supported in open-source Swift." )
267
- if not args .test_tvos_simulator :
268
- platforms_to_skip_test .add (StdlibDeploymentTarget .AppleTVSimulator )
269
- if not args .test_watchos_host :
270
- platforms_to_skip_test .add (StdlibDeploymentTarget .AppleWatch )
271
- else :
272
- exit_rejecting_arguments ("error: watchOS device tests are not " +
273
- "supported in open-source Swift." )
274
- if not args .test_watchos_simulator :
275
- platforms_to_skip_test .add (
276
- StdlibDeploymentTarget .AppleWatchSimulator )
277
- if not args .test_android :
278
- platforms_to_skip_test .add (StdlibDeploymentTarget .Android )
279
-
280
- return platforms_to_skip_test
281
-
282
- def __platforms_archs_to_skip_test (self , args ):
283
- platforms_archs_to_skip_test = set ()
284
- if not args .test_ios_32bit_simulator :
285
- platforms_archs_to_skip_test .add (
286
- StdlibDeploymentTarget .iOSSimulator .i386 )
287
- return platforms_archs_to_skip_test
288
-
289
- def __platforms_to_skip_test_host (self , args ):
290
- platforms_to_skip_test_host = set ()
291
- if not args .test_android_host :
292
- platforms_to_skip_test_host .add (StdlibDeploymentTarget .Android )
293
- if not args .test_ios_host :
294
- platforms_to_skip_test_host .add (StdlibDeploymentTarget .iOS )
295
- if not args .test_tvos_host :
296
- platforms_to_skip_test_host .add (StdlibDeploymentTarget .AppleTV )
297
- if not args .test_watchos_host :
298
- platforms_to_skip_test_host .add (StdlibDeploymentTarget .AppleWatch )
299
- return platforms_to_skip_test_host
300
-
301
-
302
71
class BuildScriptInvocation (object ):
303
72
304
73
"""Represent a single build script invocation."""
@@ -852,7 +621,10 @@ class BuildScriptInvocation(object):
852
621
options = {}
853
622
for host_target in [args .host_target ] + args .cross_compile_hosts :
854
623
# Compute the host specific configuration.
855
- config = HostSpecificConfiguration (host_target , args )
624
+ try :
625
+ config = HostSpecificConfiguration (host_target , args )
626
+ except argparse .ArgumentError as e :
627
+ exit_rejecting_arguments (e .message )
856
628
857
629
# Convert into `build-script-impl` style variables.
858
630
options [host_target ] = {
@@ -952,7 +724,10 @@ class BuildScriptInvocation(object):
952
724
# Build...
953
725
for host_target in all_hosts :
954
726
# FIXME: We should only compute these once.
955
- config = HostSpecificConfiguration (host_target .name , self .args )
727
+ try :
728
+ config = HostSpecificConfiguration (host_target .name , self .args )
729
+ except argparse .ArgumentError as e :
730
+ exit_rejecting_arguments (e .message )
956
731
print ("Building the standard library for: {}" .format (
957
732
" " .join (config .swift_stdlib_build_targets )))
958
733
if config .swift_test_run_targets and (
0 commit comments