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

The fix_wrapper.rb hook does not honor the env_shebang option #15

Closed
ryotakatsuki opened this issue May 5, 2012 · 2 comments
Closed
Assignees

Comments

@ryotakatsuki
Copy link

After installing a gem through "gem install mygem --env-shebang", after the wrapper gets overwritten by the fix-wrapper.rb hook, the shebang is overwritten as @env_shebang is not defined in RubyGemsBundlerInstaller. It should take into account the configuration passed in gem.

@mpapis
Copy link
Member

mpapis commented May 5, 2012

please point me to some documentation or source code of rubygems that handles it

@ryotakatsuki
Copy link
Author

Sorry for the lack of detail.

In rubygems (rubygems/installer.rb):

def shebang(bin_file_name)
   ruby_name = Gem::ConfigMap[:ruby_install_name] if @env_shebang
   ...
   if not ruby_name then
     "#!#{Gem.ruby}#{opts}"
   elsif opts then
     "#!/bin/sh\n'exec' #{ruby_name.dump} '-x' \"$0\" \"$@\"\n#{shebang}"
   else
     # Create a plain shebang line.
     "#!#{@env_path} #{ruby_name}"
   end
 end

Where the @env_shebang variable comes from (also in installer.rb)

def process_options
    @options = {
      :bin_dir      => nil,
      :env_shebang  => false,
      :exec_format  => false,
      :force        => false,
      :install_dir  => Gem.dir,
    }.merge options
    @env_shebang         = options[:env_shebang]
    ...
end

And is defined when launching the gem install/upgrade command with --env-shebang or -E flags.

Then, after installing the gems, the hooks are executed. In fix_wrapper.rb:

module Gem
  post_install do |inst|
    RubyGemsBundlerInstaller.bundler_generate_bin(inst)
  end
end

Which calls bundler_generate_bin to rewrite the wrapper (in rubygems-bundler/rubygems_bundler_installer.rb). It uses a modified version of the shebang proc:

def self.shebang(inst, bin_file_name)
   ruby_name = Gem::ConfigMap[:ruby_install_name] if @env_shebang 
   ...
   if not ruby_name then
      "#!#{Gem.ruby}#{opts}"
   ...
   end
   ...
end

In the above proc, as @env_shebang is never defined, the condition does not match and hence, the shebang is written as "#!#{Gem.ruby}#{opts}" (regardless of if @env_shebang was true in the rubygems portion of the execution).

I believe a possible patch would be using:

def self.shebang(inst, bin_file_name)
   ruby_name = Gem::ConfigMap[:ruby_install_name] if inst.options[@env_shebang]
   ...
end

Using inst.options to access the passed in options but I have not verified it.

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