shc icon indicating copy to clipboard operation
shc copied to clipboard

Compiled binary has trouble determining its path

Open headius opened this issue 5 years ago • 1 comments

When a compiled script is run from $PATH it appears to be unable to locate its own file path.

An example with the JRuby bash launcher:

[] ~/projects/jruby $ bin/jruby.bash -e 'puts ENV_JAVA["jruby.home"]'
/Users/headius/projects/jruby

[] ~/projects/jruby $ jruby.bash -e 'puts ENV_JAVA["jruby.home"]'
/Users/headius/projects/jruby

[] ~/projects/jruby $ shc -f bin/jruby.bash -o bin/jruby2

[] ~/projects/jruby $ bin/jruby2 -e 'puts ENV_JAVA["jruby.home"]'
/Users/headius/projects/jruby

[] ~/projects/jruby $ jruby2 -e 'puts ENV_JAVA["jruby.home"]'
Error: --module-path requires module path specification

This last error comes from the script incorrectly choosing the jruby.home directory and being unable to find the lib/jruby.jar that should be passed to Java's --module_path flag.

Echoing the actual java command this compiled script produces:

$ jruby2 -e 'puts ENV_JAVA["jruby.home"]'
java [...] --module-path  -classpath /Users/headius/projects/lib/*.jar: -Djruby.home=/Users/headius/projects -Djruby.lib=/Users/headius/projects/lib [...] org.jruby.Main -e puts ENV_JAVA["jruby.home"]

We can see that it's using the current directory instead of the directory where the compiled script is actually located.

The logic we use to determination this path is here: https://github.com/jruby/jruby/blob/master/bin/jruby.bash#L38-L60

headius avatar Aug 18 '19 01:08 headius

I have the same issue. Did you find a workaround?

Tone866 avatar Oct 19 '21 18:10 Tone866