From f62762b3abc198a927ede15df146f2b40cb86b59 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Sat, 26 Jan 2013 17:55:07 -0600 Subject: [PATCH] Generate options immediately following depends_on Given depends_on 'gnutls' => :recommended depends_on 'libgcrypt' unless build.without? 'gnutls' the dependency on libgcrypt should be enabled by default. However, the corresponding option has not yet been generated, so the condition is true and the dependency is disabled. Instead, add a hook method that fires after each depends_on and adds the appropriate option. --- Library/Homebrew/formula.rb | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 7af0989a74..9c70f0210c 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -420,8 +420,6 @@ class Formula raise NameError if !klass.ancestors.include? Formula - klass.finalize_dsl - return klass.new(name) if install_type == :from_name return klass.new(name, path.to_s) rescue NoMethodError @@ -743,6 +741,7 @@ private def depends_on dep dependencies.add(dep) + post_depends_on end def option name, description=nil @@ -805,20 +804,15 @@ private @test = block end - # This method is called once by `factory` before creating any instances. - # It allows the DSL to finalize itself, reducing complexity in the constructor. - def finalize_dsl - # Synthesize options for optional dependencies - dependencies.deps.select(&:optional?).each do |dep| - unless build.has_option? "with-#{dep.name}" - option "with-#{dep.name}", "Build with #{dep.name} support" - end - end + private - # Synthesize options for recommended dependencies - dependencies.deps.select(&:recommended?).each do |dep| - unless build.has_option? "without-#{dep.name}" - option "without-#{dep.name}", "Build without #{dep.name} support" + def post_depends_on + # Generate with- and without- options for optional and recommended deps + dependencies.deps.each do |dep| + if dep.optional? && !build.has_option?("with-#{dep.name}") + build.add("with-#{dep.name}", "Build with #{dep.name} support") + elsif dep.recommended? && !build.has_option?("without-#{dep.name}") + build.add("without-#{dep.name}", "Build without #{dep.name} support") end end end