Skip to content

Commit 9aa6f06

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

File tree

6 files changed

+152
-9
lines changed

6 files changed

+152
-9
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
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-tesitng-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/swift_testing.py

+128-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,6 +37,50 @@ 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+
59+
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):
3984
def build(self, host_target):
4085
self.cmake_options.define('BUILD_SHARED_LIBS', 'YES')
4186

@@ -45,21 +90,96 @@ def build(self, host_target):
4590

4691
self.cmake_options.define('CMAKE_BUILD_TYPE', self.args.build_variant)
4792

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

96+
self.generate_toolchain_file_for_darwin_or_linux(host_target)
5497
self.build_with_cmake([], self.args.build_variant, [],
5598
prefer_native_toolchain=True)
5699

100+
def install(self, host_target):
101+
install_destdir = self.host_install_destdir(host_target)
102+
install_prefix = install_destdir + self.args.install_prefix
103+
104+
self.install_with_cmake(['install'], install_prefix)
105+
106+
class SwiftTestingMacros(product.Product):
107+
@classmethod
108+
def is_build_script_impl_product(cls):
109+
return False
110+
111+
@classmethod
112+
def is_before_build_script_impl_product(cls):
113+
return False
114+
115+
@classmethod
116+
def product_source_name(cls):
117+
return "swift-testing/Sources/SwiftTestingMacros"
118+
119+
@classmethod
120+
def get_dependencies(cls):
121+
return [swift.Swift]
122+
123+
def should_build(self, host_target):
124+
return True
125+
57126
def should_test(self, host_target):
58-
# TODO
59127
return False
60128

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

64184
def install(self, host_target):
65185
install_destdir = self.host_install_destdir(host_target)

0 commit comments

Comments
 (0)