Blame SOURCES/rubygems-3.2.33-Fix-loading-operating_system-rb-customizations-too-late.patch

9a8c02
From e80e7a3d0b3d72f7af7286b935702b3fab117008 Mon Sep 17 00:00:00 2001
9a8c02
From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@riseup.net>
9a8c02
Date: Wed, 8 Dec 2021 21:12:24 +0100
9a8c02
Subject: [PATCH 1/5] More explicit require
9a8c02
9a8c02
This class does not use `rubygems/deprecate`. It uses
9a8c02
`rubygems/version`, which in turn uses `rubygems/deprecate`. Make this
9a8c02
explicit.
9a8c02
---
9a8c02
 lib/rubygems/requirement.rb | 2 +-
9a8c02
 1 file changed, 1 insertion(+), 1 deletion(-)
9a8c02
9a8c02
diff --git a/lib/rubygems/requirement.rb b/lib/rubygems/requirement.rb
9a8c02
index d2e28fab5b4..9edd6aa7d3c 100644
9a8c02
--- a/lib/rubygems/requirement.rb
9a8c02
+++ b/lib/rubygems/requirement.rb
9a8c02
@@ -1,5 +1,5 @@
9a8c02
 # frozen_string_literal: true
9a8c02
-require_relative "deprecate"
9a8c02
+require_relative "version"
9a8c02
 
9a8c02
 ##
9a8c02
 # A Requirement is a set of one or more version restrictions. It supports a
9a8c02
9a8c02
From 4e46dcc17ee5cabbde43b8a34063b8ab042536f9 Mon Sep 17 00:00:00 2001
9a8c02
From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@riseup.net>
9a8c02
Date: Wed, 8 Dec 2021 21:17:30 +0100
9a8c02
Subject: [PATCH 2/5] Remove ineffective autoloads
9a8c02
9a8c02
These files are loaded on startup unconditionally, so we can require
9a8c02
them relatively when needed.
9a8c02
---
9a8c02
 lib/rubygems.rb               | 4 +---
9a8c02
 lib/rubygems/specification.rb | 2 ++
9a8c02
 2 files changed, 3 insertions(+), 3 deletions(-)
9a8c02
9a8c02
diff --git a/lib/rubygems.rb b/lib/rubygems.rb
9a8c02
index f803e47628e..b8747409304 100644
9a8c02
--- a/lib/rubygems.rb
9a8c02
+++ b/lib/rubygems.rb
9a8c02
@@ -1310,19 +1310,17 @@ def default_gem_load_paths
9a8c02
   autoload :Licenses,           File.expand_path('rubygems/util/licenses', __dir__)
9a8c02
   autoload :NameTuple,          File.expand_path('rubygems/name_tuple', __dir__)
9a8c02
   autoload :PathSupport,        File.expand_path('rubygems/path_support', __dir__)
9a8c02
-  autoload :Platform,           File.expand_path('rubygems/platform', __dir__)
9a8c02
   autoload :RequestSet,         File.expand_path('rubygems/request_set', __dir__)
9a8c02
-  autoload :Requirement,        File.expand_path('rubygems/requirement', __dir__)
9a8c02
   autoload :Resolver,           File.expand_path('rubygems/resolver', __dir__)
9a8c02
   autoload :Source,             File.expand_path('rubygems/source', __dir__)
9a8c02
   autoload :SourceList,         File.expand_path('rubygems/source_list', __dir__)
9a8c02
   autoload :SpecFetcher,        File.expand_path('rubygems/spec_fetcher', __dir__)
9a8c02
-  autoload :Specification,      File.expand_path('rubygems/specification', __dir__)
9a8c02
   autoload :Util,               File.expand_path('rubygems/util', __dir__)
9a8c02
   autoload :Version,            File.expand_path('rubygems/version', __dir__)
9a8c02
 end
9a8c02
 
9a8c02
 require_relative 'rubygems/exceptions'
9a8c02
+require_relative 'rubygems/specification'
9a8c02
 
