Skip to content

Commit 89e9622

Browse files
committed
[build-script] Always clean 'SwiftTesting' and 'SwiftTestingMacros'
These products are built with CMake. In incremental build environments, these products don't detect compiler changes, so the artifacts aren't rebuilt unless the source code of these projects are changed. To workaround that, always clean them in build-script to ensure they are rebuilt. rdar://135021207
1 parent 0ad185a commit 89e9622

File tree

2 files changed

+49
-30
lines changed

2 files changed

+49
-30
lines changed

utils/swift_build_support/swift_build_support/products/swift_testing.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from . import product
1919
from . import swift
2020
from . import swift_testing_macros
21+
from .. import shell
2122

2223

2324
class SwiftTesting(product.Product):
@@ -38,6 +39,10 @@ def get_dependencies(cls):
3839
return [swift.Swift,
3940
swift_testing_macros.SwiftTestingMacros]
4041

42+
def should_clean(self, host_target):
43+
# Workaround for 'swift-testing' not detecting compiler/stdlib changes.
44+
return True
45+
4146
def should_build(self, host_target):
4247
return True
4348

@@ -59,35 +64,38 @@ def _cmake_product(self, host_target):
5964
source_dir=self.source_dir,
6065
build_dir=build_dir)
6166

62-
def _build_with_cmake(self, host_target):
63-
self._cmake_product(host_target).build(host_target)
64-
65-
def build(self, host_target):
66-
self._build_with_cmake(host_target)
67+
def _for_each_host_target(self, base_target, body):
68+
body(base_target)
6769

6870
# For Darwin host, 'build' is only called for the builder.
6971
# Manually iterate the cross compile hosts.
70-
if self.has_cross_compile_hosts() and self.is_darwin_host(host_target):
72+
if self.has_cross_compile_hosts() and self.is_darwin_host(base_target):
7173
for target in self.args.cross_compile_hosts:
72-
self._build_with_cmake(target)
74+
body(target)
75+
76+
def _clean_with_cmake(self, host_target):
77+
self._cmake_product(host_target).clean(host_target)
78+
79+
def clean(self, host_target):
80+
self._for_each_host_target(host_target, self._clean_with_cmake)
7381

74-
# FIXME: build testing library for 'stdlib_deployment_targets'?
75-
pass
82+
def _build_with_cmake(self, host_target):
83+
self._cmake_product(host_target).build(host_target)
84+
85+
def build(self, host_target):
86+
self._for_each_host_target(host_target, self._build_with_cmake)
7687

7788
def _install_with_cmake(self, host_target):
7889
self._cmake_product(host_target).install(host_target)
7990

8091
def install(self, host_target):
81-
self._install_with_cmake(host_target)
82-
83-
# For Darwin host, 'install' is only called for the builder.
84-
# Manually iterate the cross compile hosts.
85-
if self.has_cross_compile_hosts() and self.is_darwin_host(host_target):
86-
for target in self.args.cross_compile_hosts:
87-
self._install_with_cmake(target)
92+
self._for_each_host_target(host_target, self._install_with_cmake)
8893

8994

9095
class SwiftTestingCMakeShim(cmake_product.CMakeProduct):
96+
def clean(self, host_target):
97+
shell.rmtree(self.build_dir)
98+
9199
def build(self, host_target):
92100
override_deployment_version = None
93101
if host_target.startswith('macosx'):

utils/swift_build_support/swift_build_support/products/swift_testing_macros.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from . import cmake_product
1818
from . import product
1919
from . import swift
20+
from .. import shell
2021

2122

2223
class SwiftTestingMacros(product.Product):
@@ -36,6 +37,10 @@ def product_source_name(cls):
3637
def get_dependencies(cls):
3738
return [swift.Swift]
3839

40+
def should_clean(self, host_target):
41+
# Workaround for 'swift-testing' not detecting compiler/stdlib changes.
42+
return True
43+
3944
def should_build(self, host_target):
4045
return True
4146

@@ -56,32 +61,38 @@ def _cmake_product(self, host_target):
5661
source_dir=self.source_dir,
5762
build_dir=build_dir)
5863

59-
def _build_with_cmake(self, host_target):
60-
self._cmake_product(host_target).build(host_target)
61-
62-
def build(self, host_target):
63-
self._build_with_cmake(host_target)
64+
def _for_each_host_target(self, base_target, body):
65+
body(base_target)
6466

6567
# For Darwin host, 'build' is only called for the builder.
6668
# Manually iterate the cross compile hosts.
67-
if self.has_cross_compile_hosts() and self.is_darwin_host(host_target):
69+
if self.has_cross_compile_hosts() and self.is_darwin_host(base_target):
6870
for target in self.args.cross_compile_hosts:
69-
self._build_with_cmake(target)
71+
body(target)
72+
73+
def _clean_with_cmake(self, host_target):
74+
self._cmake_product(host_target).clean(host_target)
75+
76+
def clean(self, host_target):
77+
self._for_each_host_target(host_target, self._clean_with_cmake)
78+
79+
def _build_with_cmake(self, host_target):
80+
self._cmake_product(host_target).build(host_target)
81+
82+
def build(self, host_target):
83+
self._for_each_host_target(host_target, self._build_with_cmake)
7084

7185
def _install_with_cmake(self, host_target):
7286
self._cmake_product(host_target).install(host_target)
7387

7488
def install(self, host_target):
75-
self._install_with_cmake(host_target)
76-
77-
# For Darwin host, 'install' is only called for the builder.
78-
# Manually iterate the cross compile hosts.
79-
if self.has_cross_compile_hosts() and self.is_darwin_host(host_target):
80-
for target in self.args.cross_compile_hosts:
81-
self._install_with_cmake(target)
89+
self._for_each_host_target(host_target, self._install_with_cmake)
8290

8391

8492
class SwiftTestingMacrosCMakeShim(cmake_product.CMakeProduct):
93+
def clean(self, host_target):
94+
shell.rmtree(self.build_dir)
95+
8596
def build(self, host_target):
8697
override_deployment_version = None
8798
if host_target.startswith('macosx'):

0 commit comments

Comments
 (0)