diff options
author | Laszlo Csomor <laszlocsomor@google.com> | 2018-04-30 03:03:11 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-04-30 03:04:13 -0700 |
commit | eb35e41242e1f9fb0ae1061623272c891237c8a8 (patch) | |
tree | da1a07195a8f44c75ea031af2fe1499bde4c834d /tools/bash | |
parent | 1d9c606ee1598d8e575152a47c40fa48b69eeded (diff) |
runfiles,Bash: bugfix in absolute path checking
Export the variable which stores the regex pattern
that matches absolute paths, otherwise this
variable won't exist when we call rlocation from
other scripts (that are executed, not sourced).
See https://github.com/bazelbuild/bazel/issues/4460
Change-Id: Idb35ef1bc8489ee53b36b4fe21e1242ea85eeb4c
PiperOrigin-RevId: 194761352
Diffstat (limited to 'tools/bash')
-rw-r--r-- | tools/bash/runfiles/runfiles.bash | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/tools/bash/runfiles/runfiles.bash b/tools/bash/runfiles/runfiles.bash index 8dd82e23b4..cba75ab619 100644 --- a/tools/bash/runfiles/runfiles.bash +++ b/tools/bash/runfiles/runfiles.bash @@ -18,7 +18,8 @@ # - At least one of RUNFILES_MANIFEST_FILE and RUNFILES_DIR environment # variables must be set, to the absolute path of the runfiles manifest or the # <rulename>.runfiles directory respectively. -# - If RUNFILES_LIB_DEBUG=1 is set, the script will print errors to stderr. +# - If RUNFILES_LIB_DEBUG=1 is set, the script will print diagnostic messages to +# stderr. # # USAGE: # 1. Depend on this runfiles library from your build rule: @@ -59,17 +60,23 @@ case "$(uname -s | tr [:upper:] [:lower:])" in msys*|mingw*|cygwin*) # matches an absolute Windows path - _rlocation_isabs_pattern="^[a-zA-Z]:[/\\]" + export _rlocation_isabs_pattern="^[a-zA-Z]:[/\\]" ;; *) # matches an absolute Unix path - _rlocation_isabs_pattern="^/[^/].*" + export _rlocation_isabs_pattern="^/[^/].*" ;; esac # Prints to stdout the runtime location of a data-dependency. function rlocation() { + if [[ "${RUNFILES_LIB_DEBUG:-}" == 1 ]]; then + echo >&2 "INFO[runfiles.bash]: rlocation($1): start" + fi if [[ "$1" =~ $_rlocation_isabs_pattern ]]; then + if [[ "${RUNFILES_LIB_DEBUG:-}" == 1 ]]; then + echo >&2 "INFO[runfiles.bash]: rlocation($1): absolute path, return" + fi # If the path is absolute, print it as-is. echo $1 elif [[ "$1" == ../* || "$1" == */.. || "$1" == ./* || "$1" == */./* || "$1" == "*/." || "$1" == *//* ]]; then @@ -85,10 +92,26 @@ function rlocation() { return 1 else if [[ -f "${RUNFILES_DIR:-/dev/null}/$1" ]]; then + if [[ "${RUNFILES_LIB_DEBUG:-}" == 1 ]]; then + echo >&2 "INFO[runfiles.bash]: rlocation($1): found under RUNFILES_DIR ($RUNFILES_DIR), return" + fi echo "${RUNFILES_DIR}/$1" elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then + if [[ "${RUNFILES_LIB_DEBUG:-}" == 1 ]]; then + echo >&2 "INFO[runfiles.bash]: rlocation($1): looking in RUNFILES_MANIFEST_FILE ($RUNFILES_MANIFEST_FILE)" + fi local -r result=$(grep -m1 "^$1 " "${RUNFILES_MANIFEST_FILE}" | cut -d ' ' -f 2-) - [[ -f "${result:-/dev/null}" ]] && echo "$result" || echo "" + if [[ -f "${result:-/dev/null}" ]]; then + if [[ "${RUNFILES_LIB_DEBUG:-}" == 1 ]]; then + echo >&2 "INFO[runfiles.bash]: rlocation($1): found in manifest as ($result)" + fi + echo "$result" + else + if [[ "${RUNFILES_LIB_DEBUG:-}" == 1 ]]; then + echo >&2 "INFO[runfiles.bash]: rlocation($1): not found in manifest" + fi + echo "" + fi else if [[ "${RUNFILES_LIB_DEBUG:-}" == 1 ]]; then echo >&2 "ERROR[runfiles.bash]: cannot look up runfile \"$1\" " \ |