Skip to content

Commit 9460969

Browse files
committed
[build-script] Separate SwiftTestinMacros from SwiftTesting product
Also, build them for all hosts including cross compiling host.
1 parent 6a38329 commit 9460969

File tree

7 files changed

+180
-15
lines changed

7 files changed

+180
-15
lines changed

utils/build-presets.ini

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ sourcekit-lsp
384384
swiftsyntax
385385
swiftformat
386386
swift-testing
387+
swift-testing-macros
387388

388389
skstresstester
389390

@@ -408,6 +409,7 @@ install-swift-driver
408409
install-swiftsyntax
409410
install-swiftformat
410411
install-swift-testing
412+
install-swift-testing-macros
411413

412414
[preset: buildbot_incremental,tools=RA,stdlib=RA,apple_silicon]
413415
mixin-preset=buildbot_incremental,tools=RA,stdlib=RA
@@ -842,6 +844,7 @@ llbuild
842844
swiftpm
843845
swift-driver
844846
swift-testing
847+
swift-testing-macros
845848
xctest
846849
swiftdocc
847850
swiftformat
@@ -856,6 +859,7 @@ install-swiftpm
856859
install-swift-driver
857860
install-swiftsyntax
858861
install-swift-testing
862+
install-swift-testing-macros
859863
install-xctest
860864
install-prefix=/usr
861865
install-sourcekit-lsp
@@ -1185,6 +1189,7 @@ swiftpm
11851189
swift-driver
11861190
xctest
11871191
swift-testing
1192+
swift-testing-macros
11881193
foundation
11891194
libdispatch
11901195
swiftsyntax
@@ -1203,6 +1208,7 @@ install-foundation
12031208
install-libdispatch
12041209
install-xctest
12051210
install-swift-testing
1211+
install-swift-testing-macros
12061212
install-swiftformat
12071213

12081214
[preset: buildbot_incremental_linux,long_test]
@@ -1327,6 +1333,7 @@ swift-driver
13271333
# swift-inspect
13281334
swiftsyntax
13291335
swift-testing
1336+
swift-testing-macros
13301337
swiftformat
13311338
playgroundsupport
13321339
indexstore-db
@@ -1372,6 +1379,7 @@ install-swiftpm
13721379
install-swift-driver
13731380
install-swiftsyntax
13741381
install-swift-testing
1382+
install-swift-testing-macros
13751383
install-playgroundsupport
13761384
install-sourcekit-lsp
13771385
install-swiftformat
@@ -1696,6 +1704,7 @@ swiftpm
16961704
swift-driver
16971705
swiftsyntax
16981706
swift-testing
1707+
swift-testing-macros
16991708
swiftformat
17001709
swiftdocc
17011710

@@ -1716,6 +1725,7 @@ install-swiftpm
17161725
install-swift-driver
17171726
install-swiftsyntax
17181727
install-swift-testing
1728+
install-swift-testing-macros
17191729
install-swiftdocc
17201730
install-swiftformat
17211731

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,11 @@ def create_argument_parser():
813813
help='build Swift Testing')
814814
option('--install-swift-testing', toggle_true('install_swift_testing'),
815815
help='install Swift Testing')
816+
option('--swift-testing-macros', toggle_true('build_swift_testing_macros'),
817+
help='build Swift Testing macro plugin')
818+
option('--install-swift-testing-macros',
819+
toggle_true('install_swift_testing_macros'),
820+
help='install Swift Testing macro plugin')
816821

817822
option('--xctest', toggle_true('build_xctest'),
818823
help='build xctest')

