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

ruby-changes:61528

From: David <ko1@a...>
Date: Fri, 5 Jun 2020 07:34:01 +0900 (JST)
Subject: [ruby-changes:61528] 8e5fe13c08 (master): [rubygems/rubygems] Delay `fileutils` loading to fix some warnings

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

From 8e5fe13c089717c9516b1a7eb0fe22d0fbe7b25f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...>
Date: Tue, 19 May 2020 12:08:43 +0200
Subject: [rubygems/rubygems] Delay `fileutils` loading to fix some warnings

If the following conditions are met:

* You have a default version of fileutils and a higher version of
fileutils installed as a regular gem. This case is common on ruby 2.6.

* You use a bundler generated binstub on a gem setup with a `Gemfile`
using the `gemspec` DSL.

Then `fileutils` redefinition warnings happen because of the following:

The gist of a bundler generated binstub is:

```ruby
require "bundler/setup"
load Gem.bin_path("rake", "rake")
```

First configure bundler, then load the requested gem.

When `require "bundler/setup"` is called under the previously mentioned
setup, `ext_conf_builder.rb` ends up being required because of the new
validation that gemspecs with rake extensions depend on `rake`. And that
loads the latest version of `fileutils` because of using "rubygems
monkeypatched require" that auto-chooses the latest version of default
gems.

After that, when `Gem.bin_path` gets called, `ext_conf_builder.rb` gets
required again, but this time already using "bundler's unmonkeypatched
require" which means the default version is chosen and thus the
redefinition warning happens.

The solution as usual is to lazily load `fileutils`.

https://github.com/rubygems/rubygems/commit/08d64e5f06

diff --git a/lib/rubygems/ext/ext_conf_builder.rb b/lib/rubygems/ext/ext_conf_builder.rb
index d06e923..1fe1ea8 100644
--- a/lib/rubygems/ext/ext_conf_builder.rb
+++ b/lib/rubygems/ext/ext_conf_builder.rb
@@ -5,15 +5,14 @@ https://github.com/ruby/ruby/blob/trunk/lib/rubygems/ext/ext_conf_builder.rb#L5
 # See LICENSE.txt for permissions.
 #++
 
-require 'fileutils'
-require 'tempfile'
 require 'shellwords'
 
 class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder
 
-  FileEntry = FileUtils::Entry_ # :nodoc:
-
   def self.build(extension, dest_path, results, args=[], lib_dir=nil)
+    require 'fileutils'
+    require 'tempfile'
+
     tmp_dest = Dir.mktmpdir(".gem.", ".")
 
     # Some versions of `mktmpdir` return absolute paths, which will break make
@@ -71,7 +70,7 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder https://github.com/ruby/ruby/blob/trunk/lib/rubygems/ext/ext_conf_builder.rb#L70
             FileUtils.cp_r entries, lib_dir, :remove_destination => true
           end
 
-          FileEntry.new(tmp_dest).traverse do |ent|
+          FileUtils::Entry_.new(tmp_dest).traverse do |ent|
             destent = ent.class.new(dest_path, ent.rel)
             destent.exist? or FileUtils.mv(ent.path, destent.path)
           end
-- 
cgit v0.10.2


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

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