Skip to content

Commit 66944e9

Browse files
committed
Consolidate the platform into a single list:
- Similar change than 29a1be0, keep a single source of truth where we store the platform. The only change worth highlighing is the platform "maglev". It was not part of the supported platform of dependencies, so calling `gem 'foo', plaftorm: 'maglev'` would not work. However, it was supposed to according to 45ec86e. That's why it was possible to do `Bundler.current_ruby.maglev?` or `Bundler.current_ruby.maglev_30?`. I didn't change the current behaviour and maglev is not supported, though I kept the `*maglev` methods as I believe CurrentRuby is public API.
1 parent 05b9d81 commit 66944e9

File tree

5 files changed

+169
-178
lines changed

5 files changed

+169
-178
lines changed

bundler/lib/bundler/current_ruby.rb

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
require_relative "rubygems_ext"
4+
35
module Bundler
46
# Returns current version of Ruby
57
#
@@ -12,20 +14,22 @@ class CurrentRuby
1214
ALL_RUBY_VERSIONS = (18..27).to_a.concat((30..35).to_a).freeze
1315
KNOWN_MINOR_VERSIONS = ALL_RUBY_VERSIONS.map {|v| v.digits.reverse.join(".") }.freeze
1416
KNOWN_MAJOR_VERSIONS = ALL_RUBY_VERSIONS.map {|v| v.digits.last.to_s }.uniq.freeze
15-
16-
KNOWN_PLATFORMS = %w[
17-
jruby
18-
maglev
19-
mingw
20-
mri
21-
mswin
22-
mswin64
23-
rbx
24-
ruby
25-
truffleruby
26-
windows
27-
x64_mingw
28-
].freeze
17+
PLATFORM_MAP = {
18+
ruby: [Gem::Platform::RUBY, CurrentRuby::ALL_RUBY_VERSIONS],
19+
mri: [Gem::Platform::RUBY, CurrentRuby::ALL_RUBY_VERSIONS],
20+
rbx: [Gem::Platform::RUBY],
21+
truffleruby: [Gem::Platform::RUBY],
22+
jruby: [Gem::Platform::JAVA, [18, 19]],
23+
windows: [Gem::Platform::WINDOWS, CurrentRuby::ALL_RUBY_VERSIONS],
24+
# deprecated
25+
mswin: [Gem::Platform::MSWIN, CurrentRuby::ALL_RUBY_VERSIONS],
26+
mswin64: [Gem::Platform::MSWIN64, CurrentRuby::ALL_RUBY_VERSIONS - [18]],
27+
mingw: [Gem::Platform::MINGW, CurrentRuby::ALL_RUBY_VERSIONS],
28+
x64_mingw: [Gem::Platform::X64_MINGW, CurrentRuby::ALL_RUBY_VERSIONS - [18, 19]],
29+
}.each_with_object({}) do |(platform, spec), hash|
30+
hash[platform] = spec[0]
31+
spec[1]&.each {|version| hash[:"#{platform}_#{version}"] = spec[0] }
32+
end.freeze
2933

3034
def ruby?
3135
return true if Bundler::GemHelpers.generic_local_platform_is_ruby?
@@ -67,7 +71,8 @@ def windows?
6771
RUBY_VERSION.start_with?("#{version}.")
6872
end
6973

70-
KNOWN_PLATFORMS.each do |platform|
74+
all_platforms = PLATFORM_MAP.keys << "maglev"
75+
all_platforms.each do |platform|
7176
define_method(:"#{platform}_#{trimmed_version}?") do
7277
send(:"#{platform}?") && send(:"on_#{trimmed_version}?")
7378
end

bundler/lib/bundler/dependency.rb

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,6 @@ class Dependency < Gem::Dependency
99
attr_reader :autorequire
1010
attr_reader :groups, :platforms, :gemfile, :path, :git, :github, :branch, :ref, :glob
1111

12-
PLATFORM_MAP = {
13-
ruby: [Gem::Platform::RUBY, CurrentRuby::ALL_RUBY_VERSIONS],
14-
mri: [Gem::Platform::RUBY, CurrentRuby::ALL_RUBY_VERSIONS],
15-
rbx: [Gem::Platform::RUBY],
16-
truffleruby: [Gem::Platform::RUBY],
17-
jruby: [Gem::Platform::JAVA, [18, 19]],
18-
windows: [Gem::Platform::WINDOWS, CurrentRuby::ALL_RUBY_VERSIONS],
19-
# deprecated
20-
mswin: [Gem::Platform::MSWIN, CurrentRuby::ALL_RUBY_VERSIONS],
21-
mswin64: [Gem::Platform::MSWIN64, CurrentRuby::ALL_RUBY_VERSIONS - [18]],
22-
mingw: [Gem::Platform::MINGW, CurrentRuby::ALL_RUBY_VERSIONS],
23-
x64_mingw: [Gem::Platform::X64_MINGW, CurrentRuby::ALL_RUBY_VERSIONS - [18, 19]],
24-
}.each_with_object({}) do |(platform, spec), hash|
25-
hash[platform] = spec[0]
26-
spec[1]&.each {|version| hash[:"#{platform}_#{version}"] = spec[0] }
27-
end.freeze
28-
2912
def initialize(name, version, options = {}, &blk)
3013
type = options["type"] || :runtime
3114
super(name, version, type)
@@ -61,7 +44,7 @@ def gem_platforms(valid_platforms)
6144
end
6245

6346
def expanded_platforms
64-
@expanded_platforms ||= @platforms.filter_map {|pl| PLATFORM_MAP[pl] }.flatten.uniq
47+
@expanded_platforms ||= @platforms.filter_map {|pl| CurrentRuby::PLATFORM_MAP[pl] }.flatten.uniq
6548
end
6649

6750
def should_include?

bundler/lib/bundler/dsl.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def self.evaluate(gemfile, lockfile, unlock)
1313
builder.to_definition(lockfile, unlock)
1414
end
1515

16-
VALID_PLATFORMS = Bundler::Dependency::PLATFORM_MAP.keys.freeze
16+
VALID_PLATFORMS = Bundler::CurrentRuby::PLATFORM_MAP.keys.freeze
1717

1818
VALID_KEYS = %w[group groups git path glob name branch ref tag require submodules
1919
platform platforms type source install_if gemfile force_ruby_platform].freeze
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe Bundler::CurrentRuby do
4+
describe "PLATFORM_MAP" do
5+
subject { described_class::PLATFORM_MAP }
6+
7+
# rubocop:disable Naming/VariableNumber
8+
let(:platforms) do
9+
{ ruby: Gem::Platform::RUBY,
10+
ruby_18: Gem::Platform::RUBY,
11+
ruby_19: Gem::Platform::RUBY,
12+
ruby_20: Gem::Platform::RUBY,
13+
ruby_21: Gem::Platform::RUBY,
14+
ruby_22: Gem::Platform::RUBY,
15+
ruby_23: Gem::Platform::RUBY,
16+
ruby_24: Gem::Platform::RUBY,
17+
ruby_25: Gem::Platform::RUBY,
18+
ruby_26: Gem::Platform::RUBY,
19+
ruby_27: Gem::Platform::RUBY,
20+
ruby_30: Gem::Platform::RUBY,
21+
ruby_31: Gem::Platform::RUBY,
22+
ruby_32: Gem::Platform::RUBY,
23+
ruby_33: Gem::Platform::RUBY,
24+
ruby_34: Gem::Platform::RUBY,
25+
ruby_35: Gem::Platform::RUBY,
26+
mri: Gem::Platform::RUBY,
27+
mri_18: Gem::Platform::RUBY,
28+
mri_19: Gem::Platform::RUBY,
29+
mri_20: Gem::Platform::RUBY,
30+
mri_21: Gem::Platform::RUBY,
31+
mri_22: Gem::Platform::RUBY,
32+
mri_23: Gem::Platform::RUBY,
33+
mri_24: Gem::Platform::RUBY,
34+
mri_25: Gem::Platform::RUBY,
35+
mri_26: Gem::Platform::RUBY,
36+
mri_27: Gem::Platform::RUBY,
37+
mri_30: Gem::Platform::RUBY,
38+
mri_31: Gem::Platform::RUBY,
39+
mri_32: Gem::Platform::RUBY,
40+
mri_33: Gem::Platform::RUBY,
41+
mri_34: Gem::Platform::RUBY,
42+
mri_35: Gem::Platform::RUBY,
43+
rbx: Gem::Platform::RUBY,
44+
truffleruby: Gem::Platform::RUBY,
45+
jruby: Gem::Platform::JAVA,
46+
jruby_18: Gem::Platform::JAVA,
47+
jruby_19: Gem::Platform::JAVA,
48+
windows: Gem::Platform::WINDOWS,
49+
windows_18: Gem::Platform::WINDOWS,
50+
windows_19: Gem::Platform::WINDOWS,
51+
windows_20: Gem::Platform::WINDOWS,
52+
windows_21: Gem::Platform::WINDOWS,
53+
windows_22: Gem::Platform::WINDOWS,
54+
windows_23: Gem::Platform::WINDOWS,
55+
windows_24: Gem::Platform::WINDOWS,
56+
windows_25: Gem::Platform::WINDOWS,
57+
windows_26: Gem::Platform::WINDOWS,
58+
windows_27: Gem::Platform::WINDOWS,
59+
windows_30: Gem::Platform::WINDOWS,
60+
windows_31: Gem::Platform::WINDOWS,
61+
windows_32: Gem::Platform::WINDOWS,
62+
windows_33: Gem::Platform::WINDOWS,
63+
windows_34: Gem::Platform::WINDOWS,
64+
windows_35: Gem::Platform::WINDOWS }
65+
end
66+
67+
let(:deprecated) do
68+
{ mswin: Gem::Platform::MSWIN,
69+
mswin_18: Gem::Platform::MSWIN,
70+
mswin_19: Gem::Platform::MSWIN,
71+
mswin_20: Gem::Platform::MSWIN,
72+
mswin_21: Gem::Platform::MSWIN,
73+
mswin_22: Gem::Platform::MSWIN,
74+
mswin_23: Gem::Platform::MSWIN,
75+
mswin_24: Gem::Platform::MSWIN,
76+
mswin_25: Gem::Platform::MSWIN,
77+
mswin_26: Gem::Platform::MSWIN,
78+
mswin_27: Gem::Platform::MSWIN,
79+
mswin_30: Gem::Platform::MSWIN,
80+
mswin_31: Gem::Platform::MSWIN,
81+
mswin_32: Gem::Platform::MSWIN,
82+
mswin_33: Gem::Platform::MSWIN,
83+
mswin_34: Gem::Platform::MSWIN,
84+
mswin_35: Gem::Platform::MSWIN,
85+
mswin64: Gem::Platform::MSWIN64,
86+
mswin64_19: Gem::Platform::MSWIN64,
87+
mswin64_20: Gem::Platform::MSWIN64,
88+
mswin64_21: Gem::Platform::MSWIN64,
89+
mswin64_22: Gem::Platform::MSWIN64,
90+
mswin64_23: Gem::Platform::MSWIN64,
91+
mswin64_24: Gem::Platform::MSWIN64,
92+
mswin64_25: Gem::Platform::MSWIN64,
93+
mswin64_26: Gem::Platform::MSWIN64,
94+
mswin64_27: Gem::Platform::MSWIN64,
95+
mswin64_30: Gem::Platform::MSWIN64,
96+
mswin64_31: Gem::Platform::MSWIN64,
97+
mswin64_32: Gem::Platform::MSWIN64,
98+
mswin64_33: Gem::Platform::MSWIN64,
99+
mswin64_34: Gem::Platform::MSWIN64,
100+
mswin64_35: Gem::Platform::MSWIN64,
101+
mingw: Gem::Platform::MINGW,
102+
mingw_18: Gem::Platform::MINGW,
103+
mingw_19: Gem::Platform::MINGW,
104+
mingw_20: Gem::Platform::MINGW,
105+
mingw_21: Gem::Platform::MINGW,
106+
mingw_22: Gem::Platform::MINGW,
107+
mingw_23: Gem::Platform::MINGW,
108+
mingw_24: Gem::Platform::MINGW,
109+
mingw_25: Gem::Platform::MINGW,
110+
mingw_26: Gem::Platform::MINGW,
111+
mingw_27: Gem::Platform::MINGW,
112+
mingw_30: Gem::Platform::MINGW,
113+
mingw_31: Gem::Platform::MINGW,
114+
mingw_32: Gem::Platform::MINGW,
115+
mingw_33: Gem::Platform::MINGW,
116+
mingw_34: Gem::Platform::MINGW,
117+
mingw_35: Gem::Platform::MINGW,
118+
x64_mingw: Gem::Platform::X64_MINGW,
119+
x64_mingw_20: Gem::Platform::X64_MINGW,
120+
x64_mingw_21: Gem::Platform::X64_MINGW,
121+
x64_mingw_22: Gem::Platform::X64_MINGW,
122+
x64_mingw_23: Gem::Platform::X64_MINGW,
123+
x64_mingw_24: Gem::Platform::X64_MINGW,
124+
x64_mingw_25: Gem::Platform::X64_MINGW,
125+
x64_mingw_26: Gem::Platform::X64_MINGW,
126+
x64_mingw_27: Gem::Platform::X64_MINGW,
127+
x64_mingw_30: Gem::Platform::X64_MINGW,
128+
x64_mingw_31: Gem::Platform::X64_MINGW,
129+
x64_mingw_32: Gem::Platform::X64_MINGW,
130+
x64_mingw_33: Gem::Platform::X64_MINGW,
131+
x64_mingw_34: Gem::Platform::X64_MINGW,
132+
x64_mingw_35: Gem::Platform::X64_MINGW }
133+
end
134+
# rubocop:enable Naming/VariableNumber
135+
136+
it "includes all platforms" do
137+
expect(subject).to eq(platforms.merge(deprecated))
138+
end
139+
end
140+
end

bundler/spec/bundler/dependency_spec.rb

Lines changed: 7 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -35,150 +35,13 @@
3535
end
3636
end
3737

38-
describe "PLATFORM_MAP" do
39-
subject { described_class::PLATFORM_MAP }
40-
41-
# rubocop:disable Naming/VariableNumber
42-
let(:platforms) do
43-
{ ruby: Gem::Platform::RUBY,
44-
ruby_18: Gem::Platform::RUBY,
45-
ruby_19: Gem::Platform::RUBY,
46-
ruby_20: Gem::Platform::RUBY,
47-
ruby_21: Gem::Platform::RUBY,
48-
ruby_22: Gem::Platform::RUBY,
49-
ruby_23: Gem::Platform::RUBY,
50-
ruby_24: Gem::Platform::RUBY,
51-
ruby_25: Gem::Platform::RUBY,
52-
ruby_26: Gem::Platform::RUBY,
53-
ruby_27: Gem::Platform::RUBY,
54-
ruby_30: Gem::Platform::RUBY,
55-
ruby_31: Gem::Platform::RUBY,
56-
ruby_32: Gem::Platform::RUBY,
57-
ruby_33: Gem::Platform::RUBY,
58-
ruby_34: Gem::Platform::RUBY,
59-
ruby_35: Gem::Platform::RUBY,
60-
mri: Gem::Platform::RUBY,
61-
mri_18: Gem::Platform::RUBY,
62-
mri_19: Gem::Platform::RUBY,
63-
mri_20: Gem::Platform::RUBY,
64-
mri_21: Gem::Platform::RUBY,
65-
mri_22: Gem::Platform::RUBY,
66-
mri_23: Gem::Platform::RUBY,
67-
mri_24: Gem::Platform::RUBY,
68-
mri_25: Gem::Platform::RUBY,
69-
mri_26: Gem::Platform::RUBY,
70-
mri_27: Gem::Platform::RUBY,
71-
mri_30: Gem::Platform::RUBY,
72-
mri_31: Gem::Platform::RUBY,
73-
mri_32: Gem::Platform::RUBY,
74-
mri_33: Gem::Platform::RUBY,
75-
mri_34: Gem::Platform::RUBY,
76-
mri_35: Gem::Platform::RUBY,
77-
rbx: Gem::Platform::RUBY,
78-
truffleruby: Gem::Platform::RUBY,
79-
jruby: Gem::Platform::JAVA,
80-
jruby_18: Gem::Platform::JAVA,
81-
jruby_19: Gem::Platform::JAVA,
82-
windows: Gem::Platform::WINDOWS,
83-
windows_18: Gem::Platform::WINDOWS,
84-
windows_19: Gem::Platform::WINDOWS,
85-
windows_20: Gem::Platform::WINDOWS,
86-
windows_21: Gem::Platform::WINDOWS,
87-
windows_22: Gem::Platform::WINDOWS,
88-
windows_23: Gem::Platform::WINDOWS,
89-
windows_24: Gem::Platform::WINDOWS,
90-
windows_25: Gem::Platform::WINDOWS,
91-
windows_26: Gem::Platform::WINDOWS,
92-
windows_27: Gem::Platform::WINDOWS,
93-
windows_30: Gem::Platform::WINDOWS,
94-
windows_31: Gem::Platform::WINDOWS,
95-
windows_32: Gem::Platform::WINDOWS,
96-
windows_33: Gem::Platform::WINDOWS,
97-
windows_34: Gem::Platform::WINDOWS,
98-
windows_35: Gem::Platform::WINDOWS }
99-
end
100-
101-
let(:deprecated) do
102-
{ mswin: Gem::Platform::MSWIN,
103-
mswin_18: Gem::Platform::MSWIN,
104-
mswin_19: Gem::Platform::MSWIN,
105-
mswin_20: Gem::Platform::MSWIN,
106-
mswin_21: Gem::Platform::MSWIN,
107-
mswin_22: Gem::Platform::MSWIN,
108-
mswin_23: Gem::Platform::MSWIN,
109-
mswin_24: Gem::Platform::MSWIN,
110-
mswin_25: Gem::Platform::MSWIN,
111-
mswin_26: Gem::Platform::MSWIN,
112-
mswin_27: Gem::Platform::MSWIN,
113-
mswin_30: Gem::Platform::MSWIN,
114-
mswin_31: Gem::Platform::MSWIN,
115-
mswin_32: Gem::Platform::MSWIN,
116-
mswin_33: Gem::Platform::MSWIN,
117-
mswin_34: Gem::Platform::MSWIN,
118-
mswin_35: Gem::Platform::MSWIN,
119-
mswin64: Gem::Platform::MSWIN64,
120-
mswin64_19: Gem::Platform::MSWIN64,
121-
mswin64_20: Gem::Platform::MSWIN64,
122-
mswin64_21: Gem::Platform::MSWIN64,
123-
mswin64_22: Gem::Platform::MSWIN64,
124-
mswin64_23: Gem::Platform::MSWIN64,
125-
mswin64_24: Gem::Platform::MSWIN64,
126-
mswin64_25: Gem::Platform::MSWIN64,
127-
mswin64_26: Gem::Platform::MSWIN64,
128-
mswin64_27: Gem::Platform::MSWIN64,
129-
mswin64_30: Gem::Platform::MSWIN64,
130-
mswin64_31: Gem::Platform::MSWIN64,
131-
mswin64_32: Gem::Platform::MSWIN64,
132-
mswin64_33: Gem::Platform::MSWIN64,
133-
mswin64_34: Gem::Platform::MSWIN64,
134-
mswin64_35: Gem::Platform::MSWIN64,
135-
mingw: Gem::Platform::MINGW,
136-
mingw_18: Gem::Platform::MINGW,
137-
mingw_19: Gem::Platform::MINGW,
138-
mingw_20: Gem::Platform::MINGW,
139-
mingw_21: Gem::Platform::MINGW,
140-
mingw_22: Gem::Platform::MINGW,
141-
mingw_23: Gem::Platform::MINGW,
142-
mingw_24: Gem::Platform::MINGW,
143-
mingw_25: Gem::Platform::MINGW,
144-
mingw_26: Gem::Platform::MINGW,
145-
mingw_27: Gem::Platform::MINGW,
146-
mingw_30: Gem::Platform::MINGW,
147-
mingw_31: Gem::Platform::MINGW,
148-
mingw_32: Gem::Platform::MINGW,
149-
mingw_33: Gem::Platform::MINGW,
150-
mingw_34: Gem::Platform::MINGW,
151-
mingw_35: Gem::Platform::MINGW,
152-
x64_mingw: Gem::Platform::X64_MINGW,
153-
x64_mingw_20: Gem::Platform::X64_MINGW,
154-
x64_mingw_21: Gem::Platform::X64_MINGW,
155-
x64_mingw_22: Gem::Platform::X64_MINGW,
156-
x64_mingw_23: Gem::Platform::X64_MINGW,
157-
x64_mingw_24: Gem::Platform::X64_MINGW,
158-
x64_mingw_25: Gem::Platform::X64_MINGW,
159-
x64_mingw_26: Gem::Platform::X64_MINGW,
160-
x64_mingw_27: Gem::Platform::X64_MINGW,
161-
x64_mingw_30: Gem::Platform::X64_MINGW,
162-
x64_mingw_31: Gem::Platform::X64_MINGW,
163-
x64_mingw_32: Gem::Platform::X64_MINGW,
164-
x64_mingw_33: Gem::Platform::X64_MINGW,
165-
x64_mingw_34: Gem::Platform::X64_MINGW,
166-
x64_mingw_35: Gem::Platform::X64_MINGW }
167-
end
168-
# rubocop:enable Naming/VariableNumber
169-
170-
it "includes all platforms" do
171-
expect(subject).to eq(platforms.merge(deprecated))
172-
end
173-
174-
it "is on the current platform" do
175-
dep = described_class.new(
176-
"test_gem",
177-
"1.0.0",
178-
{ "platforms" => "#{RUBY_ENGINE}_#{RbConfig::CONFIG["MAJOR"]}#{RbConfig::CONFIG["MINOR"]}" },
179-
)
38+
it "is on the current platform" do
39+
dep = described_class.new(
40+
"test_gem",
41+
"1.0.0",
42+
{ "platforms" => "#{RUBY_ENGINE}_#{RbConfig::CONFIG["MAJOR"]}#{RbConfig::CONFIG["MINOR"]}" },
43+
)
18044

181-
expect(dep.current_platform?).to be_truthy
182-
end
45+
expect(dep.current_platform?).to be_truthy
18346
end
18447
end

0 commit comments

Comments
 (0)