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

Consistently resolve path of jruby.bash #5840

merged 2 commits into from Aug 18, 2019

Consistently resolve path of jruby.bash #5840

merged 2 commits into from Aug 18, 2019


Copy link

@mrnoname1000 mrnoname1000 commented Aug 18, 2019

The bash script sometimes returns an incorrect path for JRUBY_HOME. I came up with a bunch of cases where it would return the wrong directory, in no particular order:

  1. a directory in PATH is a symlink
  2. a directory in PATH is in a symlink
  3. the executable is a symlink in PATH
  4. the executable is in a directory that is a symlink
  5. the executable is a symlink that points to an executable in a directory that is a symlink
  6. the executable is being read from a pipe

Simply replacing $0 with $BASH_SOURCE fixes case 3. Obviously this is bash-specific, so this can't be ported to the sh script.
Case 4 are solved by using readlink on the executable until it isn't a symlink. The script already did this, so I made some changes to solve other issues.
Cases 1, 2, and 5 are solved by running pwd -P in the directory of the executable.
I don't know how to solve case 6 without hardcoding a directory to check.

Because pwd -P always returns the absolute working directory, it seems running dirname "$SELF_PATH" is unnecessary, so I removed it.
If anyone can think of any other torture tests, let me know.

Copy link

@headius headius commented Aug 18, 2019

Looks good, though I've never seen that syntax you used for JRUBY_HOME. What is that?

Thanks for the patch!

@headius headius self-requested a review Aug 18, 2019
bin/jruby.bash Show resolved Hide resolved
@headius headius merged commit 9b3f31f into jruby:master Aug 18, 2019
5 checks passed
@kares kares added this to the JRuby milestone Aug 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

3 participants