Skip to content

Commit

Permalink
[rubygems/rubygems] Deprecate CurrentRuby#maglev? and other related…
Browse files Browse the repository at this point in the history
… maglev methods:

- Follow up to rubygems/rubygems#8430 (comment).

  The maglev platform was not supported by Bundler, so calling
  `gem "foo", platforms: ["maglev"]` would raise an error.

  The helpers added in the `CurrentRuby` class were used at a time
  when maglev was supported (as explained in rubygems/rubygems@45ec86e2e528).
  Support of maglev was most likely dropped at some point and the helpers
  in the `CurrentRuby` class were not deprecated/removed.

  We decided to deprecate them now.

rubygems/rubygems@66388babf8
  • Loading branch information
Edouard-chin authored and hsbt committed Feb 5, 2025
1 parent afb47a1 commit c204cf7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
28 changes: 26 additions & 2 deletions lib/bundler/current_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ def jruby?
end

def maglev?
message =
"`CurrentRuby#maglev?` is deprecated with no replacement. Please use the " \
"built-in Ruby `RUBY_ENGINE` constant to check the Ruby implementation you are running on."
removed_message =
"`CurrentRuby#maglev?` was removed with no replacement. Please use the " \
"built-in Ruby `RUBY_ENGINE` constant to check the Ruby implementation you are running on."
internally_exempted = caller_locations(1, 1).first.path == __FILE__

unless internally_exempted
SharedHelpers.major_deprecation(2, message, removed_message: removed_message, print_caller_location: true)
end

RUBY_ENGINE == "maglev"
end

Expand All @@ -71,12 +83,24 @@ def windows?
RUBY_VERSION.start_with?("#{version}.")
end

all_platforms = PLATFORM_MAP.keys << "maglev"
all_platforms.each do |platform|
PLATFORM_MAP.keys.each do |platform|
define_method(:"#{platform}_#{trimmed_version}?") do
send(:"#{platform}?") && send(:"on_#{trimmed_version}?")
end
end

define_method(:"maglev_#{trimmed_version}?") do
message =
"`CurrentRuby##{__method__}` is deprecated with no replacement. Please use the " \
"built-in Ruby `RUBY_ENGINE` and `RUBY_VERSION` constants to perform a similar check."
removed_message =
"`CurrentRuby##{__method__}` was removed with no replacement. Please use the " \
"built-in Ruby `RUBY_ENGINE` and `RUBY_VERSION` constants to perform a similar check."

SharedHelpers.major_deprecation(2, message, removed_message: removed_message, print_caller_location: true)

send(:"maglev?") && send(:"on_#{trimmed_version}?")
end
end
end
end
16 changes: 16 additions & 0 deletions spec/bundler/bundler/current_ruby_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,20 @@
expect(subject).to eq(platforms.merge(deprecated))
end
end

describe "Deprecated platform" do
it "Outputs a deprecation warning when calling maglev?", bundler: "< 3" do
expect(Bundler.ui).to receive(:warn).with(/`CurrentRuby#maglev\?` is deprecated with no replacement./)

Bundler.current_ruby.maglev?
end

it "Outputs a deprecation warning when calling maglev_31?", bundler: "< 3" do
expect(Bundler.ui).to receive(:warn).with(/`CurrentRuby#maglev_31\?` is deprecated with no replacement./)

Bundler.current_ruby.maglev_31?
end

pending "is removed and shows a helpful error message about it", bundler: "3"
end
end

0 comments on commit c204cf7

Please sign in to comment.