summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBundlerbot <bot@bundler.io>2019-04-14 13:40:07 +0000
committerBundlerbot <bot@bundler.io>2019-04-14 13:40:07 +0000
commitb165ba236f3f39245bfa3c3aca88153a3a0341e3 (patch)
treef5c47efe591b0e92a9852d1ecf6d75597212fab6
parent0a20c21d87a85d5ce581480e8f6dd647b76176b2 (diff)
parent57b06c0ff671a647fbc61c87d4f36418426659dc (diff)
downloadbundler-b165ba236f3f39245bfa3c3aca88153a3a0341e3.tar.gz
Merge #7043
7043: Remove old rubygems compatibility code r=bronzdoc a=deivid-rodriguez ### What was the end-user problem that led to this PR? The problem was that I was unsure where I needed to add the compatibility layer to #6963, and it took me a bit to scan through the compatibility file and figure it out. ### What was your diagnosis of the problem? My diagnosis was that all this compatibility code is unused but makes this file harder to understand and scan through. ### What is your fix for the problem, implemented in this PR? My fix is to remove the code. ### Why did you choose this fix out of the possible options? I chose this fix because we can do it, I think. Co-authored-by: David Rodríguez <deivid.rodriguez@riseup.net>
-rw-r--r--lib/bundler/rubygems_ext.rb29
-rw-r--r--lib/bundler/rubygems_integration.rb437
2 files changed, 117 insertions, 349 deletions
diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb
index ccf71c8c00..beed6372a3 100644
--- a/lib/bundler/rubygems_ext.rb
+++ b/lib/bundler/rubygems_ext.rb
@@ -4,40 +4,25 @@ require "pathname"
require "rubygems/specification"
-begin
- # Possible use in Gem::Specification#source below and require
- # shouldn't be deferred.
- require "rubygems/source"
-rescue LoadError
- # Not available before RubyGems 2.0.0, ignore
- nil
-end
+# Possible use in Gem::Specification#source below and require
+# shouldn't be deferred.
+require "rubygems/source"
require "bundler/match_platform"
module Gem
- @loaded_stacks = Hash.new {|h, k| h[k] = [] }
-
class Specification
attr_accessor :remote, :location, :relative_loaded_from
- if instance_methods(false).include?(:source)
- remove_method :source
- attr_writer :source
- def source
- (defined?(@source) && @source) || Gem::Source::Installed.new
- end
- else
- # rubocop:disable Lint/DuplicateMethods
- attr_accessor :source
- # rubocop:enable Lint/DuplicateMethods
+ remove_method :source
+ attr_writer :source
+ def source
+ (defined?(@source) && @source) || Gem::Source::Installed.new
end
alias_method :rg_full_gem_path, :full_gem_path
alias_method :rg_loaded_from, :loaded_from
- attr_writer :full_gem_path unless instance_methods.include?(:full_gem_path=)
-
def full_gem_path
# this cannot check source.is_a?(Bundler::Plugin::API::Source)
# because that _could_ trip the autoload, and if there are unresolved
diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb
index a4519246a9..ca7dd32611 100644
--- a/lib/bundler/rubygems_integration.rb
+++ b/lib/bundler/rubygems_integration.rb
@@ -20,6 +20,7 @@ module Bundler
def initialize
@replaced_methods = {}
+ backport_ext_builder_monitor
end
def version
@@ -198,10 +199,6 @@ module Bundler
Gem::ConfigMap
end
- def repository_subdirectories
- %w[cache doc gems specifications]
- end
-
def clear_paths
Gem.clear_paths
end
@@ -210,10 +207,6 @@ module Bundler
Gem.bin_path(gem, bin, ver)
end
- def path_separator
- File::PATH_SEPARATOR
- end
-
def preserve_paths
# this is a no-op outside of RubyGems 1.8
yield
@@ -248,36 +241,12 @@ module Bundler
EXT_LOCK
end
- def fetch_specs(all, pre, &blk)
- require "rubygems/spec_fetcher"
- specs = Gem::SpecFetcher.new.list(all, pre)
- specs.each { yield } if block_given?
- specs
- end
-
def fetch_prerelease_specs
fetch_specs(false, true)
rescue Gem::RemoteFetcher::FetchError
{} # if we can't download them, there aren't any
end
- # TODO: This is for older versions of RubyGems... should we support the
- # X-Gemfile-Source header on these old versions?
- # Maybe the newer implementation will work on older RubyGems?
- # It seems difficult to keep this implementation and still send the header.
- def fetch_all_remote_specs(remote)
- old_sources = Bundler.rubygems.sources
- Bundler.rubygems.sources = [remote.uri.to_s]
- # Fetch all specs, minus prerelease specs
- spec_list = fetch_specs(true, false)
- # Then fetch the prerelease specs
- fetch_prerelease_specs.each {|k, v| spec_list[k].concat(v) }
-
- spec_list.values.first
- ensure
- Bundler.rubygems.sources = old_sources
- end
-
def with_build_args(args)
ext_lock.synchronize do
old_args = build_args
@@ -290,15 +259,6 @@ module Bundler
end
end
- def install_with_build_args(args)
- with_build_args(args) { yield }
- end
-
- def gem_from_path(path, policy = nil)
- require "rubygems/format"
- Gem::Format.from_file_by_path(path, policy)
- end
-
def spec_from_gem(path, policy = nil)
require "rubygems/security"
require "bundler/psyched_yaml"
@@ -317,23 +277,10 @@ module Bundler
end
end
- def build(spec, skip_validation = false)
- require "rubygems/builder"
- Gem::Builder.new(spec).build
- end
-
def build_gem(gem_dir, spec)
build(spec)
end
- def download_gem(spec, uri, path)
- uri = Bundler.settings.mirror_for(uri)
- fetcher = Gem::RemoteFetcher.new(configuration[:http_proxy])
- Bundler::Retry.new("download gem from #{uri}").attempts do
- fetcher.download(spec, uri, path)
- end
- end
-
def security_policy_keys
%w[High Medium Low AlmostNo No].map {|level| "#{level}Security" }
end
@@ -357,12 +304,27 @@ module Bundler
end
end
- def binstubs_call_gem?
- true
- end
+ if provides?(">= 2.5.2")
+ # RubyGems-generated binstubs call Kernel#gem
+ def binstubs_call_gem?
+ false
+ end
+
+ # only 2.5.2+ has all of the stub methods we want to use, and since this
+ # is a performance optimization _only_,
+ # we'll restrict ourselves to the most
+ # recent RG versions instead of all versions that have stubs
+ def stubs_provide_full_functionality?
+ true
+ end
+ else
+ def binstubs_call_gem?
+ true
+ end
- def stubs_provide_full_functionality?
- false
+ def stubs_provide_full_functionality?
+ false
+ end
end
def replace_gem(specs, specs_by_name)
@@ -411,26 +373,6 @@ module Bundler
end
end
- def stub_source_index(specs)
- Gem::SourceIndex.send(:alias_method, :old_initialize, :initialize)
- redefine_method(Gem::SourceIndex, :initialize) do |*args|
- @gems = {}
- # You're looking at this thinking: Oh! This is how I make those
- # rubygems deprecations go away!
- #
- # You'd be correct BUT using of this method in production code
- # must be approved by the rubygems team itself!
- #
- # This is your warning. If you use this and don't have approval
- # we can't protect you.
- #
- Deprecate.skip_during do
- self.spec_dirs = *args
- add_specs(*specs)
- end
- end
- end
-
# Used to make bin stubs that are not created by bundler work
# under bundler. The new Gem.bin_path only considers gems in
# +specs+
@@ -622,296 +564,137 @@ module Bundler
end
end
- # RubyGems 1.4 through 1.6
- class Legacy < RubygemsIntegration
- def initialize
- super
- backport_base_dir
- backport_cache_file
- backport_spec_file
- backport_yaml_initialize
- end
+ def stub_rubygems(specs)
+ Gem::Specification.all = specs
- def stub_rubygems(specs)
- # RubyGems versions lower than 1.7 use SourceIndex#from_gems_in
- source_index_class = (class << Gem::SourceIndex; self; end)
- redefine_method(source_index_class, :from_gems_in) do |*args|
- Gem::SourceIndex.new.tap do |source_index|
- source_index.spec_dirs = *args
- source_index.add_specs(*specs)
- end
- end
+ Gem.post_reset do
+ Gem::Specification.all = specs
end
- def all_specs
- Gem.source_index.gems.values
+ redefine_method((class << Gem; self; end), :finish_resolve) do |*|
+ []
end
+ end
- def find_name(name)
- Gem.source_index.find_name(name)
- end
+ def fetch_specs(source, remote, name)
+ path = source + "#{name}.#{Gem.marshal_version}.gz"
+ fetcher = gem_remote_fetcher
+ fetcher.headers = { "X-Gemfile-Source" => remote.original_uri.to_s } if remote.original_uri
+ string = fetcher.fetch_path(path)
+ Bundler.load_marshal(string)
+ rescue Gem::RemoteFetcher::FetchError => e
+ # it's okay for prerelease to fail
+ raise e unless name == "prerelease_specs"
+ end
- def validate(spec)
- # These versions of RubyGems always validate in "packaging" mode,
- # which is too strict for the kinds of checks we care about. As a
- # result, validation is disabled on versions of RubyGems below 1.7.
- end
+ def fetch_all_remote_specs(remote)
+ source = remote.uri.is_a?(URI) ? remote.uri : URI.parse(source.to_s)
- def post_reset_hooks
- []
- end
+ specs = fetch_specs(source, remote, "specs")
+ pres = fetch_specs(source, remote, "prerelease_specs") || []
- def reset
- end
+ specs.concat(pres)
end
- # RubyGems versions 1.3.6 and 1.3.7
- class Ancient < Legacy
- def initialize
- super
- backport_segment_generation
+ def download_gem(spec, uri, path)
+ uri = Bundler.settings.mirror_for(uri)
+ fetcher = gem_remote_fetcher
+ fetcher.headers = { "X-Gemfile-Source" => spec.remote.original_uri.to_s } if spec.remote.original_uri
+ Bundler::Retry.new("download gem from #{uri}").attempts do
+ fetcher.download(spec, uri, path)
end
end
- # RubyGems 1.7
- class Transitional < Legacy
- def stub_rubygems(specs)
- stub_source_index(specs)
- end
-
- def validate(spec)
- # Missing summary is downgraded to a warning in later versions,
- # so we set it to an empty string to prevent an exception here.
- spec.summary ||= ""
- RubygemsIntegration.instance_method(:validate).bind(self).call(spec)
- end
+ def gem_remote_fetcher
+ require "resolv"
+ proxy = configuration[:http_proxy]
+ dns = Resolv::DNS.new
+ Bundler::GemRemoteFetcher.new(proxy, dns)
end
- # RubyGems 1.8.5-1.8.19
- class Modern < RubygemsIntegration
- def stub_rubygems(specs)
- Gem::Specification.all = specs
-
- Gem.post_reset do
- Gem::Specification.all = specs
- end
+ def gem_from_path(path, policy = nil)
+ require "rubygems/package"
+ p = Gem::Package.new(path)
+ p.security_policy = policy if policy
+ p
+ end
- stub_source_index(specs)
- end
+ def build(spec, skip_validation = false)
+ require "rubygems/package"
+ Gem::Package.build(spec, skip_validation)
+ end
- def all_specs
- Gem::Specification.to_a
- end
+ def repository_subdirectories
+ Gem::REPOSITORY_SUBDIRECTORIES
+ end
- def find_name(name)
- Gem::Specification.find_all_by_name name
- end
+ def install_with_build_args(args)
+ yield
end
- # RubyGems 1.8.0 to 1.8.4
- class AlmostModern < Modern
- # RubyGems [>= 1.8.0, < 1.8.5] has a bug that changes Gem.dir whenever
- # you call Gem::Installer#install with an :install_dir set. We have to
- # change it back for our sudo mode to work.
- def preserve_paths
- old_dir = gem_dir
- old_path = gem_path
- yield
- Gem.use_paths(old_dir, old_path)
- end
+ def path_separator
+ Gem.path_separator
end
- # RubyGems 1.8.20+
- class MoreModern < Modern
- # RubyGems 1.8.20 and adds the skip_validation parameter, so that's
- # when we start passing it through.
- def build(spec, skip_validation = false)
- require "rubygems/builder"
- Gem::Builder.new(spec).build(skip_validation)
+ def all_specs
+ require "bundler/remote_specification"
+ Gem::Specification.stubs.map do |stub|
+ StubSpecification.from_stub(stub)
end
end
- # RubyGems 2.0
- class Future < RubygemsIntegration
- def stub_rubygems(specs)
- Gem::Specification.all = specs
-
- Gem.post_reset do
- Gem::Specification.all = specs
- end
-
- redefine_method((class << Gem; self; end), :finish_resolve) do |*|
- []
+ def backport_ext_builder_monitor
+ # So we can avoid requiring "rubygems/ext" in its entirety
+ Gem.module_eval <<-RB, __FILE__, __LINE__ + 1
+ module Ext
end
- end
+ RB
- def all_specs
- Gem::Specification.to_a
- end
+ require "rubygems/ext/builder"
- def find_name(name)
- Gem::Specification.find_all_by_name name
- end
-
- def fetch_specs(source, remote, name)
- path = source + "#{name}.#{Gem.marshal_version}.gz"
- fetcher = gem_remote_fetcher
- fetcher.headers = { "X-Gemfile-Source" => remote.original_uri.to_s } if remote.original_uri
- string = fetcher.fetch_path(path)
- Bundler.load_marshal(string)
- rescue Gem::RemoteFetcher::FetchError => e
- # it's okay for prerelease to fail
- raise e unless name == "prerelease_specs"
- end
-
- def fetch_all_remote_specs(remote)
- source = remote.uri.is_a?(URI) ? remote.uri : URI.parse(source.to_s)
-
- specs = fetch_specs(source, remote, "specs")
- pres = fetch_specs(source, remote, "prerelease_specs") || []
-
- specs.concat(pres)
- end
-
- def download_gem(spec, uri, path)
- uri = Bundler.settings.mirror_for(uri)
- fetcher = gem_remote_fetcher
- fetcher.headers = { "X-Gemfile-Source" => spec.remote.original_uri.to_s } if spec.remote.original_uri
- Bundler::Retry.new("download gem from #{uri}").attempts do
- fetcher.download(spec, uri, path)
+ Gem::Ext::Builder.class_eval do
+ unless const_defined?(:CHDIR_MONITOR)
+ const_set(:CHDIR_MONITOR, EXT_LOCK)
end
- end
-
- def gem_remote_fetcher
- require "resolv"
- proxy = configuration[:http_proxy]
- dns = Resolv::DNS.new
- Bundler::GemRemoteFetcher.new(proxy, dns)
- end
-
- def gem_from_path(path, policy = nil)
- require "rubygems/package"
- p = Gem::Package.new(path)
- p.security_policy = policy if policy
- p
- end
-
- def build(spec, skip_validation = false)
- require "rubygems/package"
- Gem::Package.build(spec, skip_validation)
- end
-
- def repository_subdirectories
- Gem::REPOSITORY_SUBDIRECTORIES
- end
-
- def install_with_build_args(args)
- yield
- end
- def path_separator
- Gem.path_separator
+ remove_const(:CHDIR_MUTEX) if const_defined?(:CHDIR_MUTEX)
+ const_set(:CHDIR_MUTEX, const_get(:CHDIR_MONITOR))
end
end
- # RubyGems 2.1.0
- class MoreFuture < Future
- def initialize
- super
- backport_ext_builder_monitor
- end
-
- def all_specs
- require "bundler/remote_specification"
- Gem::Specification.stubs.map do |stub|
- StubSpecification.from_stub(stub)
- end
- end
-
- def backport_ext_builder_monitor
- # So we can avoid requiring "rubygems/ext" in its entirety
- Gem.module_eval <<-RB, __FILE__, __LINE__ + 1
- module Ext
- end
- RB
-
- require "rubygems/ext/builder"
-
- Gem::Ext::Builder.class_eval do
- unless const_defined?(:CHDIR_MONITOR)
- const_set(:CHDIR_MONITOR, EXT_LOCK)
- end
-
- remove_const(:CHDIR_MUTEX) if const_defined?(:CHDIR_MUTEX)
- const_set(:CHDIR_MUTEX, const_get(:CHDIR_MONITOR))
- end
+ if Gem::Specification.respond_to?(:stubs_for)
+ def find_name(name)
+ Gem::Specification.stubs_for(name).map(&:to_spec)
end
-
- if Gem::Specification.respond_to?(:stubs_for)
- def find_name(name)
- Gem::Specification.stubs_for(name).map(&:to_spec)
- end
- else
- def find_name(name)
- Gem::Specification.stubs.find_all do |spec|
- spec.name == name
- end.map(&:to_spec)
- end
+ else
+ def find_name(name)
+ Gem::Specification.stubs.find_all do |spec|
+ spec.name == name
+ end.map(&:to_spec)
end
+ end
- if Gem::Specification.respond_to?(:default_stubs)
- def default_stubs
- Gem::Specification.default_stubs("*.gemspec")
- end
- else
- def default_stubs
- Gem::Specification.send(:default_stubs, "*.gemspec")
- end
+ if Gem::Specification.respond_to?(:default_stubs)
+ def default_stubs
+ Gem::Specification.default_stubs("*.gemspec")
end
-
- def use_gemdeps(gemfile)
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path(gemfile)
- require "bundler/gemdeps"
- runtime = Bundler.setup
- Bundler.ui = nil
- activated_spec_names = runtime.requested_specs.map(&:to_spec).sort_by(&:name)
- [Gemdeps.new(runtime), activated_spec_names]
+ else
+ def default_stubs
+ Gem::Specification.send(:default_stubs, "*.gemspec")
end
+ end
- if provides?(">= 2.5.2")
- # RubyGems-generated binstubs call Kernel#gem
- def binstubs_call_gem?
- false
- end
-
- # only 2.5.2+ has all of the stub methods we want to use, and since this
- # is a performance optimization _only_,
- # we'll restrict ourselves to the most
- # recent RG versions instead of all versions that have stubs
- def stubs_provide_full_functionality?
- true
- end
- end
+ def use_gemdeps(gemfile)
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path(gemfile)
+ require "bundler/gemdeps"
+ runtime = Bundler.setup
+ Bundler.ui = nil
+ activated_spec_names = runtime.requested_specs.map(&:to_spec).sort_by(&:name)
+ [Gemdeps.new(runtime), activated_spec_names]
end
end
def self.rubygems
- @rubygems ||= if RubygemsIntegration.provides?(">= 2.1.0")
- RubygemsIntegration::MoreFuture.new
- elsif RubygemsIntegration.provides?(">= 1.99.99")
- RubygemsIntegration::Future.new
- elsif RubygemsIntegration.provides?(">= 1.8.20")
- RubygemsIntegration::MoreModern.new
- elsif RubygemsIntegration.provides?(">= 1.8.5")
- RubygemsIntegration::Modern.new
- elsif RubygemsIntegration.provides?(">= 1.8.0")
- RubygemsIntegration::AlmostModern.new
- elsif RubygemsIntegration.provides?(">= 1.7.0")
- RubygemsIntegration::Transitional.new
- elsif RubygemsIntegration.provides?(">= 1.4.0")
- RubygemsIntegration::Legacy.new
- else # RubyGems 1.3.6 and 1.3.7
- RubygemsIntegration::Ancient.new
- end
+ @rubygems ||= RubygemsIntegration.new
end
end