From 9d5e7d6c67b084649a6966c69032dd35b1e16b79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Sun, 22 Mar 2020 12:50:56 +0100 Subject: [rubygems/rubygems] Revert "Remove Gem::DependencyInstaller#find_gems_with_sources" This reverts commit 04c79d3eb9d9803d9fae78575b125b325b97206e. Final removal is postponed until next year until we find a better way to manage deprecations. https://github.com/rubygems/rubygems/commit/3e1cf918a5 --- lib/rubygems/dependency_installer.rb | 77 ++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) (limited to 'lib/rubygems/dependency_installer.rb') diff --git a/lib/rubygems/dependency_installer.rb b/lib/rubygems/dependency_installer.rb index 14ff8beab2..fe89b0063d 100644 --- a/lib/rubygems/dependency_installer.rb +++ b/lib/rubygems/dependency_installer.rb @@ -7,6 +7,7 @@ require 'rubygems/spec_fetcher' require 'rubygems/user_interaction' require 'rubygems/source' require 'rubygems/available_set' +require 'rubygems/deprecate' ## # Installs a gem along with all its dependencies from local and remote gems. @@ -14,6 +15,7 @@ require 'rubygems/available_set' class Gem::DependencyInstaller include Gem::UserInteraction + extend Gem::Deprecate DEFAULT_OPTIONS = { # :nodoc: :env_shebang => false, @@ -120,6 +122,81 @@ class Gem::DependencyInstaller @domain == :both or @domain == :remote end + ## + # Returns a list of pairs of gemspecs and source_uris that match + # Gem::Dependency +dep+ from both local (Dir.pwd) and remote (Gem.sources) + # sources. Gems are sorted with newer gems preferred over older gems, and + # local gems preferred over remote gems. + + def find_gems_with_sources(dep, best_only=false) # :nodoc: + set = Gem::AvailableSet.new + + if consider_local? + sl = Gem::Source::Local.new + + if spec = sl.find_gem(dep.name) + if dep.matches_spec? spec + set.add spec, sl + end + end + end + + if consider_remote? + begin + # This is pulled from #spec_for_dependency to allow + # us to filter tuples before fetching specs. + tuples, errors = Gem::SpecFetcher.fetcher.search_for_dependency dep + + if best_only && !tuples.empty? + tuples.sort! do |a,b| + if b[0].version == a[0].version + if b[0].platform != Gem::Platform::RUBY + 1 + else + -1 + end + else + b[0].version <=> a[0].version + end + end + tuples = [tuples.first] + end + + specs = [] + tuples.each do |tup, source| + begin + spec = source.fetch_spec(tup) + rescue Gem::RemoteFetcher::FetchError => e + errors << Gem::SourceFetchProblem.new(source, e) + else + specs << [spec, source] + end + end + + if @errors + @errors += errors + else + @errors = errors + end + + set << specs + + rescue Gem::RemoteFetcher::FetchError => e + # FIX if there is a problem talking to the network, we either need to always tell + # the user (no really_verbose) or fail hard, not silently tell them that we just + # couldn't find their requested gem. + verbose do + "Error fetching remote data:\t\t#{e.message}\n" \ + "Falling back to local-only install" + end + @domain = :local + end + end + + set + end + deprecate :find_gems_with_sources, :none, 2020, 12 + def in_background(what) # :nodoc: fork_happened = false if @build_docs_in_background and Process.respond_to?(:fork) -- cgit v1.2.3