Skip to content

Commit bb9fc67

Browse files
committed
[build-script] Switch over to computing targets in build-script.
- Introduces a new `HostSpecificConfiguration` which holds the computed information for each host we need to use. - This relies on the functionality to pass host-specific variables to the script via environment variables. - The computation itself has been cleaned up a tiny bit (mostly via using the factored out platform/target properties), but is otherwise a straight port of the logic from `build-script-impl`. - This commit does not yet remove that code from `build-script-impl`; instead it validates that the two implementations are computing the same result. This is useful right now for testing the validity of the port.
1 parent f407cdf commit bb9fc67

File tree

2 files changed

+244
-4
lines changed

2 files changed

+244
-4
lines changed

utils/build-script

Lines changed: 210 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,118 @@ def call_without_sleeping(command, env=None, dry_run=False):
6565
shell.call(command, env=env, dry_run=dry_run)
6666

6767

68+
class HostSpecificConfiguration(object):
69+
"""Configuration information for an individual host."""
70+
71+
def __init__(self, host_target, invocation):
72+
"""Initialize for the given `host_target`."""
73+
74+
# Compute the set of deployment targets to configure/build.
75+
args = invocation.args
76+
if host_target == args.host_target:
77+
# This host is the user's desired product, so honor the requested
78+
# set of targets to configure/build.
79+
stdlib_targets_to_configure = args.stdlib_deployment_targets
80+
if "all" in args.build_stdlib_deployment_targets:
81+
stdlib_targets_to_build = set(stdlib_targets_to_configure)
82+
else:
83+
stdlib_targets_to_build = set(
84+
args.build_stdlib_deployment_targets).intersect(
85+
set(args.stdlib_deployment_targets))
86+
else:
87+
# Otherwise, this is a host we are building as part of
88+
# cross-compiling, so we only need the target itself.
89+
stdlib_targets_to_configure = [host_target]
90+
stdlib_targets_to_build = set(stdlib_targets_to_configure)
91+
92+
# Compute the lists of **CMake** targets for each use case (configure
93+
# vs. build vs. run) and the SDKs to configure with.
94+
self.sdks_to_configure = set()
95+
self.swift_stdlib_build_targets = []
96+
self.swift_test_run_targets = []
97+
self.swift_benchmark_build_targets = []
98+
self.swift_benchmark_run_targets = []
99+
for deployment_target_name in stdlib_targets_to_configure:
100+
# Get the target object.
101+
deployment_target = StdlibDeploymentTarget.get_target_for_name(
102+
deployment_target_name)
103+
if deployment_target is None:
104+
diagnostics.fatal("unknown target: %r" % (
105+
deployment_target_name,))
106+
107+
# Add the SDK to use.
108+
deployment_platform = deployment_target.platform
109+
self.sdks_to_configure.add(deployment_platform.sdk_name)
110+
111+
# If we aren't actually building this target (only configuring
112+
# it), do nothing else.
113+
if deployment_target_name not in stdlib_targets_to_build:
114+
continue
115+
116+
# Compute which actions are desired.
117+
build = deployment_platform not in \
118+
invocation.platforms_to_skip_build
119+
test = deployment_platform not in \
120+
invocation.platforms_to_skip_test
121+
test_host_only = None
122+
build_benchmark = build and deployment_target.supports_benchmark
123+
# FIXME: Note, `build-script-impl` computed a property here
124+
# w.r.t. testing, but it was actually unused.
125+
126+
# For platforms which normally require a connected device to
127+
# test, the default behavior is to run tests that only require
128+
# the host (i.e., they do not attempt to execute).
129+
if deployment_platform.is_darwin and \
130+
deployment_platform.is_embedded and \
131+
not deployment_platform.is_simulator:
132+
if deployment_platform not in \
133+
invocation.platforms_to_skip_test_host:
134+
test_host_only = True
135+
test = True
136+
else:
137+
test = False
138+
139+
name = deployment_target.name
140+
if build:
141+
# Validation and long tests require building the full standard
142+
# library, whereas the other targets can build a slightly
143+
# smaller subset which is faster to build.
144+
if args.build_swift_stdlib_unittest_extra or \
145+
args.validation_test or args.long_test:
146+
self.swift_stdlib_build_targets.append(
147+
"swift-stdlib-" + name)
148+
else:
149+
self.swift_stdlib_build_targets.append(
150+
"swift-test-stdlib-" + name)
151+
if build_benchmark:
152+
self.swift_benchmark_build_targets.append(
153+
"swift-benchmark-" + name)
154+
# FIXME: This probably should respect `args.benchmark`, but
155+
# a typo in build-script-impl meant we always would do this.
156+
self.swift_benchmark_run_targets.append(
157+
"check-swift-benchmark-" + name)
158+
if test:
159+
if test_host_only:
160+
suffix = "-non-executable"
161+
else:
162+
suffix = ""
163+
subset_suffix = ""
164+
if args.validation_test and args.long_test:
165+
subset_suffix = "-all"
166+
elif args.validation_test:
167+
subset_suffix = "-validation"
168+
elif args.long_test:
169+
subset_suffix = "-only_long"
170+
else:
171+
subset_suffix = ""
172+
self.swift_test_run_targets.append("check-swift{}{}-{}".format(
173+
subset_suffix, suffix, name))
174+
if args.test_optimized and not test_host_only:
175+
self.swift_test_run_targets.append(
176+
"check-swift{}-optimize-{}".format(
177+
subset_suffix, name))
178+
179+
68180
class BuildScriptInvocation(object):
69181
"""Represent a single build script invocation."""
70182

