| 1 |
# frozen_string_literal: true |
| 2 |
|
| 3 |
module Bundler |
| 4 |
class Source |
| 5 |
class RubygemsAggregate |
| 6 |
attr_reader :source_map, :sources |
| 7 |
|
| 8 |
def initialize(sources, source_map) |
| 9 |
@sources = sources |
| 10 |
@source_map = source_map |
| 11 |
|
| 12 |
@index = build_index |
| 13 |
end |
| 14 |
|
| 15 |
def specs |
| 16 |
@index |
| 17 |
end |
| 18 |
|
| 19 |
def identifier |
| 20 |
to_s |
| 21 |
end |
| 22 |
|
| 23 |
def to_s |
| 24 |
"any of the sources" |
| 25 |
end |
| 26 |
|
| 27 |
private |
| 28 |
|
| 29 |
def build_index |
| 30 |
Index.build do |idx| |
| 31 |
dependency_names = source_map.pinned_spec_names |
| 32 |
|
| 33 |
sources.all_sources.each do |source| |
| 34 |
source.dependency_names = dependency_names - source_map.pinned_spec_names(source) |
| 35 |
idx.add_source source.specs |
| 36 |
dependency_names.concat(source.unmet_deps).uniq! |
| 37 |
end |
| 38 |
|
| 39 |
double_check_for_index(idx, dependency_names) |
| 40 |
end |
| 41 |
end |
| 42 |
|
| 43 |
# Suppose the gem Foo depends on the gem Bar. Foo exists in Source A. Bar has some versions that exist in both |
| 44 |
# sources A and B. At this point, the API request will have found all the versions of Bar in source A, |
| 45 |
# but will not have found any versions of Bar from source B, which is a problem if the requested version |
| 46 |
# of Foo specifically depends on a version of Bar that is only found in source B. This ensures that for |
| 47 |
# each spec we found, we add all possible versions from all sources to the index. |
| 48 |
def double_check_for_index(idx, dependency_names) |
| 49 |
pinned_names = source_map.pinned_spec_names |
| 50 |
|
| 51 |
names = :names # do this so we only have to traverse to get dependency_names from the index once |
| 52 |
unmet_dependency_names = lambda do |
| 53 |
return names unless names == :names |
| 54 |
new_names = sources.all_sources.map(&:dependency_names_to_double_check) |
| 55 |
return names = nil if new_names.compact! |
| 56 |
names = new_names.flatten(1).concat(dependency_names) |
| 57 |
names.uniq! |
| 58 |
names -= pinned_names |
| 59 |
names |
| 60 |
end |
| 61 |
|
| 62 |
sources.all_sources.each do |source| |
| 63 |
source.double_check_for(unmet_dependency_names) |
| 64 |
end |
| 65 |
end |
| 66 |
end |
| 67 |
end |
| 68 |
end |