Skip to content

Commit b5ed851

Browse files
fix: swift_package_tool so that it works on Linux and MacOS (#1621)
The Renovate runs have been failing when trying to run `//:update_swift_packages` on modified workspaces. The issue is that the Swift worker processes behave differently on MacOS vs Linux. On MacOS, the arguments are essentially passed through to `xcrun`. On Linux, it is more of a barebones process runner. Previously, we expected the worker to find `swift` automatically. This does not work on Linux. This PR adds logic to find `swift` by attempting to ask the worker. If that fails, fall back to looking in the `PATH`. I also upgraded Swift to 6.1 on Ubuntu. Closes #1591. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 981cb8e commit b5ed851

File tree

3 files changed

+38
-21
lines changed

3 files changed

+38
-21
lines changed

.github/actions/set_up_ubuntu/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ inputs:
1010
required: true
1111
swift_release_tag:
1212
description: The Swift release tag.
13-
default: "swift-6.0.3-RELEASE"
13+
default: "swift-6.1-RELEASE"
1414

1515
runs:
1616
using: composite

examples/vapor_example/do_test

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -o errexit -o nounset -o pipefail
44

5-
# Use the Bazel binary specified by the integration test. Otherise, fall back
5+
# Use the Bazel binary specified by the integration test. Otherise, fall back
66
# to bazel.
77
bazel="${BIT_BAZEL_BINARY:-bazel}"
88

@@ -11,3 +11,7 @@ bazel="${BIT_BAZEL_BINARY:-bazel}"
1111

1212
# Ensure that it builds and tests pass
1313
"${bazel}" test //...
14+
15+
# This example is run for MacOS and Linux. Run //:update_swift_packages to
16+
# ensure that it works on both platforms.
17+
"${bazel}" run //:update_swift_packages

swiftpkg/internal/swift_package_tool_runner_template.sh

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ set -euo pipefail
1313
# %(cache_path)s - The path to the cache directory.
1414

1515
if [ -z "${BUILD_WORKSPACE_DIRECTORY:-}" ]; then
16-
echo "BUILD_WORKSPACE_DIRECTORY is not set, this target may only be \`bazel run\`"
17-
exit 1
16+
echo "BUILD_WORKSPACE_DIRECTORY is not set, this target may only be \`bazel run\`"
17+
exit 1
1818
fi
1919

2020
# Collect template values.
@@ -36,40 +36,53 @@ use_registry_identity_for_scm="%(use_registry_identity_for_scm)s"
3636
args=()
3737

3838
if [ "$enable_build_manifest_caching" = "true" ]; then
39-
args+=("--enable-build-manifest-caching")
39+
args+=("--enable-build-manifest-caching")
4040
else
41-
args+=("--disable-build-manifest-caching")
41+
args+=("--disable-build-manifest-caching")
4242
fi
4343

4444
if [ "$enable_dependency_cache" = "true" ]; then
45-
args+=("--enable-dependency-cache")
45+
args+=("--enable-dependency-cache")
4646
else
47-
args+=("--disable-dependency-cache")
47+
args+=("--disable-dependency-cache")
4848
fi
4949

5050
if [ "$replace_scm_with_registry" = "true" ]; then
51-
args+=("--replace-scm-with-registry")
51+
args+=("--replace-scm-with-registry")
5252
fi
5353

5454
if [ "$use_registry_identity_for_scm" = "true" ]; then
55-
args+=("--use-registry-identity-for-scm")
55+
args+=("--use-registry-identity-for-scm")
5656
fi
5757

5858
args+=("--manifest-cache=$manifest_cache")
5959

6060
# If registries_json is set, symlink the `.json` file to the `config_path/configuration` directory.
6161
if [ -n "$registries_json" ]; then
62-
mkdir -p "$config_path"
63-
ln -sf "$(readlink -f "$registries_json")" "$config_path/registries.json"
62+
mkdir -p "$config_path"
63+
ln -sf "$(readlink -f "$registries_json")" "$config_path/registries.json"
6464
fi
6565

66+
# On MacOS, the swift_worker passes the command to xcrun. On Linux, it is a
67+
# barebones worker implementation that does not support '--find'. So, on Linux,
68+
# we try to find the Swift executable in the PATH. This is not a good way to do
69+
# this 😔. It is good enough for now.
70+
swift_executable="$(
71+
"${swift_worker}" --find swift ||
72+
which swift ||
73+
(
74+
echo >&2 "Could not find the swift executable."
75+
exit 1
76+
)
77+
)"
78+
6679
# Run the command.
67-
"$swift_worker" swift package \
68-
--build-path "$build_path" \
69-
--cache-path "$cache_path" \
70-
--config-path "$config_path" \
71-
--package-path "$package_path" \
72-
--security-path "$security_path" \
73-
"$cmd" \
74-
"${args[@]}" \
75-
"$@"
80+
"${swift_executable}" package \
81+
--build-path "$build_path" \
82+
--cache-path "$cache_path" \
83+
--config-path "$config_path" \
84+
--package-path "$package_path" \
85+
--security-path "$security_path" \
86+
"$cmd" \
87+
"${args[@]}" \
88+
"$@"

0 commit comments

Comments
 (0)