You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix Bash rlocation failure with stricter Bash options
When run in the context of the bazel-skylib unit test setup, the new repo mapping logic in the Bash runfiles library failed due to a non-matching grep in a pipe. Fix this by using a wrapper around grep throughout that does not exit with exit code 1 if there is no match.
Fixesbazelbuild/bazel-skylib#411 (comment)Closesbazelbuild#16755.
PiperOrigin-RevId: 488749744
Change-Id: I087b03d9e95ba27a409c551bdc27d0027919a0fe
Copy file name to clipboardexpand all lines: tools/bash/runfiles/runfiles.bash
+11-5
Original file line number
Diff line number
Diff line change
@@ -105,6 +105,12 @@ msys*|mingw*|cygwin*)
105
105
;;
106
106
esac
107
107
108
+
# Does not exit with a non-zero exit code if no match is found.
109
+
function__runfiles_maybe_grep() {
110
+
grep "$@"||test$? = 1;
111
+
}
112
+
export -f __runfiles_maybe_grep
113
+
108
114
# Prints to stdout the runtime location of a data-dependency.
109
115
# The optional second argument can be used to specify the canonical name of the
110
116
# repository whose repository mapping should be used to resolve the repository
@@ -145,7 +151,7 @@ function rlocation() {
145
151
if [[ "${RUNFILES_LIB_DEBUG:-}"== 1 ]];then
146
152
echo>&2"INFO[runfiles.bash]: rlocation($1): looking up canonical name for ($target_repo_apparent_name) from ($source_repo) in ($RUNFILES_REPO_MAPPING)"
147
153
fi
148
-
local -r target_repo=$(grep -m1 "^$source_repo,$target_repo_apparent_name,""$RUNFILES_REPO_MAPPING"| cut -d , -f 3)
154
+
local -r target_repo=$(__runfiles_maybe_grep -m1 "^$source_repo,$target_repo_apparent_name,""$RUNFILES_REPO_MAPPING"| cut -d , -f 3)
149
155
if [[ "${RUNFILES_LIB_DEBUG:-}"== 1 ]];then
150
156
echo>&2"INFO[runfiles.bash]: rlocation($1): canonical name of target repo is ($target_repo)"
151
157
fi
@@ -225,7 +231,7 @@ function runfiles_current_repository() {
225
231
# uses / as the path separator even on Windows.
226
232
local -r normalized_caller_path="$(echo "$caller_path"| sed 's|\\\\*|/|g')"
227
233
local -r escaped_caller_path="$(echo "$normalized_caller_path"| sed 's/[^-A-Za-z0-9_/]/\\&/g')"
echo>&2"INFO[runfiles.bash]: runfiles_current_repository($idx): ($normalized_caller_path) is not the target of an entry in the runfiles manifest ($RUNFILES_MANIFEST_FILE)"
@@ -254,7 +260,7 @@ function runfiles_current_repository() {
254
260
# The only shell script that is not executed from the runfiles directory (if it is populated)
255
261
# is the sh_binary entrypoint. Parse its path under the execroot, using the last match to
256
262
# allow for nested execroots (e.g. in Bazel integration tests).
0 commit comments