9a8c02
 # REFACTOR: This should be pulled out into some kind of hacks file.
9a8c02
 begin
9a8c02
diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb
9a8c02
index d3b96491a28..dc5e5ba0138 100644
9a8c02
--- a/lib/rubygems/specification.rb
9a8c02
+++ b/lib/rubygems/specification.rb
9a8c02
@@ -9,6 +9,8 @@
9a8c02
 require_relative 'deprecate'
9a8c02
 require_relative 'basic_specification'
9a8c02
 require_relative 'stub_specification'
9a8c02
+require_relative 'platform'
9a8c02
+require_relative 'requirement'
9a8c02
 require_relative 'specification_policy'
9a8c02
 require_relative 'util/list'
9a8c02
 
9a8c02
9a8c02
From 96b6b3e04e8e4fec17f63079a0caf999a2709d71 Mon Sep 17 00:00:00 2001
9a8c02
From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@riseup.net>
9a8c02
Date: Wed, 8 Dec 2021 21:45:16 +0100
9a8c02
Subject: [PATCH 3/5] Load `operating_system.rb` customizations before setting
9a8c02
 up default gems
9a8c02
9a8c02
It's very common for packagers to configure gem paths in this file, for
9a8c02
example, `Gem.default_dir`. Also, setting up default gems requires these
9a8c02
paths to be set, so that we know which default gems need to be setup.
9a8c02
9a8c02
If we setup default gems before loading `operatin_system.rb`
9a8c02
customizations, the wrong default gems will be setup.
9a8c02
9a8c02
Unfortunately, default gems loaded by `operating_system.rb` can't be
9a8c02
upgraded if we do this, but it seems much of a smaller issue. I wasn't
9a8c02
even fully sure it was the right thing to do when I added that, and it
9a8c02
was not the culprit of the end user issue that led to making that
9a8c02
change.
9a8c02
---
9a8c02
 lib/rubygems.rb                | 32 ++++++++++++++++----------------
9a8c02
 test/rubygems/test_rubygems.rb | 23 +++++++++++++++++++++++
9a8c02
 2 files changed, 39 insertions(+), 16 deletions(-)
9a8c02
9a8c02
diff --git a/lib/rubygems.rb b/lib/rubygems.rb
9a8c02
index b8747409304..11474b6554c 100644
9a8c02
--- a/lib/rubygems.rb
9a8c02
+++ b/lib/rubygems.rb
9a8c02
@@ -1323,22 +1323,6 @@ def default_gem_load_paths
9a8c02
 require_relative 'rubygems/specification'
9a8c02
 
9a8c02
 # REFACTOR: This should be pulled out into some kind of hacks file.
9a8c02
-begin
9a8c02
-  ##
9a8c02
-  # Defaults the Ruby implementation wants to provide for RubyGems
9a8c02
-
9a8c02
-  require "rubygems/defaults/#{RUBY_ENGINE}"
9a8c02
-rescue LoadError
9a8c02
-end
9a8c02
-
9a8c02
-##
9a8c02
-# Loads the default specs.
9a8c02
-Gem::Specification.load_defaults
9a8c02
-
9a8c02
-require_relative 'rubygems/core_ext/kernel_gem'
9a8c02
-require_relative 'rubygems/core_ext/kernel_require'
9a8c02
-require_relative 'rubygems/core_ext/kernel_warn'
9a8c02
-
9a8c02
 begin
9a8c02
   ##
9a8c02
   # Defaults the operating system (or packager) wants to provide for RubyGems.
9a8c02
@@ -1354,3 +1338,19 @@ def default_gem_load_paths
9a8c02
     "the problem and ask for help."
9a8c02
   raise e.class, msg
9a8c02
 end
