Skip to content

Commit fc4ef19

Browse files
committed
[build-script] Add a default-enabled "clean" step for swift-driver and swiftpm
Along with options to disable the mandatory clean using: `--skip-clean-swift-driver` and `--skip-clean-swiftpm`. This will ensure that every invocation of build-script will, by default, clean up all build artifacts of these projects and re-build them from scratch. This is needed for all builds because today arbitrary changes to the compiler can lead to us being unable to incrementally build components that are themselves written in Swift. This causes now-frequent failures in incremental build bots, and is a scenario that is encountered by developers. (For example see: rdar://65006593) The proper long-term solution is to enable library evolution for these projects. Until this is done, the only safe thing to do is to always rebuild them. Resolves rdar://65006593
1 parent 5c4c4dc commit fc4ef19

File tree

6 files changed

+43
-0
lines changed

6 files changed

+43
-0
lines changed

utils/build-script

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,9 @@ class BuildScriptInvocation(object):
964964
toolchain=self.toolchain,
965965
source_dir=self.workspace.source_dir(product_source),
966966
build_dir=build_dir)
967+
if product.should_clean(host_target):
968+
print("--- Cleaning %s ---" % product_name)
969+
product.clean(host_target)
967970
if product.should_build(host_target):
968971
print("--- Building %s ---" % product_name)
969972
product.build(host_target)

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,10 @@ def create_argument_parser():
10081008
help='skip testing Android device targets on the host machine (the '
10091009
'phone itself)')
10101010

1011+
option('--skip-clean-swiftpm', toggle_false('clean_swiftpm'),
1012+
help='skip cleaning up swiftpm')
1013+
option('--skip-clean-swift-driver', toggle_false('clean_swift_driver'),
1014+
help='skip cleaning up Swift driver')
10111015
option('--skip-test-swiftpm', toggle_false('test_swiftpm'),
10121016
help='skip testing swiftpm')
10131017
option('--skip-test-swift-driver', toggle_false('test_swift_driver'),

utils/build_swift/tests/expected_options.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@
205205
defaults.SWIFT_MAX_PARALLEL_LTO_LINK_JOBS,
206206
'swift_user_visible_version': defaults.SWIFT_USER_VISIBLE_VERSION,
207207
'symbols_package': None,
208+
'clean_swiftpm': True,
209+
'clean_swift_driver': True,
208210
'test': None,
209211
'test_android': False,
210212
'test_android_host': False,
@@ -567,6 +569,8 @@ class BuildScriptImplOption(_BaseOption):
567569
dest='build_watchos_device'),
568570
DisableOption('--skip-build-watchos-simulator',
569571
dest='build_watchos_simulator'),
572+
DisableOption('--skip-clean-swiftpm', dest='clean_swiftpm'),
573+
DisableOption('--skip-clean-swift-driver', dest='clean_swift_driver'),
570574
DisableOption('--skip-test-android', dest='test_android'),
571575
DisableOption('--skip-test-android-host', dest='test_android_host'),
572576
DisableOption('--skip-test-cygwin', dest='test_cygwin'),

utils/swift_build_support/swift_build_support/products/product.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,20 @@ def get_dependencies(cls):
7878
"""Return a list of products that this product depends upon"""
7979
raise NotImplementedError
8080

81+
def should_clean(self, host_target):
82+
"""should_clean() -> Bool
83+
84+
Whether or not this product should be cleaned before being built
85+
"""
86+
return False
87+
88+
def clean(self, host_target):
89+
"""clean() -> void
90+
91+
Perform the clean, for a non-build-script-impl product.
92+
"""
93+
raise NotImplementedError
94+
8195
def should_build(self, host_target):
8296
"""should_build() -> Bool
8397

utils/swift_build_support/swift_build_support/products/swiftdriver.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ def get_dependencies(cls):
4747
xctest.XCTest,
4848
llbuild.LLBuild]
4949

50+
def should_clean(self, host_target):
51+
return self.args.clean_swift_driver
52+
53+
def clean(self, host_target):
54+
indexstoredb.run_build_script_helper(
55+
'clean', host_target, self, self.args)
56+
5057
def build(self, host_target):
5158
indexstoredb.run_build_script_helper(
5259
'build', host_target, self, self.args)

utils/swift_build_support/swift_build_support/products/swiftpm.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ def run_bootstrap_script(self, action, host_target, additional_params=[]):
5151

5252
helper_cmd = [script_path, action]
5353

54+
if action == 'clean':
55+
helper_cmd += ["--build-dir", self.build_dir]
56+
shell.call(helper_cmd)
57+
return
58+
5459
if self.is_release():
5560
helper_cmd.append("--release")
5661

@@ -94,6 +99,12 @@ def should_test(self, host_target):
9499
def test(self, host_target):
95100
self.run_bootstrap_script('test', host_target)
96101

102+
def should_clean(self, host_target):
103+
return self.args.clean_swiftpm
104+
105+
def clean(self, host_target):
106+
self.run_bootstrap_script('clean', host_target)
107+
97108
def should_install(self, host_target):
98109
return self.args.install_swiftpm
99110

0 commit comments

Comments
 (0)