Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 23 additions & 33 deletions bundler/lib/bundler/current_ruby.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require_relative "rubygems_ext"

module Bundler
# Returns current version of Ruby
#
Expand All @@ -9,38 +11,25 @@ def self.current_ruby
end

class CurrentRuby
KNOWN_MINOR_VERSIONS = %w[
1.8
1.9
2.0
2.1
2.2
2.3
2.4
2.5
2.6
2.7
3.0
3.1
3.2
3.3
].freeze

KNOWN_MAJOR_VERSIONS = KNOWN_MINOR_VERSIONS.map {|v| v.split(".", 2).first }.uniq.freeze

KNOWN_PLATFORMS = %w[
jruby
maglev
mingw
mri
mswin
mswin64
rbx
ruby
truffleruby
windows
x64_mingw
].freeze
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
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?
Expand Down Expand Up @@ -82,7 +71,8 @@ def windows?
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
Expand Down
21 changes: 1 addition & 20 deletions bundler/lib/bundler/dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +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

ALL_RUBY_VERSIONS = (18..27).to_a.concat((30..35).to_a).freeze
PLATFORM_MAP = {
ruby: [Gem::Platform::RUBY, ALL_RUBY_VERSIONS],
mri: [Gem::Platform::RUBY, ALL_RUBY_VERSIONS],
rbx: [Gem::Platform::RUBY],
truffleruby: [Gem::Platform::RUBY],
jruby: [Gem::Platform::JAVA, [18, 19]],
windows: [Gem::Platform::WINDOWS, ALL_RUBY_VERSIONS],
# deprecated
mswin: [Gem::Platform::MSWIN, ALL_RUBY_VERSIONS],
mswin64: [Gem::Platform::MSWIN64, ALL_RUBY_VERSIONS - [18]],
mingw: [Gem::Platform::MINGW, ALL_RUBY_VERSIONS],
x64_mingw: [Gem::Platform::X64_MINGW, 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)
Expand Down Expand Up @@ -62,7 +43,7 @@ def gem_platforms(valid_platforms)
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?
Expand Down
2 changes: 1 addition & 1 deletion bundler/lib/bundler/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def self.evaluate(gemfile, lockfile, unlock)
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
Expand Down
140 changes: 140 additions & 0 deletions bundler/spec/bundler/current_ruby_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Loading
Loading