Skip to content

Commit a6cb3ae

Browse files
authored
Merge pull request #32256 from gottesmm/pr-6a889299976ad0e3dfbc1849e1b7edaf177c53ce
[build-script] Add option --infer to infer dependencies.
2 parents d890f29 + a313f62 commit a6cb3ae

File tree

12 files changed

+158
-20
lines changed

12 files changed

+158
-20
lines changed

test/lit.cfg

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ config.test_format = swift_test.SwiftTest(coverage_mode=config.coverage_mode,
146146

147147
# suffixes: A list of file extensions to treat as test files.
148148
config.suffixes = ['.swift', '.ll', '.sil', '.gyb', '.m', '.c',
149-
'.swiftinterface', '.test-sh']
149+
'.swiftinterface', '.test-sh', '.test']
150150

151151
# excludes: A list of directories to exclude from the testsuite. The 'Inputs'
152152
# subdirectories contain auxiliary inputs for various tests in their parent
@@ -162,6 +162,11 @@ config.test_source_root = os.path.dirname(__file__)
162162
# test_exec_root: The root path where tests should be run.
163163
swift_obj_root = getattr(config, 'swift_obj_root', None)
164164

165+
# cmake. The path to the cmake executable we used to configure swift.
166+
assert(config.cmake)
167+
config.substitutions.append( ('%cmake', config.cmake) )
168+
lit_config.note('Using cmake: ' + config.cmake)
169+
165170
# Set llvm_{src,obj}_root for use by others.
166171
config.llvm_src_root = getattr(config, 'llvm_src_root', None)
167172
config.llvm_obj_root = getattr(config, 'llvm_obj_root', None)

test/lit.site.cfg.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import os
1414
import platform
1515
import sys
1616

17+
config.cmake = "@CMAKE_COMMAND@"
1718
config.llvm_src_root = "@LLVM_MAIN_SRC_DIR@"
1819
config.llvm_obj_root = "@LLVM_BINARY_DIR@"
1920
config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"

utils/build-script

Lines changed: 59 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ from build_swift.build_swift.constants import SWIFT_SOURCE_ROOT
3535

3636
import six
3737

38+
from swift_build_support.swift_build_support import build_graph
3839
from swift_build_support.swift_build_support import products
3940
from swift_build_support.swift_build_support import shell
4041
from swift_build_support.swift_build_support import targets
@@ -375,6 +376,10 @@ class BuildScriptInvocation(object):
375376

376377
self.build_libparser_only = args.build_libparser_only
377378

