Skip to content

Commit bd5b4b0

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

File tree

7 files changed

+174
-15
lines changed

7 files changed

+174
-15
lines changed

utils/build-presets.ini

+10
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

+5
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

+5
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

+2
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

+2-1
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

+12-6
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+
target = '{}-apple-macosx{}'.format(
311+
arch,
312+
version if version is not None else self.args.darwin_deployment_version_osx)
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,7 @@ 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(self, host_target, override_deployment_version=None):
433438
"""
434439
Checks `host_target` platform and generates a new CMake tolchain file
435440
appropriate for that target platform (either Darwin or Linux). Defines
@@ -448,7 +453,8 @@ def generate_toolchain_file_for_darwin_or_linux(self, host_target):
448453

449454
toolchain_file = None
450455
if self.is_darwin_host(host_target):
451-
toolchain_file = self.generate_darwin_toolchain_file(platform, arch)
456+
toolchain_file = self.generate_darwin_toolchain_file(
457+
platform, arch, version=override_deployment_version)
452458
self.cmake_options.define('CMAKE_TOOLCHAIN_FILE:PATH', toolchain_file)
453459
elif platform == "linux":
454460
toolchain_file = self.generate_linux_toolchain_file(platform, arch)

utils/swift_build_support/swift_build_support/products/swift_testing.py

+138-8
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,55 @@ 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(build_root, '%s-%s' % (self.product_name(), host_target))
49+
50+
return SwiftTestingImpl(
51+
args=self.args,
52+
toolchain=self.toolchain,
53+
source_dir=self.source_dir,
54+
build_dir=build_dir)
55+
56+
def _build_impl(self, host_target):
57+
self._impl_product(host_target).build(host_target)
58+
3959
def build(self, host_target):
60+
self._build_impl(host_target)
61+
62+
# For Darwin host, 'build' is only called for the builder.
63+
# Manually iterate tor the cross compile hosts.
64+
if self.has_cross_compile_hosts() and self.is_darwin_host(host_target):
65+
for target in self.args.cross_compile_hosts:
66+
self._build_impl(target)
67+
68+
# FIXME: build testing library for 'stdlib_deployment_targets'?
69+
pass
70+
71+
def _install_impl(self, host_target):
72+
self._impl_product(host_target).install(host_target)
73+
74+
def install(self, host_target):
75+
self._install_impl(host_target)
76+
77+
# For Darwin host, 'install' is only called for the builder.
78+
# Manually iterate tor the cross compile hosts.
79+
if self.has_cross_compile_hosts() and self.is_darwin_host(host_target):
80+
for target in self.args.cross_compile_hosts:
81+
self._install_impl(target)
82+
83+
class SwiftTestingImpl(cmake_product.CMakeProduct):
84+
def build(self, host_target):
85+
override_version = None
86+
if host_target.startswith('macosx'):
87+
override_version='10.15'
88+
4089
self.cmake_options.define('BUILD_SHARED_LIBS', 'YES')
4190

4291
# Use empty CMake install prefix, since the `DESTDIR` env var is set by
@@ -45,21 +94,102 @@ def build(self, host_target):
4594

4695
self.cmake_options.define('CMAKE_BUILD_TYPE', self.args.build_variant)
4796

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)
97+
# FIXME: If we build macros for the builder, specify the path.
98+
self.cmake_options.define('SwiftTesting_MACRO', 'NO')
5399

100+
self.generate_toolchain_file_for_darwin_or_linux(
101+
host_target, override_deployment_version=override_version)
54102
self.build_with_cmake([], self.args.build_variant, [],
55103
prefer_native_toolchain=True)
56104

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

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

64194
def install(self, host_target):
65195
install_destdir = self.host_install_destdir(host_target)

0 commit comments

Comments
 (0)