Skip to content

Commit 536a19a

Browse files
committed
[build-script] Move parts of BuildScriptInvocation into HostSpecificConfiguration.
The calculation of the plaforms to build/test were only used by HostSpeficicConfiguration, but were done in BuildScriptInvocation, and to make things work, the full BuildScriptInvocation object was passed down onto HostSpecificConfiguration. The changes in this commit move the code into HostSpecificConfiguration, and only pass `args` into it to let itself calculate the platforms to build/test. This will allow in the future that HostSpecificConfiguration can to be removed from the main script file, can be tested and can be used by several parts of the build script process. During a transition period, it will be useful for the builder that delegates to build-script-impl, but in the end, it might only be useful for the Swift builder.
1 parent 8cf291d commit 536a19a

File tree

1 file changed

+102
-104
lines changed

1 file changed

+102
-104
lines changed

utils/build-script

Lines changed: 102 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,10 @@ class HostSpecificConfiguration(object):
6060

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

63-
def __init__(self, host_target, invocation):
63+
def __init__(self, host_target, args):
6464
"""Initialize for the given `host_target`."""
6565

6666
# Compute the set of deployment targets to configure/build.
67-
args = invocation.args
6867
if host_target == args.host_target:
6968
# This host is the user's desired product, so honor the requested
7069
# set of targets to configure/build.
@@ -81,6 +80,17 @@ class HostSpecificConfiguration(object):
8180
stdlib_targets_to_configure = [host_target]
8281
stdlib_targets_to_build = set(stdlib_targets_to_configure)
8382

83+
# Compute derived information from the arguments.
84+
#
85+
# FIXME: We should move the platform-derived arguments to be entirely
86+
# data driven, so that we can eliminate this code duplication and just
87+
# iterate over all supported platforms.
88+
platforms_to_skip_build = self.__platforms_to_skip_build(args)
89+
platforms_to_skip_test = self.__platforms_to_skip_test(args)
90+
platforms_archs_to_skip_test = \
91+
self.__platforms_archs_to_skip_test(args)
92+
platforms_to_skip_test_host = self.__platforms_to_skip_test_host(args)
93+
8494
# Compute the lists of **CMake** targets for each use case (configure
8595
# vs. build vs. run) and the SDKs to configure with.
8696
self.sdks_to_configure = set()
@@ -107,9 +117,9 @@ class HostSpecificConfiguration(object):
107117

108118
# Compute which actions are desired.
109119
build = (
110-
deployment_platform not in invocation.platforms_to_skip_build)
120+
deployment_platform not in platforms_to_skip_build)
111121
test = (
112-
deployment_platform not in invocation.platforms_to_skip_test)
122+
deployment_platform not in platforms_to_skip_test)
113123
test_host_only = None
114124
dt_supports_benchmark = deployment_target.supports_benchmark
115125
build_benchmarks = build and dt_supports_benchmark
@@ -124,12 +134,12 @@ class HostSpecificConfiguration(object):
124134
# the host (i.e., they do not attempt to execute).
125135
if deployment_platform.uses_host_tests and \
126136
deployment_platform not in \
127-
invocation.platforms_to_skip_test_host:
137+
platforms_to_skip_test_host:
128138
test_host_only = True
129139

130140
name = deployment_target.name
131141

132-
for skip_test_arch in invocation.platforms_archs_to_skip_test:
142+
for skip_test_arch in platforms_archs_to_skip_test:
133143
if deployment_target.name == skip_test_arch.name:
134144
test = False
135145

@@ -192,6 +202,90 @@ class HostSpecificConfiguration(object):
192202
"check-swift{}-optimize_none_implicit_dynamic-{}"
193203
.format(subset_suffix, name))
194204

