1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/rubygems/installer.rb (Gem::Installer#shebang): fix for env

shebang.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22969 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2009-03-15 03:01:39 +00:00
parent 375258ed98
commit d85689f5cb
3 changed files with 19 additions and 19 deletions

View file

@ -1,3 +1,8 @@
Sun Mar 15 12:01:36 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/rubygems/installer.rb (Gem::Installer#shebang): fix for env
shebang.
Sun Mar 15 11:15:18 2009 Nobuyoshi Nakada <nobu@ruby-lang.org> Sun Mar 15 11:15:18 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* include/ruby/ruby.h ({RSTRING,RBIGNUM}_EMBED_LEN_MAX): made int. * include/ruby/ruby.h ({RSTRING,RBIGNUM}_EMBED_LEN_MAX): made int.

View file

@ -71,6 +71,8 @@ class Gem::Installer
end end
ENV_PATHS = %w[/usr/bin/env /bin/env]
## ##
# Constructs an Installer instance that will install the gem located at # Constructs an Installer instance that will install the gem located at
# +gem+. +options+ is a Hash with the following keys: # +gem+. +options+ is a Hash with the following keys:
@ -98,12 +100,7 @@ class Gem::Installer
:source_index => Gem.source_index, :source_index => Gem.source_index,
}.merge options }.merge options
if @env_shebang = options[:env_shebang] @env_shebang = options[:env_shebang]
unless File.executable?(shebang = "/usr/bin/env")
shebang = "/bin/env"
end
@env_shebang = shebang
end
@force = options[:force] @force = options[:force]
gem_home = options[:install_dir] gem_home = options[:install_dir]
@gem_home = Pathname.new(gem_home).expand_path @gem_home = Pathname.new(gem_home).expand_path
@ -392,25 +389,23 @@ class Gem::Installer
# necessary. # necessary.
def shebang(bin_file_name) def shebang(bin_file_name)
ruby_name = Gem::ConfigMap[:ruby_install_name] unless @env_shebang ruby_name = Gem::ConfigMap[:ruby_install_name] if @env_shebang
path = File.join @gem_dir, @spec.bindir, bin_file_name path = File.join @gem_dir, @spec.bindir, bin_file_name
first_line = File.open(path, "rb") {|file| file.gets} first_line = File.open(path, "rb") {|file| file.gets}
if /\A#!/ =~ first_line then if /\A#!/ =~ first_line then
# Preserve extra words on shebang line, like "-w". Thanks RPA. # Preserve extra words on shebang line, like "-w". Thanks RPA.
shebang = first_line.sub(/\A\#!.*?ruby\S*(?=\s*(\S+))/, "#!#{Gem.ruby}") shebang = first_line.sub(/\A\#!.*?ruby\S*(?=(\s+\S+))/, "#!#{Gem.ruby}")
opts = $1
shebang.strip! # Avoid nasty ^M issues. shebang.strip! # Avoid nasty ^M issues.
if ruby_name and $1 end
%{#!/bin/sh\n'exec' '#{ruby_name}' '-x' "$0" "$@"\n#{shebang}} if !ruby_name
else "#!#{Gem.ruby}#{opts}"
shebang elsif opts
end %{#!/bin/sh\n'exec' #{ruby_name.dump} '-x' "$0" "$@"\n#{shebang}}
else else
# Create a plain shebang line. # Create a plain shebang line.
if ruby_name @env_path ||= ENV_PATHS.find {|path| File.executable?(path)}
"#!#@env_shebang #{ruby_name}" "#!#{@env_path} #{ruby_name}"
else
"#!#{Gem.ruby}"
end
end end
end end

View file

@ -257,7 +257,7 @@ class TestGemDependencyInstaller < RubyGemTestCase
inst.install 'a' inst.install 'a'
end end
assert_match %r|\A#!/usr/bin/env #{Gem::ConfigMap[:RUBY_INSTALL_NAME]}\n|, assert_match %r|\A#!/\S+/env #{Gem::ConfigMap[:RUBY_INSTALL_NAME]}\n|,
File.read(File.join(@gemhome, 'bin', 'a_bin')) File.read(File.join(@gemhome, 'bin', 'a_bin'))
end end