[rubygems/rubygems] Consolidate the platform into a single list:
- Similar change than https://github.com/rubygems/rubygems/commit/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 https://github.com/rubygems/rubygems/commit/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. https://github.com/rubygems/rubygems/commit/29e219ebcf
This commit is contained in:
parent
dc7c665105
commit
2ed30c9944
@ -1,5 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "rubygems_ext"
|
||||
|
||||
module Bundler
|
||||
# Returns current version of Ruby
|
||||
#
|
||||
@ -12,20 +14,22 @@ module Bundler
|
||||
ALL_RUBY_VERSIONS = (18..27).to_a.concat((30..35).to_a).freeze
|
||||
KNOWN_MINOR_VERSIONS = ALL_RUBY_VERSIONS.map {|v| v.digits.reverse.join(".") }.freeze
|
||||
KNOWN_MAJOR_VERSIONS = ALL_RUBY_VERSIONS.map {|v| v.digits.last.to_s }.uniq.freeze
|
||||
|
||||
KNOWN_PLATFORMS = %w[
|
||||
jruby
|
||||
maglev
|
||||
mingw
|
||||
mri
|
||||
mswin
|
||||
mswin64
|
||||
rbx
|
||||
ruby
|
||||
truffleruby
|
||||
windows
|
||||
x64_mingw
|
||||
].freeze
|
||||
PLATFORM_MAP = {
|
||||
ruby: [Gem::Platform::RUBY, CurrentRuby::ALL_RUBY_VERSIONS],
|
||||
mri: [Gem::Platform::RUBY, CurrentRuby::ALL_RUBY_VERSIONS],
|
||||
rbx: [Gem::Platform::RUBY],
|
||||
truffleruby: [Gem::Platform::RUBY],
|
||||
jruby: [Gem::Platform::JAVA, [18, 19]],
|
||||
windows: [Gem::Platform::WINDOWS, CurrentRuby::ALL_RUBY_VERSIONS],
|
||||
# deprecated
|
||||
mswin: [Gem::Platform::MSWIN, CurrentRuby::ALL_RUBY_VERSIONS],
|
||||
mswin64: [Gem::Platform::MSWIN64, CurrentRuby::ALL_RUBY_VERSIONS - [18]],
|
||||
mingw: [Gem::Platform::MINGW, CurrentRuby::ALL_RUBY_VERSIONS],
|
||||
x64_mingw: [Gem::Platform::X64_MINGW, CurrentRuby::ALL_RUBY_VERSIONS - [18, 19]],
|
||||
}.each_with_object({}) do |(platform, spec), hash|
|
||||
hash[platform] = spec[0]
|
||||
spec[1]&.each {|version| hash[:"#{platform}_#{version}"] = spec[0] }
|
||||
end.freeze
|
||||
|
||||
def ruby?
|
||||
return true if Bundler::GemHelpers.generic_local_platform_is_ruby?
|
||||
@ -67,7 +71,8 @@ module Bundler
|
||||
RUBY_VERSION.start_with?("#{version}.")
|
||||
end
|
||||
|
||||
KNOWN_PLATFORMS.each do |platform|
|
||||
all_platforms = PLATFORM_MAP.keys << "maglev"
|
||||
all_platforms.each do |platform|
|
||||
define_method(:"#{platform}_#{trimmed_version}?") do
|
||||
send(:"#{platform}?") && send(:"on_#{trimmed_version}?")
|
||||
end
|
||||
|
@ -2,30 +2,12 @@
|
||||
|
||||
require "rubygems/dependency"
|
||||
require_relative "shared_helpers"
|
||||
require_relative "rubygems_ext"
|
||||
|
||||
module Bundler
|
||||
class Dependency < Gem::Dependency
|
||||
attr_reader :autorequire
|
||||
attr_reader :groups, :platforms, :gemfile, :path, :git, :github, :branch, :ref, :glob
|
||||
|
||||
PLATFORM_MAP = {
|
||||
ruby: [Gem::Platform::RUBY, CurrentRuby::ALL_RUBY_VERSIONS],
|
||||
mri: [Gem::Platform::RUBY, CurrentRuby::ALL_RUBY_VERSIONS],
|
||||
rbx: [Gem::Platform::RUBY],
|
||||
truffleruby: [Gem::Platform::RUBY],
|
||||
jruby: [Gem::Platform::JAVA, [18, 19]],
|
||||
windows: [Gem::Platform::WINDOWS, CurrentRuby::ALL_RUBY_VERSIONS],
|
||||
# deprecated
|
||||
mswin: [Gem::Platform::MSWIN, CurrentRuby::ALL_RUBY_VERSIONS],
|
||||
mswin64: [Gem::Platform::MSWIN64, CurrentRuby::ALL_RUBY_VERSIONS - [18]],
|
||||
mingw: [Gem::Platform::MINGW, CurrentRuby::ALL_RUBY_VERSIONS],
|
||||
x64_mingw: [Gem::Platform::X64_MINGW, CurrentRuby::ALL_RUBY_VERSIONS - [18, 19]],
|
||||
}.each_with_object({}) do |(platform, spec), hash|
|
||||
hash[platform] = spec[0]
|
||||
spec[1]&.each {|version| hash[:"#{platform}_#{version}"] = spec[0] }
|
||||
end.freeze
|
||||
|
||||
def initialize(name, version, options = {}, &blk)
|
||||
type = options["type"] || :runtime
|
||||
super(name, version, type)
|
||||
@ -60,7 +42,7 @@ module Bundler
|
||||
end
|
||||
|
||||
def expanded_platforms
|
||||
@expanded_platforms ||= @platforms.filter_map {|pl| PLATFORM_MAP[pl] }.flatten.uniq
|
||||
@expanded_platforms ||= @platforms.filter_map {|pl| CurrentRuby::PLATFORM_MAP[pl] }.flatten.uniq
|
||||
end
|
||||
|
||||
def should_include?
|
||||
|
@ -13,7 +13,7 @@ module Bundler
|
||||
builder.to_definition(lockfile, unlock)
|
||||
end
|
||||
|
||||
VALID_PLATFORMS = Bundler::Dependency::PLATFORM_MAP.keys.freeze
|
||||
VALID_PLATFORMS = Bundler::CurrentRuby::PLATFORM_MAP.keys.freeze
|
||||
|
||||
VALID_KEYS = %w[group groups git path glob name branch ref tag require submodules
|
||||
platform platforms type source install_if gemfile force_ruby_platform].freeze
|
||||
|
140
spec/bundler/bundler/current_ruby_spec.rb
Normal file
140
spec/bundler/bundler/current_ruby_spec.rb
Normal file
@ -0,0 +1,140 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe Bundler::CurrentRuby do
|
||||
describe "PLATFORM_MAP" do
|
||||
subject { described_class::PLATFORM_MAP }
|
||||
|
||||
# rubocop:disable Naming/VariableNumber
|
||||
let(:platforms) do
|
||||
{ ruby: Gem::Platform::RUBY,
|
||||
ruby_18: Gem::Platform::RUBY,
|
||||
ruby_19: Gem::Platform::RUBY,
|
||||
ruby_20: Gem::Platform::RUBY,
|
||||
ruby_21: Gem::Platform::RUBY,
|
||||
ruby_22: Gem::Platform::RUBY,
|
||||
ruby_23: Gem::Platform::RUBY,
|
||||
ruby_24: Gem::Platform::RUBY,
|
||||
ruby_25: Gem::Platform::RUBY,
|
||||
ruby_26: Gem::Platform::RUBY,
|
||||
ruby_27: Gem::Platform::RUBY,
|
||||
ruby_30: Gem::Platform::RUBY,
|
||||
ruby_31: Gem::Platform::RUBY,
|
||||
ruby_32: Gem::Platform::RUBY,
|
||||
ruby_33: Gem::Platform::RUBY,
|
||||
ruby_34: Gem::Platform::RUBY,
|
||||
ruby_35: Gem::Platform::RUBY,
|
||||
mri: Gem::Platform::RUBY,
|
||||
mri_18: Gem::Platform::RUBY,
|
||||
mri_19: Gem::Platform::RUBY,
|
||||
mri_20: Gem::Platform::RUBY,
|
||||
mri_21: Gem::Platform::RUBY,
|
||||
mri_22: Gem::Platform::RUBY,
|
||||
mri_23: Gem::Platform::RUBY,
|
||||
mri_24: Gem::Platform::RUBY,
|
||||
mri_25: Gem::Platform::RUBY,
|
||||
mri_26: Gem::Platform::RUBY,
|
||||
mri_27: Gem::Platform::RUBY,
|
||||
mri_30: Gem::Platform::RUBY,
|
||||
mri_31: Gem::Platform::RUBY,
|
||||
mri_32: Gem::Platform::RUBY,
|
||||
mri_33: Gem::Platform::RUBY,
|
||||
mri_34: Gem::Platform::RUBY,
|
||||
mri_35: Gem::Platform::RUBY,
|
||||
rbx: Gem::Platform::RUBY,
|
||||
truffleruby: Gem::Platform::RUBY,
|
||||
jruby: Gem::Platform::JAVA,
|
||||
jruby_18: Gem::Platform::JAVA,
|
||||
jruby_19: Gem::Platform::JAVA,
|
||||
windows: Gem::Platform::WINDOWS,
|
||||
windows_18: Gem::Platform::WINDOWS,
|
||||
windows_19: Gem::Platform::WINDOWS,
|
||||
windows_20: Gem::Platform::WINDOWS,
|
||||
windows_21: Gem::Platform::WINDOWS,
|
||||
windows_22: Gem::Platform::WINDOWS,
|
||||
windows_23: Gem::Platform::WINDOWS,
|
||||
windows_24: Gem::Platform::WINDOWS,
|
||||
windows_25: Gem::Platform::WINDOWS,
|
||||
windows_26: Gem::Platform::WINDOWS,
|
||||
windows_27: Gem::Platform::WINDOWS,
|
||||
windows_30: Gem::Platform::WINDOWS,
|
||||
windows_31: Gem::Platform::WINDOWS,
|
||||
windows_32: Gem::Platform::WINDOWS,
|
||||
windows_33: Gem::Platform::WINDOWS,
|
||||
windows_34: Gem::Platform::WINDOWS,
|
||||
windows_35: Gem::Platform::WINDOWS }
|
||||
end
|
||||
|
||||
let(:deprecated) do
|
||||
{ mswin: Gem::Platform::MSWIN,
|
||||
mswin_18: Gem::Platform::MSWIN,
|
||||
mswin_19: Gem::Platform::MSWIN,
|
||||
mswin_20: Gem::Platform::MSWIN,
|
||||
mswin_21: Gem::Platform::MSWIN,
|
||||
mswin_22: Gem::Platform::MSWIN,
|
||||
mswin_23: Gem::Platform::MSWIN,
|
||||
mswin_24: Gem::Platform::MSWIN,
|
||||
mswin_25: Gem::Platform::MSWIN,
|
||||
mswin_26: Gem::Platform::MSWIN,
|
||||
mswin_27: Gem::Platform::MSWIN,
|
||||
mswin_30: Gem::Platform::MSWIN,
|
||||
mswin_31: Gem::Platform::MSWIN,
|
||||
mswin_32: Gem::Platform::MSWIN,
|
||||
mswin_33: Gem::Platform::MSWIN,
|
||||
mswin_34: Gem::Platform::MSWIN,
|
||||
mswin_35: Gem::Platform::MSWIN,
|
||||
mswin64: Gem::Platform::MSWIN64,
|
||||
mswin64_19: Gem::Platform::MSWIN64,
|
||||
mswin64_20: Gem::Platform::MSWIN64,
|
||||
mswin64_21: Gem::Platform::MSWIN64,
|
||||
mswin64_22: Gem::Platform::MSWIN64,
|
||||
mswin64_23: Gem::Platform::MSWIN64,
|
||||
mswin64_24: Gem::Platform::MSWIN64,
|
||||
mswin64_25: Gem::Platform::MSWIN64,
|
||||
mswin64_26: Gem::Platform::MSWIN64,
|
||||
mswin64_27: Gem::Platform::MSWIN64,
|
||||
mswin64_30: Gem::Platform::MSWIN64,
|
||||
mswin64_31: Gem::Platform::MSWIN64,
|
||||
mswin64_32: Gem::Platform::MSWIN64,
|
||||
mswin64_33: Gem::Platform::MSWIN64,
|
||||
mswin64_34: Gem::Platform::MSWIN64,
|
||||
mswin64_35: Gem::Platform::MSWIN64,
|
||||
mingw: Gem::Platform::MINGW,
|
||||
mingw_18: Gem::Platform::MINGW,
|
||||
mingw_19: Gem::Platform::MINGW,
|
||||
mingw_20: Gem::Platform::MINGW,
|
||||
mingw_21: Gem::Platform::MINGW,
|
||||
mingw_22: Gem::Platform::MINGW,
|
||||
mingw_23: Gem::Platform::MINGW,
|
||||
mingw_24: Gem::Platform::MINGW,
|
||||
mingw_25: Gem::Platform::MINGW,
|
||||
mingw_26: Gem::Platform::MINGW,
|
||||
mingw_27: Gem::Platform::MINGW,
|
||||
mingw_30: Gem::Platform::MINGW,
|
||||
mingw_31: Gem::Platform::MINGW,
|
||||
mingw_32: Gem::Platform::MINGW,
|
||||
mingw_33: Gem::Platform::MINGW,
|
||||
mingw_34: Gem::Platform::MINGW,
|
||||
mingw_35: Gem::Platform::MINGW,
|
||||
x64_mingw: Gem::Platform::X64_MINGW,
|
||||
x64_mingw_20: Gem::Platform::X64_MINGW,
|
||||
x64_mingw_21: Gem::Platform::X64_MINGW,
|
||||
x64_mingw_22: Gem::Platform::X64_MINGW,
|
||||
x64_mingw_23: Gem::Platform::X64_MINGW,
|
||||
x64_mingw_24: Gem::Platform::X64_MINGW,
|
||||
x64_mingw_25: Gem::Platform::X64_MINGW,
|
||||
x64_mingw_26: Gem::Platform::X64_MINGW,
|
||||
x64_mingw_27: Gem::Platform::X64_MINGW,
|
||||
x64_mingw_30: Gem::Platform::X64_MINGW,
|
||||
x64_mingw_31: Gem::Platform::X64_MINGW,
|
||||
x64_mingw_32: Gem::Platform::X64_MINGW,
|
||||
x64_mingw_33: Gem::Platform::X64_MINGW,
|
||||
x64_mingw_34: Gem::Platform::X64_MINGW,
|
||||
x64_mingw_35: Gem::Platform::X64_MINGW }
|
||||
end
|
||||
# rubocop:enable Naming/VariableNumber
|
||||
|
||||
it "includes all platforms" do
|
||||
expect(subject).to eq(platforms.merge(deprecated))
|
||||
end
|
||||
end
|
||||
end
|
@ -35,142 +35,6 @@ RSpec.describe Bundler::Dependency do
|
||||
end
|
||||
end
|
||||
|
||||
describe "PLATFORM_MAP" do
|
||||
subject { described_class::PLATFORM_MAP }
|
||||
|
||||
# rubocop:disable Naming/VariableNumber
|
||||
let(:platforms) do
|
||||
{ ruby: Gem::Platform::RUBY,
|
||||
ruby_18: Gem::Platform::RUBY,
|
||||
ruby_19: Gem::Platform::RUBY,
|
||||
ruby_20: Gem::Platform::RUBY,
|
||||
ruby_21: Gem::Platform::RUBY,
|
||||
ruby_22: Gem::Platform::RUBY,
|
||||
ruby_23: Gem::Platform::RUBY,
|
||||
ruby_24: Gem::Platform::RUBY,
|
||||
ruby_25: Gem::Platform::RUBY,
|
||||
ruby_26: Gem::Platform::RUBY,
|
||||
ruby_27: Gem::Platform::RUBY,
|
||||
ruby_30: Gem::Platform::RUBY,
|
||||
ruby_31: Gem::Platform::RUBY,
|
||||
ruby_32: Gem::Platform::RUBY,
|
||||
ruby_33: Gem::Platform::RUBY,
|
||||
ruby_34: Gem::Platform::RUBY,
|
||||
ruby_35: Gem::Platform::RUBY,
|
||||
mri: Gem::Platform::RUBY,
|
||||
mri_18: Gem::Platform::RUBY,
|
||||
mri_19: Gem::Platform::RUBY,
|
||||
mri_20: Gem::Platform::RUBY,
|
||||
mri_21: Gem::Platform::RUBY,
|
||||
mri_22: Gem::Platform::RUBY,
|
||||
mri_23: Gem::Platform::RUBY,
|
||||
mri_24: Gem::Platform::RUBY,
|
||||
mri_25: Gem::Platform::RUBY,
|
||||
mri_26: Gem::Platform::RUBY,
|
||||
mri_27: Gem::Platform::RUBY,
|
||||
mri_30: Gem::Platform::RUBY,
|
||||
mri_31: Gem::Platform::RUBY,
|
||||
mri_32: Gem::Platform::RUBY,
|
||||
mri_33: Gem::Platform::RUBY,
|
||||
mri_34: Gem::Platform::RUBY,
|
||||
mri_35: Gem::Platform::RUBY,
|
||||
rbx: Gem::Platform::RUBY,
|
||||
truffleruby: Gem::Platform::RUBY,
|
||||
jruby: Gem::Platform::JAVA,
|
||||
jruby_18: Gem::Platform::JAVA,
|
||||
jruby_19: Gem::Platform::JAVA,
|
||||
windows: Gem::Platform::WINDOWS,
|
||||
windows_18: Gem::Platform::WINDOWS,
|
||||
windows_19: Gem::Platform::WINDOWS,
|
||||
windows_20: Gem::Platform::WINDOWS,
|
||||
windows_21: Gem::Platform::WINDOWS,
|
||||
windows_22: Gem::Platform::WINDOWS,
|
||||
windows_23: Gem::Platform::WINDOWS,
|
||||
windows_24: Gem::Platform::WINDOWS,
|
||||
windows_25: Gem::Platform::WINDOWS,
|
||||
windows_26: Gem::Platform::WINDOWS,
|
||||
windows_27: Gem::Platform::WINDOWS,
|
||||
windows_30: Gem::Platform::WINDOWS,
|
||||
windows_31: Gem::Platform::WINDOWS,
|
||||
windows_32: Gem::Platform::WINDOWS,
|
||||
windows_33: Gem::Platform::WINDOWS,
|
||||
windows_34: Gem::Platform::WINDOWS,
|
||||
windows_35: Gem::Platform::WINDOWS }
|
||||
end
|
||||
|
||||
let(:deprecated) do
|
||||
{ mswin: Gem::Platform::MSWIN,
|
||||
mswin_18: Gem::Platform::MSWIN,
|
||||
mswin_19: Gem::Platform::MSWIN,
|
||||
mswin_20: Gem::Platform::MSWIN,
|
||||
mswin_21: Gem::Platform::MSWIN,
|
||||
mswin_22: Gem::Platform::MSWIN,
|
||||
mswin_23: Gem::Platform::MSWIN,
|
||||
mswin_24: Gem::Platform::MSWIN,
|
||||
mswin_25: Gem::Platform::MSWIN,
|
||||
mswin_26: Gem::Platform::MSWIN,
|
||||
mswin_27: Gem::Platform::MSWIN,
|
||||
mswin_30: Gem::Platform::MSWIN,
|
||||
mswin_31: Gem::Platform::MSWIN,
|
||||
mswin_32: Gem::Platform::MSWIN,
|
||||
mswin_33: Gem::Platform::MSWIN,
|
||||
mswin_34: Gem::Platform::MSWIN,
|
||||
mswin_35: Gem::Platform::MSWIN,
|
||||
mswin64: Gem::Platform::MSWIN64,
|
||||
mswin64_19: Gem::Platform::MSWIN64,
|
||||
mswin64_20: Gem::Platform::MSWIN64,
|
||||
mswin64_21: Gem::Platform::MSWIN64,
|
||||
mswin64_22: Gem::Platform::MSWIN64,
|
||||
mswin64_23: Gem::Platform::MSWIN64,
|
||||
mswin64_24: Gem::Platform::MSWIN64,
|
||||
mswin64_25: Gem::Platform::MSWIN64,
|
||||
mswin64_26: Gem::Platform::MSWIN64,
|
||||
mswin64_27: Gem::Platform::MSWIN64,
|
||||
mswin64_30: Gem::Platform::MSWIN64,
|
||||
mswin64_31: Gem::Platform::MSWIN64,
|
||||
mswin64_32: Gem::Platform::MSWIN64,
|
||||
mswin64_33: Gem::Platform::MSWIN64,
|
||||
mswin64_34: Gem::Platform::MSWIN64,
|
||||
mswin64_35: Gem::Platform::MSWIN64,
|
||||
mingw: Gem::Platform::MINGW,
|
||||
mingw_18: Gem::Platform::MINGW,
|
||||
mingw_19: Gem::Platform::MINGW,
|
||||
mingw_20: Gem::Platform::MINGW,
|
||||
mingw_21: Gem::Platform::MINGW,
|
||||
mingw_22: Gem::Platform::MINGW,
|
||||
mingw_23: Gem::Platform::MINGW,
|
||||
mingw_24: Gem::Platform::MINGW,
|
||||
mingw_25: Gem::Platform::MINGW,
|
||||
mingw_26: Gem::Platform::MINGW,
|
||||
mingw_27: Gem::Platform::MINGW,
|
||||
mingw_30: Gem::Platform::MINGW,
|
||||
mingw_31: Gem::Platform::MINGW,
|
||||
mingw_32: Gem::Platform::MINGW,
|
||||
mingw_33: Gem::Platform::MINGW,
|
||||
mingw_34: Gem::Platform::MINGW,
|
||||
mingw_35: Gem::Platform::MINGW,
|
||||
x64_mingw: Gem::Platform::X64_MINGW,
|
||||
x64_mingw_20: Gem::Platform::X64_MINGW,
|
||||
x64_mingw_21: Gem::Platform::X64_MINGW,
|
||||
x64_mingw_22: Gem::Platform::X64_MINGW,
|
||||
x64_mingw_23: Gem::Platform::X64_MINGW,
|
||||
x64_mingw_24: Gem::Platform::X64_MINGW,
|
||||
x64_mingw_25: Gem::Platform::X64_MINGW,
|
||||
x64_mingw_26: Gem::Platform::X64_MINGW,
|
||||
x64_mingw_27: Gem::Platform::X64_MINGW,
|
||||
x64_mingw_30: Gem::Platform::X64_MINGW,
|
||||
x64_mingw_31: Gem::Platform::X64_MINGW,
|
||||
x64_mingw_32: Gem::Platform::X64_MINGW,
|
||||
x64_mingw_33: Gem::Platform::X64_MINGW,
|
||||
x64_mingw_34: Gem::Platform::X64_MINGW,
|
||||
x64_mingw_35: Gem::Platform::X64_MINGW }
|
||||
end
|
||||
# rubocop:enable Naming/VariableNumber
|
||||
|
||||
it "includes all platforms" do
|
||||
expect(subject).to eq(platforms.merge(deprecated))
|
||||
end
|
||||
|
||||
it "is on the current platform" do
|
||||
engine = Gem.win_platform? ? "windows" : RUBY_ENGINE
|
||||
|
||||
@ -182,5 +46,4 @@ RSpec.describe Bundler::Dependency do
|
||||
|
||||
expect(dep.current_platform?).to be_truthy
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user