diff --git a/coursier.bzl b/coursier.bzl index c7d9269a1..4a22aed31 100644 --- a/coursier.bzl +++ b/coursier.bzl @@ -49,12 +49,11 @@ genrule( sh_binary( name = "pin", srcs = ["pin.sh"], - args = [ - "$(location :jq-binary)", - ], - data = [ - ":jq-binary", - ], + # Cannot use $(location)/$(rootpath) because we'll be an external repository + # relative to where the build is taking place + args = [repository_name()[1:] + "/jq"], + deps = ["@bazel_tools//tools/bash/runfiles"], + data = [":jq-binary"], ) """ diff --git a/private/pin.sh b/private/pin.sh index 24ed745be..102be141c 100644 --- a/private/pin.sh +++ b/private/pin.sh @@ -1,12 +1,22 @@ #!/usr/bin/env bash -set -euo pipefail +# --- begin runfiles.bash initialization v2 --- +# Copy-pasted from the Bazel Bash runfiles library v2. +set -euo 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 --- + readonly maven_install_json_loc={maven_install_location} # This script is run as a `sh_binary`, so ensure we are in the calling workspace before running Bazel. readonly execution_root=$(cd "$(dirname "$maven_install_json_loc")" && bazel info execution_root) readonly workspace_name=$(basename "$execution_root") # `jq` is a platform-specific dependency with an unpredictable path. -readonly jq=$1 +readonly jq=$(rlocation $1) cat <<"RULES_JVM_EXTERNAL_EOF" | "$jq" --sort-keys --indent 4 . - > $maven_install_json_loc {dependency_tree_json} RULES_JVM_EXTERNAL_EOF