Skip to content

Commit b854e99

Browse files
authored
Merge pull request swiftlang#27768 from ahoppen/swift-build-support-refactor
2 parents 0c15021 + 39c3f39 commit b854e99

File tree

7 files changed

+102
-17
lines changed

7 files changed

+102
-17
lines changed

utils/build-script

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -790,9 +790,12 @@ class BuildScriptInvocation(object):
790790
source_dir=self.workspace.source_dir(product_source),
791791
build_dir=self.workspace.build_dir(
792792
host_target, product_name))
793-
product.build(host_target)
794-
product.test(host_target)
795-
product.install(host_target)
793+
if product.should_build(host_target):
794+
product.build(host_target)
795+
if product.should_test(host_target):
796+
product.test(host_target)
797+
if product.should_install(host_target):
798+
product.install(host_target)
796799

797800
# Extract symbols...
798801
for host_target in all_hosts:

utils/swift_build_support/swift_build_support/products/benchmarks.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,15 @@ def product_source_name(cls):
2828
def is_build_script_impl_product(cls):
2929
return False
3030

31+
def should_build(self, host_target):
32+
return True
33+
3134
def build(self, host_target):
3235
run_build_script_helper(host_target, self, self.args)
3336

37+
def should_test(self, host_target):
38+
return True
39+
3440
def test(self, host_target):
3541
"""Just run a single instance of the command for both .debug and
3642
.release.
@@ -45,6 +51,9 @@ def test(self, host_target):
4551
bench_Osize = os.path.join(self.build_dir, 'bin', 'Benchmark_Osize')
4652
shell.call([bench_Osize] + cmdline)
4753

54+
def should_install(self, host_target):
55+
return False
56+
4857
def install(self, host_target):
4958
pass
5059

utils/swift_build_support/swift_build_support/products/indexstoredb.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# ----------------------------------------------------------------------------
1212

1313
import os
14-
import platform
1514

1615
from . import product
1716
from .. import shell
@@ -27,12 +26,20 @@ def product_source_name(cls):
2726
def is_build_script_impl_product(cls):
2827
return False
2928

29+
def should_build(self, host_target):
30+
return True
31+
3032
def build(self, host_target):
3133
run_build_script_helper('build', host_target, self, self.args)
3234

35+
def should_test(self, host_target):
36+
return self.args.test_indexstoredb
37+
3338
def test(self, host_target):
34-
if self.args.test and self.args.test_indexstoredb:
35-
run_build_script_helper('test', host_target, self, self.args)
39+
run_build_script_helper('test', host_target, self, self.args)
40+
41+
def should_install(self, host_target):
42+
return False
3643

3744
def install(self, host_target):
3845
pass
@@ -41,11 +48,10 @@ def install(self, host_target):
4148
def run_build_script_helper(action, host_target, product, args):
4249
script_path = os.path.join(
4350
product.source_dir, 'Utilities', 'build-script-helper.py')
44-
toolchain_path = args.install_destdir
45-
if platform.system() == 'Darwin':
46-
# The prefix is an absolute path, so concatenate without os.path.
47-
toolchain_path += \
48-
targets.darwin_toolchain_prefix(args.install_prefix)
51+
52+
toolchain_path = targets.toolchain_path(args.install_destdir,
53+
args.install_prefix)
54+
4955
configuration = 'debug' if args.build_variant == 'Debug' else 'release'
5056
helper_cmd = [
5157
script_path,

utils/swift_build_support/swift_build_support/products/product.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,42 @@ def is_build_script_impl_product(cls):
4242
"""
4343
return True
4444

45+
def should_build(self, host_target):
46+
"""should_build() -> Bool
47+
48+
Whether or not this product should be built with the given arguments.
49+
"""
50+
raise NotImplementedError
51+
4552
def build(self, host_target):
4653
"""build() -> void
4754
4855
Perform the build, for a non-build-script-impl product.
4956
"""
5057
raise NotImplementedError
5158

59+
def should_test(self, host_target):
60+
"""should_test() -> Bool
61+
62+
Whether or not this product should be tested with the given arguments.
63+
"""
64+
raise NotImplementedError
65+
5266
def test(self, host_target):
5367
"""test() -> void
5468
5569
Run the tests, for a non-build-script-impl product.
5670
"""
5771
raise NotImplementedError
5872

