Skip to content

Commit 7be52d3

Browse files
committed
[build-script] Extract logic determining whether to test/install a product to separate function
Previously, you were to check if a build/test/install is necessary in the builds/test/install method which is easy to miss. This gives the check more visibility.
1 parent 4591811 commit 7be52d3

File tree

6 files changed

+68
-11
lines changed

6 files changed

+68
-11
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.shall_build(host_target):
794+
product.build(host_target)
795+
if product.shall_test(host_target):
796+
product.test(host_target)
797+
if product.shall_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 shall_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 shall_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 shall_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: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,20 @@ def product_source_name(cls):
2727
def is_build_script_impl_product(cls):
2828
return False
2929

30+
def shall_build(self, host_target):
31+
return True
32+
3033
def build(self, host_target):
3134
run_build_script_helper('build', host_target, self, self.args)
3235

36+
def shall_test(self, host_target):
37+
return self.args.test_indexstoredb
38+
3339
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)
40+
run_build_script_helper('test', host_target, self, self.args)
41+
42+
def shall_install(self, host_target):
43+
return False
3644

3745
def install(self, host_target):
3846
pass

utils/swift_build_support/swift_build_support/products/product.py

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

45+
def shall_build(self, host_target):
46+
"""shall_build() -> Bool
47+
48+
Whether or not this product shall 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 shall_test(self, host_target):
60+
"""shall_test() -> Bool
61+
62+
Whether or not this product shall 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 shall_install(self, host_target):
74+
"""shall_install() -> Bool
75+
76+
Whether or not this product shall be installed with the given arguments
77+
"""
78+
raise NotImplementedError
79+
5980
def install(self, host_target):
6081
"""install() -> void
6182

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 shall_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 shall_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 shall_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 shall_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 shall_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 shall_install(self, host_target):
77+
return False
78+
7079
def install(self, host_target):
7180
pass

0 commit comments

Comments
 (0)