2018-11-02 19:07:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Bundler
|
|
|
|
class Resolver
|
|
|
|
class SpecGroup
|
|
|
|
attr_accessor :name, :version, :source
|
2021-02-01 10:17:16 -05:00
|
|
|
attr_accessor :activated_platforms
|
|
|
|
|
|
|
|
def self.create_for(specs, all_platforms, specific_platform)
|
|
|
|
specific_platform_specs = specs[specific_platform]
|
|
|
|
return unless specific_platform_specs.any?
|
|
|
|
|
|
|
|
platforms = all_platforms.select {|p| specs[p].any? }
|
|
|
|
|
|
|
|
new(specific_platform_specs.first, specs, platforms)
|
|
|
|
end
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2021-02-01 10:17:16 -05:00
|
|
|
def initialize(exemplary_spec, specs, relevant_platforms)
|
|
|
|
@exemplary_spec = exemplary_spec
|
2018-11-02 19:07:56 -04:00
|
|
|
@name = exemplary_spec.name
|
|
|
|
@version = exemplary_spec.version
|
|
|
|
@source = exemplary_spec.source
|
|
|
|
|
2021-02-01 10:17:16 -05:00
|
|
|
@activated_platforms = relevant_platforms
|
|
|
|
@dependencies = Hash.new do |dependencies, platforms|
|
|
|
|
dependencies[platforms] = dependencies_for(platforms)
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
2021-02-01 10:17:16 -05:00
|
|
|
@specs = specs
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_specs
|
2021-02-01 10:17:16 -05:00
|
|
|
activated_platforms.map do |p|
|
2020-12-22 18:45:19 -05:00
|
|
|
specs = @specs[p]
|
|
|
|
next unless specs.any?
|
|
|
|
|
|
|
|
specs.map do |s|
|
|
|
|
lazy_spec = LazySpecification.new(name, version, s.platform, source)
|
|
|
|
lazy_spec.dependencies.replace s.dependencies
|
|
|
|
lazy_spec
|
|
|
|
end
|
|
|
|
end.flatten.compact.uniq
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
2020-05-08 01:19:04 -04:00
|
|
|
activated_platforms_string = sorted_activated_platforms.join(", ")
|
|
|
|
"#{name} (#{version}) (#{activated_platforms_string})"
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def dependencies_for_activated_platforms
|
2021-02-01 10:17:16 -05:00
|
|
|
@dependencies[activated_platforms]
|
|
|
|
end
|
|
|
|
|
2018-11-02 19:07:56 -04:00
|
|
|
def ==(other)
|
|
|
|
return unless other.is_a?(SpecGroup)
|
|
|
|
name == other.name &&
|
|
|
|
version == other.version &&
|
2020-05-08 01:19:04 -04:00
|
|
|
sorted_activated_platforms == other.sorted_activated_platforms &&
|
2018-11-02 19:07:56 -04:00
|
|
|
source == other.source
|
|
|
|
end
|
|
|
|
|
|
|
|
def eql?(other)
|
2019-08-29 23:49:27 -04:00
|
|
|
return unless other.is_a?(SpecGroup)
|
2018-11-02 19:07:56 -04:00
|
|
|
name.eql?(other.name) &&
|
|
|
|
version.eql?(other.version) &&
|
2020-05-08 01:19:04 -04:00
|
|
|
sorted_activated_platforms.eql?(other.sorted_activated_platforms) &&
|
2018-11-02 19:07:56 -04:00
|
|
|
source.eql?(other.source)
|
|
|
|
end
|
|
|
|
|
|
|
|
def hash
|
2020-05-08 01:19:04 -04:00
|
|
|
name.hash ^ version.hash ^ sorted_activated_platforms.hash ^ source.hash
|
|
|
|
end
|
|
|
|
|
2020-10-15 00:20:25 -04:00
|
|
|
protected
|
2020-05-08 01:19:04 -04:00
|
|
|
|
|
|
|
def sorted_activated_platforms
|
2021-02-01 10:17:16 -05:00
|
|
|
activated_platforms.sort_by(&:to_s)
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
2020-10-15 00:20:25 -04:00
|
|
|
private
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2021-02-01 10:17:16 -05:00
|
|
|
def dependencies_for(platforms)
|
|
|
|
platforms.map do |platform|
|
|
|
|
__dependencies(platform) + metadata_dependencies(platform)
|
|
|
|
end.flatten
|
|
|
|
end
|
|
|
|
|
|
|
|
def __dependencies(platform)
|
|
|
|
dependencies = []
|
|
|
|
@specs[platform].first.dependencies.each do |dep|
|
|
|
|
next if dep.type == :development
|
|
|
|
dependencies << DepProxy.get_proxy(dep, platform)
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
2021-02-01 10:17:16 -05:00
|
|
|
dependencies
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
|
2021-02-01 10:17:16 -05:00
|
|
|
def metadata_dependencies(platform)
|
|
|
|
spec = @specs[platform].first
|
|
|
|
return [] unless spec.is_a?(Gem::Specification)
|
2018-11-02 19:07:56 -04:00
|
|
|
dependencies = []
|
|
|
|
if !spec.required_ruby_version.nil? && !spec.required_ruby_version.none?
|
2021-02-01 10:17:16 -05:00
|
|
|
dependencies << DepProxy.get_proxy(Gem::Dependency.new("Ruby\0", spec.required_ruby_version), platform)
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
if !spec.required_rubygems_version.nil? && !spec.required_rubygems_version.none?
|
2021-02-01 10:17:16 -05:00
|
|
|
dependencies << DepProxy.get_proxy(Gem::Dependency.new("RubyGems\0", spec.required_rubygems_version), platform)
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
dependencies
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|