utils/build_swift/tests/expected_options.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
'build_swift_driver': False,
9797
'build_swift_libexec': True,
9898
'build_swift_testing': False,
99+
'build_swift_testing_macros': False,
99100
'build_early_swift_driver': True,
100101
'build_early_swiftsyntax': True,
101102
'build_swiftsyntax': False,
@@ -113,6 +114,7 @@
113114
'install_swiftpm': False,
114115
'install_swiftsyntax': False,
115116
'install_swift_testing': False,
117+
'install_swift_testing_macros': False,
116118
'install_swift_driver': False,
117119
'install_swiftdocc': False,
118120
'swiftsyntax_verify_generated_files': False,
@@ -569,6 +571,7 @@ class BuildScriptImplOption(_BaseOption):
569571
SetTrueOption('--swift-driver', dest='build_swift_driver'),
570572
SetTrueOption('--swiftsyntax', dest='build_swiftsyntax'),
571573
SetTrueOption('--swift-testing', dest='build_swift_testing'),
574+
SetTrueOption('--swift-testing-macros', dest='build_swift_testing_macros'),
572575
SetTrueOption('--skstresstester', dest='build_skstresstester'),
573576
SetTrueOption('--swiftformat', dest='build_swiftformat'),
574577
SetTrueOption('--swiftdocc', dest='build_swiftdocc'),
@@ -650,6 +653,8 @@ class BuildScriptImplOption(_BaseOption):
650653
EnableOption('--install-static-linux-config', dest='install_static_linux_config'),
651654
EnableOption('--install-swiftsyntax', dest='install_swiftsyntax'),
652655
EnableOption('--install-swift-testing', dest='install_swift_testing'),
656+
EnableOption('--install-swift-testing-macros',
657+
dest='install_swift_testing_macros'),
653658
EnableOption('--swiftsyntax-verify-generated-files',
654659
dest='swiftsyntax_verify_generated_files'),
655660
EnableOption('--swiftsyntax-enable-rawsyntax-validation',

utils/swift_build_support/swift_build_support/build_script_invocation.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,8 @@ def compute_product_pipelines(self):
678678
is_enabled=self.args.build_foundation)
679679
builder.add_product(products.SwiftSyntax,
680680
is_enabled=self.args.build_swiftsyntax)
681+
builder.add_product(products.SwiftTestingMacros,
682+
is_enabled=self.args.build_swift_testing_macros)
681683
builder.add_product(products.SwiftTesting,
682684
is_enabled=self.args.build_swift_testing)
683685
builder.add_product(products.SwiftFormat,

utils/swift_build_support/swift_build_support/products/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from .sourcekitlsp import SourceKitLSP
3131
from .staticswiftlinux import StaticSwiftLinuxConfig
3232
from .swift import Swift
33-
from .swift_testing import SwiftTesting
33+
from .swift_testing import SwiftTesting, SwiftTestingMacros
3434
from .swiftdocc import SwiftDocC
3535
from .swiftdoccrender import SwiftDocCRender
3636
from .swiftdriver import SwiftDriver
@@ -70,6 +70,7 @@
7070
'SwiftPM',
7171
'SwiftDriver',
7272
'SwiftTesting',
73+
'SwiftTestingMacros',
7374
'EarlySwiftDriver',
7475
'XCTest',
7576
'SwiftSyntax',

utils/swift_build_support/swift_build_support/products/product.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def target_for_platform(self, platform, arch, include_version=True):
293293
arch, self.args.darwin_deployment_version_xros)
294294
return target
295295

296-
def generate_darwin_toolchain_file(self, platform, arch):
296+
def generate_darwin_toolchain_file(self, platform, arch, version=None):
297297
"""
298298
Generates a new CMake tolchain file that specifies Darwin as a target
299299
platform.
@@ -306,9 +306,14 @@ def generate_darwin_toolchain_file(self, platform, arch):
306306

307307
cmake_osx_sysroot = xcrun.sdk_path(platform)
308308

309-
target = self.target_for_platform(platform, arch)
310-
if not target:
311-
raise RuntimeError('Unhandled platform {}?!'.format(platform))
309+
if platform == 'macosx':
310+
if version is None:
311+
version = self.args.darwin_deployment_version_osx
312+
target = '{}-apple-macosx{}'.format(arch, version)
313+
else:
314+
target = self.target_for_platform(platform, arch)
315+
if not target:
316+
raise RuntimeError('Unhandled platform {}?!'.format(platform))
312317

313318
toolchain_args = {}
314319

@@ -429,7 +434,8 @@ def generate_linux_toolchain_file(self, platform, arch):
429434

430435
return toolchain_file
431436

432-
def generate_toolchain_file_for_darwin_or_linux(self, host_target):
437+
def generate_toolchain_file_for_darwin_or_linux(
438+
self, host_target, override_deployment_version=None):
433439
"""
434440
Checks `host_target` platform and generates a new CMake tolchain file
435441
appropriate for that target platform (either Darwin or Linux). Defines
@@ -448,7 +454,8 @@ def generate_toolchain_file_for_darwin_or_linux(self, host_target):
448454

