Skip to content

[build-script] Move HostSpecificConfiguration out of main script. #23810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
234 changes: 10 additions & 224 deletions utils/build-script
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ from swift_build_support.swift_build_support.SwiftBuildSupport import (
SWIFT_SOURCE_ROOT,
)
from swift_build_support.swift_build_support.cmake import CMake
from swift_build_support.swift_build_support.host_specific_configuration \
import HostSpecificConfiguration
from swift_build_support.swift_build_support.targets import \
StdlibDeploymentTarget
from swift_build_support.swift_build_support.toolchain import host_toolchain
Expand All @@ -56,143 +58,6 @@ def exit_rejecting_arguments(message, parser=None):
sys.exit(2) # 2 is the same as `argparse` error exit code.


class HostSpecificConfiguration(object):

"""Configuration information for an individual host."""

def __init__(self, host_target, invocation):
"""Initialize for the given `host_target`."""

# Compute the set of deployment targets to configure/build.
args = invocation.args
if host_target == args.host_target:
# This host is the user's desired product, so honor the requested
# set of targets to configure/build.
stdlib_targets_to_configure = args.stdlib_deployment_targets
if "all" in args.build_stdlib_deployment_targets:
stdlib_targets_to_build = set(stdlib_targets_to_configure)
else:
stdlib_targets_to_build = set(
args.build_stdlib_deployment_targets).intersection(
set(args.stdlib_deployment_targets))
else:
# Otherwise, this is a host we are building as part of
# cross-compiling, so we only need the target itself.
stdlib_targets_to_configure = [host_target]
stdlib_targets_to_build = set(stdlib_targets_to_configure)

# Compute the lists of **CMake** targets for each use case (configure
# vs. build vs. run) and the SDKs to configure with.
self.sdks_to_configure = set()
self.swift_stdlib_build_targets = []
self.swift_test_run_targets = []
self.swift_benchmark_build_targets = []
self.swift_benchmark_run_targets = []
for deployment_target_name in stdlib_targets_to_configure:
# Get the target object.
deployment_target = StdlibDeploymentTarget.get_target_for_name(
deployment_target_name)
if deployment_target is None:
diagnostics.fatal("unknown target: %r" % (
deployment_target_name,))

# Add the SDK to use.
deployment_platform = deployment_target.platform
self.sdks_to_configure.add(deployment_platform.sdk_name)

# If we aren't actually building this target (only configuring
# it), do nothing else.
if deployment_target_name not in stdlib_targets_to_build:
continue

# Compute which actions are desired.
build = (
deployment_platform not in invocation.platforms_to_skip_build)
test = (
deployment_platform not in invocation.platforms_to_skip_test)
test_host_only = None
dt_supports_benchmark = deployment_target.supports_benchmark
build_benchmarks = build and dt_supports_benchmark
build_external_benchmarks = all([build, dt_supports_benchmark,
args.build_external_benchmarks])

# FIXME: Note, `build-script-impl` computed a property here
# w.r.t. testing, but it was actually unused.

# For platforms which normally require a connected device to
# test, the default behavior is to run tests that only require
# the host (i.e., they do not attempt to execute).
if deployment_platform.uses_host_tests and \
deployment_platform not in \
invocation.platforms_to_skip_test_host:
test_host_only = True

name = deployment_target.name

for skip_test_arch in invocation.platforms_archs_to_skip_test:
if deployment_target.name == skip_test_arch.name:
test = False

if build:
# Validation, long, and stress tests require building the full
# standard library, whereas the other targets can build a
# slightly smaller subset which is faster to build.
if args.build_swift_stdlib_unittest_extra or \
args.validation_test or args.long_test or \
args.stress_test:
self.swift_stdlib_build_targets.append(
"swift-stdlib-" + name)
else:
self.swift_stdlib_build_targets.append(
"swift-test-stdlib-" + name)
if build_benchmarks:
self.swift_benchmark_build_targets.append(
"swift-benchmark-" + name)
if args.benchmark:
self.swift_benchmark_run_targets.append(
"check-swift-benchmark-" + name)

if build_external_benchmarks:
# Add support for the external benchmarks.
self.swift_benchmark_build_targets.append(
"swift-benchmark-{}-external".format(name))
if args.benchmark:
self.swift_benchmark_run_targets.append(
"check-swift-benchmark-{}-external".format(name))
if test:
if test_host_only:
suffix = "-only_non_executable"
else:
suffix = ""
subset_suffix = ""
if args.validation_test and args.long_test and \
args.stress_test:
subset_suffix = "-all"
elif args.validation_test:
subset_suffix = "-validation"
elif args.long_test:
subset_suffix = "-only_long"
elif args.stress_test:
subset_suffix = "-only_stress"
else:
subset_suffix = ""
self.swift_test_run_targets.append("check-swift{}{}-{}".format(
subset_suffix, suffix, name))
if args.test_optimized and not test_host_only:
self.swift_test_run_targets.append(
"check-swift{}-optimize-{}".format(
subset_suffix, name))
if args.test_optimize_for_size and not test_host_only:
self.swift_test_run_targets.append(
"check-swift{}-optimize_size-{}".format(
subset_suffix, name))
if args.test_optimize_none_implicit_dynamic and \
not test_host_only:
self.swift_test_run_targets.append(
"check-swift{}-optimize_none_implicit_dynamic-{}"
.format(subset_suffix, name))


class BuildScriptInvocation(object):

"""Represent a single build script invocation."""
Expand Down Expand Up @@ -317,91 +182,6 @@ class BuildScriptInvocation(object):
source_root=SWIFT_SOURCE_ROOT,
build_root=os.path.join(SWIFT_BUILD_ROOT, args.build_subdir))