9a8c02
+
9a8c02
+begin
9a8c02
+  ##
9a8c02
+  # Defaults the Ruby implementation wants to provide for RubyGems
9a8c02
+
9a8c02
+  require "rubygems/defaults/#{RUBY_ENGINE}"
9a8c02
+rescue LoadError
9a8c02
+end
9a8c02
+
9a8c02
+##
9a8c02
+# Loads the default specs.
9a8c02
+Gem::Specification.load_defaults
9a8c02
+
9a8c02
+require_relative 'rubygems/core_ext/kernel_gem'
9a8c02
+require_relative 'rubygems/core_ext/kernel_require'
9a8c02
+require_relative 'rubygems/core_ext/kernel_warn'
9a8c02
diff --git a/test/rubygems/test_rubygems.rb b/test/rubygems/test_rubygems.rb
9a8c02
index 493b9fdf4a3..fa77a299322 100644
9a8c02
--- a/test/rubygems/test_rubygems.rb
9a8c02
+++ b/test/rubygems/test_rubygems.rb
9a8c02
@@ -22,6 +22,29 @@ def test_operating_system_other_exceptions
9a8c02
     "the problem and ask for help."
9a8c02
   end
9a8c02
 
9a8c02
+  def test_operating_system_customizing_default_dir
9a8c02
+    pend "does not apply to truffleruby" if RUBY_ENGINE == 'truffleruby'
9a8c02
+    pend "loads a custom defaults/jruby file that gets in the middle" if RUBY_ENGINE == 'jruby'
9a8c02
+
9a8c02
+    # On a non existing default dir, there should be no gems
9a8c02
+
9a8c02
+    path = util_install_operating_system_rb <<-RUBY
9a8c02
+      module Gem
9a8c02
+        def self.default_dir
9a8c02
+          File.expand_path("foo")
9a8c02
+        end
9a8c02
+      end
9a8c02
+    RUBY
9a8c02
+
9a8c02
+    output = Gem::Util.popen(
9a8c02
+      *ruby_with_rubygems_and_fake_operating_system_in_load_path(path),
9a8c02
+      '-e',
9a8c02
+      "require \"rubygems\"; puts Gem::Specification.stubs.map(&:full_name)",
9a8c02
+      {:err => [:child, :out]}
9a8c02
+    ).strip
9a8c02
+    assert_empty output
9a8c02
+  end
9a8c02
+
9a8c02
   private
9a8c02
 
9a8c02
   def util_install_operating_system_rb(content)
9a8c02
9a8c02
From 52cfdd14fd1213a97aac12f01177e27779de9035 Mon Sep 17 00:00:00 2001
9a8c02
From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@riseup.net>
9a8c02
Date: Thu, 9 Dec 2021 06:08:31 +0100
9a8c02
Subject: [PATCH 4/5] Install default fiddle on latest ruby on specs that need
9a8c02
 it
9a8c02
9a8c02
Otherwise first OS customizations load and activate that fiddle version,
9a8c02
but then when we change to `Gem.default_dir`, that fiddle version is no
9a8c02
longer there.
9a8c02
---
9a8c02
 spec/bundler/commands/clean_spec.rb          | 2 +-
9a8c02
 spec/bundler/install/gems/standalone_spec.rb | 2 +-
9a8c02
 2 files changed, 2 insertions(+), 2 deletions(-)
9a8c02
9a8c02
diff --git a/spec/bundler/commands/clean_spec.rb b/spec/bundler/commands/clean_spec.rb
9a8c02
index ffaf22dbb32..65231b35fac 100644
9a8c02
--- a/spec/bundler/commands/clean_spec.rb
9a8c02
+++ b/spec/bundler/commands/clean_spec.rb
9a8c02
@@ -638,7 +638,7 @@ def should_not_have_gems(*gems)
9a8c02
       s.executables = "irb"
9a8c02
     end
9a8c02
 
9a8c02
-    realworld_system_gems "fiddle --version 1.0.6", "tsort --version 0.1.0", "pathname --version 0.1.0", "set --version 1.0.1"
9a8c02
+    realworld_system_gems "fiddle --version 1.0.8", "tsort --version 0.1.0", "pathname --version 0.1.0", "set --version 1.0.1"
9a8c02
 
