-
-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: determine the RUNFILES directory when running a js_binary in an sh_binary #286
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,13 +138,12 @@ function is_windows { | |
# 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 | ||
# C:/Users/XUser/_bazel_XUser/7q7kkv32/execroot/A/b/C -> /c/Users/XUser/_bazel_XUser/7q7kkv32/execroot/A/b/C | ||
function normalize_windows_path { | ||
# Apply the followings paths transformations to normalize paths on Windows | ||
# -process driver letter | ||
# -convert path separator | ||
# -lowercase everything | ||
sed -e 's#^\(.\):#/\L\1#' -e 's#\\#/#g' -e 's/[A-Z]/\L&/g' <<< "$1" | ||
sed -e 's#^\(.\):#/\L\1#' -e 's#\\#/#g' <<< "$1" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How did windows capitalization come into play with this issue? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The replacement of |
||
return | ||
} | ||
|
||
|
@@ -173,15 +172,24 @@ function normalize_windows_path { | |
if [ "${TEST_SRCDIR:-}" ]; then | ||
# Case 4, bazel has identified runfiles for us. | ||
RUNFILES="$TEST_SRCDIR" | ||
elif [ "${RUNFILES_MANIFEST_ONLY:-}" ]; then | ||
# Windows only has a manifest file instead of symlinks. | ||
elif [ "${RUNFILES_MANIFEST_FILE:-}" ]; then | ||
if [ "$(is_windows)" -eq "1" ]; then | ||
# If Windows normalizing the path and case insensitive removing the `/MANIFEST` part of the path | ||
NORMALIZED_RUNFILES_MANIFEST_FILE_PATH=$(normalize_windows_path "$RUNFILES_MANIFEST_FILE") | ||
# shellcheck disable=SC2001 | ||
RUNFILES=$(sed 's|\/MANIFEST$||i' <<< "$NORMALIZED_RUNFILES_MANIFEST_FILE_PATH") | ||
# If Windows, normalize the path | ||
NORMALIZED_RUNFILES_MANIFEST_FILE=$(normalize_windows_path "$RUNFILES_MANIFEST_FILE") | ||
else | ||
RUNFILES=${RUNFILES_MANIFEST_FILE%/MANIFEST} | ||
NORMALIZED_RUNFILES_MANIFEST_FILE="$RUNFILES_MANIFEST_FILE" | ||
fi | ||
if [[ "${NORMALIZED_RUNFILES_MANIFEST_FILE}" == *.runfiles_manifest ]]; then | ||
# Newer versions of Bazel put the manifest besides the runfiles with the suffix .runfiles_manifest. | ||
# For example, the runfiles directory is named my_binary.runfiles then the manifest is beside the | ||
# runfiles directory and named my_binary.runfiles_manifest | ||
RUNFILES=${NORMALIZED_RUNFILES_MANIFEST_FILE%_manifest} | ||
elif [[ "${NORMALIZED_RUNFILES_MANIFEST_FILE}" == */MANIFEST ]]; then | ||
# Older versions of Bazel put the manifest file named MANIFEST in the runfiles directory | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you know what version switched it? Can we put a comment so we can potentially remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure and doesn't seem worthwhile to do a binary search for this one |
||
RUNFILES=${NORMALIZED_RUNFILES_MANIFEST_FILE%/MANIFEST} | ||
else | ||
logf_fatal "Unexpected RUNFILES_MANIFEST_FILE value $RUNFILES_MANIFEST_FILE" | ||
exit 1 | ||
fi | ||
else | ||
case "$0" in | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this is a
sh_binary
and not ash_test
like we probably want. But the bug doesn't occur withsh_test
. Any idea why the bug wouldn't occur when testing?I think if we leave it as
sh_binary
then we need to add another rule (which I forget) to run it as a test?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, it is sh_binary specific since sh_test sets the TEST_SRCDIR env var so RUNFILES is determined that way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you run the sh_binary through a genrule it is not reproducible either as the environment is setup differently in that case. only
bazel run
directly on thesh_binary
will reproduceThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really related to this PR... but can RUNFILES be determined the same everywhere? Doing it different for tests seems odd 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that code could get simplified in the future. Tricky to do right now as we don't have great coverage for different platforms and all of the corner cases.