# Compute derived information from the arguments.
#
# FIXME: We should move the platform-derived arguments to be entirely
# data driven, so that we can eliminate this code duplication and just
# iterate over all supported platforms.

self.platforms_to_skip_build = set()
if not args.build_linux:
self.platforms_to_skip_build.add(StdlibDeploymentTarget.Linux)
if not args.build_freebsd:
self.platforms_to_skip_build.add(StdlibDeploymentTarget.FreeBSD)
if not args.build_cygwin:
self.platforms_to_skip_build.add(StdlibDeploymentTarget.Cygwin)
if not args.build_osx:
self.platforms_to_skip_build.add(StdlibDeploymentTarget.OSX)
if not args.build_ios_device:
self.platforms_to_skip_build.add(StdlibDeploymentTarget.iOS)
if not args.build_ios_simulator:
self.platforms_to_skip_build.add(
StdlibDeploymentTarget.iOSSimulator)
if not args.build_tvos_device:
self.platforms_to_skip_build.add(StdlibDeploymentTarget.AppleTV)
if not args.build_tvos_simulator:
self.platforms_to_skip_build.add(
StdlibDeploymentTarget.AppleTVSimulator)
if not args.build_watchos_device:
self.platforms_to_skip_build.add(StdlibDeploymentTarget.AppleWatch)
if not args.build_watchos_simulator:
self.platforms_to_skip_build.add(
StdlibDeploymentTarget.AppleWatchSimulator)
if not args.build_android:
self.platforms_to_skip_build.add(StdlibDeploymentTarget.Android)

self.platforms_to_skip_test = set()
self.platforms_archs_to_skip_test = set()
if not args.test_linux:
self.platforms_to_skip_test.add(StdlibDeploymentTarget.Linux)
if not args.test_freebsd:
self.platforms_to_skip_test.add(StdlibDeploymentTarget.FreeBSD)
if not args.test_cygwin:
self.platforms_to_skip_test.add(StdlibDeploymentTarget.Cygwin)
if not args.test_osx:
self.platforms_to_skip_test.add(StdlibDeploymentTarget.OSX)
if not args.test_ios_host:
self.platforms_to_skip_test.add(StdlibDeploymentTarget.iOS)
else:
exit_rejecting_arguments("error: iOS device tests are not " +
"supported in open-source Swift.")
if not args.test_ios_simulator:
self.platforms_to_skip_test.add(
StdlibDeploymentTarget.iOSSimulator)
if not args.test_ios_32bit_simulator:
self.platforms_archs_to_skip_test.add(
StdlibDeploymentTarget.iOSSimulator.i386)
if not args.test_tvos_host:
self.platforms_to_skip_test.add(StdlibDeploymentTarget.AppleTV)
else:
exit_rejecting_arguments("error: tvOS device tests are not " +
"supported in open-source Swift.")
if not args.test_tvos_simulator:
self.platforms_to_skip_test.add(
StdlibDeploymentTarget.AppleTVSimulator)
if not args.test_watchos_host:
self.platforms_to_skip_test.add(StdlibDeploymentTarget.AppleWatch)
else:
exit_rejecting_arguments("error: watchOS device tests are not " +
"supported in open-source Swift.")
if not args.test_watchos_simulator:
self.platforms_to_skip_test.add(
StdlibDeploymentTarget.AppleWatchSimulator)
if not args.test_android:
self.platforms_to_skip_test.add(StdlibDeploymentTarget.Android)

self.platforms_to_skip_test_host = set()
if not args.test_android_host:
self.platforms_to_skip_test_host.add(
StdlibDeploymentTarget.Android)
if not args.test_ios_host:
self.platforms_to_skip_test_host.add(StdlibDeploymentTarget.iOS)
if not args.test_tvos_host:
self.platforms_to_skip_test_host.add(
StdlibDeploymentTarget.AppleTV)
if not args.test_watchos_host:
self.platforms_to_skip_test_host.add(
StdlibDeploymentTarget.AppleWatch)
self.build_libparser_only = args.build_libparser_only

def initialize_runtime_environment(self):
Expand Down Expand Up @@ -821,7 +601,10 @@ class BuildScriptInvocation(object):
options = {}
for host_target in [args.host_target] + args.cross_compile_hosts:
# Compute the host specific configuration.
config = HostSpecificConfiguration(host_target, self)
try:
config = HostSpecificConfiguration(self.args, host_target)
except argparse.ArgumentError as e:
exit_rejecting_arguments(e.message)

# Convert into `build-script-impl` style variables.
options[host_target] = {
Expand Down Expand Up @@ -934,7 +717,10 @@ class BuildScriptInvocation(object):
# Build...
for host_target in all_hosts:
# FIXME: We should only compute these once.
config = HostSpecificConfiguration(host_target.name, self)
try:
config = HostSpecificConfiguration(self.args, host_target.name)
except argparse.ArgumentError as e:
exit_rejecting_arguments(e.message)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and in the previous code change: BuildScriptInvocation was calling a function exit_rejecting_arguments in the middle of the calculation of platforms_to_skip_test. Since those variables are only used in HostSpecificConfiguration, I moved them there, and to reproduce the previous behaviour, if HostSpecificConfiguration finds some problem with the passed arguments, it will raise ArgumentError, which will be dealt here. That allows the users of HostSpecificConfiguration decide how to act in the case of an error.

print("Building the standard library for: {}".format(
" ".join(config.swift_stdlib_build_targets)))
if config.swift_test_run_targets and (
Expand Down
1 change: 1 addition & 0 deletions utils/swift_build_support/swift_build_support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"cmake",
"debug",
"diagnostics",
"host_specific_configuration",
"migration",
"tar",
"targets",
Expand Down
Loading