379+
@property
380+
def install_all(self):
381+
return self.args.install_all or self.args.infer_dependencies
382+
378383
def build_ninja(self):
379384
if not os.path.exists(self.workspace.source_dir("ninja")):
380385
fatal_error(
@@ -548,20 +553,28 @@ class BuildScriptInvocation(object):
548553
# Currently we do not build external benchmarks by default.
549554
if args.build_external_benchmarks:
550555
impl_args += ["--skip-build-external-benchmarks=0"]
551-
if not args.build_foundation:
552-
impl_args += ["--skip-build-foundation"]
553-
if not args.build_xctest:
554-
impl_args += ["--skip-build-xctest"]
555-
if not args.build_lldb:
556-
impl_args += ["--skip-build-lldb"]
557-
if not args.build_llbuild:
558-
impl_args += ["--skip-build-llbuild"]
559-
if not args.build_libcxx:
560-
impl_args += ["--skip-build-libcxx"]
561-
if not args.build_libdispatch:
562-
impl_args += ["--skip-build-libdispatch"]
563-
if not args.build_libicu:
564-
impl_args += ["--skip-build-libicu"]
556+
557+
# Then add subproject install flags that either skip building them /or/
558+
# if we are going to build them and install_all is set, we also install
559+
# them.
560+
conditional_subproject_configs = [
561+
(args.build_cmark, "cmark"),
562+
(args.build_llvm, "llvm"),
563+
(args.build_swift, "swift"),
564+
(args.build_foundation, "foundation"),
565+
(args.build_xctest, "xctest"),
566+
(args.build_lldb, "lldb"),
567+
(args.build_llbuild, "llbuild"),
568+
(args.build_libcxx, "libcxx"),
569+
(args.build_libdispatch, "libdispatch"),
570+
(args.build_libicu, "libicu")
571+
]
572+
for (should_build, string_name) in conditional_subproject_configs:
573+
if not should_build and not self.args.infer_dependencies:
574+
impl_args += ["--skip-build-{}".format(string_name)]
575+
elif self.install_all:
576+
impl_args += ["--install-{}".format(string_name)]
577+
565578
if args.build_swift_dynamic_stdlib:
566579
impl_args += ["--build-swift-dynamic-stdlib"]
567580
if args.build_swift_static_stdlib:
@@ -816,13 +829,16 @@ class BuildScriptInvocation(object):
816829
# FIXME: This is a weird division (returning a list of class objects),
817830
# but it matches the existing structure of the `build-script-impl`.
818831
impl_product_classes = []
819-
impl_product_classes.append(products.CMark)
820-
impl_product_classes.append(products.LLVM)
832+
if self.args.build_cmark:
833+
impl_product_classes.append(products.CMark)
834+
if self.args.build_llvm:
835+
impl_product_classes.append(products.LLVM)
821836
if self.args.build_libcxx:
822837
impl_product_classes.append(products.LibCXX)
823838
if self.args.build_libicu:
824839
impl_product_classes.append(products.LibICU)
825-
impl_product_classes.append(products.Swift)
840+
if self.args.build_swift:
841+
impl_product_classes.append(products.Swift)
826842
if self.args.build_lldb:
827843
impl_product_classes.append(products.LLDB)
828844
if self.args.build_libdispatch:
@@ -868,6 +884,30 @@ class BuildScriptInvocation(object):
868884
for prod in product_classes:
869885
assert(not prod.is_build_script_impl_product())
870886

887+
# Now that we have our two lists of product_classes, if we are asked to
888+
# infer dependencies, infer the dependencies now and then re-split the
889+
# list.
890+
if self.args.infer_dependencies:
891+
combined = impl_product_classes + product_classes
892+
893+
# Now that we have produced the schedule, resplit. We require our
894+
# dependencies to respect our build-script-impl property. This means
895+
# that no build-script-impl products can have dependencies on
896+
# non-build-script-impl products. Otherwise, it would be unsafe to
897+
# re-order build-script-impl products in front of non
898+
# build-script-impl products.
899+
impl_product_classes = []
900+
product_classes = []
901+
is_darwin = platform.system() == 'Darwin'
902+
final_schedule = build_graph.produce_scheduled_build(combined)[0]
903+
for p in final_schedule:
904+
if is_darwin and p.is_nondarwin_only_build_product():
905+
continue
906+
907+
if p.is_build_script_impl_product():
908+
impl_product_classes.append(p)
909+
else:
910+
product_classes.append(p)
871911
return (impl_product_classes, product_classes)
872912

873913
def execute(self):
@@ -956,7 +996,8 @@ class BuildScriptInvocation(object):
956996
print("--- Running tests for %s ---" % product_name)
957997
product.test(host_target)
958998
print("--- Finished tests for %s ---" % product_name)
959-
if product.should_install(host_target):
999+
if product.should_install(host_target) or \
1000+
(self.install_all and product.should_build(host_target)):
9601001
print("--- Installing %s ---" % product_name)
9611002
product.install(host_target)
9621003

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ def create_argument_parser():
345345
help='the path to install debug symbols into')
346346
option('--install-destdir', store_path,
347347
help='the path to use as the filesystem root for the installation')
348+
option('--install-all', toggle_true,
349+
help='Assume all built products should be installed')
348350