449455
toolchain_file = None
450456
if self.is_darwin_host(host_target):
451-
toolchain_file = self.generate_darwin_toolchain_file(platform, arch)
457+
toolchain_file = self.generate_darwin_toolchain_file(
458+
platform, arch, version=override_deployment_version)
452459
self.cmake_options.define('CMAKE_TOOLCHAIN_FILE:PATH', toolchain_file)
453460
elif platform == "linux":
454461
toolchain_file = self.generate_linux_toolchain_file(platform, arch)

utils/swift_build_support/swift_build_support/products/swift_testing.py

Lines changed: 143 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
import os
1414

1515
from . import cmake_product
16+
from . import product
1617
from . import swift
1718

1819

19-
class SwiftTesting(cmake_product.CMakeProduct):
20+
class SwiftTesting(product.Product):
2021
@classmethod
2122
def is_build_script_impl_product(cls):
2223
return False
@@ -36,7 +37,57 @@ def get_dependencies(cls):
3637
def should_build(self, host_target):
3738
return True
3839

40+
def should_test(self, host_target):
41+
return False
42+
43+
def should_install(self, host_target):
44+
return self.args.install_swift_testing_macros
45+
46+
def _impl_product(self, host_target):
47+
build_root = os.path.dirname(self.build_dir)
48+
build_dir = os.path.join(
49+
build_root, '%s-%s' % (self.product_name(), host_target))
50+
51+
return SwiftTestingImpl(
52+
args=self.args,
53+
toolchain=self.toolchain,
54+
source_dir=self.source_dir,
55+
build_dir=build_dir)
56+
57+
def _build_impl(self, host_target):
58+
self._impl_product(host_target).build(host_target)
59+
60+
def build(self, host_target):
61+
self._build_impl(host_target)
62+
63+
# For Darwin host, 'build' is only called for the builder.
64+
# Manually iterate tor the cross compile hosts.
65+
if self.has_cross_compile_hosts() and self.is_darwin_host(host_target):
66+
for target in self.args.cross_compile_hosts:
67+
self._build_impl(target)
68+
69+
# FIXME: build testing library for 'stdlib_deployment_targets'?
70+
pass
71+
72+
def _install_impl(self, host_target):
73+
self._impl_product(host_target).install(host_target)
74+
75+
def install(self, host_target):
76+
self._install_impl(host_target)
77+
78+
# For Darwin host, 'install' is only called for the builder.
79+
# Manually iterate tor the cross compile hosts.
80+
if self.has_cross_compile_hosts() and self.is_darwin_host(host_target):
81+
for target in self.args.cross_compile_hosts:
82+
self._install_impl(target)
83+
84+
85+
class SwiftTestingImpl(cmake_product.CMakeProduct):
3986
def build(self, host_target):
87+
override_version = None
88+
if host_target.startswith('macosx'):
89+
override_version = '10.15'
90+
4091
self.cmake_options.define('BUILD_SHARED_LIBS', 'YES')
4192

4293
# Use empty CMake install prefix, since the `DESTDIR` env var is set by
@@ -45,21 +96,105 @@ def build(self, host_target):
4596

4697
self.cmake_options.define('CMAKE_BUILD_TYPE', self.args.build_variant)
4798

48-
build_root = os.path.dirname(self.build_dir)
49-
swift_build_dir = os.path.join(
50-
'..', build_root, '%s-%s' % ('swift', host_target))
51-
swift_cmake_dir = os.path.join(swift_build_dir, 'cmake', 'modules')
52-
self.cmake_options.define('SwiftSyntax_DIR:PATH', swift_cmake_dir)
99+
# FIXME: If we build macros for the builder, specify the path.
100+
self.cmake_options.define('SwiftTesting_MACRO', 'NO')
53101

