Skip to content

Commit

Permalink
missing_deps: extract formula instance method
Browse files Browse the repository at this point in the history
  • Loading branch information
alyssais committed Oct 25, 2016
1 parent 99a7fb8 commit 0cd9834
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
22 changes: 4 additions & 18 deletions Library/Homebrew/diagnostic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,13 @@
module Homebrew
module Diagnostic
def self.missing_deps(ff, hide = nil)
hide ||= []

missing = {}
ff.each do |f|
missing_deps = f.recursive_dependencies do |dependent, dep|
if dep.optional? || dep.recommended?
tab = Tab.for_formula(dependent)
Dependency.prune unless tab.with?(dep)
elsif dep.build?
Dependency.prune
end
end

missing_deps.map!(&:to_formula)
missing_deps.reject! do |d|
!hide.include?(d.name) && d.installed_prefixes.any?
end
missing_dependencies = f.missing_dependencies(hide: hide)

unless missing_deps.empty?
yield f.full_name, missing_deps if block_given?
missing[f.full_name] = missing_deps
unless missing_dependencies.empty?
yield f.full_name, missing_dependencies if block_given?
missing[f.full_name] = missing_dependencies
end
end
missing
Expand Down
20 changes: 20 additions & 0 deletions Library/Homebrew/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1466,6 +1466,26 @@ def runtime_dependencies
recursive_dependencies.reject(&:build?)
end

# Returns a list of formulae depended on by this formula that aren't
# installed
def missing_dependencies(hide: nil)
hide ||= []
missing_dependencies = recursive_dependencies do |dependent, dep|
if dep.optional? || dep.recommended?
tab = Tab.for_formula(dependent)
Dependency.prune unless tab.with?(dep)
elsif dep.build?
Dependency.prune
end
end

missing_dependencies.map!(&:to_formula)
missing_dependencies.select! do |d|
hide.include?(d.name) || d.installed_prefixes.empty?
end
missing_dependencies
end

# @private
def to_hash
hsh = {
Expand Down

0 comments on commit 0cd9834

Please sign in to comment.