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

ruby-changes:73051

From: David <ko1@a...>
Date: Wed, 24 Aug 2022 17:59:29 +0900 (JST)
Subject: [ruby-changes:73051] 0ad9cc1696 (master): [rubygems/rubygems] Backport non-gnu libc on linux platform matching to Bundler

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

From 0ad9cc16966c2e56f0fe7e5992edf76033d3a83f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...>
Date: Thu, 4 Aug 2022 13:03:29 +0200
Subject: [rubygems/rubygems] Backport non-gnu libc on linux platform matching
 to Bundler

https://github.com/rubygems/rubygems/commit/703373b41f

Co-authored-by: Loic Nageleisen <loic.nageleisen@g...>
---
 lib/bundler/rubygems_ext.rb            | 26 ++++++++++++
 spec/bundler/resolver/platform_spec.rb | 73 ++++++++++++++++++++++++++++++++++
 spec/bundler/support/indexes.rb        |  4 ++
 3 files changed, 103 insertions(+)

diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb
index dee15f8ac2..d976170f12 100644
--- a/lib/bundler/rubygems_ext.rb
+++ b/lib/bundler/rubygems_ext.rb
@@ -237,6 +237,32 @@ module Gem https://github.com/ruby/ruby/blob/trunk/lib/bundler/rubygems_ext.rb#L237
     MINGW = Gem::Platform.new("x86-mingw32")
     X64_MINGW = [Gem::Platform.new("x64-mingw32"),
                  Gem::Platform.new("x64-mingw-ucrt")].freeze
+
+    if Gem::Platform.new("x86_64-linux-musl") === Gem::Platform.new("x86_64-linux")
+      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?("arm"))) &&
+
+          # os
+          @os == other.os &&
+
+          # version
+          (
+            (@os != "linux" && (@version.nil? || other.version.nil?)) ||
+            (@os == "linux" && ((@version.nil? && ["gnu", "musl"].include?(other.version)) || (@version == "gnu" && other.version.nil?))) ||
+            @version == other.version
+          )
+      end
+    end
   end
 
   Platform.singleton_class.module_eval do
diff --git a/spec/bundler/resolver/platform_spec.rb b/spec/bundler/resolver/platform_spec.rb
index 8eaed4220a..418293365c 100644
--- a/spec/bundler/resolver/platform_spec.rb
+++ b/spec/bundler/resolver/platform_spec.rb
@@ -82,6 +82,79 @@ RSpec.describe "Resolving platform craziness" do https://github.com/ruby/ruby/blob/trunk/spec/bundler/resolver/platform_spec.rb#L82
     should_resolve_as %w[foo-1.0.0-x64-mingw32]
   end
 
+  describe "on a linux platform", :rubygems => ">= 3.1.0.pre.1" do
+    # Ruby's platform is *-linux => platform's libc is glibc, so not musl
+    # Ruby's platform is *-linux-musl => platform's libc is musl, so not glibc
+    # Gem's platform is *-linux => gem is glibc + maybe musl compatible
+    # Gem's platform is *-linux-musl => gem is musl compatible but not glibc
+
+    it "favors the platform version-specific gem on a version-specifying linux platform" do
+      @index = build_index do
+        gem "foo", "1.0.0"
+        gem "foo", "1.0.0", "x86_64-linux"
+        gem "foo", "1.0.0", "x86_64-linux-musl"
+      end
+      dep "foo"
+      platforms "x86_64-linux-musl"
+
+      should_resolve_as %w[foo-1.0.0-x86_64-linux-musl]
+    end
+
+    it "favors the version-less gem over the version-specific gem on a gnu linux platform" do
+      @index = build_index do
+        gem "foo", "1.0.0"
+        gem "foo", "1.0.0", "x86_64-linux"
+        gem "foo", "1.0.0", "x86_64-linux-musl"
+      end
+      dep "foo"
+      platforms "x86_64-linux"
+
+      should_resolve_as %w[foo-1.0.0-x86_64-linux]
+    end
+
+    it "ignores the platform version-specific gem on a gnu linux platform" do
+      @index = build_index do
+        gem "foo", "1.0.0", "x86_64-linux-musl"
+      end
+      dep "foo"
+      platforms "x86_64-linux"
+
+      should_not_resolve
+    end
+
+    it "falls back to the platform version-less gem on a linux platform with a version" do
+      @index = build_index do
+        gem "foo", "1.0.0"
+        gem "foo", "1.0.0", "x86_64-linux"
+      end
+      dep "foo"
+      platforms "x86_64-linux-musl"
+
+      should_resolve_as %w[foo-1.0.0-x86_64-linux]
+    end
+
+    it "falls back to the ruby platform gem on a gnu linux platform when only a version-specifying gem is available" do
+      @index = build_index do
+        gem "foo", "1.0.0"
+        gem "foo", "1.0.0", "x86_64-linux-musl"
+      end
+      dep "foo"
+      platforms "x86_64-linux"
+
+      should_resolve_as %w[foo-1.0.0]
+    end
+
+    it "falls back to the platform version-less gem on a version-specifying linux platform and no ruby platform gem is available" do
+      @index = build_index do
+        gem "foo", "1.0.0", "x86_64-linux"
+      end
+      dep "foo"
+      platforms "x86_64-linux-musl"
+
+      should_resolve_as %w[foo-1.0.0-x86_64-linux]
+    end
+  end
+
   it "takes the latest ruby gem if the platform specific gem doesn't match the required_ruby_version" do
     @index = build_index do
       gem "foo", "1.0.0"
diff --git a/spec/bundler/support/indexes.rb b/spec/bundler/support/indexes.rb
index 55d798a90a..c496679ee6 100644
--- a/spec/bundler/support/indexes.rb
+++ b/spec/bundler/support/indexes.rb
@@ -33,6 +33,10 @@ module Spec https://github.com/ruby/ruby/blob/trunk/spec/bundler/support/indexes.rb#L33
       Bundler::Resolver.resolve(deps, source_requirements, *args)
     end
 
+    def should_not_resolve
+      expect { resolve }.to raise_error(Bundler::GemNotFound)
+    end
+
     def should_resolve_as(specs)
       got = resolve
       got = got.map(&:full_name).sort
-- 
cgit v1.2.1


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

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