Skip to content

Commit

Permalink
fix(runfiles): use normalized paths when guarding runfiles root and n…
Browse files Browse the repository at this point in the history
…ode_modules on Windows
  • Loading branch information
mistic committed Feb 16, 2022
1 parent 550673f commit f80bacb
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion internal/node/launcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,34 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# It helps to normalizes paths when running on Windows.

# Example:
# C:/Users/XUser/_bazel_XUser/7q7kkv32/execroot/A/b/C -> /c/users/xuser/_bazel_xuser/7q7kkv32/execroot/a/b/c
function normalizeWindowsPath {
# Determine if we are running on a Windows environment
# that can generate problematic paths (excludes WSL as it acts like unix)
case "$(uname -s)" in
CYGWIN*) local IS_WINDOWS=true ;;
MINGW*) local IS_WINDOWS=true ;;
MSYS_NT*) local IS_WINDOWS=true ;;
*) local IS_WINDOWS=false ;;
esac

# In case we are running on Windows apply the paths transformations
# -process driver letter
# -convert path separator
# -lowercase everything
if $IS_WINDOWS ; then
local retval=$(sed -e 's#^\(.\):#/\L\1#' -e 's#\\#/#g' -e 's/[A-Z]/\L&/g' <<< "$1")
echo "$retval"
return
fi

# otherwise doesnt change the given path and just return the argument as is
echo "$1"
}

# --- begin runfiles.bash initialization v2 ---
# Copy-pasted from the Bazel Bash runfiles library v2.
set -uo pipefail; f=build_bazel_rules_nodejs/third_party/github.com/bazelbuild/bazel/tools/bash/runfiles/runfiles.bash
Expand Down Expand Up @@ -49,7 +77,9 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
# Case 6a is handled like case 3.
if [[ -n "${RUNFILES_MANIFEST_ONLY:-}" ]]; then
# Windows only has a manifest file instead of symlinks.
RUNFILES=${RUNFILES_MANIFEST_FILE%/MANIFEST}
# Normalizing the path and case insensitive removing the `/MANIFEST` part of the path
NORMALIZED_RUNFILES_MANIFEST_FILE_PATH=$(normalizeWindowsPath $RUNFILES_MANIFEST_FILE)
RUNFILES=$(sed 's|\/MANIFEST$||i' <<< $NORMALIZED_RUNFILES_MANIFEST_FILE_PATH)
elif [[ -n "${TEST_SRCDIR:-}" ]]; then
# Case 4, bazel has identified runfiles for us.
RUNFILES="${TEST_SRCDIR:-}"
Expand Down

0 comments on commit f80bacb

Please sign in to comment.