Skip to content

Commit 869f8b4

Browse files
authored
Merge pull request #28005 from ahoppen/unified-build
Build SwiftSyntax and the stress tester using a unified build
2 parents 489c80a + 5764b77 commit 869f8b4

File tree

10 files changed

+125
-10
lines changed

10 files changed

+125
-10
lines changed

utils/build-script

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -804,12 +804,17 @@ class BuildScriptInvocation(object):
804804
continue
805805
product_source = product_class.product_source_name()
806806
product_name = product_class.product_name()
807+
if product_class.is_swiftpm_unified_build_product():
808+
build_dir = self.workspace.swiftpm_unified_build_dir(
809+
host_target)
810+
else:
811+
build_dir = self.workspace.build_dir(
812+
host_target, product_name)
807813
product = product_class(
808814
args=self.args,
809815
toolchain=self.toolchain,
810816
source_dir=self.workspace.source_dir(product_source),
811-
build_dir=self.workspace.build_dir(
812-
host_target, product_name))
817+
build_dir=build_dir)
813818
if product.should_build(host_target):
814819
print("--- Building %s ---" % product_name)
815820
product.build(host_target)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/xcuserdata

utils/swift_build_support/SwiftPM-Unified-Build.xcworkspace/contents.xcworkspacedata

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# swift_build_support/multiroot_data_file.py - Unified build -----*- python -*-
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See https://swift.org/LICENSE.txt for license information
9+
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
#
11+
# ----------------------------------------------------------------------------
12+
13+
import os
14+
15+
16+
def path():
17+
"""product_source_name() -> str
18+
19+
The path to the Xcode workspace to use for a unified build of multiple
20+
SwiftPM projects.
21+
"""
22+
return os.path.join(os.path.dirname(__file__), '..',
23+
'SwiftPM-Unified-Build.xcworkspace')

utils/swift_build_support/swift_build_support/products/product.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ def is_build_script_impl_product(cls):
4747
"""
4848
return True
4949

50+
@classmethod
51+
def is_swiftpm_unified_build_product(cls):
52+
"""is_swiftpm_unified_build_product -> bool
53+
54+
Whether this product should be build in the unified build of SwiftPM
55+
products.
56+
"""
57+
return False
58+
5059
def should_build(self, host_target):
5160
"""should_build() -> Bool
5261

utils/swift_build_support/swift_build_support/products/skstresstester.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
# swift_build_support/products/skstresstester.py -----------------*- python -*-
23
#
34
# This source file is part of the Swift.org open source project
@@ -14,6 +15,7 @@
1415
import platform
1516

1617
from . import product
18+
from .. import multiroot_data_file
1719
from .. import shell
1820

1921

@@ -26,6 +28,14 @@ def product_source_name(cls):
2628
"""
2729
return "swift-stress-tester"
2830

31+
@classmethod
32+
def is_build_script_impl_product(cls):
33+
return False
34+
35+
@classmethod
36+
def is_swiftpm_unified_build_product(cls):
37+
return True
38+
2939
def package_name(self):
3040
return 'SourceKitStressTester'
3141

@@ -42,17 +52,18 @@ def run_build_script_helper(self, action, additional_params=[]):
4252
'--toolchain', self.install_toolchain_path(),
4353
'--config', configuration,
4454
'--build-dir', self.build_dir,
55+
'--multiroot-data-file', multiroot_data_file.path(),
56+
# There might have been a Package.resolved created by other builds
57+
# or by the package being opened using Xcode. Discard that and
58+
# reset the dependencies to be local.
59+
'--update'
4560
]
4661
if self.args.verbose_build:
4762
helper_cmd.append('--verbose')
4863
helper_cmd.extend(additional_params)
4964

5065
shell.call(helper_cmd)
5166

52-
@classmethod
53-
def is_build_script_impl_product(cls):
54-
return False
55-
5667
def should_build(self, host_target):
5768
return True
5869

utils/swift_build_support/swift_build_support/products/swiftevolve.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
#
1111
# ----------------------------------------------------------------------------
1212

13+
import os
14+
1315
from . import skstresstester
16+
from .. import shell
1417

1518

1619
class SwiftEvolve(skstresstester.SKStressTester):
@@ -22,9 +25,39 @@ def product_source_name(cls):
2225
"""
2326
return "swift-stress-tester"
2427

