1 # frozen_string_literal: true
3 require_relative "package"
8 attr_reader :packages, :requirements, :source_requirements
10 def initialize(source_requirements, dependencies, base, platforms, options)
11 @source_requirements = source_requirements
15 @packages = Hash.new do |hash, name|
16 hash[name] = Package.new(name, platforms, **options)
19 @requirements = dependencies.map do |dep|
20 dep_platforms = dep.gem_platforms(platforms)
22 # Dependencies scoped to external platforms are ignored
23 next if dep_platforms.empty?
27 @packages[name] = Package.new(name, dep_platforms, **options.merge(dependency: dep))
46 @base_requirements ||= build_base_requirements
49 def unlock_names(names)
50 indirect_pins = indirect_pins(names)
53 loosen_names(indirect_pins)
60 unrestrict_names(names)
65 def include_prereleases(names)
67 get_package(name).consider_prereleases!
73 def indirect_pins(names)
74 names.select {|name| @base_requirements[name].exact? && @requirements.none? {|dep| dep.name == name } }
78 names.select {|name| @base_requirements[name].exact? }
81 def loosen_names(names)
83 version = @base_requirements[name].requirements.first[1]
85 @base_requirements[name] = Gem::Requirement.new(">= #{version}")
87 @base.delete_by_name(name)
91 def unrestrict_names(names)
93 @base_requirements.delete(name)
97 def build_base_requirements
98 base_requirements = {}
100 req = Gem::Requirement.new(ls.version)
101 base_requirements[ls.name] = req