From db02afc41e4916713403a89290eaca34d6efd7c7 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Wed, 19 Feb 2025 17:53:50 +0900 Subject: [PATCH 1/5] Skip to warn if target specification is different from the current RUBY_PLATFORM with java and JRuby platforms --- bundler/lib/bundler/stub_specification.rb | 6 +++++- lib/rubygems/basic_specification.rb | 8 ++++++-- test/rubygems/test_gem.rb | 6 +++++- test/rubygems/test_gem_specification.rb | 6 +++++- test/rubygems/test_gem_stub_specification.rb | 6 +++++- 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/bundler/lib/bundler/stub_specification.rb b/bundler/lib/bundler/stub_specification.rb index 026f753d411f..9ba456ad3527 100644 --- a/bundler/lib/bundler/stub_specification.rb +++ b/bundler/lib/bundler/stub_specification.rb @@ -38,7 +38,11 @@ def ignored? @ignored = missing_extensions? return false unless @ignored - warn "Source #{source} is ignoring #{self} because it is missing extensions" + # If we share GEM_HOME for all of Ruby platform, the platform specific gem always warn that specification. + # ex `jruby-launcher` and CRuby + if RUBY_PLATFORM != Gem::Platform::JAVA + warn "Source #{source} is ignoring #{self} because it is missing extensions" + end true end diff --git a/lib/rubygems/basic_specification.rb b/lib/rubygems/basic_specification.rb index a0b552f63ceb..f5c1d036dde6 100644 --- a/lib/rubygems/basic_specification.rb +++ b/lib/rubygems/basic_specification.rb @@ -73,8 +73,12 @@ def base_dir def contains_requirable_file?(file) if ignored? if platform == Gem::Platform::RUBY || Gem::Platform.local === platform - warn "Ignoring #{full_name} because its extensions are not built. " \ - "Try: gem pristine #{name} --version #{version}" + # RubyGems warns gem specification of C extensions. But JRuby couldn't + # rebuild with `gem pristine` command. So, we skip the warning. + if RUBY_PLATFORM != Gem::Platform::JAVA + warn "Ignoring #{full_name} because its extensions are not built. " \ + "Try: gem pristine #{name} --version #{version}" + end end return false diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb index cdc3479e3739..49dd4c88baec 100644 --- a/test/rubygems/test_gem.rb +++ b/test/rubygems/test_gem.rb @@ -1308,8 +1308,12 @@ def test_self_try_activate_missing_extensions refute Gem.try_activate "nonexistent" end - expected = "Ignoring ext-1 because its extensions are not built. " \ + expected = if RUBY_PLATFORM == "java" + "" + else + "Ignoring ext-1 because its extensions are not built. " \ "Try: gem pristine ext --version 1\n" + end assert_equal expected, err end diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb index af351f4d2e1f..53d700a1e97f 100644 --- a/test/rubygems/test_gem_specification.rb +++ b/test/rubygems/test_gem_specification.rb @@ -1557,8 +1557,12 @@ def test_contains_requirable_file_eh_extension refute @ext.contains_requirable_file? "nonexistent" end - expected = "Ignoring ext-1 because its extensions are not built. " \ + expected = if RUBY_PLATFORM == "java" + "" + else + "Ignoring ext-1 because its extensions are not built. " \ "Try: gem pristine ext --version 1\n" + end assert_equal expected, err end diff --git a/test/rubygems/test_gem_stub_specification.rb b/test/rubygems/test_gem_stub_specification.rb index 4b2d4c570a13..9612e74862e8 100644 --- a/test/rubygems/test_gem_stub_specification.rb +++ b/test/rubygems/test_gem_stub_specification.rb @@ -71,8 +71,12 @@ def test_contains_requirable_file_eh_extension refute stub.contains_requirable_file? "nonexistent" end - expected = "Ignoring stub_e-2 because its extensions are not built. " \ + expected = if RUBY_PLATFORM == "java" + "" + else + "Ignoring stub_e-2 because its extensions are not built. " \ "Try: gem pristine stub_e --version 2\n" + end assert_equal expected, err end From a0bfdb2b7a806fe228f8de63bcc9081078ce71ff Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Thu, 20 Feb 2025 15:45:10 +0900 Subject: [PATCH 2/5] Gem::Platform::JAVA is only provided under the bundler --- lib/rubygems/basic_specification.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rubygems/basic_specification.rb b/lib/rubygems/basic_specification.rb index f5c1d036dde6..92d4a60fa5f5 100644 --- a/lib/rubygems/basic_specification.rb +++ b/lib/rubygems/basic_specification.rb @@ -75,7 +75,7 @@ def contains_requirable_file?(file) if platform == Gem::Platform::RUBY || Gem::Platform.local === platform # RubyGems warns gem specification of C extensions. But JRuby couldn't # rebuild with `gem pristine` command. So, we skip the warning. - if RUBY_PLATFORM != Gem::Platform::JAVA + if RUBY_PLATFORM != "java" # JRuby warn "Ignoring #{full_name} because its extensions are not built. " \ "Try: gem pristine #{name} --version #{version}" end From ef15824db8a12ae7fb5c72d040779242b6397722 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Thu, 20 Feb 2025 16:24:29 +0900 Subject: [PATCH 3/5] Added simple example for suppressing warning with JRuby --- .../spec/bundler/stub_specification_spec.rb | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/bundler/spec/bundler/stub_specification_spec.rb b/bundler/spec/bundler/stub_specification_spec.rb index beb966b3ce8b..10d4b81445f1 100644 --- a/bundler/spec/bundler/stub_specification_spec.rb +++ b/bundler/spec/bundler/stub_specification_spec.rb @@ -12,6 +12,17 @@ described_class.from_stub(gemspec) end + let(:with_java_gem_stub_spec) do + gemspec = Gem::Specification.new do |s| + s.name = "gemname" + s.version = "1.0.0" + s.loaded_from = __FILE__ + s.platform = "java" + end + + described_class.from_stub(gemspec) + end + describe "#from_stub" do it "returns the same stub if already a Bundler::StubSpecification" do stub = described_class.from_stub(with_bundler_stub_spec) @@ -43,6 +54,17 @@ end end + describe "#ignored?" do + skip "This example is only for without JRuby" if RUBY_ENGINE == 'jruby' + + it "returns true if the gem is for different platform" do + stub = described_class.from_stub(with_java_gem_stub_spec) + allow(stub).to receive(:missing_extensions?).and_return(true) + expect(stub).to_not receive(:warn) + expect(stub.ignored?).to be true + end + end + describe "#missing_extensions?" do it "returns false if manually_installed?" do stub = described_class.from_stub(with_bundler_stub_spec) From 8cca3856857024d6e13014864dd29336e81aa574 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Thu, 20 Feb 2025 16:26:58 +0900 Subject: [PATCH 4/5] Use RUBY_ENGINE instead of RUBY_PLATFORM --- bundler/lib/bundler/stub_specification.rb | 2 +- bundler/spec/bundler/stub_specification_spec.rb | 2 +- lib/rubygems/basic_specification.rb | 2 +- test/rubygems/test_gem.rb | 2 +- test/rubygems/test_gem_specification.rb | 2 +- test/rubygems/test_gem_stub_specification.rb | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bundler/lib/bundler/stub_specification.rb b/bundler/lib/bundler/stub_specification.rb index 9ba456ad3527..a36224da9451 100644 --- a/bundler/lib/bundler/stub_specification.rb +++ b/bundler/lib/bundler/stub_specification.rb @@ -40,7 +40,7 @@ def ignored? # If we share GEM_HOME for all of Ruby platform, the platform specific gem always warn that specification. # ex `jruby-launcher` and CRuby - if RUBY_PLATFORM != Gem::Platform::JAVA + if RUBY_ENGINE != "jruby" warn "Source #{source} is ignoring #{self} because it is missing extensions" end diff --git a/bundler/spec/bundler/stub_specification_spec.rb b/bundler/spec/bundler/stub_specification_spec.rb index 10d4b81445f1..8efe460d05be 100644 --- a/bundler/spec/bundler/stub_specification_spec.rb +++ b/bundler/spec/bundler/stub_specification_spec.rb @@ -55,7 +55,7 @@ end describe "#ignored?" do - skip "This example is only for without JRuby" if RUBY_ENGINE == 'jruby' + skip "This example is only for without JRuby" if RUBY_ENGINE == "jruby" it "returns true if the gem is for different platform" do stub = described_class.from_stub(with_java_gem_stub_spec) diff --git a/lib/rubygems/basic_specification.rb b/lib/rubygems/basic_specification.rb index 92d4a60fa5f5..619bbd7ed474 100644 --- a/lib/rubygems/basic_specification.rb +++ b/lib/rubygems/basic_specification.rb @@ -75,7 +75,7 @@ def contains_requirable_file?(file) if platform == Gem::Platform::RUBY || Gem::Platform.local === platform # RubyGems warns gem specification of C extensions. But JRuby couldn't # rebuild with `gem pristine` command. So, we skip the warning. - if RUBY_PLATFORM != "java" # JRuby + if RUBY_ENGINE != "jruby" warn "Ignoring #{full_name} because its extensions are not built. " \ "Try: gem pristine #{name} --version #{version}" end diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb index 49dd4c88baec..c48cfc2ec8da 100644 --- a/test/rubygems/test_gem.rb +++ b/test/rubygems/test_gem.rb @@ -1308,7 +1308,7 @@ def test_self_try_activate_missing_extensions refute Gem.try_activate "nonexistent" end - expected = if RUBY_PLATFORM == "java" + expected = if RUBY_ENGINE == "jruby" "" else "Ignoring ext-1 because its extensions are not built. " \ diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb index 53d700a1e97f..c7e114118682 100644 --- a/test/rubygems/test_gem_specification.rb +++ b/test/rubygems/test_gem_specification.rb @@ -1557,7 +1557,7 @@ def test_contains_requirable_file_eh_extension refute @ext.contains_requirable_file? "nonexistent" end - expected = if RUBY_PLATFORM == "java" + expected = if RUBY_ENGINE == "jruby" "" else "Ignoring ext-1 because its extensions are not built. " \ diff --git a/test/rubygems/test_gem_stub_specification.rb b/test/rubygems/test_gem_stub_specification.rb index 9612e74862e8..de91896f85b3 100644 --- a/test/rubygems/test_gem_stub_specification.rb +++ b/test/rubygems/test_gem_stub_specification.rb @@ -71,7 +71,7 @@ def test_contains_requirable_file_eh_extension refute stub.contains_requirable_file? "nonexistent" end - expected = if RUBY_PLATFORM == "java" + expected = if RUBY_ENGINE == "jruby" "" else "Ignoring stub_e-2 because its extensions are not built. " \ From 7148b2e2824b6ec152745871540812944bd80bc7 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Fri, 27 Jun 2025 14:32:59 +0900 Subject: [PATCH 5/5] Applied same condition with RubyGems --- bundler/lib/bundler/stub_specification.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundler/lib/bundler/stub_specification.rb b/bundler/lib/bundler/stub_specification.rb index a36224da9451..00e5cae04275 100644 --- a/bundler/lib/bundler/stub_specification.rb +++ b/bundler/lib/bundler/stub_specification.rb @@ -40,7 +40,7 @@ def ignored? # If we share GEM_HOME for all of Ruby platform, the platform specific gem always warn that specification. # ex `jruby-launcher` and CRuby - if RUBY_ENGINE != "jruby" + if (platform == Gem::Platform::RUBY || Gem::Platform.local === platform) && RUBY_ENGINE != "jruby" warn "Source #{source} is ignoring #{self} because it is missing extensions" end