@@ -291,6 +403,77 @@ class BuildScriptInvocation(object):
291403
source_root=SWIFT_SOURCE_ROOT,
292404
build_root=os.path.join(SWIFT_BUILD_ROOT, args.build_subdir))
293405

406+
# Compute derived information from the arguments.
407+
#
408+
# FIXME: We should move the platform-derived arguments to be entirely
409+
# data driven, so that we can eliminate this code duplication and just
410+
# iterate over all supported platforms.
411+
412+
self.platforms_to_skip_build = set()
413+
if args.skip_build_linux:
414+
self.platforms_to_skip_build.add(StdlibDeploymentTarget.Linux)
415+
if args.skip_build_freebsd:
416+
self.platforms_to_skip_build.add(StdlibDeploymentTarget.FreeBSD)
417+
if args.skip_build_cygwin:
418+
self.platforms_to_skip_build.add(StdlibDeploymentTarget.Cygwin)
419+
if args.skip_build_osx:
420+
self.platforms_to_skip_build.add(StdlibDeploymentTarget.OSX)
421+
if args.skip_build_ios_device:
422+
self.platforms_to_skip_build.add(StdlibDeploymentTarget.iOS)
423+
if args.skip_build_ios_simulator:
424+
self.platforms_to_skip_build.add(
425+
StdlibDeploymentTarget.iOSSimulator)
426+
if args.skip_build_tvos_device:
427+
self.platforms_to_skip_build.add(StdlibDeploymentTarget.AppleTV)
428+
if args.skip_build_tvos_simulator:
429+
self.platforms_to_skip_build.add(
430+
StdlibDeploymentTarget.AppleTVSimulator)
431+
if args.skip_build_watchos_device:
432+
self.platforms_to_skip_build.add(StdlibDeploymentTarget.AppleWatch)
433+
if args.skip_build_watchos_simulator:
434+
self.platforms_to_skip_build.add(
435+
StdlibDeploymentTarget.AppleWatchSimulator)
436+
if args.skip_build_android:
437+
self.platforms_to_skip_build.add(StdlibDeploymentTarget.Android)
438+
439+
self.platforms_to_skip_test = set()
440+
if args.skip_test_linux:
441+
self.platforms_to_skip_test.add(StdlibDeploymentTarget.Linux)
442+
if args.skip_test_freebsd:
443+
self.platforms_to_skip_test.add(StdlibDeploymentTarget.FreeBSD)
444+
if args.skip_test_cygwin:
445+
self.platforms_to_skip_test.add(StdlibDeploymentTarget.Cygwin)
446+
if args.skip_test_osx:
447+
self.platforms_to_skip_test.add(StdlibDeploymentTarget.OSX)
448+
if args.skip_test_ios_host:
449+
self.platforms_to_skip_test.add(StdlibDeploymentTarget.iOS)
450+
if args.skip_test_ios_simulator:
451+
self.platforms_to_skip_test.add(StdlibDeploymentTarget.iOSSimulator)
452+
if args.skip_test_tvos_host:
453+
self.platforms_to_skip_test.add(StdlibDeploymentTarget.AppleTV)
454+
if args.skip_test_tvos_simulator:
455+
self.platforms_to_skip_test.add(
456+
StdlibDeploymentTarget.AppleTVSimulator)
457+
if args.skip_test_watchos_host:
458+
self.platforms_to_skip_test.add(StdlibDeploymentTarget.AppleWatch)
459+
if args.skip_test_watchos_simulator:
460+
self.platforms_to_skip_test.add(
461+
StdlibDeploymentTarget.AppleWatchSimulator)
462+
# We never allow testing Android, currently.
463+
#
464+
# FIXME: Allow Android host tests to be enabled/disabled by the build
465+
# script.
466+
self.platforms_to_skip_test.add(StdlibDeploymentTarget.Android)
467+
468+
self.platforms_to_skip_test_host = set()
469+
if args.skip_test_ios_host:
470+
self.platforms_to_skip_test_host.add(StdlibDeploymentTarget.iOS)
471+
if args.skip_test_tvos_host:
472+
self.platforms_to_skip_test_host.add(StdlibDeploymentTarget.AppleTV)
473+
if args.skip_test_watchos_host:
474+
self.platforms_to_skip_test_host.add(
475+
StdlibDeploymentTarget.AppleWatch)
476+
294477
def initialize_runtime_environment(self):
295478
"""Change the program environment for building."""
296479

