[前][次][番号順一覧][スレッド一覧]

ruby-changes:72143

From: David <ko1@a...>
Date: Sun, 12 Jun 2022 02:02:33 +0900 (JST)
Subject: [ruby-changes:72143] d0bf31e6cf (master): [rubygems/rubygems] Don't on gemspecs with invalid `require_paths`, just warn

https://git.ruby-lang.org/ruby.git/commit/?id=d0bf31e6cf

From d0bf31e6cffa7537ed4b69a86c58b285433143f7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...>
Date: Sun, 27 Mar 2022 13:19:49 +0200
Subject: [rubygems/rubygems] Don't on gemspecs with invalid `require_paths`,
 just warn

These gemspecs already work most of the times. When they are installed
normally, the require_paths in the gemspec stub line becomes actually
correct, and the incorrect value in the real gemspec is ignored. It only
becomes an issue in standalone mode.

In Ruby 3.2, `Kernel#=~` has been removed, and that means that it
becomes harder for us to gracefully deal with this error in standalone
mode, because it now happens earlier due to calling `Array#=~` for this
invalid gemspec (since require_paths is incorrectly an array of arrays).

The easiest way to fix this is to actually make this just work instead
by automatically fixing the issue when reading the packaged gemspec.

https://github.com/rubygems/rubygems/commit/d3f2fe6d26
---
 lib/rubygems/specification.rb            |  8 ++++++++
 spec/bundler/realworld/edgecases_spec.rb | 12 +++++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb
index 01d3fd0eff..d8a212a04a 100644
--- a/lib/rubygems/specification.rb
+++ b/lib/rubygems/specification.rb
@@ -1081,6 +1081,7 @@ class Gem::Specification < Gem::BasicSpecification https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification.rb#L1081
 
     spec.specification_version ||= NONEXISTENT_SPECIFICATION_VERSION
     spec.reset_nil_attributes_to_default
+    spec.flatten_require_paths
 
     spec
   end
@@ -2674,6 +2675,13 @@ class Gem::Specification < Gem::BasicSpecification https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification.rb#L2675
     @installed_by_version ||= nil
   end
 
+  def flatten_require_paths # :nodoc:
+    return unless raw_require_paths.first.is_a?(Array)
+
+    warn "#{name} #{version} includes a gemspec with `require_paths` set to an array of arrays. Newer versions of this gem might've already fixed this"
+    raw_require_paths.flatten!
+  end
+
   def raw_require_paths # :nodoc:
     @require_paths
   end
diff --git a/spec/bundler/realworld/edgecases_spec.rb b/spec/bundler/realworld/edgecases_spec.rb
index df5eeda9fe..30c922efb0 100644
--- a/spec/bundler/realworld/edgecases_spec.rb
+++ b/spec/bundler/realworld/edgecases_spec.rb
@@ -196,7 +196,7 @@ RSpec.describe "real world edgecases", :realworld => true do https://github.com/ruby/ruby/blob/trunk/spec/bundler/realworld/edgecases_spec.rb#L196
     expect(lockfile).to include(rubygems_version("paperclip", "~> 5.1.0"))
   end
 
-  it "outputs a helpful error message when gems have invalid gemspecs" do
+  it "outputs a helpful error message when gems have invalid gemspecs", :rubygems => "< 3.3.16" do
     install_gemfile <<-G, :standalone => true, :raise_on_error => false, :env => { "BUNDLE_FORCE_RUBY_PLATFORM" => "1" }
       source 'https://rubygems.org'
       gem "resque-scheduler", "2.2.0"
@@ -207,6 +207,16 @@ RSpec.describe "real world edgecases", :realworld => true do https://github.com/ruby/ruby/blob/trunk/spec/bundler/realworld/edgecases_spec.rb#L207
     expect(err).to include("resque-scheduler 2.2.0 has an invalid gemspec")
   end
 
+  it "outputs a helpful warning when gems have a gemspec with invalid `require_paths`", :rubygems => ">= 3.3.16" do
+    install_gemfile <<-G, :standalone => true, :env => { "BUNDLE_FORCE_RUBY_PLATFORM" => "1" }
+      source 'https://rubygems.org'
+      gem "resque-scheduler", "2.2.0"
+      gem "redis-namespace", "1.6.0" # for a consistent resolution including ruby 2.3.0
+      gem "ruby2_keywords", "0.0.5"
+    G
+    expect(err).to include("resque-scheduler 2.2.0 includes a gemspec with `require_paths` set to an array of arrays. Newer versions of this gem might've already fixed this").once
+  end
+
   it "doesn't hang on big gemfile" do
     skip "Only for ruby 2.7.3" if RUBY_VERSION != "2.7.3" || RUBY_PLATFORM =~ /darwin/
 
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]