From 9cf5a18dd56538a1c4e776bff5ce69e5a808c4b7 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Sat, 23 Sep 2023 08:21:25 +0200 Subject: [PATCH] Use case-insensitive comparison for Windows paths in runfiles.bash When matching the path of `rlocation`'s caller in the Bash runfiles library, use a case-insensitive comparison when running in MSYS2 as Bazel emits paths that can be capitalized differently. In particular, this fixes failures when the output base path contains uppercase letters. --- tools/bash/runfiles/runfiles.bash | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/bash/runfiles/runfiles.bash b/tools/bash/runfiles/runfiles.bash index d6e142b8d4690e..e2d0f5eb05be92 100644 --- a/tools/bash/runfiles/runfiles.bash +++ b/tools/bash/runfiles/runfiles.bash @@ -235,7 +235,14 @@ function runfiles_current_repository() { # uses / as the path separator even on Windows. local -r normalized_caller_path="$(echo "$caller_path" | sed 's|\\\\*|/|g')" local -r escaped_caller_path="$(echo "$normalized_caller_path" | sed 's/[^-A-Za-z0-9_/]/\\&/g')" - rlocation_path=$(__runfiles_maybe_grep -m1 "^[^ ]* ${escaped_caller_path}$" "${RUNFILES_MANIFEST_FILE}" | cut -d ' ' -f 1) + if [[ "$(uname -o)" == Msys ]]; then + # Windows paths are case insensitive and Bazel and MSYS2 capitalize differently, so we can't + # assume that all paths are in the same native case. + local -r grep_arg="-i" + else + local -r grep_arg= + fi + rlocation_path=$(__runfiles_maybe_grep "$grep_arg" -m1 "^[^ ]* ${escaped_caller_path}$" "${RUNFILES_MANIFEST_FILE}" | cut -d ' ' -f 1) if [[ -z "$rlocation_path" ]]; then if [[ "${RUNFILES_LIB_DEBUG:-}" == 1 ]]; then echo >&2 "ERROR[runfiles.bash]: runfiles_current_repository($idx): ($normalized_caller_path) is not the target of an entry in the runfiles manifest ($RUNFILES_MANIFEST_FILE)"