73+
def should_install(self, host_target):
74+
"""should_install() -> Bool
75+
76+
Whether or not this product should be installed with the given
77+
arguments.
78+
"""
79+
raise NotImplementedError
80+
5981
def install(self, host_target):
6082
"""install() -> void
6183
@@ -64,6 +86,19 @@ def install(self, host_target):
6486
raise NotImplementedError
6587

6688
def __init__(self, args, toolchain, source_dir, build_dir):
89+
"""
90+
Parameters
91+
----------
92+
args : `argparse.Namespace`
93+
The arguments passed by the user to the invocation of the script.
94+
toolchain : `swift_build_support.toolchain.Toolchain`
95+
The toolchain being used to build the product. The toolchain will
96+
point to the tools that the builder should use to build (like the
97+
compiler or the linker).
98+
build_dir: string
99+
The directory in which the product should put all of its build
100+
products.
101+
"""
67102
self.args = args
68103
self.toolchain = toolchain
69104
self.source_dir = source_dir

utils/swift_build_support/swift_build_support/products/sourcekitlsp.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,23 @@ def product_source_name(cls):
2323
def is_build_script_impl_product(cls):
2424
return False
2525

26+
def should_build(self, host_target):
27+
return True
28+
2629
def build(self, host_target):
2730
indexstoredb.run_build_script_helper(
2831
'build', host_target, self, self.args)
2932

33+
def should_test(self, host_target):
34+
return self.args.test_sourcekitlsp
35+
3036
def test(self, host_target):
31-
if self.args.test_sourcekitlsp:
32-
indexstoredb.run_build_script_helper(
33-
'test', host_target, self, self.args)
37+
indexstoredb.run_build_script_helper(
38+
'test', host_target, self, self.args)
39+
40+
def should_install(self, host_target):
41+
return self.args.install_sourcekitlsp
3442

3543
def install(self, host_target):
36-
if self.args.install_sourcekitlsp:
37-
indexstoredb.run_build_script_helper(
38-
'install', host_target, self, self.args)
44+
indexstoredb.run_build_script_helper(
45+
'install', host_target, self, self.args)

utils/swift_build_support/swift_build_support/products/tsan_libdispatch.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ def product_source_name(cls):
2929
def is_build_script_impl_product(cls):
3030
return False
3131

32+
def should_build(self, host_target):
33+
return True
34+
3235
def build(self, host_target):
3336
"""Build TSan runtime (compiler-rt)."""
3437
rt_source_dir = join_path(self.source_dir, os.pardir, 'compiler-rt')
@@ -59,6 +62,9 @@ def build(self, host_target):
5962
shell.call(config_cmd)
6063
shell.call(build_cmd)
6164

65+
def should_test(self, host_target):
66+
return True
67+
6268
def test(self, host_target):
6369
"""Run check-tsan target with a LIT filter for libdispatch."""
6470
cmd = ['ninja', 'check-tsan']
@@ -67,5 +73,8 @@ def test(self, host_target):
6773
with shell.pushd(self.build_dir):
6874
shell.call(cmd, env=env)
6975

76+
def should_install(self, host_target):
77+
return False
78+
7079
def install(self, host_target):
7180
pass

utils/swift_build_support/swift_build_support/targets.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,19 @@ def darwin_toolchain_prefix(darwin_install_prefix):
283283
directory.
284284
"""
285285
return os.path.split(darwin_install_prefix)[0]
286+
287+
288+
def toolchain_path(install_destdir, install_prefix):
289+
"""
290+
Given the install prefix for a Darwin system, and assuming that that path
291+
is to a .xctoolchain directory, return the path to the .xctoolchain
292+
directory in the given install directory.
293+
This toolchain is being populated during the build-script invocation.
294+
Downstream products can use products that were previously installed into
295+
this toolchain.
296+
"""
297+
built_toolchain_path = install_destdir
298+
if platform.system() == 'Darwin':
299+
# The prefix is an absolute path, so concatenate without os.path.
300+
built_toolchain_path += darwin_toolchain_prefix(install_prefix)
301+
return built_toolchain_path

0 commit comments

Comments
 (0)