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

ruby-changes:74398

From: Bo <ko1@a...>
Date: Wed, 9 Nov 2022 02:05:38 +0900 (JST)
Subject: [ruby-changes:74398] 0df47fdaf9 (master): [rubygems/rubygems] Add tests for universal Ruby with arch-specific prebuilt gems

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

From 0df47fdaf9c8bcfad0180aab81f9ceb162b360a1 Mon Sep 17 00:00:00 2001
From: Bo Anderson <mail@b...>
Date: Sat, 15 Oct 2022 22:51:39 +0100
Subject: [rubygems/rubygems] Add tests for universal Ruby with arch-specific
 prebuilt gems

https://github.com/rubygems/rubygems/commit/11229b16c3
---
 lib/bundler/rubygems_ext.rb                   |  2 +-
 spec/bundler/install/gemfile/platform_spec.rb | 75 +++++++++++++++++++++++++++
 spec/bundler/support/hax.rb                   |  5 ++
 spec/bundler/support/helpers.rb               |  8 +++
 4 files changed, 89 insertions(+), 1 deletion(-)

diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb
index 22cb797b5e..12d6789065 100644
--- a/lib/bundler/rubygems_ext.rb
+++ b/lib/bundler/rubygems_ext.rb
@@ -310,7 +310,7 @@ module Gem https://github.com/ruby/ruby/blob/trunk/lib/bundler/rubygems_ext.rb#L310
 
   # On universal Rubies, resolve the "universal" arch to the real CPU arch, without changing the extension directory.
   class Specification
-    if /^universal\.(?<arch>.*?)-/ =~ RUBY_PLATFORM
+    if /^universal\.(?<arch>.*?)-/ =~ (CROSS_COMPILING || RUBY_PLATFORM)
       local_platform = Platform.local
       if local_platform.cpu == "universal"
         ORIGINAL_LOCAL_PLATFORM = local_platform.to_s.freeze
diff --git a/spec/bundler/install/gemfile/platform_spec.rb b/spec/bundler/install/gemfile/platform_spec.rb
index 1bae0bb371..69918cf9f9 100644
--- a/spec/bundler/install/gemfile/platform_spec.rb
+++ b/spec/bundler/install/gemfile/platform_spec.rb
@@ -75,6 +75,81 @@ RSpec.describe "bundle install across platforms" do https://github.com/ruby/ruby/blob/trunk/spec/bundler/install/gemfile/platform_spec.rb#L75
     expect(the_bundle).to include_gems "platform_specific 1.0 RUBY"
   end
 
+  context "on universal Rubies" do
+    before do
+      build_repo4 do
+        build_gem "darwin_single_arch" do |s|
+          s.platform = "ruby"
+          s.write "lib/darwin_single_arch.rb", "DARWIN_SINGLE_ARCH = '1.0 RUBY'"
+        end
+        build_gem "darwin_single_arch" do |s|
+          s.platform = "arm64-darwin"
+          s.write "lib/darwin_single_arch.rb", "DARWIN_SINGLE_ARCH = '1.0 arm64-darwin'"
+        end
+        build_gem "darwin_single_arch" do |s|
+          s.platform = "x86_64-darwin"
+          s.write "lib/darwin_single_arch.rb", "DARWIN_SINGLE_ARCH = '1.0 x86_64-darwin'"
+        end
+      end
+    end
+
+    it "pulls in the correct architecture gem" do
+      lockfile <<-G
+        GEM
+          remote: #{file_uri_for(gem_repo4)}
+          specs:
+            darwin_single_arch (1.0)
+            darwin_single_arch (1.0-arm64-darwin)
+            darwin_single_arch (1.0-x86_64-darwin)
+
+        PLATFORMS
+          ruby
+
+        DEPENDENCIES
+          darwin_single_arch
+      G
+
+      simulate_platform "universal-darwin-21"
+      simulate_ruby_platform "universal.x86_64-darwin21" do
+        install_gemfile <<-G
+          source "#{file_uri_for(gem_repo4)}"
+
+          gem "darwin_single_arch"
+        G
+
+        expect(the_bundle).to include_gems "darwin_single_arch 1.0 x86_64-darwin"
+      end
+    end
+
+    it "pulls in the correct architecture gem on arm64e macOS Ruby" do
+      lockfile <<-G
+        GEM
+          remote: #{file_uri_for(gem_repo4)}
+          specs:
+            darwin_single_arch (1.0)
+            darwin_single_arch (1.0-arm64-darwin)
+            darwin_single_arch (1.0-x86_64-darwin)
+
+        PLATFORMS
+          ruby
+
+        DEPENDENCIES
+          darwin_single_arch
+      G
+
+      simulate_platform "universal-darwin-21"
+      simulate_ruby_platform "universal.arm64e-darwin21" do
+        install_gemfile <<-G
+          source "#{file_uri_for(gem_repo4)}"
+
+          gem "darwin_single_arch"
+        G
+
+        expect(the_bundle).to include_gems "darwin_single_arch 1.0 arm64-darwin"
+      end
+    end
+  end
+
   it "works with gems that have different dependencies" do
     simulate_platform "java"
     install_gemfile <<-G
diff --git a/spec/bundler/support/hax.rb b/spec/bundler/support/hax.rb
index da67e8c5d1..76e3b05ee1 100644
--- a/spec/bundler/support/hax.rb
+++ b/spec/bundler/support/hax.rb
@@ -1,5 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/spec/bundler/support/hax.rb#L1
 # frozen_string_literal: true
 
+if ENV["BUNDLER_SPEC_RUBY_PLATFORM"]
+  Object.send(:remove_const, :RUBY_PLATFORM)
+  RUBY_PLATFORM = ENV["BUNDLER_SPEC_RUBY_PLATFORM"]
+end
+
 module Gem
   def self.ruby=(ruby)
     @ruby = ruby
diff --git a/spec/bundler/support/helpers.rb b/spec/bundler/support/helpers.rb
index dfc358796a..1541f903c7 100644
--- a/spec/bundler/support/helpers.rb
+++ b/spec/bundler/support/helpers.rb
@@ -432,6 +432,14 @@ module Spec https://github.com/ruby/ruby/blob/trunk/spec/bundler/support/helpers.rb#L432
       pristine_system_gems :bundler
     end
 
+    def simulate_ruby_platform(ruby_platform)
+      old = ENV["BUNDLER_SPEC_RUBY_PLATFORM"]
+      ENV["BUNDLER_SPEC_RUBY_PLATFORM"] = ruby_platform.to_s
+      yield
+    ensure
+      ENV["BUNDLER_SPEC_RUBY_PLATFORM"] = old
+    end
+
     def simulate_platform(platform)
       old = ENV["BUNDLER_SPEC_PLATFORM"]
       ENV["BUNDLER_SPEC_PLATFORM"] = platform.to_s
-- 
cgit v1.2.3


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

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