Refactor Requirement.expand
This commit is contained in:
parent
ceb01c3124
commit
3937d2bb84
@ -120,12 +120,13 @@ class Requirement
|
||||
end
|
||||
end
|
||||
|
||||
class << self
|
||||
# Expand the requirements of dependent recursively, optionally yielding
|
||||
# [dependent, req] pairs to allow callers to apply arbitrary filters to
|
||||
# the list.
|
||||
# The default filter, which is applied when a block is not given, omits
|
||||
# optionals and recommendeds based on what the dependent has asked for.
|
||||
def self.expand(dependent, &block)
|
||||
def expand(dependent, &block)
|
||||
reqs = ComparableSet.new
|
||||
|
||||
formulae = dependent.recursive_dependencies.map(&:to_formula)
|
||||
@ -133,26 +134,18 @@ class Requirement
|
||||
|
||||
formulae.map(&:requirements).each do |requirements|
|
||||
requirements.each do |req|
|
||||
prune = catch(:prune) do
|
||||
if block_given?
|
||||
yield dependent, req
|
||||
elsif req.optional? || req.recommended?
|
||||
Requirement.prune unless dependent.build.with?(req.name)
|
||||
end
|
||||
end
|
||||
|
||||
next if prune
|
||||
|
||||
if prune?(dependent, req, &block)
|
||||
next
|
||||
# TODO: Do this in a cleaner way, perhaps with another type of
|
||||
# dependency type.
|
||||
if req.class.default_formula
|
||||
elsif req.class.default_formula
|
||||
dependent.class.depends_on(req.class.default_formula)
|
||||
next
|
||||
end
|
||||
|
||||
else
|
||||
reqs << req
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# We special case handling of X11Dependency and its subclasses to
|
||||
# ensure the correct dependencies are present in the final list.
|
||||
@ -172,8 +165,19 @@ class Requirement
|
||||
reqs
|
||||
end
|
||||
|
||||
def prune?(dependent, req, &block)
|
||||
catch(:prune) do
|
||||
if block_given?
|
||||
yield dependent, req
|
||||
elsif req.optional? || req.recommended?
|
||||
prune unless dependent.build.with?(req.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Used to prune requirements when calling expand with a block.
|
||||
def self.prune
|
||||
def prune
|
||||
throw(:prune, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user