From c204cf7cb123b4c0aa50b3049c82caed3e6f2826 Mon Sep 17 00:00:00 2001 From: Edouard CHIN Date: Wed, 29 Jan 2025 19:41:56 +0100 Subject: [PATCH] [rubygems/rubygems] Deprecate `CurrentRuby#maglev?` and other related maglev methods: - Follow up to https://github.com/rubygems/rubygems/pull/8430#discussion_r1927239555. 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 https://github.com/rubygems/rubygems/commit/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. https://github.com/rubygems/rubygems/commit/66388babf8 --- lib/bundler/current_ruby.rb | 28 +++++++++++++++++++++-- spec/bundler/bundler/current_ruby_spec.rb | 16 +++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/lib/bundler/current_ruby.rb b/lib/bundler/current_ruby.rb index 9cd08f4d09fd53..0d416ef60dfb07 100644 --- a/lib/bundler/current_ruby.rb +++ b/lib/bundler/current_ruby.rb @@ -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 @@ -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 diff --git a/spec/bundler/bundler/current_ruby_spec.rb b/spec/bundler/bundler/current_ruby_spec.rb index e0498d5a9e99ec..7f1f1dac935be1 100644 --- a/spec/bundler/bundler/current_ruby_spec.rb +++ b/spec/bundler/bundler/current_ruby_spec.rb @@ -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