diff options
author | David RodrÃguez <[email protected]> | 2020-03-22 12:50:56 +0100 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2020-03-30 12:54:58 +0900 |
commit | 9d5e7d6c67b084649a6966c69032dd35b1e16b79 (patch) | |
tree | 7f16f5c47582ccf198aa3530db528afd7c18255b /lib/rubygems | |
parent | 7f8f33ebb9a8eba3d6721e24eac248ff75e2c615 (diff) |
[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
Diffstat (limited to 'lib/rubygems')
-rw-r--r-- | lib/rubygems/dependency_installer.rb | 77 |
1 files changed, 77 insertions, 0 deletions
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) |