@@ -381,7 +564,7 @@ class BuildScriptInvocation(object):
381564
if args.cross_compile_hosts:
382565
impl_args += [
383566
"--cross-compile-hosts", " ".join(args.cross_compile_hosts)]
384-
567+
385568
if toolchain.ninja:
386569
impl_args += ["--ninja-bin=%s" % toolchain.ninja]
387570
if args.distcc:
@@ -565,7 +748,29 @@ class BuildScriptInvocation(object):
565748
Compute the host-specific options, organized as a dictionary keyed by
566749
host of options.
567750
"""
568-
return {}
751+
752+
args = self.args
753+
754+
options = {}
755+
for host in [args.host_target] + args.cross_compile_hosts:
756+
# Compute the host specific configuration.
757+
config = HostSpecificConfiguration(host, self)
758+
759+
# Convert into `build-script-impl` style variables.
760+
options[host] = {
761+
"SWIFT_SDKS": " ".join(sorted(
762+
config.sdks_to_configure)),
763+
"SWIFT_STDLIB_TARGETS": " ".join(
764+
config.swift_stdlib_build_targets),
765+
"SWIFT_BENCHMARK_TARGETS": " ".join(
766+
config.swift_benchmark_build_targets),
767+
"SWIFT_RUN_BENCHMARK_TARGETS": " ".join(
768+
config.swift_benchmark_run_targets),
769+
"SWIFT_TEST_TARGETS": " ".join(
770+
config.swift_test_run_targets),
771+
}
772+
773+
return options
569774

570775

571776
# Main entry point for the preset mode.
@@ -850,15 +1055,15 @@ details of the setups of other systems or automated environments.""")
8501055
"tools for. Can be used multiple times.",
8511056
action=arguments.action.concat, type=arguments.type.shell_split,
8521057
default=[])
1058+
stdlib_targets = StdlibDeploymentTarget.default_stdlib_deployment_targets()
8531059
targets_group.add_argument(
8541060
"--stdlib-deployment-targets",
8551061
help="list of targets to compile or cross-compile the Swift standard "
8561062
"library for. %(default)s by default.",
8571063
nargs="*",
8581064
default=[
8591065
target.name
860-
for target in
861-
StdlibDeploymentTarget.default_stdlib_deployment_targets()])
1066+
for target in stdlib_targets])
8621067
targets_group.add_argument(
8631068
"--build-stdlib-deployment-targets",
8641069
help="A space-separated list that filters which of the configured "
@@ -1527,6 +1732,7 @@ details of the setups of other systems or automated environments.""")
15271732
"--build-jobs",
15281733
"--common-cmake-options",
15291734
"--only-execute",
1735+
"--skip-test-optimized",
15301736
action=arguments.action.unavailable)
15311737

15321738
args = migration.parse_args(parser, sys.argv[1:])

utils/build-script-impl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,40 @@ function calculate_targets_for_host() {
13061306
# Filter duplicate SWIFT_SDKs
13071307
# We will get them if building for multiple architecture variants
13081308
SWIFT_SDKS=(`echo "${SWIFT_SDKS[@]}" | tr " " "\n" | sort -u | tr "\n" " "`)
1309+
1310+
# Get the values passed by `build-script`.
1311+
LEGACY_SWIFT_STDLIB_TARGETS=(${SWIFT_STDLIB_TARGETS[@]})
1312+
LEGACY_SWIFT_SDKS=(${SWIFT_SDKS[@]})
1313+
LEGACY_SWIFT_BENCHMARK_TARGETS=(${SWIFT_BENCHMARK_TARGETS[@]})
1314+
LEGACY_SWIFT_RUN_BENCHMARK_TARGETS=(${SWIFT_RUN_BENCHMARK_TARGETS[@]})
1315+
LEGACY_SWIFT_TEST_TARGETS=(${SWIFT_TEST_TARGETS[@]})
1316+
SWIFT_STDLIB_TARGETS=($(get_host_specific_variable ${host} SWIFT_STDLIB_TARGETS))
1317+
SWIFT_SDKS=($(get_host_specific_variable ${host} SWIFT_SDKS))
1318+
SWIFT_BENCHMARK_TARGETS=($(get_host_specific_variable ${host} SWIFT_BENCHMARK_TARGETS))
1319+
SWIFT_RUN_BENCHMARK_TARGETS=($(get_host_specific_variable ${host} SWIFT_RUN_BENCHMARK_TARGETS))
1320+
SWIFT_TEST_TARGETS=($(get_host_specific_variable ${host} SWIFT_TEST_TARGETS))
1321+
1322+
# Validate the parameters match.
1323+
if [[ "${SWIFT_STDLIB_TARGETS[*]}" != "${LEGACY_SWIFT_STDLIB_TARGETS[*]}" ]]; then
1324+
printf "error: invalid build-script refactor for 'SWIFT_STDLIB_TARGETS': '%s' vs '%s'\n" "${SWIFT_STDLIB_TARGETS[*]}" "${LEGACY_SWIFT_STDLIB_TARGETS[*]}"
1325+
exit 1
1326+
fi
1327+
if [[ "${SWIFT_SDKS[*]}" != "${LEGACY_SWIFT_SDKS[*]}" ]]; then
1328+
printf "error: invalid build-script for 'SWIFT_SDKS' refactor: '%s' vs '%s'\n" "${SWIFT_SDKS[*]}" "${LEGACY_SWIFT_SDKS[*]}"
1329+
exit 1
1330+
fi
1331+
if [[ "${SWIFT_BENCHMARK_TARGETS[*]}" != "${LEGACY_SWIFT_BENCHMARK_TARGETS[*]}" ]]; then
1332+
printf "error: invalid build-script refactor for 'SWIFT_BENCHMARK_TARGETS': '%s' vs '%s'\n" "${SWIFT_BENCHMARK_TARGETS[*]}" "${LEGACY_SWIFT_BENCHMARK_TARGETS[*]}"
1333+
exit 1
1334+
fi
1335+
if [[ "${SWIFT_RUN_BENCHMARK_TARGETS[*]}" != "${LEGACY_SWIFT_RUN_BENCHMARK_TARGETS[*]}" ]]; then
1336+
printf "error: invalid build-script refactor for 'SWIFT_RUN_BENCHMARK_TARGETS': '%s' vs '%s'\n" "${SWIFT_RUN_BENCHMARK_TARGETS[*]}" "${LEGACY_SWIFT_RUN_BENCHMARK_TARGETS[*]}"
1337+
exit 1
1338+
fi
1339+
if [[ "${SWIFT_TEST_TARGETS[*]}" != "${LEGACY_SWIFT_TEST_TARGETS[*]}" ]]; then
1340+
printf "error: invalid build-script refactor for 'SWIFT_TEST_TARGETS': '%s' vs '%s'\n" "${SWIFT_TEST_TARGETS[*]}" "${LEGACY_SWIFT_TEST_TARGETS[*]}"
1341+
exit 1
1342+
fi
13091343
}
13101344

13111345

0 commit comments

Comments
 (0)