28+
@classmethod
29+
def is_swiftpm_unified_build_product(cls):
30+
return False
31+
2532
def package_name(self):
2633
return 'SwiftEvolve'
2734

35+
# Copy of the build-script-helper invocation without the multiroot data
36+
# file. Remove again once SwiftEvolve also builds in the unified build.
37+
def run_build_script_helper(self, action, additional_params=[]):
38+
script_path = os.path.join(
39+
self.source_dir, 'build-script-helper.py')
40+
41+
configuration = 'release' if self.is_release() else 'debug'
42+
43+
helper_cmd = [
44+
script_path,
45+
action,
46+
'--package-dir', self.package_name(),
47+
'--toolchain', self.install_toolchain_path(),
48+
'--config', configuration,
49+
'--build-dir', self.build_dir,
50+
# There might have been a Package.resolved created by other builds
51+
# or by the package being opened using Xcode. Discard that and
52+
# reset the dependencies to be local.
53+
'--update'
54+
]
55+
if self.args.verbose_build:
56+
helper_cmd.append('--verbose')
57+
helper_cmd.extend(additional_params)
58+
59+
shell.call(helper_cmd)
60+
2861
# Inherit the entire build configuration from the SourceKit stress tester
2962

3063
def should_build(self, host_target):

utils/swift_build_support/swift_build_support/products/swiftsyntax.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import os
1414

1515
from . import product
16+
from .. import multiroot_data_file
1617
from .. import shell
1718
from .. import targets
1819

@@ -26,6 +27,14 @@ def product_source_name(cls):
2627
"""
2728
return "swift-syntax"
2829

30+
@classmethod
31+
def is_build_script_impl_product(cls):
32+
return False
33+
34+
@classmethod
35+
def is_swiftpm_unified_build_product(cls):
36+
return True
37+
2938
def run_swiftsyntax_build_script(self, target, additional_params=[]):
3039
llvm_build_dir = os.path.join(self.build_dir, '..', 'llvm-' + target)
3140
llvm_build_dir = os.path.realpath(llvm_build_dir)
@@ -35,6 +44,7 @@ def run_swiftsyntax_build_script(self, target, additional_params=[]):
3544
build_cmd = [
3645
script_path,
3746
'--build-dir', self.build_dir,
47+
'--multiroot-data-file', multiroot_data_file.path(),
3848
'--toolchain', self.install_toolchain_path(),
3949
'--filecheck-exec', os.path.join(llvm_build_dir, 'bin',
4050
'FileCheck'),
@@ -53,10 +63,6 @@ def run_swiftsyntax_build_script(self, target, additional_params=[]):
5363

5464
shell.call(build_cmd)
5565

56-
@classmethod
57-
def is_build_script_impl_product(cls):
58-
return False
59-
6066
def should_build(self, host_target):
6167
return True
6268

utils/swift_build_support/swift_build_support/workspace.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ def build_dir(self, deployment_target, product):
2929
return os.path.join(self.build_root,
3030
'%s-%s' % (product, deployment_target))
3131

32+
def swiftpm_unified_build_dir(self, deployment_target):
33+
""" swiftpm_unified_build_dir() -> str
34+
35+
Build directory that all SwiftPM unified build products share.
36+
"""
37+
return os.path.join(self.build_root,
38+
'unified-swiftpm-build-%s' %
39+
deployment_target)
40+
3241

3342
def compute_build_subdir(args):
3443
# Create a name for the build directory.

0 commit comments

Comments
 (0)