Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds an optional attribute `stack_snapshot_json` to `stack_snapshot` which pins the result of `stack ls dependencies json` and additional reproducibility information. If specified, then `stack_snapshot` will not need to invoke `stack` to resolve package versions and dependencies or to fetch Hackage or archive dependencies. - This makes re-fetching `stack_snapshot` repositories faster as Hackage and archive dependencies can be cached in Bazel's repository cache, and `stack` does not need to update it's database to determine package versions and dependencies. - Additionally, this avoids issues due to concurrent invocations of `stack` which can fail due to a race condition on the Hackage security lock. The lock file can be generated or updated by invoking the script `@<workspace>-unpinned//:pin`. If the `stack_snapshot_json` attribute is not specified, then `stack_snapshot` will behave as before and resolve and fetch external packages using `stack` on every Bazel fetch.
- Loading branch information
Showing
4 changed files
with
369 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
if [ "$BUILD_WORKSPACE_DIRECTORY" = "" ]; then | ||
cat <<EOF >&2 | ||
It looks like you are trying to invoke the pin script incorrectly. | ||
We only support calling the pin script with | ||
bazel run @STACKAGE-unpinned//:pin | ||
EOF | ||
exit 1 | ||
fi | ||
cd "$BUILD_WORKSPACE_DIRECTORY" | ||
|
||
# Copy-pasted from the Bazel Bash runfiles library v2. | ||
set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash | ||
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ | ||
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ | ||
source "$0.runfiles/$f" 2>/dev/null || \ | ||
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ | ||
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ | ||
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e | ||
# --- end runfiles.bash initialization v2 --- | ||
|
||
set -euo pipefail | ||
|
||
cp "$(rlocation "{repository_name}-unpinned/{stack_snapshot_source}")" "{stack_snapshot_location}" | ||
|
||
if [ "{predefined_stack_snapshot}" = "True" ]; then | ||
cat <<EOF >&2 | ||
Successfully pinned resolved artifacts for @{repository_name}, {stack_snapshot_location} is now up-to-date. | ||
EOF | ||
else | ||
cat <<EOF >&2 | ||
Successfully pinned resolved artifacts for @{repository_name} in {stack_snapshot_location}. | ||
This file should be checked in your version control system. | ||
Next, please update your WORKSPACE file by adding the stack_snapshot_json attribute. | ||
For example: | ||
============================================================= | ||
stack_snapshot( | ||
packages = ..., | ||
snapshot = ..., | ||
stack_snapshot_json = "//:{repository_name}_snapshot.json", | ||
) | ||
============================================================= | ||
To update {repository_name}_snapshot.json, run this command to re-pin the unpinned repository: | ||
bazel run @{repository_name}-unpinned//:pin | ||
EOF | ||
fi |
Oops, something went wrong.