Skip to content
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

Explicitly set RUNFILES_DIR #58

Merged
merged 2 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions appimage/private/tool/mkappimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,13 @@ def populate_appdir(appdir: Path, params: AppDirParams) -> None:
# If running as AppImage outside Bazel, conveniently set BUILD_WORKING_DIRECTORY, like `bazel run` would
# `$OWD` ("Original Working Directory") is set by the AppImage runtime in
# https://github.com/lalten/type2-runtime/blob/84f7a00/src/runtime/runtime.c#L1757
# Note that we can not set BUILD_WORKSPACE_DIRECTORY as it's not known if the AppImage is deployed
# Note that we can not set BUILD_WORKSPACE_DIRECTORY as it's not known when the AppImage is deployed
'[ "${BUILD_WORKING_DIRECTORY+1}" ] || export BUILD_WORKING_DIRECTORY="$OWD"',
# Explicitly set RUNFILES_DIR to the runfiles dir of the binary instead of the appimage rule itself
f'workdir="$(dirname $0)/{params.workdir}"',
'export RUNFILES_DIR="$(dirname "${workdir}")"',
# Run under runfiles
f'cd "$(dirname $0)/{params.workdir}"',
'cd "${workdir}"',
# Launch the actual binary
f'exec "./{params.entrypoint}" "$@"',
]
Expand Down
15 changes: 15 additions & 0 deletions tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,18 @@ rules_appimage_test_rule(
name = "symlink_and_emptyfile",
symlink = "data.txt",
)

sh_test(
name = "runfiles_test_sh",
size = "small",
srcs = ["runfiles_test.sh"],
deps = ["@bazel_tools//tools/bash/runfiles"],
)

appimage_test(
name = "runfiles_test_sh.appimage",
size = "small",
binary = ":runfiles_test_sh",
env = {"RUNFILES_LIB_DEBUG": "1"},
tags = ["requires-fakeroot"],
)
19 changes: 19 additions & 0 deletions tests/runfiles_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

# --- begin runfiles.bash initialization v3 ---
# Copy-pasted from the Bazel Bash runfiles library v3.
set -uo pipefail
set +e
f=bazel_tools/tools/bash/runfiles/runfiles.bash
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null ||
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null ||
source "$0.runfiles/$f" 2>/dev/null ||
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null ||
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null ||
{
echo >&2 "ERROR: cannot find $f"
exit 1
}
f=
set -e
# --- end runfiles.bash initialization v3 ---