349351
option(['-j', '--jobs'], store_int('build_jobs'),
350352
default=multiprocessing.cpu_count(),
@@ -545,6 +547,9 @@ def create_argument_parser():
545547
# -------------------------------------------------------------------------
546548
in_group('Options to select projects')
547549

550+
option('--infer', store_true('infer_dependencies'),
551+
help='Infer any downstream dependencies from enabled projects')
552+
548553
option(['-l', '--lldb'], store_true('build_lldb'),
549554
help='build LLDB')
550555

@@ -1096,6 +1101,16 @@ def create_argument_parser():
10961101

10971102
# -------------------------------------------------------------------------
10981103
in_group('Build-script-impl arguments (for disambiguation)')
1104+
1105+
# We need to represent these options so that we can skip installing them if
1106+
# the user is running in install-all mode.
1107+
option('--skip-build-cmark', toggle_false('build_cmark'),
1108+
help='skip building cmark')
1109+
option('--skip-build-llvm', toggle_false('build_llvm'),
1110+
help='skip building llvm')
1111+
option('--skip-build-swift', toggle_false('build_swift'),
1112+
help='skip building swift')
1113+
10991114
# We need to list --skip-test-swift explicitly because otherwise argparse
11001115
# will auto-expand arguments like --skip-test-swift to the only known
11011116
# argument --skip-test-swiftevolve.

utils/build_swift/tests/build_swift/test_presets.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
'extra_swift_args': '',
4040
'install_destdir': '/tmp/install',
4141
'install_symroot': '/tmp/install/symroot',
42+
'install_all': False,
4243
'install_toolchain_dir': '/tmp/install/toolchain',
4344
'install_prefix': '/usr',
4445
'installable_package': '/tmp/install/pkg',

utils/build_swift/tests/expected_options.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@
6161
'build_cygwin': True,
6262
'build_external_benchmarks': False,
6363
'build_foundation': False,
64+
'build_cmark': True,
65+
'build_swift': True,
66+
'build_llvm': True,
6467
'build_freebsd': True,
6568
'build_ios': True,
6669
'build_ios_device': False,
@@ -159,9 +162,11 @@
159162
'host_test': False,
160163
'only_executable_test': False,
161164
'only_non_executable_test': False,
165+
'infer_dependencies': False,
162166
'install_prefix': targets.install_prefix(),
163167
'install_symroot': None,
164168
'install_destdir': None,
169+
'install_all': False,
165170
'ios': False,
166171
'ios_all': False,
167172
'legacy_impl': False,
@@ -482,6 +487,7 @@ class BuildScriptImplOption(_BaseOption):
482487
SetTrueOption('-p', dest='build_swiftpm'),
483488

484489
SetTrueOption('--legacy-impl', dest='legacy_impl'),
490+
SetTrueOption('--infer', dest='infer_dependencies'),
485491

486492
EnableOption('--android'),
487493
EnableOption('--build-external-benchmarks'),
@@ -537,6 +543,10 @@ class BuildScriptImplOption(_BaseOption):
537543
EnableOption('--watchos'),
538544
EnableOption('--xctest', dest='build_xctest'),
539545

546+
DisableOption('--skip-build-cmark', dest='build_cmark'),
547+
DisableOption('--skip-build-llvm', dest='build_llvm'),
548+
DisableOption('--skip-build-swift', dest='build_swift'),
549+
540550
DisableOption('--skip-build-android', dest='build_android'),
541551
DisableOption('--skip-build-benchmarks', dest='build_benchmarks'),
542552
DisableOption('--skip-build-cygwin', dest='build_cygwin'),
@@ -632,6 +642,7 @@ class BuildScriptImplOption(_BaseOption):
632642
PathOption('--install-prefix'),
633643
PathOption('--install-symroot'),
634644
PathOption('--install-destdir'),
645+
EnableOption('--install-all'),
635646
PathOption('--symbols-package'),
636647
PathOption('--cmake-c-launcher'),
637648
PathOption('--cmake-cxx-launcher'),

utils/swift_build_support/swift_build_support/cmake.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def check_cmake_version(self, source_root, build_root):
272272
cmake_binary = 'cmake'
273273

274274
installed_ver = self.installed_cmake_version(cmake_binary)
275-
if installed_ver > self.cmake_source_version(cmake_source_dir):
275+
if installed_ver >= self.cmake_source_version(cmake_source_dir):
276276
return
277277
else:
278278
# Build CMake from source and return the path to the executable.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# RUN: %empty-directory(%t)
2+
# RUN: mkdir -p %t
3+
# RUN: SWIFT_BUILD_ROOT=%t %swift_src_root/utils/build-script --dry-run --infer --swiftpm --cmake %cmake 2>&1 | %FileCheck %s
4+
5+
# CHECK: --- Installing cmark ---
6+
# CHECK: --- Installing llvm ---
7+
# CHECK: --- Installing swift ---
8+
# CHECK: --- Installing llbuild ---
9+
# CHECK: --- Building swiftpm ---
10+
# CHECK: --- Installing swiftpm ---
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# RUN: %empty-directory(%t)
2+
# RUN: mkdir -p %t
3+
# RUN: SWIFT_BUILD_ROOT=%t %swift_src_root/utils/build-script --dry-run --install-all --cmake %cmake 2>&1 | %FileCheck %s
4+
5+
# CHECK: --- Installing cmark ---
6+
# CHECK: --- Installing llvm ---
7+
# CHECK: --- Installing swift ---
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# RUN: %empty-directory(%t)
2+
# RUN: mkdir -p %t
3+
# RUN: SWIFT_BUILD_ROOT=%t %swift_src_root/utils/build-script --dry-run --install-all --llbuild --swiftpm --foundation --libdispatch --cmake %cmake 2>&1 | %FileCheck %s
4+
5+
# REQUIRES: OS=linux-gnu
6+
7+
# CHECK-DAG: --- Installing cmark ---
8+
# CHECK-DAG: --- Installing swift ---
9+
# CHECK-DAG: --- Installing llvm ---
10+
# CHECK-DAG: --- Installing llbuild ---
11+
# CHECK-DAG: --- Installing foundation ---
12+
# CHECK-DAG: --- Installing libdispatch ---
13+
# CHECK-DAG: --- Installing swiftpm ---
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# RUN: %empty-directory(%t)
2+
# RUN: mkdir -p %t
3+
# RUN: SWIFT_BUILD_ROOT=%t %swift_src_root/utils/build-script --dry-run --install-all --cmake %cmake --skip-build-cmark 2>&1 | %FileCheck --check-prefix=SKIP-CMARK-CHECK %s
4+
5+
# RUN: %empty-directory(%t)
6+
# RUN: mkdir -p %t
7+
# RUN: SWIFT_BUILD_ROOT=%t %swift_src_root/utils/build-script --dry-run --install-all --cmake %cmake --skip-build-llvm 2>&1 | %FileCheck --check-prefix=SKIP-LLVM-CHECK %s
8+
9+
# RUN: %empty-directory(%t)
10+
# RUN: mkdir -p %t
11+
# RUN: SWIFT_BUILD_ROOT=%t %swift_src_root/utils/build-script --dry-run --install-all --cmake %cmake --skip-build-swift 2>&1 | %FileCheck --check-prefix=SKIP-SWIFT-CHECK %s
12+
13+
# SKIP-CMARK-CHECK-NOT: cmake --build {{.*}}cmark-
14+
# SKIP-CMARK-CHECK: cmake --build {{.*}}llvm-
15+
# SKIP-CMARK-CHECK: cmake --build {{.*}}swift-
16+
# SKIP-CMARK-CHECK-NOT: --- Installing cmark ---
17+
# SKIP-CMARK-CHECK: --- Installing llvm ---
18+
# SKIP-CMARK-CHECK: --- Installing swift ---
19+
20+
# SKIP-LLVM-CHECK: cmake --build {{.*}}cmark-
21+
# SKIP-LLVM-CHECK-NOT: cmake --build {{.*}}llvm-
22+
# SKIP-LLVM-CHECK: cmake --build {{.*}}swift-
23+
# SKIP-LLVM-CHECK: --- Installing cmark ---
24+
# SKIP-LLVM-CHECK-NOT: --- Installing llvm ---
25+
# SKIP-LLVM-CHECK: --- Installing swift ---
26+
27+
# SKIP-SWIFT-CHECK: cmake --build {{.*}}cmark-
28+
# SKIP-SWIFT-CHECK: cmake --build {{.*}}llvm-
29+
# SKIP-SWIFT-CHECK-NOT: cmake --build {{.*}}swift-
30+
# SKIP-SWIFT-CHECK: --- Installing cmark ---
31+
# SKIP-SWIFT-CHECK: --- Installing llvm ---
32+
# SKIP-SWIFT-CHECK-NOT: --- Installing swift ---
33+

validation-test/lit.site.cfg.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import sys
1414
import platform
1515

16+
config.cmake = "@CMAKE_COMMAND@"
1617
config.llvm_src_root = "@LLVM_MAIN_SRC_DIR@"
1718
config.llvm_obj_root = "@LLVM_BINARY_DIR@"
1819
config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"

0 commit comments

Comments
 (0)