Skip to content

Commit db538f6

Browse files
committed
WIP: Create a unified build for (swift-)foundation-tests
We can’t add the tests to the general unified build because they use testable imports and building a package with testable imports also re-builds all of its dependencies with testable imports (swiftlang/swift-package-manager#8344) and is thus incompatible with the other package’s unified build. But we should still be able to share build products between corelibs-foundation tests and swift-foundation-tests.
1 parent 33eab01 commit db538f6

File tree

14 files changed

+87
-34
lines changed

14 files changed

+87
-34
lines changed

utils/build_swift/resources/SwiftPM-Unified-Build.xcworkspace/contents.xcworkspacedata

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

utils/swift_build_support/swift_build_support/build_script_invocation.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -893,9 +893,8 @@ def _execute_action(self, action_name):
893893
def execute_product_build_steps(self, product_class, host_target):
894894
product_source = product_class.product_source_name()
895895
product_name = product_class.product_name()
896-
if product_class.is_swiftpm_unified_build_product():
897-
build_dir = self.workspace.swiftpm_unified_build_dir(
898-
host_target)
896+
if arena := product_class.swiftpm_unified_build_product_arena():
897+
build_dir = self.workspace.swiftpm_unified_build_dir(arena, host_target)
899898
else:
900899
build_dir = self.workspace.build_dir(
901900
host_target, product_name)

utils/swift_build_support/swift_build_support/products/foundationtests.py

+42-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
import os
1414

15+
from build_swift.build_swift.constants import MULTIROOT_DATA_FILE_PATH
16+
1517
from . import cmark
1618
from . import foundation
1719
from . import libcxx
@@ -35,6 +37,10 @@ def is_build_script_impl_product(cls):
3537
def is_before_build_script_impl_product(cls):
3638
return False
3739

40+
@classmethod
41+
def swiftpm_unified_build_product_arena(cls):
42+
return 'foundationtests'
43+
3844
@classmethod
3945
def is_ignore_install_all_product(cls):
4046
return True
@@ -68,16 +74,51 @@ def test(self, host_target):
6874
'lib',
6975
'swift'
7076
)
77+
plutil_cmd = [
78+
swift_exec,
79+
'build',
80+
'--toolchain', self.install_toolchain_path(host_target),
81+
'--configuration', self.configuration(),
82+
'--scratch-path', self.build_dir,
83+
'--package-path', package_path,
84+
'--product', 'plutil',
85+
'--multiroot-data-file', MULTIROOT_DATA_FILE_PATH
86+
]
87+
if self.args.verbose_build:
88+
plutil_cmd.append('--verbose')
89+
90+
# On amazon-linux2 the gold linker (version 1.14) crashes when linking
91+
# debug info for swift-foundation. Workaround this issue by building without
92+
# debug info. In order to re-use the build products from swiftfoundationtests
93+
# we need to build without debug info here as well. rdar://137760869
94+
if host_target.startswith('linux'):
95+
plutil_cmd += ['-Xswiftc', '-gnone']
96+
97+
shell.call(plutil_cmd, env={
98+
'SWIFTCI_USE_LOCAL_DEPS': '1',
99+
'DISPATCH_INCLUDE_PATH': include_path
100+
})
101+
71102
cmd = [
72103
swift_exec,
73104
'test',
74105
'--toolchain', self.install_toolchain_path(host_target),
75106
'--configuration', self.configuration(),
76107
'--scratch-path', self.build_dir,
77-
'--package-path', package_path
108+
'--package-path', package_path,
109+
'--test-product', 'swift-corelibs-foundationPackageTests',
110+
'--multiroot-data-file', MULTIROOT_DATA_FILE_PATH
78111
]
79112
if self.args.verbose_build:
80113
cmd.append('--verbose')
114+
115+
# On amazon-linux2 the gold linker (version 1.14) crashes when linking
116+
# debug info for swift-foundation. Workaround this issue by building without
117+
# debug info. In order to re-use the build products from swiftfoundationtests
118+
# we need to build without debug info here as well. rdar://137760869
119+
if host_target.startswith('linux'):
120+
cmd += ['-Xswiftc', '-gnone']
121+
81122
shell.call(cmd, env={
82123
'SWIFTCI_USE_LOCAL_DEPS': '1',
83124
'DISPATCH_INCLUDE_PATH': include_path

utils/swift_build_support/swift_build_support/products/indexstoredb.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def is_before_build_script_impl_product(cls):
4242
return False
4343

4444
@classmethod
45-
def is_swiftpm_unified_build_product(cls):
46-
return True
45+
def swiftpm_unified_build_product_arena(cls):
46+
return 'unified'
4747

4848
def should_build(self, host_target):
4949
return True

utils/swift_build_support/swift_build_support/products/product.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,16 @@ def is_ignore_install_all_product(cls):
8989
return False
9090

9191
@classmethod
92-
def is_swiftpm_unified_build_product(cls):
93-
"""is_swiftpm_unified_build_product -> bool
92+
def swiftpm_unified_build_product_arena(cls):
93+
"""swiftpm_unified_build_product_arena -> Optional[str]
9494
95-
Whether this product should be built in the unified build of SwiftPM
96-
products.
95+
If this product should be built in the unified build of SwiftPM
96+
products, a name that identifies the build directory for the unified
97+
build. This should be 'unified' or 'foundationtests'. Foundation and
98+
the rest can't share a unified build because of
99+
https://github.com/swiftlang/swift-package-manager/issues/8344
97100
"""
98-
return False
101+
return None
99102

100103
@classmethod
101104
def is_nondarwin_only_build_product(cls):

utils/swift_build_support/swift_build_support/products/skstresstester.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ def is_before_build_script_impl_product(cls):
4747
return False
4848

4949
@classmethod
50-
def is_swiftpm_unified_build_product(cls):
51-
return True
50+
def swiftpm_unified_build_product_arena(cls):
51+
return 'unified'
5252

5353
def package_name(self):
5454
return 'SourceKitStressTester'

utils/swift_build_support/swift_build_support/products/sourcekitlsp.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def is_before_build_script_impl_product(cls):
4242
return False
4343

4444
@classmethod
45-
def is_swiftpm_unified_build_product(cls):
46-
return True
45+
def swiftpm_unified_build_product_arena(cls):
46+
return 'unified'
4747

4848
def should_build(self, host_target):
4949
return True

utils/swift_build_support/swift_build_support/products/stdlib_docs.py

-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ def is_build_script_impl_product(cls):
2727
def is_before_build_script_impl_product(cls):
2828
return False
2929

30-
@classmethod
31-
def is_swiftpm_unified_build_product(cls):
32-
return False
33-
3430
def should_build(self, host_target):
3531
return self.args.build_stdlib_docs
3632

utils/swift_build_support/swift_build_support/products/swiftdocc.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ def is_before_build_script_impl_product(cls):
4646
return False
4747

4848
@classmethod
49-
def is_swiftpm_unified_build_product(cls):
50-
return True
49+
def swiftpm_unified_build_product_arena(cls):
50+
return 'unified'
5151

5252
def run_build_script_helper(self, action, host_target, additional_params=[]):
5353
script_path = os.path.join(

utils/swift_build_support/swift_build_support/products/swiftdoccrender.py

-4
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ def is_build_script_impl_product(cls):
3434
def is_before_build_script_impl_product(cls):
3535
return False
3636

37-
@classmethod
38-
def is_swiftpm_unified_build_product(cls):
39-
return False
40-
4137
def should_build(self, host_target):
4238
# Swift-DocC-Render is a pre-built, installable artifact.
4339
return False

utils/swift_build_support/swift_build_support/products/swiftformat.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ def is_before_build_script_impl_product(cls):
4747
return False
4848

4949
@classmethod
50-
def is_swiftpm_unified_build_product(cls):
51-
return True
50+
def swiftpm_unified_build_product_arena(cls):
51+
return 'unified'
5252

5353
def configuration(self):
5454
return 'release' if self.is_release() else 'debug'

utils/swift_build_support/swift_build_support/products/swiftfoundationtests.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
import os
1414

15+
from build_swift.build_swift.constants import MULTIROOT_DATA_FILE_PATH
16+
1517
from . import cmark
1618
from . import foundation
1719
from . import libcxx
@@ -35,6 +37,10 @@ def is_build_script_impl_product(cls):
3537
def is_before_build_script_impl_product(cls):
3638
return False
3739

40+
@classmethod
41+
def swiftpm_unified_build_product_arena(cls):
42+
return 'foundationtests'
43+
3844
@classmethod
3945
def is_ignore_install_all_product(cls):
4046
return True
@@ -63,13 +69,20 @@ def test(self, host_target):
6369
)
6470
package_path = os.path.join(self.source_dir, '..', 'swift-foundation')
6571
package_path = os.path.abspath(package_path)
72+
include_path = os.path.join(
73+
self.install_toolchain_path(host_target),
74+
'lib',
75+
'swift'
76+
)
6677
cmd = [
6778
swift_exec,
6879
'test',
6980
'--toolchain', self.install_toolchain_path(host_target),
7081
'--configuration', self.configuration(),
7182
'--scratch-path', self.build_dir,
72-
'--package-path', package_path
83+
'--package-path', package_path,
84+
'--test-product', 'swift-foundationPackageTests',
85+
'--multiroot-data-file', MULTIROOT_DATA_FILE_PATH
7386
]
7487
if self.args.verbose_build:
7588
cmd.append('--verbose')
@@ -80,7 +93,10 @@ def test(self, host_target):
8093
if host_target.startswith('linux'):
8194
cmd += ['-Xswiftc', '-gnone']
8295

83-
shell.call(cmd, env={'SWIFTCI_USE_LOCAL_DEPS': '1'})
96+
shell.call(cmd, env={
97+
'SWIFTCI_USE_LOCAL_DEPS': '1',
98+
'DISPATCH_INCLUDE_PATH': include_path
99+
})
84100

85101
@classmethod
86102
def get_dependencies(cls):

utils/swift_build_support/swift_build_support/products/swiftsyntax.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ def is_before_build_script_impl_product(cls):
4646
return False
4747

4848
@classmethod
49-
def is_swiftpm_unified_build_product(cls):
50-
return True
49+
def swiftpm_unified_build_product_arena(cls):
50+
return 'unified'
5151

5252
def run_swiftsyntax_build_script(self, target, command, additional_params=[]):
5353
script_path = os.path.join(self.source_dir, 'SwiftSyntaxDevUtils')

utils/swift_build_support/swift_build_support/workspace.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,13 @@ def build_dir(self, deployment_target, product):
2929
return os.path.join(self.build_root,
3030
'%s-%s' % (product, deployment_target))
3131

32-
def swiftpm_unified_build_dir(self, deployment_target):
32+
def swiftpm_unified_build_dir(self, arena, deployment_target):
3333
""" swiftpm_unified_build_dir() -> str
3434
3535
Build directory that all SwiftPM unified build products share.
3636
"""
3737
return os.path.join(self.build_root,
38-
'unified-swiftpm-build-%s' %
39-
deployment_target)
38+
f'{arena}-swiftpm-build-{deployment_target}')
4039

4140

4241
def compute_build_subdir(args):

0 commit comments

Comments
 (0)