205+
def __platforms_to_skip_build(self, args):
206+
platforms_to_skip_build = set()
207+
if not args.build_linux:
208+
platforms_to_skip_build.add(StdlibDeploymentTarget.Linux)
209+
if not args.build_freebsd:
210+
platforms_to_skip_build.add(StdlibDeploymentTarget.FreeBSD)
211+
if not args.build_cygwin:
212+
platforms_to_skip_build.add(StdlibDeploymentTarget.Cygwin)
213+
if not args.build_osx:
214+
platforms_to_skip_build.add(StdlibDeploymentTarget.OSX)
215+
if not args.build_ios_device:
216+
platforms_to_skip_build.add(StdlibDeploymentTarget.iOS)
217+
if not args.build_ios_simulator:
218+
platforms_to_skip_build.add(StdlibDeploymentTarget.iOSSimulator)
219+
if not args.build_tvos_device:
220+
platforms_to_skip_build.add(StdlibDeploymentTarget.AppleTV)
221+
if not args.build_tvos_simulator:
222+
platforms_to_skip_build.add(
223+
StdlibDeploymentTarget.AppleTVSimulator)
224+
if not args.build_watchos_device:
225+
platforms_to_skip_build.add(StdlibDeploymentTarget.AppleWatch)
226+
if not args.build_watchos_simulator:
227+
platforms_to_skip_build.add(
228+
StdlibDeploymentTarget.AppleWatchSimulator)
229+
if not args.build_android:
230+
platforms_to_skip_build.add(StdlibDeploymentTarget.Android)
231+
return platforms_to_skip_build
232+
233+
def __platforms_to_skip_test(self, args):
234+
platforms_to_skip_test = set()
235+
if not args.test_linux:
236+
platforms_to_skip_test.add(StdlibDeploymentTarget.Linux)
237+
if not args.test_freebsd:
238+
platforms_to_skip_test.add(StdlibDeploymentTarget.FreeBSD)
239+
if not args.test_cygwin:
240+
platforms_to_skip_test.add(StdlibDeploymentTarget.Cygwin)
241+
if not args.test_osx:
242+
platforms_to_skip_test.add(StdlibDeploymentTarget.OSX)
243+
if not args.test_ios_host:
244+
platforms_to_skip_test.add(StdlibDeploymentTarget.iOS)
245+
else:
246+
exit_rejecting_arguments("error: iOS device tests are not " +
247+
"supported in open-source Swift.")
248+
if not args.test_ios_simulator:
249+
platforms_to_skip_test.add(StdlibDeploymentTarget.iOSSimulator)
250+
if not args.test_tvos_host:
251+
platforms_to_skip_test.add(StdlibDeploymentTarget.AppleTV)
252+
else:
253+
exit_rejecting_arguments("error: tvOS device tests are not " +
254+
"supported in open-source Swift.")
255+
if not args.test_tvos_simulator:
256+
platforms_to_skip_test.add(StdlibDeploymentTarget.AppleTVSimulator)
257+
if not args.test_watchos_host:
258+
platforms_to_skip_test.add(StdlibDeploymentTarget.AppleWatch)
259+
else:
260+
exit_rejecting_arguments("error: watchOS device tests are not " +
261+
"supported in open-source Swift.")
262+
if not args.test_watchos_simulator:
263+
platforms_to_skip_test.add(
264+
StdlibDeploymentTarget.AppleWatchSimulator)
265+
if not args.test_android:
266+
platforms_to_skip_test.add(StdlibDeploymentTarget.Android)
267+
268+
return platforms_to_skip_test
269+
270+
def __platforms_archs_to_skip_test(self, args):
271+
platforms_archs_to_skip_test = set()
272+
if not args.test_ios_32bit_simulator:
273+
platforms_archs_to_skip_test.add(
274+
StdlibDeploymentTarget.iOSSimulator.i386)
275+
return platforms_archs_to_skip_test
276+
277+
def __platforms_to_skip_test_host(self, args):
278+
platforms_to_skip_test_host = set()
279+
if not args.test_android_host:
280+
platforms_to_skip_test_host.add(StdlibDeploymentTarget.Android)
281+
if not args.test_ios_host:
282+
platforms_to_skip_test_host.add(StdlibDeploymentTarget.iOS)
283+
if not args.test_tvos_host:
284+
platforms_to_skip_test_host.add(StdlibDeploymentTarget.AppleTV)
285+
if not args.test_watchos_host:
286+
platforms_to_skip_test_host.add(StdlibDeploymentTarget.AppleWatch)
287+
return platforms_to_skip_test_host
288+
195289

196290
class BuildScriptInvocation(object):
197291

@@ -323,104 +417,8 @@ class BuildScriptInvocation(object):
323417
source_root=SWIFT_SOURCE_ROOT,
324418
build_root=os.path.join(SWIFT_BUILD_ROOT, args.build_subdir))
325419

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-
self.platforms_to_skip_build = self.__platforms_to_skip_build(args)
332-
self.platforms_to_skip_test = self.__platforms_to_skip_test(args)
333-
self.platforms_archs_to_skip_test = \
334-
self.__platforms_archs_to_skip_test(args)
335-
self.platforms_to_skip_test_host = \
336-
self.__platforms_to_skip_test_host(args)
337-
338420
self.build_libparser_only = args.build_libparser_only
339421

