Skip to content

Commit 3511d5f

Browse files
committed
[Build Script] Fix --infer with earlyswiftdriver.
In the original implementation (#36377), using `--infer` accidentally disables the `earlyswiftdriver` product (`before_impl_product_classes` set to always empty). This change fixes that and makes sure early SwiftDriver is always built, regardless of whether or not `--infer` is used. This change also ensures that `install_all` setting triggered by `--infer` does not affect products which specify `is_ignore_install_all_product` to return True. This is useful for products which should not be installed into the toolchain (corresponding build products that use the just-built toolchain are the products that get installed, e.g. `swiftdriver` to `earlyswiftdriver`).
1 parent cb319fc commit 3511d5f

File tree

7 files changed

+55
-7
lines changed

7 files changed

+55
-7
lines changed

utils/build-script

+14-5
Original file line numberDiff line numberDiff line change
@@ -957,11 +957,13 @@ class BuildScriptInvocation(object):
957957
# infer dependencies, infer the dependencies now and then re-split the
958958
# list.
959959
if self.args.infer_dependencies:
960-
combined = impl_product_classes + product_classes
960+
combined_classes = before_impl_product_classes +\
961+
impl_product_classes +\
962+
product_classes
961963
if self.args.verbose_build:
962964
print("-- Build Graph Inference --")
963965
print("Initial Product List:")
964-
for p in combined:
966+
for p in combined_classes:
965967
print(" {}".format(p.product_name()))
966968

967969
# Now that we have produced the schedule, resplit. We require our
@@ -974,17 +976,18 @@ class BuildScriptInvocation(object):
974976
impl_product_classes = []
975977
product_classes = []
976978
is_darwin = platform.system() == 'Darwin'
977-
final_schedule = build_graph.produce_scheduled_build(combined)[0]
979+
final_schedule =\
980+
build_graph.produce_scheduled_build(combined_classes)[0]
978981
for p in final_schedule:
979982
if is_darwin and p.is_nondarwin_only_build_product():
980983
continue
981-
982984
if p.is_build_script_impl_product():
983985
impl_product_classes.append(p)
984986
elif p.is_before_build_script_impl_product():
985987
before_impl_product_classes.append(p)
986988
else:
987989
product_classes.append(p)
990+
988991
if self.args.verbose_build:
989992
print("Final Build Order:")
990993
for p in before_impl_product_classes:
@@ -1148,8 +1151,14 @@ class BuildScriptInvocation(object):
11481151
print("--- Running tests for %s ---" % product_name)
11491152
product.test(host_target)
11501153
print("--- Finished tests for %s ---" % product_name)
1154+
# Install the product if it should be installed specifically, or
1155+
# if it should be built and `install_all` is set to True.
1156+
# The exception is select before_build_script_impl products
1157+
# which set `is_ignore_install_all_product` to True, ensuring
1158+
# they are never installed. (e.g. earlySwiftDriver).
11511159
if product.should_install(host_target) or \
1152-
(self.install_all and product.should_build(host_target)):
1160+
(self.install_all and product.should_build(host_target) and
1161+
not product.is_ignore_install_all_product()):
11531162
print("--- Installing %s ---" % product_name)
11541163
product.install(host_target)
11551164

utils/swift_build_support/swift_build_support/products/cmark.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from build_swift.build_swift.wrappers import xcrun
1414

1515
from . import cmake_product
16+
from . import earlyswiftdriver
1617

1718

1819
class CMark(cmake_product.CMakeProduct):
@@ -32,10 +33,11 @@ def is_before_build_script_impl_product(cls):
3233
"""
3334
return True
3435

35-
# This is the root of the build-graph, so it doesn't have any dependencies.
36+
# EarlySwiftDriver is the root of the graph, and is the only dependency of
37+
# this product.
3638
@classmethod
3739
def get_dependencies(cls):
38-
return []
40+
return [earlyswiftdriver.EarlySwiftDriver]
3941

4042
def should_build(self, host_target):
4143
"""should_build() -> Bool

utils/swift_build_support/swift_build_support/products/earlyswiftdriver.py

+10
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ def should_install(self, host_target):
8383
# product with `--swift-driver --install-swift-driver`.
8484
return False
8585

86+
@classmethod
87+
def is_ignore_install_all_product(cls):
88+
# Ensures that `install_all` setting triggered by `--infer` does not
89+
# affect products which specify `is_ignore_install_all_product` as
90+
# True. This is useful for products which should not be installed into the
91+
# toolchain (corresponding build products that use the just-built
92+
# toolchain are the products that get installed, e.g. `swiftdriver` to
93+
# `earlyswiftdriver`).
94+
return True
95+
8696
def install(self, host_target):
8797
run_build_script_helper('install', host_target, self, self.args)
8898

utils/swift_build_support/swift_build_support/products/product.py

+12
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,18 @@ def is_before_build_script_impl_product(cls):
6969
"""
7070
raise NotImplementedError
7171

72+
@classmethod
73+
def is_ignore_install_all_product(cls):
74+
"""is_ignore_install_all_product -> bool
75+
76+
Whether this product is to ignore the install-all directive
77+
and insted always respect its own should_install.
78+
This is useful when we run -install-all but have products
79+
which should never be installed into the toolchain
80+
(e.g. earlyswiftdriver)
81+
"""
82+
return False
83+
7284
@classmethod
7385
def is_swiftpm_unified_build_product(cls):
7486
"""is_swiftpm_unified_build_product -> bool

utils/swift_build_support/swift_build_support/products/swift.py

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# ----------------------------------------------------------------------------
1212

1313
from . import cmark
14+
from . import earlyswiftdriver
1415
from . import libcxx
1516
from . import libicu
1617
from . import llvm
@@ -149,6 +150,7 @@ def _enable_experimental_concurrency(self):
149150
@classmethod
150151
def get_dependencies(cls):
151152
return [cmark.CMark,
153+
earlyswiftdriver.EarlySwiftDriver,
152154
llvm.LLVM,
153155
libcxx.LibCXX,
154156
libicu.LibICU]

validation-test/BuildSystem/infer_dumps_deps_if_verbose_build.test

+6
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@
88
#
99
# CHECK: -- Build Graph Inference --
1010
# CHECK: Initial Product List:
11+
# CHECK: earlyswiftdriver
1112
# CHECK: llvm
1213
# CHECK: swift
1314
# CHECK: Final Build Order:
15+
# CHECK: earlyswiftdriver
1416
# CHECK: cmark
1517
# CHECK: llvm
1618
# CHECK: swift
1719

20+
# Ensure early SwiftDriver is built first
21+
#
22+
# CHECK: --- Building earlyswiftdriver ---
23+
1824
# Build and install the SwiftPM dependencies first.
1925
#
2026
# CHECK: --- Installing cmark ---
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# REQUIRES: standalone_build
2+
3+
# RUN: %empty-directory(%t)
4+
# RUN: mkdir -p %t
5+
# RUN: SKIP_XCODE_VERSION_CHECK=1 SWIFT_BUILD_ROOT=%t %swift_src_root/utils/build-script --dry-run --swiftpm --infer 2>&1 | %FileCheck %s
6+
7+
# CHECK: --- Building earlyswiftdriver ---

0 commit comments

Comments
 (0)