From 2d93d8c1a0ffccbcceb7d7581aa4b635731ea7c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Tue, 29 Sep 2020 12:23:14 +0200 Subject: [PATCH] No need to monkeypatch rubygems, actually --- bundler/lib/bundler/dsl.rb | 2 +- bundler/lib/bundler/gem_helper.rb | 4 ++-- bundler/lib/bundler/rubygems_ext.rb | 16 ---------------- bundler/lib/bundler/shared_helpers.rb | 8 ++++++++ bundler/lib/bundler/source/path.rb | 2 +- 5 files changed, 12 insertions(+), 20 deletions(-) diff --git a/bundler/lib/bundler/dsl.rb b/bundler/lib/bundler/dsl.rb index 1cc7908b8a88..b915deb64391 100644 --- a/bundler/lib/bundler/dsl.rb +++ b/bundler/lib/bundler/dsl.rb @@ -63,7 +63,7 @@ def gemspec(opts = nil) development_group = opts[:development_group] || :development expanded_path = gemfile_root.join(path) - gemspecs = Gem::Util.glob_files_in_dir("{,*}.gemspec", expanded_path).map {|g| Bundler.load_gemspec(g) }.compact + gemspecs = Bundler::SharedHelpers.glob_files_in_dir("{,*}.gemspec", expanded_path).map {|g| Bundler.load_gemspec(g) }.compact gemspecs.reject! {|s| s.name != name } if name Index.sort_specs(gemspecs) specs_by_name_and_version = gemspecs.group_by {|s| [s.name, s.version] } diff --git a/bundler/lib/bundler/gem_helper.rb b/bundler/lib/bundler/gem_helper.rb index 4ada36aef487..8db5a9892fad 100644 --- a/bundler/lib/bundler/gem_helper.rb +++ b/bundler/lib/bundler/gem_helper.rb @@ -32,7 +32,7 @@ def gemspec(&block) def initialize(base = nil, name = nil) @base = File.expand_path(base || SharedHelpers.pwd) - gemspecs = name ? [File.join(@base, "#{name}.gemspec")] : Gem::Util.glob_files_in_dir("{,*}.gemspec", @base) + gemspecs = name ? [File.join(@base, "#{name}.gemspec")] : SharedHelpers.glob_files_in_dir("{,*}.gemspec", @base) raise "Unable to determine name from existing gemspec. Use :name => 'gemname' in #install_tasks to manually set it." unless gemspecs.size == 1 @spec_path = gemspecs.first @gemspec = Bundler.load_gemspec(@spec_path) @@ -111,7 +111,7 @@ def rubygem_push(path) end def built_gem_path - Gem::Util.glob_files_in_dir("#{name}-*.gem", base).sort_by {|f| File.mtime(f) }.last + SharedHelpers.glob_files_in_dir("#{name}-*.gem", base).sort_by {|f| File.mtime(f) }.last end def git_push(remote = nil) diff --git a/bundler/lib/bundler/rubygems_ext.rb b/bundler/lib/bundler/rubygems_ext.rb index 0322b06d0787..82816d24fab2 100644 --- a/bundler/lib/bundler/rubygems_ext.rb +++ b/bundler/lib/bundler/rubygems_ext.rb @@ -173,22 +173,6 @@ def hash undef_method :eql? if method_defined? :eql? alias_method :eql?, :== end - - require "rubygems/util" - - Util.singleton_class.module_eval do - if Util.singleton_methods.include?(:glob_files_in_dir) # since 3.0.0.beta.2 - remove_method :glob_files_in_dir - end - - def glob_files_in_dir(glob, base_path) - if RUBY_VERSION >= "2.5" - Dir.glob(glob, :base => base_path).map! {|f| File.expand_path(f, base_path) } - else - Dir.glob(File.join(base_path.to_s.gsub(/[\[\]]/, '\\\\\\&'), glob)).map! {|f| File.expand_path(f) } - end - end - end end module Gem diff --git a/bundler/lib/bundler/shared_helpers.rb b/bundler/lib/bundler/shared_helpers.rb index a56a3bff4b5e..58f23c3c43de 100644 --- a/bundler/lib/bundler/shared_helpers.rb +++ b/bundler/lib/bundler/shared_helpers.rb @@ -205,6 +205,14 @@ def write_to_gemfile(gemfile_path, contents) filesystem_access(gemfile_path) {|g| File.open(g, "w") {|file| file.puts contents } } end + def glob_files_in_dir(glob, base_path) + if RUBY_VERSION >= "2.5" + Dir.glob(glob, :base => base_path).map! {|f| File.expand_path(f, base_path) } + else + Dir.glob(File.join(base_path.to_s.gsub(/[\[\]]/, '\\\\\\&'), glob)).map! {|f| File.expand_path(f) } + end + end + private def validate_bundle_path diff --git a/bundler/lib/bundler/source/path.rb b/bundler/lib/bundler/source/path.rb index 2c2e9023b3d4..928c0e606419 100644 --- a/bundler/lib/bundler/source/path.rb +++ b/bundler/lib/bundler/source/path.rb @@ -171,7 +171,7 @@ def load_spec_files if File.directory?(expanded_path) # We sort depth-first since `<<` will override the earlier-found specs - Gem::Util.glob_files_in_dir(@glob, expanded_path).sort_by {|p| -p.split(File::SEPARATOR).size }.each do |file| + SharedHelpers.glob_files_in_dir(@glob, expanded_path).sort_by {|p| -p.split(File::SEPARATOR).size }.each do |file| next unless spec = load_gemspec(file) spec.source = self