aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDavid Rodríguez <deivid.rodriguez@riseup.net>2019-10-21 19:26:51 +0200
committergit <svn-admin@ruby-lang.org>2022-01-15 00:00:11 +0900
commit7d42b442bb42d8958daf978a0fe14b948f49609f (patch)
treea9266d936aa31b89e79ff937dbe8eb0e180c2028 /lib
parent044b0ae8e054b9959dc48bd5e663cbf2dea653a4 (diff)
downloadruby-7d42b442bb42d8958daf978a0fe14b948f49609f.tar.gz
[rubygems/rubygems] Support binstubs with `--enable-load-relative` prolog
https://github.com/rubygems/rubygems/commit/32a5e9057a
Diffstat (limited to 'lib')
-rw-r--r--lib/rubygems/installer.rb48
1 files changed, 40 insertions, 8 deletions
diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb
index 0224b91898..4cda09f200 100644
--- a/lib/rubygems/installer.rb
+++ b/lib/rubygems/installer.rb
@@ -220,7 +220,17 @@ class Gem::Installer
existing = nil
File.open generated_bin, 'rb' do |io|
- next unless io.gets =~ /^#!/ # shebang
+ line = io.gets
+ shebang = /^#!.*ruby/
+
+ if load_relative_enabled?
+ until line.nil? || line =~ shebang do
+ line = io.gets
+ end
+ end
+
+ next unless line =~ shebang
+
io.gets # blankline
# TODO detect a specially formatted comment instead of trying
@@ -585,7 +595,6 @@ class Gem::Installer
#
def shebang(bin_file_name)
- ruby_name = ruby_install_name if @env_shebang
path = File.join gem_dir, spec.bindir, bin_file_name
first_line = File.open(path, "rb") {|file| file.gets } || ""
@@ -614,14 +623,12 @@ class Gem::Installer
end
"#!#{which}"
- elsif not ruby_name
- "#!#{Gem.ruby}#{opts}"
- elsif opts
- "#!/bin/sh\n'exec' #{ruby_name.dump} '-x' \"$0\" \"$@\"\n#{shebang}"
- else
+ elsif @env_shebang
# Create a plain shebang line.
@env_path ||= ENV_PATHS.find {|env_path| File.executable? env_path }
- "#!#{@env_path} #{ruby_name}"
+ "#!#{@env_path} #{ruby_install_name}"
+ else
+ "#{bash_prolog_script}#!#{Gem.ruby}#{opts}"
end
end
@@ -980,4 +987,29 @@ TEXT
def ruby_install_name
rb_config["ruby_install_name"]
end
+
+ def load_relative_enabled?
+ rb_config["LIBRUBY_RELATIVE"] == 'yes'
+ end
+
+ def bash_prolog_script
+ if load_relative_enabled?
+ script = +<<~EOS
+ bindir="${0%/*}"
+ EOS
+
+ script << %Q(exec "$bindir/#{ruby_install_name}" "-x" "$0" "$@"\n)
+
+ <<~EOS
+ #!/bin/sh
+ # -*- ruby -*-
+ _=_\\
+ =begin
+ #{script.chomp}
+ =end
+ EOS
+ else
+ ""
+ end
+ end
end