102+
self.generate_toolchain_file_for_darwin_or_linux(
103+
host_target, override_deployment_version=override_version)
54104
self.build_with_cmake([], self.args.build_variant, [],
55105
prefer_native_toolchain=True)
56106

107+
def install(self, host_target):
108+
install_destdir = self.host_install_destdir(host_target)
109+
install_prefix = install_destdir + self.args.install_prefix
110+
111+
self.install_with_cmake(['install'], install_prefix)
112+
113+
114+
class SwiftTestingMacros(product.Product):
115+
@classmethod
116+
def is_build_script_impl_product(cls):
117+
return False
118+
119+
@classmethod
120+
def is_before_build_script_impl_product(cls):
121+
return False
122+
123+
@classmethod
124+
def product_source_name(cls):
125+
return "swift-testing/Sources/TestingMacros"
126+
127+
@classmethod
128+
def get_dependencies(cls):
129+
return [swift.Swift]
130+
131+
def should_build(self, host_target):
132+
return True
133+
57134
def should_test(self, host_target):
58-
# TODO
59135
return False
60136

61137
def should_install(self, host_target):
62-
return self.args.install_swift_testing
138+
return self.args.install_swift_testing_macros
139+
140+
def _impl_product(self, host_target):
141+
build_root = os.path.dirname(self.build_dir)
142+
build_dir = os.path.join(
143+
build_root, '%s-%s' % (self.product_name(), host_target))
144+
145+
return SwiftTestingMacrosImpl(
146+
args=self.args,
147+
toolchain=self.toolchain,
148+
source_dir=self.source_dir,
149+
build_dir=build_dir)
150+
151+
def _build_impl(self, host_target):
152+
self._impl_product(host_target).build(host_target)
153+
154+
def build(self, host_target):
155+
self._build_impl(host_target)
156+
157+
# For Darwin host, 'build' is only called for the builder.
158+
# Manually iterate tor the cross compile hosts.
159+
if self.has_cross_compile_hosts() and self.is_darwin_host(host_target):
160+
for target in self.args.cross_compile_hosts:
161+
self._build_impl(target)
162+
163+
def _install_impl(self, host_target):
164+
self._impl_product(host_target).install(host_target)
165+
166+
def install(self, host_target):
167+
self._install_impl(host_target)
168+
169+
# For Darwin host, 'install' is only called for the builder.
170+
# Manually iterate tor the cross compile hosts.
171+
if self.has_cross_compile_hosts() and self.is_darwin_host(host_target):
172+
for target in self.args.cross_compile_hosts:
173+
self._install_impl(target)
174+
175+
176+
class SwiftTestingMacrosImpl(cmake_product.CMakeProduct):
177+
def build(self, host_target):
178+
override_version = None
179+
if host_target.startswith('macosx'):
180+
override_version = '10.15'
181+
182+
# Use empty CMake install prefix, since the `DESTDIR` env var is set by
183+
# `install_with_cmake` later which already has the same prefix.
184+
self.cmake_options.define('CMAKE_INSTALL_PREFIX', '')
185+
186+
self.cmake_options.define('CMAKE_BUILD_TYPE', self.args.build_variant)
187+
188+
build_root = os.path.dirname(self.build_dir)
189+
swift_build_dir = os.path.join(
190+
'..', build_root, '%s-%s' % ('swift', host_target))
191+
swift_cmake_dir = os.path.join(swift_build_dir, 'cmake', 'modules')
192+
self.cmake_options.define('SwiftSyntax_DIR:PATH', swift_cmake_dir)
193+
194+
self.generate_toolchain_file_for_darwin_or_linux(
195+
host_target, override_deployment_version=override_version)
196+
self.build_with_cmake([], self.args.build_variant, [],
197+
prefer_native_toolchain=True)
63198

64199
def install(self, host_target):
65200
install_destdir = self.host_install_destdir(host_target)

0 commit comments

Comments
 (0)