diff --git a/bundler/lib/bundler/definition.rb b/bundler/lib/bundler/definition.rb index 09be2db68ca0..044445e11b2d 100644 --- a/bundler/lib/bundler/definition.rb +++ b/bundler/lib/bundler/definition.rb @@ -746,17 +746,8 @@ def metadata_dependencies def ruby_version_requirements(ruby_version) return [] unless ruby_version - if ruby_version.patchlevel - [ruby_version.to_gem_version_with_patchlevel] - else - ruby_version.versions.map do |version| - requirement = Gem::Requirement.new(version) - if requirement.exact? - "~> #{version}.0" - else - requirement - end - end + ruby_version.versions.map do |version| + Gem::Requirement.new(version) end end diff --git a/bundler/lib/bundler/ruby_version.rb b/bundler/lib/bundler/ruby_version.rb index d3b7963920c9..5a2c362677da 100644 --- a/bundler/lib/bundler/ruby_version.rb +++ b/bundler/lib/bundler/ruby_version.rb @@ -110,14 +110,6 @@ def self.system @ruby_version ||= RubyVersion.new(ruby_version, patchlevel, ruby_engine, ruby_engine_version) end - def to_gem_version_with_patchlevel - @gem_version_with_patch ||= begin - Gem::Version.create("#{@gem_version}.#{@patchlevel}") - rescue ArgumentError - @gem_version - end - end - def exact? return @exact if defined?(@exact) @exact = versions.all? {|v| Gem::Requirement.create(v).exact? } diff --git a/bundler/lib/bundler/rubygems_ext.rb b/bundler/lib/bundler/rubygems_ext.rb index 78422ceb765c..b0e35e005ea2 100644 --- a/bundler/lib/bundler/rubygems_ext.rb +++ b/bundler/lib/bundler/rubygems_ext.rb @@ -67,6 +67,23 @@ def gem_dir full_gem_path end + unless const_defined?(:LATEST_RUBY_WITHOUT_PATCH_VERSIONS) + LATEST_RUBY_WITHOUT_PATCH_VERSIONS = Gem::Version.new("2.1") + + alias_method :rg_required_ruby_version=, :required_ruby_version= + def required_ruby_version=(req) + self.rg_required_ruby_version = req + + @required_ruby_version.requirements.map! do |op, v| + if v >= LATEST_RUBY_WITHOUT_PATCH_VERSIONS && v.release.segments.size == 4 + [op == "~>" ? "=" : op, Gem::Version.new(v.segments.tap {|s| s.delete_at(3) }.join("."))] + else + [op, v] + end + end + end + end + def groups @groups ||= [] end diff --git a/bundler/lib/bundler/source/metadata.rb b/bundler/lib/bundler/source/metadata.rb index 524afd750a84..185fe7082474 100644 --- a/bundler/lib/bundler/source/metadata.rb +++ b/bundler/lib/bundler/source/metadata.rb @@ -5,7 +5,7 @@ class Source class Metadata < Source def specs @specs ||= Index.build do |idx| - idx << Gem::Specification.new("Ruby\0", RubyVersion.system.to_gem_version_with_patchlevel) + idx << Gem::Specification.new("Ruby\0", RubyVersion.system.gem_version) idx << Gem::Specification.new("RubyGems\0", Gem::VERSION) do |s| s.required_rubygems_version = Gem::Requirement.default end diff --git a/bundler/spec/bundler/ruby_version_spec.rb b/bundler/spec/bundler/ruby_version_spec.rb index 8c6c071d7f01..3e3850031c24 100644 --- a/bundler/spec/bundler/ruby_version_spec.rb +++ b/bundler/spec/bundler/ruby_version_spec.rb @@ -498,31 +498,5 @@ end end end - - describe "#to_gem_version_with_patchlevel" do - shared_examples_for "the patchlevel is omitted" do - it "does not include a patch level" do - expect(subject.to_gem_version_with_patchlevel.to_s).to eq(version) - end - end - - context "with nil patch number" do - let(:patchlevel) { nil } - - it_behaves_like "the patchlevel is omitted" - end - - context "with negative patch number" do - let(:patchlevel) { -1 } - - it_behaves_like "the patchlevel is omitted" - end - - context "with a valid patch number" do - it "uses the specified patchlevel as patchlevel" do - expect(subject.to_gem_version_with_patchlevel.to_s).to eq("#{version}.#{patchlevel}") - end - end - end end end diff --git a/bundler/spec/install/gems/resolving_spec.rb b/bundler/spec/install/gems/resolving_spec.rb index 209996f61fde..21ecaad50e0f 100644 --- a/bundler/spec/install/gems/resolving_spec.rb +++ b/bundler/spec/install/gems/resolving_spec.rb @@ -301,7 +301,7 @@ end let(:ruby_requirement) { %("#{RUBY_VERSION}") } - let(:error_message_requirement) { "~> #{RUBY_VERSION}.0" } + let(:error_message_requirement) { "= #{RUBY_VERSION}" } shared_examples_for "ruby version conflicts" do it "raises an error during resolution" do diff --git a/lib/rubygems.rb b/lib/rubygems.rb index d2c404d7d3f5..886b7167c485 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -864,9 +864,7 @@ def self.ruby_version return @ruby_version if defined? @ruby_version version = RUBY_VERSION.dup - if defined?(RUBY_PATCHLEVEL) && RUBY_PATCHLEVEL != -1 - version << ".#{RUBY_PATCHLEVEL}" - elsif defined?(RUBY_DESCRIPTION) + if defined?(RUBY_DESCRIPTION) if RUBY_ENGINE == "ruby" desc = RUBY_DESCRIPTION[/\Aruby #{Regexp.quote(RUBY_VERSION)}([^ ]+) /, 1] else diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index 0d72cee51d5b..7e7599f7dbf9 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -657,6 +657,8 @@ def rdoc_options @rdoc_options ||= [] end + LATEST_RUBY_WITHOUT_PATCH_VERSIONS = Gem::Version.new("2.1") + ## # The version of Ruby required by this gem. The ruby version can be # specified to the patch-level: @@ -683,6 +685,14 @@ def rdoc_options def required_ruby_version=(req) @required_ruby_version = Gem::Requirement.create req + + @required_ruby_version.requirements.map! do |op, v| + if v >= LATEST_RUBY_WITHOUT_PATCH_VERSIONS && v.release.segments.size == 4 + [op == "~>" ? "=" : op, Gem::Version.new(v.segments.tap {|s| s.delete_at(3) }.join("."))] + else + [op, v] + end + end end ## diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb index a8be07804660..df1c6e0e58ea 100644 --- a/test/rubygems/test_gem.rb +++ b/test/rubygems/test_gem.rb @@ -1114,14 +1114,6 @@ def test_self_ruby_version_with_patchlevel_less_ancient_rubies util_restore_RUBY_VERSION end - def test_self_ruby_version_with_release - util_set_RUBY_VERSION '1.8.6', 287 - - assert_equal Gem::Version.new('1.8.6.287'), Gem.ruby_version - ensure - util_restore_RUBY_VERSION - end - def test_self_ruby_version_with_non_mri_implementations util_set_RUBY_VERSION '2.5.0', 0, 60928, 'jruby 9.2.0.0 (2.5.0) 2018-05-24 81156a8 OpenJDK 64-Bit Server VM 25.171-b11 on 1.8.0_171-8u171-b11-0ubuntu0.16.04.1-b11 [linux-x86_64]'