From a6329944031c1e5af821272fda9aada1b994d77e Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Tue, 16 Jul 2013 20:38:50 -0500 Subject: [PATCH] Audit conditional deps that can be made declarative --- Library/Homebrew/cmd/audit.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Library/Homebrew/cmd/audit.rb b/Library/Homebrew/cmd/audit.rb index ae5b2410ad..3e30753139 100644 --- a/Library/Homebrew/cmd/audit.rb +++ b/Library/Homebrew/cmd/audit.rb @@ -493,6 +493,27 @@ class FormulaAuditor if text =~ /ENV.fortran/ problem "Use `depends_on :fortran` instead of `ENV.fortran`" end + + if text =~ /depends_on :(.+) (if.+|unless.+)$/ + audit_conditional_dep($1.to_sym, $2, $&) + end + + if text =~ /depends_on ['"](.+)['"] (if.+|unless.+)$/ + audit_conditional_dep($1, $2, $&) + end + end + + def audit_conditional_dep(dep, condition, line) + case condition + when /if build\.include\? ['"]with-#{dep}['"]$/, /if build\.with\? ['"]#{dep}['"]$/ + problem %{Replace #{line.inspect} with "depends_on #{quote_dep(dep)} => :optional"} + when /unless build\.include\? ['"]without-#{dep}['"]$/, /unless build\.without\? ['"]#{dep}['"]$/ + problem %{Replace #{line.inspect} with "depends_on #{quote_dep(dep)} => :recommended"} + end + end + + def quote_dep(dep) + Symbol === dep ? dep.inspect : "'#{dep}'" end def audit_python