Skip to content

Commit b169cb5

Browse files
authored
Merge pull request #2988 from ddunbar/build-script-isolated-actions
[build-script] Add support for using isolated -impl actions.
2 parents a51aa91 + b1d56ea commit b169cb5

File tree

13 files changed

+327
-19
lines changed

13 files changed

+327
-19
lines changed

utils/build-script

Lines changed: 121 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ sys.path.append(os.path.join(os.path.dirname(__file__), 'android'))
5353
import adb.commands # noqa (E402)
5454

5555

56-
def call_without_sleeping(command, env=None, dry_run=False):
56+
build_script_impl = os.path.join(
57+
SWIFT_SOURCE_ROOT, "swift", "utils", "build-script-impl")
58+
59+
60+
def call_without_sleeping(command, env=None, dry_run=False, echo=False):
5761
"""
5862
Execute a command during which system sleep is disabled.
5963
@@ -65,7 +69,7 @@ def call_without_sleeping(command, env=None, dry_run=False):
6569
# Don't mutate the caller's copy of the arguments.
6670
command = ["caffeinate"] + list(command)
6771

68-
shell.call(command, env=env, dry_run=dry_run)
72+
shell.call(command, env=env, dry_run=dry_run, echo=echo)
6973

7074

7175
class HostSpecificConfiguration(object):
@@ -798,6 +802,115 @@ class BuildScriptInvocation(object):
798802

799803
return options
800804

805+
def compute_product_classes(self):
806+
"""compute_product_classes() -> list
807+
808+
Compute the list of all Product classes used in this build. This list
809+
is constructed in dependency order.
810+
"""
811+
812+
# FIXME: This is a weird division (returning a list of class objects),
813+
# but it matches the existing structure of the `build-script-impl`.
814+
815+
product_classes = []
816+
product_classes.append(products.CMark)
817+
product_classes.append(products.LLVM)
818+
product_classes.append(products.Swift)
819+
if self.args.build_lldb:
820+
product_classes.append(products.LLDB)
821+
if self.args.build_llbuild:
822+
product_classes.append(products.LLBuild)
823+
if self.args.build_libdispatch:
824+
product_classes.append(products.LibDispatch)
825+
if self.args.build_foundation:
826+
product_classes.append(products.Foundation)
827+
if self.args.build_xctest:
828+
product_classes.append(products.XCTest)
829+
if self.args.build_swiftpm:
830+
product_classes.append(products.SwiftPM)
831+
return product_classes
832+
833+
def execute(self):
834+
"""Execute the invocation with the configured arguments."""
835+
836+
# Convert to a build-script-impl invocation.
837+
(impl_env, impl_args) = self.convert_to_impl_arguments()
838+
839+
# If using the legacy implementation, delegate all behavior to
840+
# `build-script-impl`.
841+
if self.args.legacy_impl:
842+
# Execute the underlying build script implementation.
843+
call_without_sleeping([build_script_impl] + impl_args,
844+
env=impl_env, echo=True)
845+
return
846+
847+
# Otherwise, we compute and execute the individual actions ourselves.
848+
849+
def execute_one_impl_action(host=None, product_class=None, name=None):
850+
if host is None:
851+
assert (product_class is None and
852+
name == "merged-hosts-lipo"), "invalid action"
853+
action_name = name
854+
elif product_class is None:
855+
assert name == "package", "invalid action"
856+
action_name = "{}-{}".format(host.name, name)
857+
else:
858+
assert name is not None, "invalid action"
859+
action_name = "{}-{}-{}".format(
860+
host.name, product_class.product_name(), name)
861+
call_without_sleeping(
862+
[build_script_impl] + impl_args + [
863+
"--only-execute", action_name],
864+
env=impl_env, echo=self.args.verbose_build)
865+
866+
# Compute the list of hosts to operate on.
867+
all_host_names = [
868+
self.args.host_target] + self.args.cross_compile_hosts
869+
all_hosts = [StdlibDeploymentTarget.get_target_for_name(name)
870+
for name in all_host_names]
871+
872+
# Compute the list of product classes to operate on.
873+
#
874+
# FIXME: This should really be per-host, but the current structure
875+
# matches that of `build-script-impl`.
876+
product_classes = self.compute_product_classes()
877+
878+
# Execute each "pass".
879+
880+
# Build...
881+
for host_target in all_hosts:
882+
# FIXME: We should only compute these once.
883+
config = HostSpecificConfiguration(host_target.name, self)
884+
print("Building the standard library for: {}".format(
885+
" ".join(config.swift_stdlib_build_targets)))
886+
if config.swift_test_run_targets and (
887+
self.args.test or self.args.long_test):
888+
print("Running Swift tests for: {}".format(
889+
" ".join(config.swift_test_run_targets)))
890+
if config.swift_benchmark_run_targets and self.args.benchmark:
891+
print("Running Swift benchmarks for: {}".format(
892+
" ".join(config.swift_benchmark_run_targets)))
893+
894+
for product_class in product_classes:
895+
execute_one_impl_action(host_target, product_class, "build")
896+
897+
# Test...
898+
for host_target in all_hosts:
899+
for product_class in product_classes:
900+
execute_one_impl_action(host_target, product_class, "test")
901+
902+
# Install...
903+
for host_target in all_hosts:
904+
for product_class in product_classes:
905+
execute_one_impl_action(host_target, product_class, "install")
906+
907+
# Package...
908+
for host_target in all_hosts:
909+
execute_one_impl_action(host_target, name="package")
910+
911+
# Lipo...
912+
execute_one_impl_action(name="merged-hosts-lipo")
913+
801914

802915
# Main entry point for the preset mode.
803916
def main_preset():
@@ -1073,6 +1186,11 @@ details of the setups of other systems or automated environments.""")
10731186
"them",
10741187
action="store_true",
10751188
default=False)
1189+
parser.add_argument(
1190+
"--no-legacy-impl", dest="legacy_impl",
1191+
help="avoid legacy implementation",
1192+
action="store_false",
1193+
default=True)
10761194

