Skip to content

Commit 66388ba

Browse files
committed
Deprecate CurrentRuby#maglev? and other related maglev methods:
- Follow up to #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 45ec86e). 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.
1 parent 658f7a9 commit 66388ba

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

bundler/lib/bundler/current_ruby.rb

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ def jruby?
5050
end
5151

5252
def maglev?
53+
message =
54+
"`CurrentRuby#maglev?` is deprecated with no replacement. Please use the " \
55+
"built-in Ruby `RUBY_ENGINE` constant to check the Ruby implementation you are running on."
56+
removed_message =
57+
"`CurrentRuby#maglev?` was removed with no replacement. Please use the " \
58+
"built-in Ruby `RUBY_ENGINE` constant to check the Ruby implementation you are running on."
59+
internally_exempted = caller_locations(1, 1).first.path == __FILE__
60+
61+
unless internally_exempted
62+
SharedHelpers.major_deprecation(2, message, removed_message: removed_message, print_caller_location: true)
63+
end
64+
5365
RUBY_ENGINE == "maglev"
5466
end
5567

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

74-
all_platforms = PLATFORM_MAP.keys << "maglev"
75-
all_platforms.each do |platform|
86+
PLATFORM_MAP.keys.each do |platform|
7687
define_method(:"#{platform}_#{trimmed_version}?") do
7788
send(:"#{platform}?") && send(:"on_#{trimmed_version}?")
7889
end
7990
end
91+
92+
define_method(:"maglev_#{trimmed_version}?") do
93+
message =
94+
"`CurrentRuby##{__method__}` is deprecated with no replacement. Please use the " \
95+
"built-in Ruby `RUBY_ENGINE` and `RUBY_VERSION` constants to perform a similar check."
96+
removed_message =
97+
"`CurrentRuby##{__method__}` was removed with no replacement. Please use the " \
98+
"built-in Ruby `RUBY_ENGINE` and `RUBY_VERSION` constants to perform a similar check."
99+
100+
SharedHelpers.major_deprecation(2, message, removed_message: removed_message, print_caller_location: true)
101+
102+
send(:"maglev?") && send(:"on_#{trimmed_version}?")
103+
end
80104
end
81105
end
82106
end

bundler/spec/bundler/current_ruby_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,20 @@
137137
expect(subject).to eq(platforms.merge(deprecated))
138138
end
139139
end
140+
141+
describe "Deprecated platform" do
142+
it "Outputs a deprecation warning when calling maglev?", bundler: "< 3" do
143+
expect(Bundler.ui).to receive(:warn).with(/`CurrentRuby#maglev\?` is deprecated with no replacement./)
144+
145+
Bundler.current_ruby.maglev?
146+
end
147+
148+
it "Outputs a deprecation warning when calling maglev_31?", bundler: "< 3" do
149+
expect(Bundler.ui).to receive(:warn).with(/`CurrentRuby#maglev_31\?` is deprecated with no replacement./)
150+
151+
Bundler.current_ruby.maglev_31?
152+
end
153+
154+
pending "is removed and shows a helpful error message about it", bundler: "3"
155+
end
140156
end

0 commit comments

Comments
 (0)