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

Handle RUNFILES_DIR and/or RUNFILES_MANIFEST_FILE in java_stub_template.txt #20465

Open
ar3s3ru opened this issue Dec 7, 2023 · 2 comments
Open
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Rules-Java Issues for Java rules type: feature request

Comments

@ar3s3ru
Copy link

ar3s3ru commented Dec 7, 2023

Description of the feature request:

The current implementation of java_stub_template.txt, used in java_binary, requires JAVA_RUNFILES to be present in the environment:

if [[ -z "$JAVA_RUNFILES" ]]; then
while true; do
if [[ -e "$self.runfiles" ]]; then
JAVA_RUNFILES="$self.runfiles"
break
fi
if [[ $self == *.runfiles/* ]]; then
JAVA_RUNFILES="${self%.runfiles/*}.runfiles"
break
fi
if [[ ! -L "$self" ]]; then
break
fi
readlink="$(readlink "$self")"
if [[ "$readlink" = /* ]]; then
self="$readlink"
else
# resolve relative symlink
self="${self%/*}/$readlink"
fi
done
if [[ -n "$JAVA_RUNFILES" ]]; then
export TEST_SRCDIR=${TEST_SRCDIR:-$JAVA_RUNFILES}
elif [[ -f "${self}_deploy.jar" && "%needs_runfiles%" == 0 ]]; then
SINGLEJAR=1;
else
die 'Cannot locate runfiles directory. (Set $JAVA_RUNFILES to inhibit searching.)'
fi
fi

At the very least, it should also support the newer RUNFILES_DIR variable.

Additionally, the script could also gracefully handle having RUNFILES_MANIFEST_FILE in the env over RUNFILES_DIR or JAVA_RUNFILES.

Which category does this issue belong to?

Java Rules

What underlying problem are you trying to solve with this feature?

No response

Which operating system are you running Bazel on?

Darwin

What is the output of bazel info release?

release 6.4.0

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

Issue was highlighed while trying to solve bazel-contrib/rules_jvm#211 through bazel-contrib/rules_jvm#224.

More context on Bazel Slack: https://bazelbuild.slack.com/archives/C01HMGN77Q8/p1701887957242259

@peakschris
Copy link

There is a related issue here. If one java_binary invokes a second java_binary through system call, the second java_binary should run correctly, even though its environment is inherited from the first. This means that really the first java_binary invokation should succeed even without RUNFILES environment variables having been set.

@peakschris
Copy link

Currently, the second java_binary fails, as its JAVA_RUNFILES and RUNFILES_DIR env vars are inherited from the first process and point to the wrong thing.

@hvadehra hvadehra added P2 We'll consider working on this in future. (Assignee optional) and removed untriaged labels Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Rules-Java Issues for Java rules type: feature request
Projects
None yet
Development

No branches or pull requests

6 participants