Skip to content

Commit d9acc80

Browse files
Merge pull request #8833 from rubygems/deivid-rodriguez/drop-support-for-ancient-binstubs
Stop generating binstubs with support for RubyGems before 2.6.2
2 parents 9dda0c8 + 346d491 commit d9acc80

File tree

2 files changed

+77
-89
lines changed

2 files changed

+77
-89
lines changed

lib/rubygems/installer.rb

Lines changed: 38 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,6 @@ def check_executable_overwrite(filename) # :nodoc:
228228
ruby_executable = true
229229
existing = io.read.slice(/
230230
^\s*(
231-
gem \s |
232-
load \s Gem\.bin_path\( |
233231
load \s Gem\.activate_bin_path\(
234232
)
235233
(['"])(.*?)(\2),
@@ -749,54 +747,49 @@ def verify_spec
749747
def app_script_text(bin_file_name)
750748
# NOTE: that the `load` lines cannot be indented, as old RG versions match
751749
# against the beginning of the line
752-
<<-TEXT
753-
#{shebang bin_file_name}
754-
#
755-
# This file was generated by RubyGems.
756-
#
757-
# The application '#{spec.name}' is installed as part of a gem, and
758-
# this file is here to facilitate running it.
759-
#
760-
761-
require 'rubygems'
762-
#{gemdeps_load(spec.name)}
763-
version = "#{Gem::Requirement.default_prerelease}"
764-
765-
str = ARGV.first
766-
if str
767-
str = str.b[/\\A_(.*)_\\z/, 1]
768-
if str and Gem::Version.correct?(str)
769-
#{explicit_version_requirement(spec.name)}
770-
ARGV.shift
771-
end
772-
end
750+
<<~TEXT
751+
#{shebang bin_file_name}
752+
#
753+
# This file was generated by RubyGems.
754+
#
755+
# The application '#{spec.name}' is installed as part of a gem, and
756+
# this file is here to facilitate running it.
757+
#
758+
759+
require 'rubygems'
760+
#{gemdeps_load(spec.name)}
761+
version = "#{Gem::Requirement.default_prerelease}"
762+
763+
str = ARGV.first
764+
if str
765+
str = str.b[/\\A_(.*)_\\z/, 1]
766+
if str and Gem::Version.correct?(str)
767+
#{explicit_version_requirement(spec.name)}
768+
ARGV.shift
769+
end
770+
end
773771
774-
if Gem.respond_to?(:activate_bin_path)
775-
load Gem.activate_bin_path('#{spec.name}', '#{bin_file_name}', version)
776-
else
777-
gem #{spec.name.dump}, version
778-
load Gem.bin_path(#{spec.name.dump}, #{bin_file_name.dump}, version)
779-
end
780-
TEXT
772+
load Gem.activate_bin_path('#{spec.name}', '#{bin_file_name}', version)
773+
TEXT
781774
end
782775

783776
def gemdeps_load(name)
784777
return "" if name == "bundler"
785778

786-
<<-TEXT
779+
<<~TEXT
787780
788-
Gem.use_gemdeps
789-
TEXT
781+
Gem.use_gemdeps
782+
TEXT
790783
end
791784

792785
def explicit_version_requirement(name)
793786
code = "version = str"
794787
return code unless name == "bundler"
795788

796-
code += <<-TEXT
789+
code += <<~TEXT
797790
798-
ENV['BUNDLER_VERSION'] = str
799-
TEXT
791+
ENV['BUNDLER_VERSION'] = str
792+
TEXT
800793
end
801794

802795
##
@@ -811,26 +804,26 @@ def windows_stub_script(bindir, bin_file_name)
811804

812805
if File.exist?(File.join(bindir, ruby_exe))
813806
# stub & ruby.exe within same folder. Portable
814-
<<-TEXT
815-
@ECHO OFF
816-
@"%~dp0#{ruby_exe}" "%~dpn0" %*
807+
<<~TEXT
808+
@ECHO OFF
809+
@"%~dp0#{ruby_exe}" "%~dpn0" %*
817810
TEXT
818811
elsif bindir.downcase.start_with? rb_topdir.downcase
819812
# stub within ruby folder, but not standard bin. Portable
820813
require "pathname"
821814
from = Pathname.new bindir
822815
to = Pathname.new "#{rb_topdir}/bin"
823816
rel = to.relative_path_from from
824-
<<-TEXT
825-
@ECHO OFF
826-
@"%~dp0#{rel}/#{ruby_exe}" "%~dpn0" %*
817+
<<~TEXT
818+
@ECHO OFF
819+
@"%~dp0#{rel}/#{ruby_exe}" "%~dpn0" %*
827820
TEXT
828821
else
829822
# outside ruby folder, maybe -user-install or bundler. Portable, but ruby
830823
# is dependent on PATH
831-
<<-TEXT
832-
@ECHO OFF
833-
@#{ruby_exe} "%~dpn0" %*
824+
<<~TEXT
825+
@ECHO OFF
826+
@#{ruby_exe} "%~dpn0" %*
834827
TEXT
835828
end
836829
end

test/rubygems/test_gem_installer.rb

Lines changed: 39 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,31 @@ def test_app_script_text
2424

2525
util_make_exec @spec, ""
2626

27-
expected = <<-EOF
28-
#!#{Gem.ruby}
29-
#
30-
# This file was generated by RubyGems.
31-
#
32-
# The application 'a' is installed as part of a gem, and
33-
# this file is here to facilitate running it.
34-
#
35-
36-
require 'rubygems'
37-
38-
Gem.use_gemdeps
39-
40-
version = \">= 0.a\"
41-
42-
str = ARGV.first
43-
if str
44-
str = str.b[/\\A_(.*)_\\z/, 1]
45-
if str and Gem::Version.correct?(str)
46-
version = str
47-
ARGV.shift
48-
end
49-
end
27+
expected = <<~EOF
28+
#!#{Gem.ruby}
29+
#
30+
# This file was generated by RubyGems.
31+
#
32+
# The application 'a' is installed as part of a gem, and
33+
# this file is here to facilitate running it.
34+
#
35+
36+
require 'rubygems'
37+
38+
Gem.use_gemdeps
39+
40+
version = \">= 0.a\"
41+
42+
str = ARGV.first
43+
if str
44+
str = str.b[/\\A_(.*)_\\z/, 1]
45+
if str and Gem::Version.correct?(str)
46+
version = str
47+
ARGV.shift
48+
end
49+
end
5050
51-
if Gem.respond_to?(:activate_bin_path)
52-
load Gem.activate_bin_path('a', 'executable', version)
53-
else
54-
gem "a", version
55-
load Gem.bin_path("a", "executable", version)
56-
end
51+
load Gem.activate_bin_path('a', 'executable', version)
5752
EOF
5853

5954
wrapper = installer.app_script_text "executable"
@@ -121,12 +116,12 @@ def test_check_executable_overwrite_format_executable
121116
end
122117

123118
File.open File.join(util_inst_bindir, "executable"), "w" do |io|
124-
io.write <<-EXEC
125-
#!/usr/local/bin/ruby
126-
#
127-
# This file was generated by RubyGems
119+
io.write <<~EXEC
120+
#!/usr/local/bin/ruby
121+
#
122+
# This file was generated by RubyGems
128123
129-
gem 'other', version
124+
gem 'other', version
130125
EXEC
131126
end
132127

@@ -869,11 +864,11 @@ def test_use_plugin_immediately
869864
spec_version = spec.version
870865
plugin_path = File.join("lib", "rubygems_plugin.rb")
871866
write_file File.join(@tempdir, plugin_path) do |io|
872-
io.write <<-PLUGIN
873-
#{self.class}.plugin_loaded = true
874-
Gem.post_install do
875-
#{self.class}.post_install_is_called = true
876-
end
867+
io.write <<~PLUGIN
868+
#{self.class}.plugin_loaded = true
869+
Gem.post_install do
870+
#{self.class}.post_install_is_called = true
871+
end
877872
PLUGIN
878873
end
879874
spec.files += [plugin_path]
@@ -1557,7 +1552,7 @@ def test_find_lib_file_after_install
15571552
@spec = setup_base_spec
15581553
@spec.extensions << "extconf.rb"
15591554
write_dummy_extconf @spec.name do |io|
1560-
io.write <<-RUBY
1555+
io.write <<~RUBY
15611556
15621557
CONFIG['CC'] = '$(TOUCH) $@ ||'
15631558
CONFIG['LDSHARED'] = '$(TOUCH) $@ ||'
@@ -1569,7 +1564,7 @@ def test_find_lib_file_after_install
15691564
write_file File.join(@tempdir, "depend")
15701565

15711566
write_file File.join(@tempdir, "a.c") do |io|
1572-
io.write <<-C
1567+
io.write <<~C
15731568
#include <ruby.h>
15741569
void Init_a() { }
15751570
C
@@ -1606,7 +1601,7 @@ def test_install_extension_and_script
16061601
rb = File.join("lib", "#{@spec.name}.rb")
16071602
@spec.files += [rb]
16081603
write_file File.join(@tempdir, rb) do |io|
1609-
io.write <<-RUBY
1604+
io.write <<~RUBY
16101605
# #{@spec.name}.rb
16111606
RUBY
16121607
end
@@ -1615,7 +1610,7 @@ def test_install_extension_and_script
16151610
rb2 = File.join("lib", @spec.name, "#{@spec.name}.rb")
16161611
@spec.files << rb2
16171612
write_file File.join(@tempdir, rb2) do |io|
1618-
io.write <<-RUBY
1613+
io.write <<~RUBY
16191614
# #{@spec.name}/#{@spec.name}.rb
16201615
RUBY
16211616
end
@@ -1642,7 +1637,7 @@ def test_install_extension_flat
16421637
@spec.extensions << "extconf.rb"
16431638

16441639
write_dummy_extconf @spec.name do |io|
1645-
io.write <<-RUBY
1640+
io.write <<~RUBY
16461641
16471642
CONFIG['CC'] = '$(TOUCH) $@ ||'
16481643
CONFIG['LDSHARED'] = '$(TOUCH) $@ ||'

0 commit comments

Comments
 (0)