Skip to content

[Build Script] Fix --infer with earlyswiftdriver. #37349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions utils/build-script
Original file line number Diff line number Diff line change
Expand Up @@ -957,11 +957,13 @@ class BuildScriptInvocation(object):
# infer dependencies, infer the dependencies now and then re-split the
# list.
if self.args.infer_dependencies:
combined = impl_product_classes + product_classes
combined_classes = before_impl_product_classes +\
impl_product_classes +\
product_classes
if self.args.verbose_build:
print("-- Build Graph Inference --")
print("Initial Product List:")
for p in combined:
for p in combined_classes:
print(" {}".format(p.product_name()))

# Now that we have produced the schedule, resplit. We require our
Expand All @@ -974,17 +976,18 @@ class BuildScriptInvocation(object):
impl_product_classes = []
product_classes = []
is_darwin = platform.system() == 'Darwin'
final_schedule = build_graph.produce_scheduled_build(combined)[0]
final_schedule =\
build_graph.produce_scheduled_build(combined_classes)[0]
for p in final_schedule:
if is_darwin and p.is_nondarwin_only_build_product():
continue

if p.is_build_script_impl_product():
impl_product_classes.append(p)
elif p.is_before_build_script_impl_product():
before_impl_product_classes.append(p)
else:
product_classes.append(p)

if self.args.verbose_build:
print("Final Build Order:")
for p in before_impl_product_classes:
Expand Down Expand Up @@ -1148,8 +1151,14 @@ class BuildScriptInvocation(object):
print("--- Running tests for %s ---" % product_name)
product.test(host_target)
print("--- Finished tests for %s ---" % product_name)
# Install the product if it should be installed specifically, or
# if it should be built and `install_all` is set to True.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer true. CMark I think does install things and is now an early product. So I would say products like early-swift-driver which are before_build_script_impl products that are never installed.

# The exception is select before_build_script_impl products
# which set `is_ignore_install_all_product` to True, ensuring
# they are never installed. (e.g. earlySwiftDriver).
if product.should_install(host_target) or \
(self.install_all and product.should_build(host_target)):
(self.install_all and product.should_build(host_target) and
not product.is_ignore_install_all_product()):
print("--- Installing %s ---" % product_name)
product.install(host_target)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from build_swift.build_swift.wrappers import xcrun

from . import cmake_product
from . import earlyswiftdriver


class CMark(cmake_product.CMakeProduct):
Expand All @@ -32,10 +33,11 @@ def is_before_build_script_impl_product(cls):
"""
return True

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

def should_build(self, host_target):
"""should_build() -> Bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ def should_install(self, host_target):
# product with `--swift-driver --install-swift-driver`.
return False

@classmethod
def is_ignore_install_all_product(cls):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add your explanation from the commit msg (which is great btw) to this?

# Ensures that `install_all` setting triggered by `--infer` does not
# affect products which specify `is_ignore_install_all_product` as
# 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`).
return True

def install(self, host_target):
run_build_script_helper('install', host_target, self, self.args)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ def is_before_build_script_impl_product(cls):
"""
raise NotImplementedError

@classmethod
def is_ignore_install_all_product(cls):
"""is_ignore_install_all_product -> bool

Whether this product is to ignore the install-all directive
and insted always respect its own should_install.
This is useful when we run -install-all but have products
which should never be installed into the toolchain
(e.g. earlyswiftdriver)
"""
return False

@classmethod
def is_swiftpm_unified_build_product(cls):
"""is_swiftpm_unified_build_product -> bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# ----------------------------------------------------------------------------

from . import cmark
from . import earlyswiftdriver
from . import libcxx
from . import libicu
from . import llvm
Expand Down Expand Up @@ -149,6 +150,7 @@ def _enable_experimental_concurrency(self):
@classmethod
def get_dependencies(cls):
return [cmark.CMark,
earlyswiftdriver.EarlySwiftDriver,
llvm.LLVM,
libcxx.LibCXX,
libicu.LibICU]
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@
#
# CHECK: -- Build Graph Inference --
# CHECK: Initial Product List:
# CHECK: earlyswiftdriver
# CHECK: llvm
# CHECK: swift
# CHECK: Final Build Order:
# CHECK: earlyswiftdriver
# CHECK: cmark
# CHECK: llvm
# CHECK: swift

# Ensure early SwiftDriver is built first
#
# CHECK: --- Building earlyswiftdriver ---

# Build and install the SwiftPM dependencies first.
#
# CHECK: --- Installing cmark ---
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# REQUIRES: standalone_build

# RUN: %empty-directory(%t)
# RUN: mkdir -p %t
# RUN: SKIP_XCODE_VERSION_CHECK=1 SWIFT_BUILD_ROOT=%t %swift_src_root/utils/build-script --dry-run --swiftpm --infer 2>&1 | %FileCheck %s

# CHECK: --- Building earlyswiftdriver ---