Skip to content

Commit 71fb04a

Browse files
authored
Merge pull request #37349 from artemcm/InferEarlyDriver
[Build Script] Fix `--infer` with `earlyswiftdriver`.
2 parents 6e1ca99 + 3511d5f commit 71fb04a

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
@@ -960,11 +960,13 @@ class BuildScriptInvocation(object):
960960
# infer dependencies, infer the dependencies now and then re-split the
961961
# list.
962962
if self.args.infer_dependencies:
963-
combined = impl_product_classes + product_classes
963+
combined_classes = before_impl_product_classes +\
964+
impl_product_classes +\
965+
product_classes
964966
if self.args.verbose_build:
965967
print("-- Build Graph Inference --")
966968
print("Initial Product List:")
967-
for p in combined:
969+
for p in combined_classes:
968970
print(" {}".format(p.product_name()))
969971

970972
# Now that we have produced the schedule, resplit. We require our
@@ -977,17 +979,18 @@ class BuildScriptInvocation(object):
977979
impl_product_classes = []
978980
product_classes = []
979981
is_darwin = platform.system() == 'Darwin'
980-
final_schedule = build_graph.produce_scheduled_build(combined)[0]
982+
final_schedule =\
983+
build_graph.produce_scheduled_build(combined_classes)[0]
981984
for p in final_schedule:
982985
if is_darwin and p.is_nondarwin_only_build_product():
983986
continue
984-
985987
if p.is_build_script_impl_product():
986988
impl_product_classes.append(p)
987989
elif p.is_before_build_script_impl_product():
988990
before_impl_product_classes.append(p)
989991
else:
990992
product_classes.append(p)
993+
991994
if self.args.verbose_build:
992995
print("Final Build Order:")
993996
for p in before_impl_product_classes:
@@ -1151,8 +1154,14 @@ class BuildScriptInvocation(object):
11511154
print("--- Running tests for %s ---" % product_name)
11521155
product.test(host_target)
11531156
print("--- Finished tests for %s ---" % product_name)
1157+
# Install the product if it should be installed specifically, or
1158+
# if it should be built and `install_all` is set to True.
1159+
# The exception is select before_build_script_impl products
1160+
# which set `is_ignore_install_all_product` to True, ensuring
1161+
# they are never installed. (e.g. earlySwiftDriver).
11541162
if product.should_install(host_target) or \
1155-
(self.install_all and product.should_build(host_target)):
1163+
(self.install_all and product.should_build(host_target) and
1164+
not product.is_ignore_install_all_product()):
11561165
print("--- Installing %s ---" % product_name)
11571166
product.install(host_target)
11581167

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
@@ -157,6 +158,7 @@ def _enable_experimental_distributed(self):
157158
@classmethod
158159
def get_dependencies(cls):
159160
return [cmark.CMark,
161+
earlyswiftdriver.EarlySwiftDriver,
160162
llvm.LLVM,
161163
libcxx.LibCXX,
162164
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)