Skip to content

Commit 2e7ae3d

Browse files
committed
Merge pull request #2844 from ddunbar/build-script-isolated-actions
[build-script-impl] Add support for performing isolated actions.
2 parents c1953e0 + 1a694dc commit 2e7ae3d

File tree

2 files changed

+97
-10
lines changed

2 files changed

+97
-10
lines changed

utils/build-script

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,7 @@ details of the setups of other systems or automated environments.""")
980980
# Explicitly unavailable options here.
981981
"--build-jobs",
982982
"--common-cmake-options",
983+
"--only-execute",
983984
action=arguments.action.unavailable)
984985

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

utils/build-script-impl

Lines changed: 96 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ KNOWN_SETTINGS=(
218218
common-cmake-options "" "CMake options used for all targets, including LLVM/Clang"
219219
# TODO: Remove this some time later.
220220
user-config-args "" "**Renamed to --extra-cmake-options**: User-supplied arguments to cmake when used to do configuration."
221+
only-execute "all" "Only execute the named action (see implementation)"
221222
)
222223

223224
# Centalized access point for traced command invocation.
@@ -308,6 +309,51 @@ function float_min() {
308309
fi
309310
}
310311

312+
# Support for performing isolated actions.
313+
#
314+
# This is part of refactoring more work to be done or controllable via
315+
# `build-script` itself. For additional information, see:
316+
# https://bugs.swift.org/browse/SR-237
317+
#
318+
# To use this functionality, the script is invoked with:
319+
# ONLY_EXECUTE=<action name>
320+
# where <action name> is one of:
321+
# all -- execute all actions
322+
# ${host}-${product}-build -- the build of the product
323+
# ${host}-${product}-test -- the test of the product
324+
# ${host}-${product}-install -- the install of the product
325+
# ${host}-package -- the package construction and test
326+
# merged-hosts-lipo -- the lipo step, if used
327+
# and if used, only the one individual action will be performed.
328+
#
329+
# If not set, the default is `all`.
330+
331+
# should_execute_action(name) -> 1 or nil
332+
#
333+
# Check if the named action should be run in the given script invocation.
334+
function should_execute_action() {
335+
local name="$1"
336+
337+
if [[ "${ONLY_EXECUTE}" = "all" ]] ||
338+
[[ "${ONLY_EXECUTE}" = "${name}" ]]; then
339+
echo 1
340+
fi
341+
}
342+
343+
# should_execute_host_actions_for_phase(host, phase-name) -> 1 or nil
344+
#
345+
# Check if the there are any actions to execute for this host and phase (i.e.,
346+
# "build", "test", or "install")
347+
function should_execute_host_actions_for_phase() {
348+
local host="$1"
349+
local phase_name="$2"
350+
351+
if [[ "${ONLY_EXECUTE}" = "all" ]] ||
352+
[[ "${ONLY_EXECUTE}" == ${host}-*-${phase_name} ]]; then
353+
echo 1
354+
fi
355+
}
356+
311357
function num_llvm_parallel_lto_link_jobs() {
312358
case "$(uname -s -m)" in
313359
Darwin\ x86_64)
@@ -1512,19 +1558,26 @@ function set_swiftpm_bootstrap_command() {
15121558

15131559

15141560
for host in "${ALL_HOSTS[@]}"; do
1561+
# Skip this pass when the only action to execute can't match.
1562+
if ! [[ $(should_execute_host_actions_for_phase ${host} build) ]]; then
1563+
continue
1564+
fi
15151565

15161566
calculate_targets_for_host $host
15171567

15181568
set_build_options_for_host $host
15191569

1520-
echo "Building the standard library for: ${SWIFT_STDLIB_TARGETS[@]}"
1521-
if [[ "${SWIFT_TEST_TARGETS[@]}" ]] && ! [[ "${SKIP_TEST_SWIFT}" ]]; then
1522-
echo "Running Swift tests for: ${SWIFT_TEST_TARGETS[@]}"
1523-
fi
1524-
if ! [[ "${SKIP_TEST_BENCHMARKS}" ]] &&
1525-
[[ "${SWIFT_RUN_BENCHMARK_TARGETS[@]}" ]] &&
1526-
! [[ "${SKIP_TEST_BENCHMARK}" ]]; then
1527-
echo "Running Swift benchmarks for: ${SWIFT_RUN_BENCHMARK_TARGETS[@]}"
1570+
# Don't echo anything if only executing an individual action.
1571+
if [[ "${ONLY_EXECUTE}" = "all" ]]; then
1572+
echo "Building the standard library for: ${SWIFT_STDLIB_TARGETS[@]}"
1573+
if [[ "${SWIFT_TEST_TARGETS[@]}" ]] && ! [[ "${SKIP_TEST_SWIFT}" ]]; then
1574+
echo "Running Swift tests for: ${SWIFT_TEST_TARGETS[@]}"
1575+
fi
1576+
if ! [[ "${SKIP_TEST_BENCHMARKS}" ]] &&
1577+
[[ "${SWIFT_RUN_BENCHMARK_TARGETS[@]}" ]] &&
1578+
! [[ "${SKIP_TEST_BENCHMARK}" ]]; then
1579+
echo "Running Swift benchmarks for: ${SWIFT_RUN_BENCHMARK_TARGETS[@]}"
1580+
fi
15281581
fi
15291582

15301583
common_cmake_options_host=("${COMMON_CMAKE_OPTIONS[@]}")
@@ -1644,6 +1697,11 @@ for host in "${ALL_HOSTS[@]}"; do
16441697
)
16451698

16461699
for product in "${PRODUCTS[@]}"; do
1700+
# Check if we should perform this action.
1701+
if ! [[ $(should_execute_action "${host}-${product}-build") ]]; then
1702+
continue
1703+
fi
1704+
16471705
unset skip_build
16481706
source_dir_var="$(toupper ${product})_SOURCE_DIR"
16491707
source_dir=${!source_dir_var}
@@ -2198,12 +2256,21 @@ tests_busted ()
21982256
}
21992257

22002258
for host in "${ALL_HOSTS[@]}"; do
2259+
# Skip this pass when the only action to execute can't match.
2260+
if ! [[ $(should_execute_host_actions_for_phase ${host} test) ]]; then
2261+
continue
2262+
fi
22012263

22022264
# Calculate test targets
22032265
calculate_targets_for_host $host
22042266

22052267
# Run the tests for each product
22062268
for product in "${PRODUCTS[@]}"; do
2269+
# Check if we should perform this action.
2270+
if ! [[ $(should_execute_action "${host}-${product}-test") ]]; then
2271+
continue
2272+
fi
2273+
22072274
case ${product} in
22082275
cmark)
22092276
if [[ "${SKIP_TEST_CMARK}" ]]; then
@@ -2410,6 +2477,10 @@ done
24102477
LIPO_SRC_DIRS=()
24112478

24122479
for host in "${ALL_HOSTS[@]}"; do
2480+
# Skip this pass when the only action to execute can't match.
2481+
if ! [[ $(should_execute_host_actions_for_phase ${host} install) ]]; then
2482+
continue
2483+
fi
24132484

24142485
# Calculate the directory to install products in to.
24152486
host_install_destdir=$(get_host_install_destdir ${host})
@@ -2423,6 +2494,10 @@ for host in "${ALL_HOSTS[@]}"; do
24232494
set_build_options_for_host $host
24242495

24252496
for product in "${PRODUCTS[@]}"; do
2497+
# Check if we should perform this action.
2498+
if ! [[ $(should_execute_action "${host}-${product}-install") ]]; then
2499+
continue
2500+
fi
24262501

24272502
INSTALL_TARGETS="install"
24282503

@@ -2729,6 +2804,11 @@ function build_and_test_installable_package() {
27292804
# Build and test packages.
27302805
for host in "${ALL_HOSTS[@]}"; do
27312806

2807+
# Check if we should perform this action.
2808+
if ! [[ $(should_execute_action "${host}-package") ]]; then
2809+
continue
2810+
fi
2811+
27322812
if [[ $(should_include_host_in_lipo ${host}) ]]; then
27332813
continue
27342814
fi
@@ -2738,11 +2818,17 @@ done
27382818

27392819
# Lipo those products which require it, optionally build and test an installable package.
27402820
if [[ ${#LIPO_SRC_DIRS[@]} -gt 0 ]]; then
2741-
echo "--- Merging and running lipo ---"
2742-
27432821
# This is from multiple hosts; Which host should we say it is?
27442822
# Let's call it 'merged-hosts' so that we can identify it.
27452823
mergedHost="merged-hosts"
2824+
2825+
# Check if we should perform this action.
2826+
if ! [[ $(should_execute_action "${mergedHost}-lipo") ]]; then
2827+
continue
2828+
fi
2829+
2830+
echo "--- Merging and running lipo ---"
2831+
27462832
call "${SWIFT_SOURCE_DIR}"/utils/recursive-lipo --lipo=$(xcrun_find_tool lipo) --copy-subdirs="$(get_host_install_prefix ${host})lib/swift $(get_host_install_prefix ${host})lib/swift_static" --destination="$(get_host_install_destdir ${mergedHost})" ${LIPO_SRC_DIRS[@]}
27472833

27482834
# Build and test the lipo-ed package.

0 commit comments

Comments
 (0)