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

Make rubygem use /usr/bin/env in shebang in script #4907

Closed
oxygene opened this issue Dec 19, 2017 · 9 comments
Closed

Make rubygem use /usr/bin/env in shebang in script #4907

oxygene opened this issue Dec 19, 2017 · 9 comments

Comments

@oxygene
Copy link

oxygene commented Dec 19, 2017

I have another issue, kind of related to #4890, which affects portability. I want to use jruby in a portable way within a build machine. In my particular case, I'm using jekyll installed by rubygems in jruby, setting the PATH variable to include <path-to-jruby>/bin. However, this currently fails because of the shebang used in bin/jekyll reads

#! jruby

I'd like to propose to use /usr/bin/env instead:

#!/usr/bin/env jruby

There seems to be a configuration variable which is used by the shebang function within jruby. See https://github.com/rubygems/rubygems/blob/dfc9c72a91b14a5d630fc141cf30312da3bf2ba7/lib/rubygems/installer.rb#L538-L592

I don't really know a thing about ruby and how things work together in detail, but in contrast to #4890 it looks to me as if this issue should be directly fixable in jruby by setting the configuration. But I might be completely wrong, of course.

@headius
Copy link
Member

headius commented Dec 19, 2017

JRuby should default RubyGems to using "env shebang" lines. If you install the native JRuby executable, we change that logic to use absolute path to the native binary, but that doesn't match what you're seeing here.

How did you install JRuby?

@headius
Copy link
Member

headius commented Dec 19, 2017

@oxygene
Copy link
Author

oxygene commented Dec 19, 2017

I have a python script for "bootstraping" jruby with jekyll on a Windows 7 machine because -- as I have written in #4890 -- I need to later run jekyll on build machines with no internet access. The bootstrap python script does the following steps:

  • unpack jruby-dist-9.1.15.0-bin.tar.gz
  • call gem.bat install --http-proxy http://username:password@proxy.example.com:8080/ jekyll

I have to note that bin/jruby has the expected shebang #!/usr/bin/env bash. It's also correct (#!/usr/bin/env jruby) for e.g. bin/gem and other shell scripts that are already in jruby-dist-9.1.15.0-bin.tar.gz.
However, all shell scripts in bin that have been pulled by the call to gem only have the #! jruby shebang.

@oxygene
Copy link
Author

oxygene commented Dec 19, 2017

One more insight:

I've run my bootstrap script on a linux machine and got a bin/jekyll file with the correct shebang (#!/usr/bin/env jruby). So apparently running gem on a linux machine produces scripts in bin dir that work fine on the same platform. Interestingly, rubygems did not install any windows batch stubs (*.bat) for any installed program. So e.g. there is no jekyll.bat lying around.

This is a bit assymetric. "Bootstrapping" on Windows produces batch files and shell scripts (with the latter having wrong shebangs), while "bootstrapping" on Linux produces correct shell scripts, but no batch files at all.

This breaks my naive assumption that I could "bootstrap" jruby with jekyll on any platform, either Windows or Linux, and then use the produced self-contained jruby folder on any machine with an installed JRE, be it Windows or Linux.

@headius
Copy link
Member

headius commented Dec 20, 2017

Ahh so this seems to be a limitation of RubyGems then? We make no modifications to RubyGems other than through defaults...perhaps there's a way to configure it to always install batch files.

@headius
Copy link
Member

headius commented Dec 20, 2017

To clarify what I'm hearing:

  • On Windows, batch files are produced. On unix, they are not, and there appears to be no way to force them to generate.

Here's the code that generates the .bat files:

  def generate_windows_script(filename, bindir)
    if Gem.win_platform? then
      script_name = filename + ".bat"
      script_path = File.join bindir, File.basename(script_name)
      File.open script_path, 'w' do |file|
        file.puts windows_stub_script(bindir, filename)
      end

      verbose script_path
    end
  end

Seems like you want a new feature for RubyGems to force it to always generate both.

  • The non-batch scripts generated on Windows do not seem to have shebang lines.

Is this correct?

In any case this seems like RubyGems issues or features, so perhaps there's nothing to do on JRuby's end.

@oxygene
Copy link
Author

oxygene commented Dec 20, 2017

Hi Charles,

Thank you very much for your time looking into it. Your summary is correct.

I'm sorry for the noise here on the jruby issue tracker. The fact that the behavior was inconsistent depending on the platform misled me into thinking that some config option has not been set correctly in jruby. But as you have already pointed out, this seems to be an issue with rubygems.

Being completely new to the ruby ecosystem, it was hard for me to see where exactly the root cause might have been. So thanks again for pointing me in the right direction.

Then again, it is not yet completely clear to me whether the behaviour I naively expected would be a feature request for jruby or rubygems. I was thinking of jruby as a portable alternative to a native ruby setup and therefore assumed that it just came with working scripts for Windows (batch files) and Unix-style systems (shebang). And I think my assumption was not too far-stretched as the vanilla jruby distribution contains batch files and shebang-files for jruby, gem, rake etc.

I assume that asking rubygems to generate batch files on Unix-like systems and shebang-style files on Windows systems per default would be frowned upon for a native ruby installation, don't you think? So maybe the feature request for rubygems would be the following:

  • Give a configuration option to create batch files even while being run on a Unix system
  • Give a configuration option to create shebang-style files while running on a Windows system and use the correct shebang-format with /usr/bin/env if configured so (because this seems not to work right now).

Once this is possible, a feature request for jruby might be:

  • Always configure rubygems in a way that it always generates batch files and env-style shebang files, regardless of the host operating system.

This would result in a jruby folder with optionally addition gems that could be just copied over across different host operating systems. Things would then work as long as there is a JRE installed and the PATH variable set correctly.

Does that sound reasonable to you?

@ghost
Copy link

ghost commented Dec 22, 2017

Seems like you want a new feature for RubyGems to force it to always generate both.

I think one possible solution would be for users to be able to generate the desired variants,
using rubygems itself with some --option, but I think this should be a discussion for rubygems
rather than jruby directly (though of course jruby could also add code for this, but I think it
makes more sense for rubygems to have it directly).

@headius
Copy link
Member

headius commented Jan 24, 2018

It looks like a RubyGems flag is acceptable to the RG folks, so I'm going to close this.

@headius headius closed this as completed Jan 24, 2018
@headius headius added this to the Invalid or Duplicate milestone Jan 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants