summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rodríguez <deivid.rodriguez@riseup.net>2025-01-21 17:36:17 +0100
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2025-01-28 15:31:52 +0900
commit47888801043e2c7ca8be03a5a5bbfae6cd1748b7 (patch)
tree57a5f03adba2bdc21c6eeb87dcb2d6c9b3c68c8d
parent4035003fd03d91b7b2856d97d58ad23f930e42cd (diff)
[rubygems/rubygems] Reuse platform constants
We need to move platform monkeypatching to happen earlier because otherwise `Bundler::GemHelpers` will use the constants before they have actually been defined. https://github.com/rubygems/rubygems/commit/086c3438dc
-rw-r--r--lib/bundler/gem_helpers.rb9
-rw-r--r--lib/bundler/rubygems_ext.rb160
2 files changed, 82 insertions, 87 deletions
diff --git a/lib/bundler/gem_helpers.rb b/lib/bundler/gem_helpers.rb
index 56aefadc74..0e8cba0d99 100644
--- a/lib/bundler/gem_helpers.rb
+++ b/lib/bundler/gem_helpers.rb
@@ -4,13 +4,8 @@ module Bundler
module GemHelpers
GENERIC_CACHE = { Gem::Platform::RUBY => Gem::Platform::RUBY } # rubocop:disable Style/MutableConstant
GENERICS = [
- Gem::Platform.new("java"),
- Gem::Platform.new("mswin32"),
- Gem::Platform.new("mswin64"),
- Gem::Platform.new("universal-mingw32"),
- Gem::Platform.new("x64-mingw32"),
- Gem::Platform.new("x64-mingw-ucrt"),
- Gem::Platform.new("x86-mingw32"),
+ Gem::Platform::JAVA,
+ *Gem::Platform::WINDOWS,
].freeze
def generic(p)
diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb
index bc7f65c7f7..6d4a8e5857 100644
--- a/lib/bundler/rubygems_ext.rb
+++ b/lib/bundler/rubygems_ext.rb
@@ -58,6 +58,86 @@ module Gem
end
end
+ require "rubygems/platform"
+
+ class Platform
+ JAVA = Gem::Platform.new("java")
+ MSWIN = Gem::Platform.new("mswin32")
+ MSWIN64 = Gem::Platform.new("mswin64")
+ MINGW = Gem::Platform.new("x86-mingw32")
+ X64_MINGW = [Gem::Platform.new("x64-mingw32"),
+ Gem::Platform.new("x64-mingw-ucrt")].freeze
+ WINDOWS = [MSWIN, MSWIN64, MINGW, X64_MINGW].flatten.freeze
+ X64_LINUX = Gem::Platform.new("x86_64-linux")
+ X64_LINUX_MUSL = Gem::Platform.new("x86_64-linux-musl")
+
+ if X64_LINUX === X64_LINUX_MUSL
+ remove_method :===
+
+ def ===(other)
+ return nil unless Gem::Platform === other
+
+ # universal-mingw32 matches x64-mingw-ucrt
+ return true if (@cpu == "universal" || other.cpu == "universal") &&
+ @os.start_with?("mingw") && other.os.start_with?("mingw")
+
+ # cpu
+ ([nil,"universal"].include?(@cpu) || [nil, "universal"].include?(other.cpu) || @cpu == other.cpu ||
+ (@cpu == "arm" && other.cpu.start_with?("armv"))) &&
+
+ # os
+ @os == other.os &&
+
+ # version
+ (
+ (@os != "linux" && (@version.nil? || other.version.nil?)) ||
+ (@os == "linux" && (normalized_linux_version_ext == other.normalized_linux_version_ext || ["musl#{@version}", "musleabi#{@version}", "musleabihf#{@version}"].include?(other.version))) ||
+ @version == other.version
+ )
+ end
+
+ # This is a copy of RubyGems 3.3.23 or higher `normalized_linux_method`.
+ # Once only 3.3.23 is supported, we can use the method in RubyGems.
+ def normalized_linux_version_ext
+ return nil unless @version
+
+ without_gnu_nor_abi_modifiers = @version.sub(/\Agnu/, "").sub(/eabi(hf)?\Z/, "")
+ return nil if without_gnu_nor_abi_modifiers.empty?
+
+ without_gnu_nor_abi_modifiers
+ end
+ end
+ end
+
+ Platform.singleton_class.module_eval do
+ unless Platform.singleton_methods.include?(:match_spec?)
+ def match_spec?(spec)
+ match_gem?(spec.platform, spec.name)
+ end
+
+ def match_gem?(platform, gem_name)
+ match_platforms?(platform, Gem.platforms)
+ end
+ end
+
+ match_platforms_defined = Gem::Platform.respond_to?(:match_platforms?, true)
+
+ if !match_platforms_defined || Gem::Platform.send(:match_platforms?, Gem::Platform::X64_LINUX_MUSL, [Gem::Platform::X64_LINUX])
+
+ private
+
+ remove_method :match_platforms? if match_platforms_defined
+
+ def match_platforms?(platform, platforms)
+ platforms.any? do |local_platform|
+ platform.nil? ||
+ local_platform == platform ||
+ (local_platform != Gem::Platform::RUBY && platform =~ local_platform)
+ end
+ end
+ end
+ end
+
require "rubygems/specification"
# Can be removed once RubyGems 3.5.14 support is dropped
@@ -288,86 +368,6 @@ module Gem
end
end
- require "rubygems/platform"
-
- class Platform
- JAVA = Gem::Platform.new("java")
- MSWIN = Gem::Platform.new("mswin32")
- MSWIN64 = Gem::Platform.new("mswin64")
- MINGW = Gem::Platform.new("x86-mingw32")
- X64_MINGW = [Gem::Platform.new("x64-mingw32"),
- Gem::Platform.new("x64-mingw-ucrt")].freeze
- WINDOWS = [MSWIN, MSWIN64, MINGW, X64_MINGW].flatten.freeze
- X64_LINUX = Gem::Platform.new("x86_64-linux")
- X64_LINUX_MUSL = Gem::Platform.new("x86_64-linux-musl")
-
- if X64_LINUX === X64_LINUX_MUSL
- remove_method :===
-
- def ===(other)
- return nil unless Gem::Platform === other
-
- # universal-mingw32 matches x64-mingw-ucrt
- return true if (@cpu == "universal" || other.cpu == "universal") &&
- @os.start_with?("mingw") && other.os.start_with?("mingw")
-
- # cpu
- ([nil,"universal"].include?(@cpu) || [nil, "universal"].include?(other.cpu) || @cpu == other.cpu ||
- (@cpu == "arm" && other.cpu.start_with?("armv"))) &&
-
- # os
- @os == other.os &&
-
- # version
- (
- (@os != "linux" && (@version.nil? || other.version.nil?)) ||
- (@os == "linux" && (normalized_linux_version_ext == other.normalized_linux_version_ext || ["musl#{@version}", "musleabi#{@version}", "musleabihf#{@version}"].include?(other.version))) ||
- @version == other.version
- )
- end
-
- # This is a copy of RubyGems 3.3.23 or higher `normalized_linux_method`.
- # Once only 3.3.23 is supported, we can use the method in RubyGems.
- def normalized_linux_version_ext
- return nil unless @version
-
- without_gnu_nor_abi_modifiers = @version.sub(/\Agnu/, "").sub(/eabi(hf)?\Z/, "")
- return nil if without_gnu_nor_abi_modifiers.empty?
-
- without_gnu_nor_abi_modifiers
- end
- end
- end
-
- Platform.singleton_class.module_eval do
- unless Platform.singleton_methods.include?(:match_spec?)
- def match_spec?(spec)
- match_gem?(spec.platform, spec.name)
- end
-
- def match_gem?(platform, gem_name)
- match_platforms?(platform, Gem.platforms)
- end
- end
-
- match_platforms_defined = Gem::Platform.respond_to?(:match_platforms?, true)
-
- if !match_platforms_defined || Gem::Platform.send(:match_platforms?, Gem::Platform::X64_LINUX_MUSL, [Gem::Platform::X64_LINUX])
-
- private
-
- remove_method :match_platforms? if match_platforms_defined
-
- def match_platforms?(platform, platforms)
- platforms.any? do |local_platform|
- platform.nil? ||
- local_platform == platform ||
- (local_platform != Gem::Platform::RUBY && platform =~ local_platform)
- end
- end
- end
- end
-
# On universal Rubies, resolve the "universal" arch to the real CPU arch, without changing the extension directory.
class BasicSpecification
if /^universal\.(?<arch>.*?)-/ =~ (CROSS_COMPILING || RUBY_PLATFORM)