340-
def __platforms_to_skip_build(self, args):
341-
platforms_to_skip_build = set()
342-
if not args.build_linux:
343-
platforms_to_skip_build.add(StdlibDeploymentTarget.Linux)
344-
if not args.build_freebsd:
345-
platforms_to_skip_build.add(StdlibDeploymentTarget.FreeBSD)
346-
if not args.build_cygwin:
347-
platforms_to_skip_build.add(StdlibDeploymentTarget.Cygwin)
348-
if not args.build_osx:
349-
platforms_to_skip_build.add(StdlibDeploymentTarget.OSX)
350-
if not args.build_ios_device:
351-
platforms_to_skip_build.add(StdlibDeploymentTarget.iOS)
352-
if not args.build_ios_simulator:
353-
platforms_to_skip_build.add(StdlibDeploymentTarget.iOSSimulator)
354-
if not args.build_tvos_device:
355-
platforms_to_skip_build.add(StdlibDeploymentTarget.AppleTV)
356-
if not args.build_tvos_simulator:
357-
platforms_to_skip_build.add(
358-
StdlibDeploymentTarget.AppleTVSimulator)
359-
if not args.build_watchos_device:
360-
platforms_to_skip_build.add(StdlibDeploymentTarget.AppleWatch)
361-
if not args.build_watchos_simulator:
362-
platforms_to_skip_build.add(
363-
StdlibDeploymentTarget.AppleWatchSimulator)
364-
if not args.build_android:
365-
platforms_to_skip_build.add(StdlibDeploymentTarget.Android)
366-
return platforms_to_skip_build
367-
368-
def __platforms_to_skip_test(self, args):
369-
platforms_to_skip_test = set()
370-
if not args.test_linux:
371-
platforms_to_skip_test.add(StdlibDeploymentTarget.Linux)
372-
if not args.test_freebsd:
373-
platforms_to_skip_test.add(StdlibDeploymentTarget.FreeBSD)
374-
if not args.test_cygwin:
375-
platforms_to_skip_test.add(StdlibDeploymentTarget.Cygwin)
376-
if not args.test_osx:
377-
platforms_to_skip_test.add(StdlibDeploymentTarget.OSX)
378-
if not args.test_ios_host:
379-
platforms_to_skip_test.add(StdlibDeploymentTarget.iOS)
380-
else:
381-
exit_rejecting_arguments("error: iOS device tests are not " +
382-
"supported in open-source Swift.")
383-
if not args.test_ios_simulator:
384-
platforms_to_skip_test.add(StdlibDeploymentTarget.iOSSimulator)
385-
if not args.test_tvos_host:
386-
platforms_to_skip_test.add(StdlibDeploymentTarget.AppleTV)
387-
else:
388-
exit_rejecting_arguments("error: tvOS device tests are not " +
389-
"supported in open-source Swift.")
390-
if not args.test_tvos_simulator:
391-
platforms_to_skip_test.add(StdlibDeploymentTarget.AppleTVSimulator)
392-
if not args.test_watchos_host:
393-
platforms_to_skip_test.add(StdlibDeploymentTarget.AppleWatch)
394-
else:
395-
exit_rejecting_arguments("error: watchOS device tests are not " +
396-
"supported in open-source Swift.")
397-
if not args.test_watchos_simulator:
398-
platforms_to_skip_test.add(
399-
StdlibDeploymentTarget.AppleWatchSimulator)
400-
if not args.test_android:
401-
platforms_to_skip_test.add(StdlibDeploymentTarget.Android)
402-
403-
return platforms_to_skip_test
404-
405-
def __platforms_archs_to_skip_test(self, args):
406-
platforms_archs_to_skip_test = set()
407-
if not args.test_ios_32bit_simulator:
408-
platforms_archs_to_skip_test.add(
409-
StdlibDeploymentTarget.iOSSimulator.i386)
410-
return platforms_archs_to_skip_test
411-
412-
def __platforms_to_skip_test_host(self, args):
413-
platforms_to_skip_test_host = set()
414-
if not args.test_android_host:
415-
platforms_to_skip_test_host.add(StdlibDeploymentTarget.Android)
416-
if not args.test_ios_host:
417-
platforms_to_skip_test_host.add(StdlibDeploymentTarget.iOS)
418-
if not args.test_tvos_host:
419-
platforms_to_skip_test_host.add(StdlibDeploymentTarget.AppleTV)
420-
if not args.test_watchos_host:
421-
platforms_to_skip_test_host.add(StdlibDeploymentTarget.AppleWatch)
422-
return platforms_to_skip_test_host
423-
424422
def initialize_runtime_environment(self):
425423
"""Change the program environment for building."""
426424

@@ -838,7 +836,7 @@ class BuildScriptInvocation(object):
838836
options = {}
839837
for host_target in [args.host_target] + args.cross_compile_hosts:
840838
# Compute the host specific configuration.
841-
config = HostSpecificConfiguration(host_target, self)
839+
config = HostSpecificConfiguration(host_target, args)
842840

843841
# Convert into `build-script-impl` style variables.
844842
options[host_target] = {
@@ -953,7 +951,7 @@ class BuildScriptInvocation(object):
953951
# Build...
954952
for host_target in all_hosts:
955953
# FIXME: We should only compute these once.
956-
config = HostSpecificConfiguration(host_target.name, self)
954+
config = HostSpecificConfiguration(host_target.name, self.args)
957955
print("Building the standard library for: {}".format(
958956
" ".join(config.swift_stdlib_build_targets)))
959957
if config.swift_test_run_targets and (

0 commit comments

Comments
 (0)