@@ -41,8 +41,6 @@ from swift_build_support.swift_build_support.SwiftBuildSupport import (
4141 SWIFT_SOURCE_ROOT ,
4242)
4343from swift_build_support .swift_build_support .cmake import CMake
44- from swift_build_support .swift_build_support .host_specific_configuration \
45- import HostSpecificConfiguration
4644from swift_build_support .swift_build_support .targets import \
4745 StdlibDeploymentTarget
4846from swift_build_support .swift_build_support .toolchain import host_toolchain
@@ -58,6 +56,143 @@ def exit_rejecting_arguments(message, parser=None):
5856 sys .exit (2 ) # 2 is the same as `argparse` error exit code.
5957
6058
59+ class HostSpecificConfiguration (object ):
60+
61+ """Configuration information for an individual host."""
62+
63+ def __init__ (self , host_target , invocation ):
64+ """Initialize for the given `host_target`."""
65+
66+ # Compute the set of deployment targets to configure/build.
67+ args = invocation .args
68+ if host_target == args .host_target :
69+ # This host is the user's desired product, so honor the requested
70+ # set of targets to configure/build.
71+ stdlib_targets_to_configure = args .stdlib_deployment_targets
72+ if "all" in args .build_stdlib_deployment_targets :
73+ stdlib_targets_to_build = set (stdlib_targets_to_configure )
74+ else :
75+ stdlib_targets_to_build = set (
76+ args .build_stdlib_deployment_targets ).intersection (
77+ set (args .stdlib_deployment_targets ))
78+ else :
79+ # Otherwise, this is a host we are building as part of
80+ # cross-compiling, so we only need the target itself.
81+ stdlib_targets_to_configure = [host_target ]
82+ stdlib_targets_to_build = set (stdlib_targets_to_configure )
83+
84+ # Compute the lists of **CMake** targets for each use case (configure
85+ # vs. build vs. run) and the SDKs to configure with.
86+ self .sdks_to_configure = set ()
87+ self .swift_stdlib_build_targets = []
88+ self .swift_test_run_targets = []
89+ self .swift_benchmark_build_targets = []
90+ self .swift_benchmark_run_targets = []
91+ for deployment_target_name in stdlib_targets_to_configure :
92+ # Get the target object.
93+ deployment_target = StdlibDeploymentTarget .get_target_for_name (
94+ deployment_target_name )
95+ if deployment_target is None :
96+ diagnostics .fatal ("unknown target: %r" % (
97+ deployment_target_name ,))
98+
99+ # Add the SDK to use.
100+ deployment_platform = deployment_target .platform
101+ self .sdks_to_configure .add (deployment_platform .sdk_name )
102+
103+ # If we aren't actually building this target (only configuring
104+ # it), do nothing else.
105+ if deployment_target_name not in stdlib_targets_to_build :
106+ continue
107+
108+ # Compute which actions are desired.
109+ build = (
110+ deployment_platform not in invocation .platforms_to_skip_build )
111+ test = (
112+ deployment_platform not in invocation .platforms_to_skip_test )
113+ test_host_only = None
114+ dt_supports_benchmark = deployment_target .supports_benchmark
115+ build_benchmarks = build and dt_supports_benchmark
116+ build_external_benchmarks = all ([build , dt_supports_benchmark ,
117+ args .build_external_benchmarks ])
118+
119+ # FIXME: Note, `build-script-impl` computed a property here
120+ # w.r.t. testing, but it was actually unused.
121+
122+ # For platforms which normally require a connected device to
123+ # test, the default behavior is to run tests that only require
124+ # the host (i.e., they do not attempt to execute).
125+ if deployment_platform .uses_host_tests and \
126+ deployment_platform not in \
127+ invocation .platforms_to_skip_test_host :
128+ test_host_only = True
129+
130+ name = deployment_target .name
131+
132+ for skip_test_arch in invocation .platforms_archs_to_skip_test :
133+ if deployment_target .name == skip_test_arch .name :
134+ test = False
135+
136+ if build :
137+ # Validation, long, and stress tests require building the full
138+ # standard library, whereas the other targets can build a
139+ # slightly smaller subset which is faster to build.
140+ if args .build_swift_stdlib_unittest_extra or \
141+ args .validation_test or args .long_test or \
142+ args .stress_test :
143+ self .swift_stdlib_build_targets .append (
144+ "swift-stdlib-" + name )
145+ else :
146+ self .swift_stdlib_build_targets .append (
147+ "swift-test-stdlib-" + name )
148+ if build_benchmarks :
149+ self .swift_benchmark_build_targets .append (
150+ "swift-benchmark-" + name )
151+ if args .benchmark :
152+ self .swift_benchmark_run_targets .append (
153+ "check-swift-benchmark-" + name )
154+
155+ if build_external_benchmarks :
156+ # Add support for the external benchmarks.
157+ self .swift_benchmark_build_targets .append (
158+ "swift-benchmark-{}-external" .format (name ))
159+ if args .benchmark :
160+ self .swift_benchmark_run_targets .append (
161+ "check-swift-benchmark-{}-external" .format (name ))
162+ if test :
163+ if test_host_only :
164+ suffix = "-only_non_executable"
165+ else :
166+ suffix = ""
167+ subset_suffix = ""
168+ if args .validation_test and args .long_test and \
169+ args .stress_test :
170+ subset_suffix = "-all"
171+ elif args .validation_test :
172+ subset_suffix = "-validation"
173+ elif args .long_test :
174+ subset_suffix = "-only_long"
175+ elif args .stress_test :
176+ subset_suffix = "-only_stress"
177+ else :
178+ subset_suffix = ""
179+ self .swift_test_run_targets .append ("check-swift{}{}-{}" .format (
180+ subset_suffix , suffix , name ))
181+ if args .test_optimized and not test_host_only :
182+ self .swift_test_run_targets .append (
183+ "check-swift{}-optimize-{}" .format (
184+ subset_suffix , name ))
185+ if args .test_optimize_for_size and not test_host_only :
186+ self .swift_test_run_targets .append (
187+ "check-swift{}-optimize_size-{}" .format (
188+ subset_suffix , name ))
189+ if args .test_optimize_none_implicit_dynamic and \
190+ not test_host_only :
191+ self .swift_test_run_targets .append (
192+ "check-swift{}-optimize_none_implicit_dynamic-{}"
193+ .format (subset_suffix , name ))
194+
195+
61196class BuildScriptInvocation (object ):
62197
63198 """Represent a single build script invocation."""
@@ -188,6 +323,91 @@ class BuildScriptInvocation(object):
188323 source_root = SWIFT_SOURCE_ROOT ,
189324 build_root = os .path .join (SWIFT_BUILD_ROOT , args .build_subdir ))
190325
326+ # Compute derived information from the arguments.
327+ #
328+ # FIXME: We should move the platform-derived arguments to be entirely
329+ # data driven, so that we can eliminate this code duplication and just
330+ # iterate over all supported platforms.
331+
332+ self .platforms_to_skip_build = set ()
333+ if not args .build_linux :
334+ self .platforms_to_skip_build .add (StdlibDeploymentTarget .Linux )
335+ if not args .build_freebsd :
336+ self .platforms_to_skip_build .add (StdlibDeploymentTarget .FreeBSD )
337+ if not args .build_cygwin :
338+ self .platforms_to_skip_build .add (StdlibDeploymentTarget .Cygwin )
339+ if not args .build_osx :
340+ self .platforms_to_skip_build .add (StdlibDeploymentTarget .OSX )
341+ if not args .build_ios_device :
342+ self .platforms_to_skip_build .add (StdlibDeploymentTarget .iOS )
343+ if not args .build_ios_simulator :
344+ self .platforms_to_skip_build .add (
345+ StdlibDeploymentTarget .iOSSimulator )
346+ if not args .build_tvos_device :
347+ self .platforms_to_skip_build .add (StdlibDeploymentTarget .AppleTV )
348+ if not args .build_tvos_simulator :
349+ self .platforms_to_skip_build .add (
350+ StdlibDeploymentTarget .AppleTVSimulator )
351+ if not args .build_watchos_device :
352+ self .platforms_to_skip_build .add (StdlibDeploymentTarget .AppleWatch )
353+ if not args .build_watchos_simulator :
354+ self .platforms_to_skip_build .add (
355+ StdlibDeploymentTarget .AppleWatchSimulator )
356+ if not args .build_android :
357+ self .platforms_to_skip_build .add (StdlibDeploymentTarget .Android )
358+
359+ self .platforms_to_skip_test = set ()
360+ self .platforms_archs_to_skip_test = set ()
361+ if not args .test_linux :
362+ self .platforms_to_skip_test .add (StdlibDeploymentTarget .Linux )
363+ if not args .test_freebsd :
364+ self .platforms_to_skip_test .add (StdlibDeploymentTarget .FreeBSD )
365+ if not args .test_cygwin :
366+ self .platforms_to_skip_test .add (StdlibDeploymentTarget .Cygwin )
367+ if not args .test_osx :
368+ self .platforms_to_skip_test .add (StdlibDeploymentTarget .OSX )
369+ if not args .test_ios_host :
370+ self .platforms_to_skip_test .add (StdlibDeploymentTarget .iOS )
371+ else :
372+ exit_rejecting_arguments ("error: iOS device tests are not " +
373+ "supported in open-source Swift." )
374+ if not args .test_ios_simulator :
375+ self .platforms_to_skip_test .add (
376+ StdlibDeploymentTarget .iOSSimulator )
377+ if not args .test_ios_32bit_simulator :
378+ self .platforms_archs_to_skip_test .add (
379+ StdlibDeploymentTarget .iOSSimulator .i386 )
380+ if not args .test_tvos_host :
381+ self .platforms_to_skip_test .add (StdlibDeploymentTarget .AppleTV )
382+ else :
383+ exit_rejecting_arguments ("error: tvOS device tests are not " +
384+ "supported in open-source Swift." )
385+ if not args .test_tvos_simulator :
386+ self .platforms_to_skip_test .add (
387+ StdlibDeploymentTarget .AppleTVSimulator )
388+ if not args .test_watchos_host :
389+ self .platforms_to_skip_test .add (StdlibDeploymentTarget .AppleWatch )
390+ else :
391+ exit_rejecting_arguments ("error: watchOS device tests are not " +
392+ "supported in open-source Swift." )
393+ if not args .test_watchos_simulator :
394+ self .platforms_to_skip_test .add (
395+ StdlibDeploymentTarget .AppleWatchSimulator )
396+ if not args .test_android :
397+ self .platforms_to_skip_test .add (StdlibDeploymentTarget .Android )
398+
399+ self .platforms_to_skip_test_host = set ()
400+ if not args .test_android_host :
401+ self .platforms_to_skip_test_host .add (
402+ StdlibDeploymentTarget .Android )
403+ if not args .test_ios_host :
404+ self .platforms_to_skip_test_host .add (StdlibDeploymentTarget .iOS )
405+ if not args .test_tvos_host :
406+ self .platforms_to_skip_test_host .add (
407+ StdlibDeploymentTarget .AppleTV )
408+ if not args .test_watchos_host :
409+ self .platforms_to_skip_test_host .add (
410+ StdlibDeploymentTarget .AppleWatch )
191411 self .build_libparser_only = args .build_libparser_only
192412
193413 def initialize_runtime_environment (self ):
@@ -607,10 +827,7 @@ class BuildScriptInvocation(object):
607827 options = {}
608828 for host_target in [args .host_target ] + args .cross_compile_hosts :
609829 # Compute the host specific configuration.
610- try :
611- config = HostSpecificConfiguration (self .args , host_target )
612- except argparse .ArgumentError as e :
613- exit_rejecting_arguments (e .message )
830+ config = HostSpecificConfiguration (host_target , self )
614831
615832 # Convert into `build-script-impl` style variables.
616833 options [host_target ] = {
@@ -725,10 +942,7 @@ class BuildScriptInvocation(object):
725942 # Build...
726943 for host_target in all_hosts :
727944 # FIXME: We should only compute these once.
728- try :
729- config = HostSpecificConfiguration (self .args , host_target .name )
730- except argparse .ArgumentError as e :
731- exit_rejecting_arguments (e .message )
945+ config = HostSpecificConfiguration (host_target .name , self )
732946 print ("Building the standard library for: {}" .format (
733947 " " .join (config .swift_stdlib_build_targets )))
734948 if config .swift_test_run_targets and (
0 commit comments