Skip to content

Commit e98c5ea

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

File tree

8 files changed

+211
-19
lines changed

8 files changed

+211
-19
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
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from .staticswiftlinux import StaticSwiftLinuxConfig
3232
from .swift import Swift
3333
from .swift_testing import SwiftTesting
34+
from .swift_testing_macros import SwiftTestingMacros
3435
from .swiftdocc import SwiftDocC
3536
from .swiftdoccrender import SwiftDocCRender
3637
from .swiftdriver import SwiftDriver
@@ -70,6 +71,7 @@
7071
'SwiftPM',
7172
'SwiftDriver',
7273
'SwiftTesting',
74+
'SwiftTestingMacros',
7375
'EarlySwiftDriver',
7476
'XCTest',
7577
'SwiftSyntax',

utils/swift_build_support/swift_build_support/products/product.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@ 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,
297+
macos_deployment_version=None):
297298
"""
298299
Generates a new CMake tolchain file that specifies Darwin as a target
299300
platform.
@@ -306,9 +307,14 @@ def generate_darwin_toolchain_file(self, platform, arch):
306307

307308
cmake_osx_sysroot = xcrun.sdk_path(platform)
308309

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

313319
toolchain_args = {}
314320

@@ -429,7 +435,8 @@ def generate_linux_toolchain_file(self, platform, arch):
429435

430436
return toolchain_file
431437

432-
def generate_toolchain_file_for_darwin_or_linux(self, host_target):
438+
def generate_toolchain_file_for_darwin_or_linux(
439+
self, host_target, override_macos_deployment_version=None):
433440
"""
434441
Checks `host_target` platform and generates a new CMake tolchain file
435442
appropriate for that target platform (either Darwin or Linux). Defines
@@ -448,7 +455,9 @@ def generate_toolchain_file_for_darwin_or_linux(self, host_target):
448455

449456
toolchain_file = None
450457
if self.is_darwin_host(host_target):
451-
toolchain_file = self.generate_darwin_toolchain_file(platform, arch)
458+
toolchain_file = self.generate_darwin_toolchain_file(
459+
platform, arch,
460+
macos_deployment_version=override_macos_deployment_version)
452461
self.cmake_options.define('CMAKE_TOOLCHAIN_FILE:PATH', toolchain_file)
453462
elif platform == "linux":
454463
toolchain_file = self.generate_linux_toolchain_file(platform, arch)

utils/swift_build_support/swift_build_support/products/swift_testing.py

+60-13
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212

1313
import os
1414

15+
from build_swift.build_swift.versions import Version
16+
1517
from . import cmake_product
18+
from . import product
1619
from . import swift
1720

1821

19-
class SwiftTesting(cmake_product.CMakeProduct):
22+
class SwiftTesting(product.Product):
2023
@classmethod
2124
def is_build_script_impl_product(cls):
2225
return False
@@ -36,7 +39,59 @@ def get_dependencies(cls):
3639
def should_build(self, host_target):
3740
return True
3841

42+
def should_test(self, host_target):
43+
# TODO: Implement.
44+
return False
45+
46+
def should_install(self, host_target):
47+
return self.args.install_swift_testing_macros
48+
49+
def _cmake_product(self, host_target):
50+
build_root = os.path.dirname(self.build_dir)
51+
build_dir = os.path.join(
52+
build_root, '%s-%s' % (self.product_name(), host_target))
53+
54+
return SwiftTestingCMakeShim(
55+
args=self.args,
56+
toolchain=self.toolchain,
57+
source_dir=self.source_dir,
58+
build_dir=build_dir)
59+
60+
def _build_with_cmake(self, host_target):
61+
self._cmake_product(host_target).build(host_target)
62+
63+
def build(self, host_target):
64+
self._build_with_cmake(host_target)
65+
66+
# For Darwin host, 'build' is only called for the builder.
67+
# Manually iterate the cross compile hosts.
68+
if self.has_cross_compile_hosts() and self.is_darwin_host(host_target):
69+
for target in self.args.cross_compile_hosts:
70+
self._build_with_cmake(target)
71+
72+
# FIXME: build testing library for 'stdlib_deployment_targets'?
73+
pass
74+
75+
def _install_with_cmake(self, host_target):
76+
self._cmake_product(host_target).install(host_target)
77+
78+
def install(self, host_target):
79+
self._install_with_cmake(host_target)
80+
81+
# For Darwin host, 'install' is only called for the builder.
82+
# Manually iterate the cross compile hosts.
83+
if self.has_cross_compile_hosts() and self.is_darwin_host(host_target):
84+
for target in self.args.cross_compile_hosts:
85+
self._install_with_cmake(target)
86+
87+
88+
class SwiftTestingCMakeShim(cmake_product.CMakeProduct):
3989
def build(self, host_target):
90+
override_deployment_version = None
91+
if host_target.startswith('macosx'):
92+
if Version(self.args.darwin_deployment_version_osx) < Version('10.15'):
93+
override_deployment_version = '10.15'
94+
4095
self.cmake_options.define('BUILD_SHARED_LIBS', 'YES')
4196

4297
# Use empty CMake install prefix, since the `DESTDIR` env var is set by
@@ -45,22 +100,14 @@ def build(self, host_target):
45100

46101
self.cmake_options.define('CMAKE_BUILD_TYPE', self.args.build_variant)
47102

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

106+
self.generate_toolchain_file_for_darwin_or_linux(
107+
host_target, override_macos_deployment_version=override_deployment_version)
54108
self.build_with_cmake([], self.args.build_variant, [],
55109
prefer_native_toolchain=True)
56110

57-
def should_test(self, host_target):
58-
# TODO
59-
return False
60-
61-
def should_install(self, host_target):
62-
return self.args.install_swift_testing
63-
64111
def install(self, host_target):
65112
install_destdir = self.host_install_destdir(host_target)
66113
install_prefix = install_destdir + self.args.install_prefix

0 commit comments

Comments
 (0)