Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Remove version overriding stuff unless necessary
Browse files Browse the repository at this point in the history
By doing this we avoid circular requires (`rubygems` requires `bundler` via
`USE_GEMDEPS`, `bundler` requires `rubygems` when loading its own version), and
also redefinition warnings when the `bundler.gemspec` is evaluated with
`rubygems` already loaded (for example, when running `ruby setup.rb`
from `rubygems` repo).

When working with rubygems versions that didn't have the bundler version
finder, it seems to be necessary, but for newer rubygems versions it's
not.
  • Loading branch information
deivid-rodriguez committed May 3, 2019
1 parent 9cc693b commit 824b6ef
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
4 changes: 4 additions & 0 deletions lib/bundler/rubygems_integration.rb
Expand Up @@ -317,6 +317,10 @@ def stubs_provide_full_functionality?
provides?(">= 2.5.2")
end

def has_bundler_version_finder?
provides?(">= 2.7.0")
end

def replace_gem(specs, specs_by_name)
reverse_rubygems_kernel_mixin

Expand Down
34 changes: 20 additions & 14 deletions lib/bundler/version.rb
@@ -1,23 +1,29 @@
# frozen_string_literal: false

require_relative "rubygems_integration"

module Bundler
# We're doing this because we might write tests that deal
# with other versions of bundler and we are unsure how to
# handle this better.
VERSION = "2.1.0.pre.1".freeze unless defined?(::Bundler::VERSION)
if Bundler.rubygems.has_bundler_version_finder?
VERSION = "2.1.0.pre.1".freeze
else
# We're doing this because we might write tests that deal
# with other versions of bundler and we are unsure how to
# handle this better.
VERSION = "2.1.0.pre.1".freeze unless defined?(::Bundler::VERSION)

def self.overwrite_loaded_gem_version
begin
require "rubygems"
rescue LoadError
return
def self.overwrite_loaded_gem_version
begin
require "rubygems"
rescue LoadError
return
end
return unless bundler_spec = Gem.loaded_specs["bundler"]
return if bundler_spec.version == VERSION
bundler_spec.version = Bundler::VERSION
end
return unless bundler_spec = Gem.loaded_specs["bundler"]
return if bundler_spec.version == VERSION
bundler_spec.version = Bundler::VERSION
private_class_method :overwrite_loaded_gem_version
overwrite_loaded_gem_version
end
private_class_method :overwrite_loaded_gem_version
overwrite_loaded_gem_version

def self.bundler_major_version
@bundler_major_version ||= VERSION.split(".").first.to_i
Expand Down

0 comments on commit 824b6ef

Please sign in to comment.