shc
shc copied to clipboard
Compiled binary has trouble determining its path
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
I have the same issue. Did you find a workaround?