ruby-changes:72291
From: David <ko1@a...>
Date: Thu, 23 Jun 2022 18:17:47 +0900 (JST)
Subject: [ruby-changes:72291] 6f229da2c0 (master): [rubygems/rubygems] Fix standalone script generation for statically linked dev ruby
https://git.ruby-lang.org/ruby.git/commit/?id=6f229da2c0 From 6f229da2c07aec3441078248d7fd2fe844e8bc92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...> Date: Tue, 21 Jun 2022 18:45:45 +0200 Subject: [rubygems/rubygems] Fix standalone script generation for statically linked dev ruby https://github.com/rubygems/rubygems/commit/4d0d7b3c97 --- lib/bundler/installer/standalone.rb | 29 ++++++++++++++++++++++++---- spec/bundler/install/gems/standalone_spec.rb | 28 ++++++++++++++++++++++----- 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/lib/bundler/installer/standalone.rb b/lib/bundler/installer/standalone.rb index 2aba648e77..248b677233 100644 --- a/lib/bundler/installer/standalone.rb +++ b/lib/bundler/installer/standalone.rb @@ -12,6 +12,7 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/installer/standalone.rb#L12 end File.open File.join(bundler_path, "setup.rb"), "w" do |file| file.puts "require 'rbconfig'" + file.puts define_path_helpers file.puts reverse_rubygems_kernel_mixin paths.each do |path| if Pathname.new(path).absolute? @@ -30,19 +31,19 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/installer/standalone.rb#L31 next if spec.name == "bundler" Array(spec.require_paths).map do |path| gem_path(path, spec). - sub(version_dir, '#{RUBY_ENGINE}/#{RbConfig::CONFIG["ruby_version"]}'). - sub(extensions_dir, 'extensions/\k<platform>/#{RbConfig::CONFIG["ruby_version"]}') + sub(version_dir, '#{RUBY_ENGINE}/#{Gem.ruby_api_version}'). + sub(extensions_dir, 'extensions/\k<platform>/#{Gem.extension_api_version}') # This is a static string intentionally. It's interpolated at a later time. end end.flatten.compact end def version_dir - "#{RUBY_ENGINE}/#{RbConfig::CONFIG["ruby_version"]}" + "#{RUBY_ENGINE}/#{Gem.ruby_api_version}" end def extensions_dir - %r{extensions/(?<platform>[^/]+)/#{RbConfig::CONFIG["ruby_version"]}} + %r{extensions/(?<platform>[^/]+)/#{Regexp.escape(Gem.extension_api_version)}} end def bundler_path @@ -61,6 +62,26 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/installer/standalone.rb#L62 raise Gem::InvalidSpecificationException.new(error_message) end + def define_path_helpers + <<~'END' + unless defined?(Gem) + module Gem + def self.ruby_api_version + RbConfig::CONFIG["ruby_version"] + end + + def self.extension_api_version + if 'no' == RbConfig::CONFIG['ENABLE_SHARED'] + "#{ruby_api_version}-static" + else + ruby_api_version + end + end + end + end + END + end + def reverse_rubygems_kernel_mixin <<~END kernel = (class << ::Kernel; self; end) diff --git a/spec/bundler/install/gems/standalone_spec.rb b/spec/bundler/install/gems/standalone_spec.rb index f856d6b51e..fc1efe8d60 100644 --- a/spec/bundler/install/gems/standalone_spec.rb +++ b/spec/bundler/install/gems/standalone_spec.rb @@ -32,6 +32,21 @@ RSpec.shared_examples "bundle install --standalone" do https://github.com/ruby/ruby/blob/trunk/spec/bundler/install/gems/standalone_spec.rb#L32 expect(out).to eq(expected_gems.values.join("\n")) end + it "makes the gems available without bundler nor rubygems" do + testrb = String.new <<-RUBY + $:.unshift File.expand_path("bundle") + require "bundler/setup" + + RUBY + expected_gems.each do |k, _| + testrb << "\nrequire \"#{k}\"" + testrb << "\nputs #{k.upcase}" + end + sys_exec %(#{Gem.ruby} --disable-gems -w -e #{testrb.shellescape}) + + expect(out).to eq(expected_gems.values.join("\n")) + end + it "makes the gems available without bundler via Kernel.require" do testrb = String.new <<-RUBY $:.unshift File.expand_path("bundle") @@ -154,8 +169,8 @@ RSpec.shared_examples "bundle install --standalone" do https://github.com/ruby/ruby/blob/trunk/spec/bundler/install/gems/standalone_spec.rb#L169 load_path_lines = bundled_app("bundle/bundler/setup.rb").read.split("\n").select {|line| line.start_with?("$:.unshift") } expect(load_path_lines).to eq [ - '$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{RbConfig::CONFIG["ruby_version"]}/gems/bar-1.0.0/lib")', - '$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{RbConfig::CONFIG["ruby_version"]}/gems/foo-1.0.0/lib")', + '$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/bar-1.0.0/lib")', + '$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/foo-1.0.0/lib")', ] end end @@ -201,10 +216,13 @@ RSpec.shared_examples "bundle install --standalone" do https://github.com/ruby/ruby/blob/trunk/spec/bundler/install/gems/standalone_spec.rb#L216 it "generates a bundle/bundler/setup.rb with the proper paths" do expected_path = bundled_app("bundle/bundler/setup.rb") - extension_line = File.read(expected_path).each_line.find {|line| line.include? "/extensions/" }.strip + script_content = File.read(expected_path) + expect(script_content).to include("def self.ruby_api_version") + expect(script_content).to include("def self.extension_api_version") + extension_line = script_content.each_line.find {|line| line.include? "/extensions/" }.strip platform = Gem::Platform.local - expect(extension_line).to start_with '$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{RbConfig::CONFIG["ruby_version"]}/extensions/' - expect(extension_line).to end_with platform.to_s + '/#{RbConfig::CONFIG["ruby_version"]}/very_simple_binary-1.0")' + expect(extension_line).to start_with '$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/extensions/' + expect(extension_line).to end_with platform.to_s + '/#{Gem.extension_api_version}/very_simple_binary-1.0")' end end -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/