9a8c02
     install_gemfile <<-G
9a8c02
       source "#{file_uri_for(gem_repo2)}"
9a8c02
diff --git a/spec/bundler/install/gems/standalone_spec.rb b/spec/bundler/install/gems/standalone_spec.rb
9a8c02
index db16a1b0e13..faefda25f45 100644
9a8c02
--- a/spec/bundler/install/gems/standalone_spec.rb
9a8c02
+++ b/spec/bundler/install/gems/standalone_spec.rb
9a8c02
@@ -113,7 +113,7 @@
9a8c02
       skip "does not work on rubygems versions where `--install_dir` doesn't respect --default" unless Gem::Installer.for_spec(loaded_gemspec, :install_dir => "/foo").default_spec_file == "/foo/specifications/default/bundler-#{Bundler::VERSION}.gemspec" # Since rubygems 3.2.0.rc.2
9a8c02
       skip "does not work on old rubies because the realworld gems that need to be installed don't support them" if RUBY_VERSION < "2.7.0"
9a8c02
 
9a8c02
-      realworld_system_gems "fiddle --version 1.0.6", "tsort --version 0.1.0"
9a8c02
+      realworld_system_gems "fiddle --version 1.0.8", "tsort --version 0.1.0"
9a8c02
 
9a8c02
       necessary_system_gems = ["optparse --version 0.1.1", "psych --version 3.3.2", "yaml --version 0.1.1", "logger --version 1.4.3", "etc --version 1.2.0", "stringio --version 3.0.0"]
9a8c02
       necessary_system_gems += ["shellwords --version 0.1.0", "base64 --version 0.1.0", "resolv --version 0.2.1"] if Gem.rubygems_version < Gem::Version.new("3.3.3.a")
9a8c02
9a8c02
From c6a9c81021092c9157f5616a2bbe1323411a5bf8 Mon Sep 17 00:00:00 2001
9a8c02
From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@riseup.net>
9a8c02
Date: Thu, 9 Dec 2021 12:46:23 +0100
9a8c02
Subject: [PATCH 5/5] Resolve symlinks in LOAD_PATH when activating
9a8c02
 pre-required default gems
9a8c02
9a8c02
Some double load issues were reported a while ago by OS packagers where
9a8c02
if a gem has been required before rubygems, and then after, rubygems
9a8c02
require would cause a double load.
9a8c02
9a8c02
We avoid this issue by activating the corresponding gem if we detect
9a8c02
that a file in the default LOAD_PATH that belongs to a default gem has
9a8c02
already been required when rubygems registers default gems.
9a8c02
9a8c02
However, the fix does not take into account that the default LOAD_PATH
9a8c02
could potentially include symlinks. This change fixes the same double
9a8c02
load issue described above but for situations where the default
9a8c02
LOAD_PATH includes symlinks.
9a8c02
---
9a8c02
 lib/rubygems.rb | 7 ++++++-
9a8c02
 1 file changed, 6 insertions(+), 1 deletion(-)
9a8c02
9a8c02
diff --git a/lib/rubygems.rb b/lib/rubygems.rb
9a8c02
index 11474b6554c..b7dda38d522 100644
9a8c02
--- a/lib/rubygems.rb
9a8c02
+++ b/lib/rubygems.rb
9a8c02
@@ -1293,7 +1293,12 @@ def already_loaded?(file)
9a8c02
     end
9a8c02
 
9a8c02
     def default_gem_load_paths
9a8c02
-      @default_gem_load_paths ||= $LOAD_PATH[load_path_insert_index..-1]
9a8c02
+      @default_gem_load_paths ||= $LOAD_PATH[load_path_insert_index..-1].map do |lp|
9a8c02
+        expanded = File.expand_path(lp)
9a8c02
+        next expanded unless File.exist?(expanded)
9a8c02
+
9a8c02
+        File.realpath(expanded)
9a8c02
+      end
9a8c02
     end
9a8c02
   end
9a8c02