Skip to content

Commit c725169

Browse files
authored
fix(builtin): use updated rules_js launcher logic to source RUNFILES (#3557)
1 parent 805116e commit c725169

File tree

1 file changed

+65
-51
lines changed

1 file changed

+65
-51
lines changed

internal/node/launcher.sh

Lines changed: 65 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# limitations under the License.
1515

1616
# It helps to determine if we are running on a Windows environment (excludes WSL as it acts like Unix)
17-
function isWindows {
17+
function is_windows {
1818
case "$(uname -s)" in
1919
CYGWIN*) local IS_WINDOWS=1 ;;
2020
MINGW*) local IS_WINDOWS=1 ;;
@@ -29,14 +29,13 @@ function isWindows {
2929
# It helps to normalizes paths when running on Windows.
3030
#
3131
# Example:
32-
# C:/Users/XUser/_bazel_XUser/7q7kkv32/execroot/A/b/C -> /c/users/xuser/_bazel_xuser/7q7kkv32/execroot/a/b/c
33-
function normalizeWindowsPath {
34-
# Apply the followings paths transformations to normalize paths on Windows
35-
# -process driver letter
36-
# -convert path separator
37-
# -lowercase everything
38-
echo $(sed -e 's#^\(.\):#/\L\1#' -e 's#\\#/#g' -e 's/[A-Z]/\L&/g' <<< "$1")
39-
return
32+
# C:/Users/XUser/_bazel_XUser/7q7kkv32/execroot/A/b/C -> /c/Users/XUser/_bazel_XUser/7q7kkv32/execroot/A/b/C
33+
function normalize_windows_path {
34+
# Apply the followings paths transformations to normalize paths on Windows
35+
# -process driver letter
36+
# -convert path separator
37+
sed -e 's#^\(.\):#/\L\1#' -e 's#\\#/#g' <<< "$1"
38+
return
4039
}
4140

4241
# --- begin runfiles.bash initialization v2 ---
@@ -73,51 +72,66 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
7372
# blaze.
7473
# Case 5a is handled like case 1.
7574
# Case 6a is handled like case 3.
76-
if [[ -n "${RUNFILES_MANIFEST_ONLY:-}" ]]; then
77-
# Windows only has a manifest file instead of symlinks.
78-
if [[ $(isWindows) -eq "1" ]]; then
79-
# If Windows normalizing the path and case insensitive removing the `/MANIFEST` part of the path
80-
NORMALIZED_RUNFILES_MANIFEST_FILE_PATH=$(normalizeWindowsPath $RUNFILES_MANIFEST_FILE)
81-
RUNFILES=$(sed 's|\/MANIFEST$||i' <<< $NORMALIZED_RUNFILES_MANIFEST_FILE_PATH)
82-
else
83-
RUNFILES=${RUNFILES_MANIFEST_FILE%/MANIFEST}
84-
fi
85-
elif [[ -n "${TEST_SRCDIR:-}" ]]; then
86-
# Case 4, bazel has identified runfiles for us.
87-
RUNFILES="${TEST_SRCDIR:-}"
88-
else
89-
case "$0" in
90-
/*) self="$0" ;;
91-
*) self="$PWD/$0" ;;
92-
esac
93-
while true; do
94-
if [[ -e "$self.runfiles" ]]; then
95-
RUNFILES="$self.runfiles"
96-
break
97-
fi
98-
99-
if [[ $self == *.runfiles/* ]]; then
100-
RUNFILES="${self%%.runfiles/*}.runfiles"
101-
# don't break; this is a last resort for case 6b
102-
fi
103-
104-
if [[ ! -L "$self" ]]; then
105-
break;
75+
if [ "${TEST_SRCDIR:-}" ]; then
76+
# Case 4, bazel has identified runfiles for us.
77+
RUNFILES="$TEST_SRCDIR"
78+
elif [ "${RUNFILES_MANIFEST_FILE:-}" ]; then
79+
if [ "$(is_windows)" -eq "1" ]; then
80+
# If Windows, normalize the path
81+
NORMALIZED_RUNFILES_MANIFEST_FILE=$(normalize_windows_path "$RUNFILES_MANIFEST_FILE")
82+
else
83+
NORMALIZED_RUNFILES_MANIFEST_FILE="$RUNFILES_MANIFEST_FILE"
10684
fi
107-
108-
readlink="$(readlink "$self")"
109-
if [[ "$readlink" = /* ]]; then
110-
self="$readlink"
85+
if [[ "${NORMALIZED_RUNFILES_MANIFEST_FILE}" == *.runfiles_manifest ]]; then
86+
# Newer versions of Bazel put the manifest besides the runfiles with the suffix .runfiles_manifest.
87+
# For example, the runfiles directory is named my_binary.runfiles then the manifest is beside the
88+
# runfiles directory and named my_binary.runfiles_manifest
89+
RUNFILES=${NORMALIZED_RUNFILES_MANIFEST_FILE%_manifest}
90+
elif [[ "${NORMALIZED_RUNFILES_MANIFEST_FILE}" == */MANIFEST ]]; then
91+
# Older versions of Bazel put the manifest file named MANIFEST in the runfiles directory
92+
RUNFILES=${NORMALIZED_RUNFILES_MANIFEST_FILE%/MANIFEST}
11193
else
112-
# resolve relative symlink
113-
self="${self%%/*}/$readlink"
94+
echo "\n>>>> FAIL: Unexpected RUNFILES_MANIFEST_FILE value $RUNFILES_MANIFEST_FILE. <<<<\n\n" >&2
95+
exit 1
11496
fi
115-
done
116-
117-
if [[ -z "$RUNFILES" ]]; then
118-
echo " >>>> FAIL: RUNFILES environment variable is not set. <<<<" >&2
119-
exit 1
120-
fi
97+
else
98+
case "$0" in
99+
/*) self="$0" ;;
100+
*) self="$PWD/$0" ;;
101+
esac
102+
while true; do
103+
if [ -e "$self.runfiles" ]; then
104+
RUNFILES="$self.runfiles"
105+
break
106+
fi
107+
108+
if [[ "$self" == *.runfiles/* ]]; then
109+
RUNFILES="${self%%.runfiles/*}.runfiles"
110+
# don't break; this is a last resort for case 6b
111+
fi
112+
113+
if [ ! -L "$self" ]; then
114+
break;
115+
fi
116+
117+
readlink="$(readlink "$self")"
118+
if [[ "$readlink" == /* ]]; then
119+
self="$readlink"
120+
else
121+
# resolve relative symlink
122+
self="${self%%/*}/$readlink"
123+
fi
124+
done
125+
126+
if [ -z "${RUNFILES:-}" ]; then
127+
echo "\n>>>> FAIL: RUNFILES environment variable is not set. <<<<\n\n" >&2
128+
exit 1
129+
fi
130+
fi
131+
if [ "${RUNFILES:0:1}" != "/" ]; then
132+
# Ensure RUNFILES set above is an absolute path. It may be a path relative
133+
# to the PWD in case where RUNFILES_MANIFEST_FILE is used above.
134+
RUNFILES="$PWD/$RUNFILES"
121135
fi
122136
export RUNFILES
123137
# --- end RUNFILES initialization ---

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy