Skip to content

Commit 2ed30c9

Browse files
Edouard-chinhsbt
authored andcommitted
[rubygems/rubygems] Consolidate the platform into a single list:
- Similar change than ruby/rubygems@29a1be0008e6, 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 ruby/rubygems@45ec86e2e528. 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. ruby/rubygems@29e219ebcf
1 parent dc7c665 commit 2ed30c9

File tree

5 files changed

+170
-180
lines changed

5 files changed

+170
-180
lines changed

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

lib/bundler/dependency.rb

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,12 @@
22

33
require "rubygems/dependency"
44
require_relative "shared_helpers"
5-
require_relative "rubygems_ext"
65

76
module Bundler
87
class Dependency < Gem::Dependency
98
attr_reader :autorequire
109
attr_reader :groups, :platforms, :gemfile, :path, :git, :github, :branch, :ref, :glob
1110

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-
2911
def initialize(name, version, options = {}, &blk)
3012
type = options["type"] || :runtime
3113
super(name, version, type)
@@ -60,7 +42,7 @@ def gem_platforms(valid_platforms)
6042
end
6143

6244
def expanded_platforms
63-
@expanded_platforms ||= @platforms.filter_map {|pl| PLATFORM_MAP[pl] }.flatten.uniq
45+
@expanded_platforms ||= @platforms.filter_map {|pl| CurrentRuby::PLATFORM_MAP[pl] }.flatten.uniq
6446
end
6547

6648
def should_include?

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

0 commit comments

Comments
 (0)