Skip to content

Commit cb75f04

Browse files
hsbtclaude
authored andcommitted
[ruby/rubygems] Skip missing_extensions? check on JRuby
JRuby does not require extension rebuilds when switching JRuby or Java versions because Java extensions are shipped pre-compiled and JRuby does not expose a version-specific C API. This means missing_extensions? returning true on JRuby is almost always a false positive and the suggested `gem pristine` is not actionable. Return false early from missing_extensions? on JRuby so that all downstream warnings and ignored-spec filtering are suppressed at the source rather than patching each warning site individually. ruby/rubygems@ba5c7cc0ce Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 79c0a02 commit cb75f04

7 files changed

Lines changed: 50 additions & 15 deletions

File tree

lib/bundler/stub_specification.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def manually_installed?
5252

5353
# This is defined directly to avoid having to loading the full spec
5454
def missing_extensions?
55+
return false if RUBY_ENGINE == "jruby"
5556
return false if default_gem?
5657
return false if extensions.empty?
5758
return false if File.exist? gem_build_complete_path

lib/rubygems/specification.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2070,6 +2070,7 @@ def method_missing(sym, *a, &b) # :nodoc:
20702070
# probably want to build_extensions
20712071

20722072
def missing_extensions?
2073+
return false if RUBY_ENGINE == "jruby"
20732074
return false if extensions.empty?
20742075
return false if default_gem?
20752076
return false if File.exist? gem_build_complete_path

lib/rubygems/stub_specification.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ def raw_require_paths # :nodoc:
140140
end
141141

142142
def missing_extensions?
143+
return false if RUBY_ENGINE == "jruby"
143144
return false if default_gem?
144145
return false if extensions.empty?
145146
return false if File.exist? gem_build_complete_path

spec/bundler/bundler/stub_specification_spec.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,14 @@
4949
expect(stub.missing_extensions?).to be false
5050
end
5151

52-
it "returns true if not manually_installed?" do
52+
it "returns #{RUBY_ENGINE == "jruby" ? "false" : "true"} if not manually_installed?" do
5353
stub = described_class.from_stub(with_bundler_stub_spec)
5454
stub.installed_by_version = Gem::Version.new(1)
55-
expect(stub.missing_extensions?).to be true
55+
if RUBY_ENGINE == "jruby"
56+
expect(stub.missing_extensions?).to be false
57+
else
58+
expect(stub.missing_extensions?).to be true
59+
end
5660
end
5761
end
5862

test/rubygems/test_gem.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,10 +1304,14 @@ def test_self_try_activate_missing_extensions
13041304
refute Gem.try_activate "nonexistent"
13051305
end
13061306

1307-
expected = "Ignoring ext-1 because its extensions are not built. " \
1308-
"Try: gem pristine ext --version 1\n"
1307+
if RUBY_ENGINE == "jruby"
1308+
assert_equal "", err
1309+
else
1310+
expected = "Ignoring ext-1 because its extensions are not built. " \
1311+
"Try: gem pristine ext --version 1\n"
13091312

1310-
assert_equal expected, err
1313+
assert_equal expected, err
1314+
end
13111315
end
13121316

13131317
def test_self_use_paths_with_nils

test/rubygems/test_gem_specification.rb

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,13 +1578,21 @@ def test_contains_requirable_file_eh_extension
15781578
ext_spec
15791579

15801580
_, err = capture_output do
1581-
refute @ext.contains_requirable_file? "nonexistent"
1581+
if RUBY_ENGINE == "jruby"
1582+
refute @ext.ignored?
1583+
else
1584+
refute @ext.contains_requirable_file? "nonexistent"
1585+
end
15821586
end
15831587

1584-
expected = "Ignoring ext-1 because its extensions are not built. " \
1585-
"Try: gem pristine ext --version 1\n"
1588+
if RUBY_ENGINE == "jruby"
1589+
assert_equal "", err
1590+
else
1591+
expected = "Ignoring ext-1 because its extensions are not built. " \
1592+
"Try: gem pristine ext --version 1\n"
15861593

1587-
assert_equal expected, err
1594+
assert_equal expected, err
1595+
end
15881596
end
15891597

15901598
def test_contains_requirable_file_eh_extension_java_platform
@@ -4007,7 +4015,11 @@ def test_metadata_specs
40074015
def test_missing_extensions_eh
40084016
ext_spec
40094017

4010-
assert @ext.missing_extensions?
4018+
if RUBY_ENGINE == "jruby"
4019+
refute @ext.missing_extensions?
4020+
else
4021+
assert @ext.missing_extensions?
4022+
end
40114023

40124024
extconf_rb = File.join @ext.gem_dir, @ext.extensions.first
40134025
FileUtils.mkdir_p File.dirname extconf_rb

test/rubygems/test_gem_stub_specification.rb

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,21 @@ def test_contains_requirable_file_eh
6868
def test_contains_requirable_file_eh_extension
6969
stub_with_extension do |stub|
7070
_, err = capture_output do
71-
refute stub.contains_requirable_file? "nonexistent"
71+
if RUBY_ENGINE == "jruby"
72+
refute stub.ignored?
73+
else
74+
refute stub.contains_requirable_file? "nonexistent"
75+
end
7276
end
7377

74-
expected = "Ignoring stub_e-2 because its extensions are not built. " \
75-
"Try: gem pristine stub_e --version 2\n"
78+
if RUBY_ENGINE == "jruby"
79+
assert_equal "", err
80+
else
81+
expected = "Ignoring stub_e-2 because its extensions are not built. " \
82+
"Try: gem pristine stub_e --version 2\n"
7683

77-
assert_equal expected, err
84+
assert_equal expected, err
85+
end
7886
end
7987
end
8088

@@ -137,7 +145,11 @@ def test_missing_extensions_eh
137145
end
138146
end
139147

140-
assert stub.missing_extensions?
148+
if RUBY_ENGINE == "jruby"
149+
refute stub.missing_extensions?
150+
else
151+
assert stub.missing_extensions?
152+
end
141153

142154
stub.build_extensions
143155

0 commit comments

Comments
 (0)