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.
This commit is contained in:
Jack Nagel 2013-01-26 17:55:07 -06:00
parent 036f3e7bfc
commit f62762b3ab

View File

@ -420,8 +420,6 @@ class Formula
raise NameError if !klass.ancestors.include? Formula raise NameError if !klass.ancestors.include? Formula
klass.finalize_dsl
return klass.new(name) if install_type == :from_name return klass.new(name) if install_type == :from_name
return klass.new(name, path.to_s) return klass.new(name, path.to_s)
rescue NoMethodError rescue NoMethodError
@ -743,6 +741,7 @@ private
def depends_on dep def depends_on dep
dependencies.add(dep) dependencies.add(dep)
post_depends_on
end end
def option name, description=nil def option name, description=nil
@ -805,20 +804,15 @@ private
@test = block @test = block
end end
# This method is called once by `factory` before creating any instances. private
# 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
# Synthesize options for recommended dependencies def post_depends_on
dependencies.deps.select(&:recommended?).each do |dep| # Generate with- and without- options for optional and recommended deps
unless build.has_option? "without-#{dep.name}" dependencies.deps.each do |dep|
option "without-#{dep.name}", "Build without #{dep.name} support" 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 end
end end