Skip to content

Commit

Permalink
Refactor brew missing
Browse files Browse the repository at this point in the history
The heuristic for determining whether something is installed changes
from "f.installed?" to "f.rack.exist? and f.rack.subdirs.length > 0" in
order to properly consider outdated formulae.

Signed-off-by: Jack Nagel <jacknagel@gmail.com>
  • Loading branch information
jacknagel committed Aug 18, 2012
1 parent ce604c6 commit 094ce49
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
5 changes: 2 additions & 3 deletions Library/Homebrew/cmd/doctor.rb
Expand Up @@ -764,9 +764,8 @@ def check_tmpdir
def check_missing_deps
return unless HOMEBREW_CELLAR.exist?
s = Set.new
missing_deps = Homebrew.find_missing_brews(Homebrew.installed_brews)
missing_deps.each do |m|
s.merge m[1]
Homebrew.missing_deps(Homebrew.installed_brews).each do |_, deps|
s.merge deps
end

if s.length > 0 then <<-EOS.undent
Expand Down
32 changes: 13 additions & 19 deletions Library/Homebrew/cmd/missing.rb
@@ -1,47 +1,41 @@
require 'formula'
require 'cmd/outdated'

module Homebrew extend self
def installed_brews
formulae = []
HOMEBREW_CELLAR.subdirs.each do |rack|
f = Formula.factory rack.basename.to_s rescue nil
formulae << f if f and f.installed?
formulae << f if f and f.rack.exist? and f.rack.subdirs.length > 0
end
formulae
end

def find_missing_brews top_level
# Names of outdated brews; they count as installed.
outdated = Homebrew.outdated_brews.collect{ |b| b.name }

brews = []
top_level.each do |f|
missing_deps = f.recursive_deps.map{ |g| g.name }.uniq.reject do |dep_name|
Formula.factory(dep_name).installed? or outdated.include?(dep_name)
end
def missing_deps ff
missing = {}
ff.each do |f|
missing_deps = f.recursive_deps.uniq.reject do |dep|
dep.rack.exist? and dep.rack.subdirs.length > 0
end

unless missing_deps.empty?
brews << [f.name, missing_deps]
yield f.name, missing_deps if block_given?
missing[f.name] = missing_deps
end
end
brews
missing
end

def missing
return unless HOMEBREW_CELLAR.exist?

formulae_to_check = if ARGV.named.empty?
ff = if ARGV.named.empty?
installed_brews
else
ARGV.formulae
end

missing_deps = find_missing_brews(formulae_to_check)
missing_deps.each do |d|
name = d[0]
missing = d[1]
print "#{name}: " if formulae_to_check.size > 1
missing_deps(ff) do |name, missing|
print "#{name}: " if ff.size > 1
puts "#{missing * ' '}"
end
end
Expand Down

0 comments on commit 094ce49

Please sign in to comment.