Skip to content

Commit 28bd9b6

Browse files
committed
[build-script] Separate SwiftTestinMacros from SwiftTesting product
Also, build them for all hosts including cross compiling host. (cherry picked from commit e98c5ea)
1 parent 4a8a8c7 commit 28bd9b6

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
@@ -380,6 +380,7 @@ sourcekit-lsp
380380
swiftsyntax
381381
swiftformat
382382
swift-testing
383+
swift-testing-macros
383384

384385
skstresstester
385386

@@ -404,6 +405,7 @@ install-swift-driver
404405
install-swiftsyntax
405406
install-swiftformat
406407
install-swift-testing
408+
install-swift-testing-macros
407409

408410
[preset: buildbot_incremental,tools=RA,stdlib=RA,apple_silicon]
409411
mixin-preset=buildbot_incremental,tools=RA,stdlib=RA
@@ -838,6 +840,7 @@ llbuild
838840
swiftpm
839841
swift-driver
840842
swift-testing
843+
swift-testing-macros
841844
xctest
842845
libicu
843846
swiftdocc
@@ -853,6 +856,7 @@ install-swiftpm
853856
install-swift-driver
854857
install-swiftsyntax
855858
install-swift-testing
859+
install-swift-testing-macros
856860
install-xctest
857861
install-libicu
858862
install-prefix=/usr
@@ -1174,6 +1178,7 @@ swiftpm
11741178
swift-driver
11751179
xctest
11761180
swift-testing
1181+
swift-testing-macros
11771182
foundation
11781183
libdispatch
11791184
swiftsyntax
@@ -1193,6 +1198,7 @@ install-foundation
11931198
install-libdispatch
11941199
install-xctest
11951200
install-swift-testing
1201+
install-swift-testing-macros
11961202
install-swiftformat
11971203

11981204
[preset: buildbot_incremental_linux,long_test]
@@ -1317,6 +1323,7 @@ swift-driver
13171323
# swift-inspect
13181324
swiftsyntax
13191325
swift-testing
1326+
swift-testing-macros
13201327
swiftformat
13211328
playgroundsupport
13221329
indexstore-db
@@ -1360,6 +1367,7 @@ install-swiftpm
13601367
install-swift-driver
13611368
install-swiftsyntax
13621369
install-swift-testing
1370+
install-swift-testing-macros
13631371
install-playgroundsupport
13641372
install-sourcekit-lsp
13651373
install-swiftformat
@@ -1662,6 +1670,7 @@ swiftpm
16621670
swift-driver
16631671
swiftsyntax
16641672
swift-testing
1673+
swift-testing-macros
16651674
swiftformat
16661675
swiftdocc
16671676

@@ -1682,6 +1691,7 @@ install-swiftpm
16821691
install-swift-driver
16831692
install-swiftsyntax
16841693
install-swift-testing
1694+
install-swift-testing-macros
16851695
install-swiftdocc
16861696
install-swiftformat
16871697

utils/build_swift/build_swift/driver_arguments.py

+5
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,11 @@ def create_argument_parser():
815815
help='build Swift Testing')
816816
option('--install-swift-testing', toggle_true('install_swift_testing'),
817817
help='install Swift Testing')
818+
option('--swift-testing-macros', toggle_true('build_swift_testing_macros'),
819+
help='build Swift Testing macro plugin')
820+
option('--install-swift-testing-macros',
821+
toggle_true('install_swift_testing_macros'),
822+
help='install Swift Testing macro plugin')
818823

819824
option('--xctest', toggle_true('build_xctest'),
820825
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,
@@ -568,6 +570,7 @@ class BuildScriptImplOption(_BaseOption):
568570
SetTrueOption('--swift-driver', dest='build_swift_driver'),
569571
SetTrueOption('--swiftsyntax', dest='build_swiftsyntax'),
570572
SetTrueOption('--swift-testing', dest='build_swift_testing'),
573+
SetTrueOption('--swift-testing-macros', dest='build_swift_testing_macros'),
571574
SetTrueOption('--skstresstester', dest='build_skstresstester'),
572575
SetTrueOption('--swiftformat', dest='build_swiftformat'),
573576
SetTrueOption('--swiftdocc', dest='build_swiftdocc'),
@@ -648,6 +651,8 @@ class BuildScriptImplOption(_BaseOption):
648651
EnableOption('--install-static-linux-config', dest='install_static_linux_config'),
649652
EnableOption('--install-swiftsyntax', dest='install_swiftsyntax'),
650653
EnableOption('--install-swift-testing', dest='install_swift_testing'),
654+
EnableOption('--install-swift-testing-macros',
655+
dest='install_swift_testing_macros'),
651656
EnableOption('--swiftsyntax-verify-generated-files',
652657
dest='swiftsyntax_verify_generated_files'),
653658
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
@@ -666,6 +666,8 @@ def compute_product_pipelines(self):
666666
is_enabled=self.args.build_swiftpm)
667667
builder.add_product(products.SwiftSyntax,
668668
is_enabled=self.args.build_swiftsyntax)
669+
builder.add_product(products.SwiftTestingMacros,
670+
is_enabled=self.args.build_swift_testing_macros)
669671
builder.add_product(products.SwiftTesting,
670672
is_enabled=self.args.build_swift_testing)
671673
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
@@ -67,6 +68,7 @@
6768
'SwiftPM',
6869
'SwiftDriver',
6970
'SwiftTesting',
71+
'SwiftTestingMacros',
7072
'EarlySwiftDriver',
7173
'XCTest',
7274
'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
plaftorm.
@@ -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 plaftorm (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)