Skip to content

Commit 8aca221

Browse files
homusegiddins
authored andcommitted
Auto merge of #1904 - rubygems:seg-binstubs-backwards-compat, r=indirect
[Installer] Generate backwards-compatible binstubs # Description: Since older versions of RubyGems didn't include `Gem.activate_bin_path`, installing with the latest version would then make using the binstubs with an older RG version re-installed impossible. Re-introduce backwards compatibility in those binstubs. # Tasks: - [ ] Describe the problem / feature - [ ] Write tests - [ ] Write code to solve the problem - [ ] Get code review from coworkers / friends I will abide by the [code of conduct](https://github.com/rubygems/rubygems/blob/master/CODE_OF_CONDUCT.md). (cherry picked from commit 20bece5)
1 parent 2acfd65 commit 8aca221

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/rubygems/installer.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def check_executable_overwrite filename # :nodoc:
214214

215215
ruby_executable = true
216216
existing = io.read.slice(%r{
217-
^(
217+
^\s*(
218218
gem \s |
219219
load \s Gem\.bin_path\( |
220220
load \s Gem\.activate_bin_path\(
@@ -701,6 +701,8 @@ def verify_gem_home(unpack = false) # :nodoc:
701701
# Return the text for an application file.
702702

703703
def app_script_text(bin_file_name)
704+
# note that the `load` lines cannot be indented, as old RG versions match
705+
# against the beginning of the line
704706
return <<-TEXT
705707
#{shebang bin_file_name}
706708
#
@@ -723,7 +725,12 @@ def app_script_text(bin_file_name)
723725
end
724726
end
725727
728+
if Gem.respond_to?(:activate_bin_path)
726729
load Gem.activate_bin_path('#{spec.name}', '#{bin_file_name}', version)
730+
else
731+
gem #{spec.name.dump}, version
732+
load Gem.bin_path(#{spec.name.dump}, #{bin_file_name.dump}, version)
733+
end
727734
TEXT
728735
end
729736

test/rubygems/test_gem_installer.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,12 @@ def test_app_script_text
6262
end
6363
end
6464
65+
if Gem.respond_to?(:activate_bin_path)
6566
load Gem.activate_bin_path('a', 'executable', version)
67+
else
68+
gem "a", version
69+
load Gem.bin_path("a", "executable", version)
70+
end
6671
EOF
6772

6873
wrapper = @installer.app_script_text 'executable'

0 commit comments

Comments
 (0)