10771195
targets_group = parser.add_argument_group(
10781196
title="Host and cross-compilation targets")
@@ -1764,9 +1882,6 @@ details of the setups of other systems or automated environments.""")
17641882

17651883
args = migration.parse_args(parser, sys.argv[1:])
17661884

1767-
build_script_impl = os.path.join(
1768-
SWIFT_SOURCE_ROOT, "swift", "utils", "build-script-impl")
1769-
17701885
if args.build_script_impl_args:
17711886
# If we received any impl args, check if `build-script-impl` would
17721887
# accept them or not before any further processing.
@@ -1820,13 +1935,8 @@ details of the setups of other systems or automated environments.""")
18201935
if args.build_ninja:
18211936
invocation.build_ninja()
18221937

1823-
# Convert to a build-script-impl invocation.
1824-
(build_script_impl_env, build_script_impl_args) = \
1825-
invocation.convert_to_impl_arguments()
1826-
18271938
# Execute the underlying build script implementation.
1828-
call_without_sleeping([build_script_impl] + build_script_impl_args,
1829-
env=build_script_impl_env)
1939+
invocation.execute()
18301940

18311941
if args.symbols_package:
18321942
print('--- Creating symbols package ---')

utils/swift_build_support/swift_build_support/products/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,27 @@
1010
#
1111
# ----------------------------------------------------------------------------
1212

13+
from .cmark import CMark
14+
from .foundation import Foundation
15+
from .libdispatch import LibDispatch
16+
from .llbuild import LLBuild
17+
from .lldb import LLDB
18+
from .llvm import LLVM
1319
from .ninja import Ninja
20+
from .swift import Swift
21+
from .swiftpm import SwiftPM
22+
from .xctest import XCTest
1423

1524
__all__ = [
25+
'CMark',
1626
'Ninja',
27+
'Foundation',
28+
'LibDispatch',
29+
'LLBuild',
30+
'LLDB',
31+
'LLVM',
32+
'Ninja',
33+
'Swift',
34+
'SwiftPM',
35+
'XCTest',
1736
]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# swift_build_support/products/cmark.py -------------------------*- python -*-
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See http://swift.org/LICENSE.txt for license information
9+
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
#
11+
# ----------------------------------------------------------------------------
12+
13+
from . import product
14+
15+
16+
class CMark(product.Product):
17+
pass
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# swift_build_support/products/foundation.py ---------------------*- python -*-
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See http://swift.org/LICENSE.txt for license information
9+
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
#
11+
# ----------------------------------------------------------------------------
12+
13+
from . import product
14+
15+
16+
class Foundation(product.Product):
17+
pass
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# swift_build_support/products/libdispatch.py -------------------*- python -*-
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See http://swift.org/LICENSE.txt for license information
9+
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
#
11+
# ----------------------------------------------------------------------------
12+
13+
from . import product
14+
15+
16+
class LibDispatch(product.Product):
17+
pass
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# swift_build_support/products/clang.py -------------------------*- python -*-
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See http://swift.org/LICENSE.txt for license information
9+
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
#
11+
# ----------------------------------------------------------------------------
12+
13+
from . import product
14+
15+
16+
class LLBuild(product.Product):
17+
pass
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# swift_build_support/products/lldb.py --------------------------*- python -*-
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See http://swift.org/LICENSE.txt for license information
9+
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
#
11+
# ----------------------------------------------------------------------------
12+
13+
from . import product
14+
15+
16+
class LLDB(product.Product):
17+
pass
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# swift_build_support/products/llvm.py --------------------------*- python -*-
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See http://swift.org/LICENSE.txt for license information
9+
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
#
11+
# ----------------------------------------------------------------------------
12+
13+
from . import product
14+
15+
16+
class LLVM(product.Product):
17+
pass

utils/swift_build_support/swift_build_support/products/ninja.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,12 @@
1818
import platform
1919
import sys
2020

21+
from . import product
2122
from .. import cache_util
2223
from .. import shell
2324

2425

25-
class Ninja(object):
26-
27-
def __init__(self, args, toolchain, source_dir, build_dir):
28-
self.args = args
29-
self.toolchain = toolchain
30-
self.source_dir = source_dir
31-
self.build_dir = build_dir
32-
26+
class Ninja(product.Product):
3327
@cache_util.reify
3428
def ninja_bin_path(self):
3529
return os.path.join(self.build_dir, 'ninja')
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# swift_build_support/products/product.py -----------------------*- python -*-
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See http://swift.org/LICENSE.txt for license information
9+
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
#
11+
# ----------------------------------------------------------------------------
12+
13+
14+
class Product(object):
15+
@classmethod
16+
def product_name(cls):
17+
"""product_name() -> str
18+
19+
The identifier-style name to use for this product.
20+
"""
21+
return cls.__name__.lower()
22+
23+
@classmethod
24+
def get_build_directory_name(cls, host_target):
25+
return "{}-{}".format(cls.product_name(),
26+
host_target.name)
27+
28+
def __init__(self, args, toolchain, source_dir, build_dir):
29+
self.args = args
30+
self.toolchain = toolchain
31+
self.source_dir = source_dir
32+
self.build_dir = build_dir
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# swift_build_support/products/swift.py -------------------------*- python -*-
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See http://swift.org/LICENSE.txt for license information
9+
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
#
11+
# ----------------------------------------------------------------------------
12+
13+
from . import product
14+
15+
16+
class Swift(product.Product):
17+
pass

0 commit comments

Comments
 (0)