aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Library/Homebrew/formula.rb19
-rw-r--r--Library/Homebrew/software_spec.rb16
-rw-r--r--Library/Homebrew/test/test_formula.rb21
-rw-r--r--Library/Homebrew/test/test_software_spec.rb18
4 files changed, 43 insertions, 31 deletions
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb
index 4011a6210..35dc9a08d 100644
--- a/Library/Homebrew/formula.rb
+++ b/Library/Homebrew/formula.rb
@@ -1,4 +1,3 @@
-require 'dependency_collector'
require 'formula_support'
require 'formula_lock'
require 'formula_pin'
@@ -105,6 +104,14 @@ class Formula
active_spec.resources.values
end
+ def deps
+ active_spec.deps
+ end
+
+ def requirements
+ active_spec.requirements
+ end
+
# if the dir is there, but it's empty we consider it not installed
def installed?
(dir = installed_prefix).directory? && dir.children.length > 0
@@ -442,9 +449,6 @@ class Formula
Pathname.new("#{HOMEBREW_REPOSITORY}/Library/Formula/#{name.downcase}.rb")
end
- def deps; self.class.dependencies.deps; end
- def requirements; self.class.dependencies.requirements; end
-
def env
@env ||= self.class.env
end
@@ -719,13 +723,8 @@ class Formula
end
end
- def dependencies
- @dependencies ||= DependencyCollector.new
- end
-
def depends_on dep
- d = dependencies.add(dep)
- build.add_dep_option(d) unless d.nil?
+ specs.each { |spec| spec.depends_on(dep) }
end
def option name, description=nil
diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb
index 81adc83ff..1fd8a8fc6 100644
--- a/Library/Homebrew/software_spec.rb
+++ b/Library/Homebrew/software_spec.rb
@@ -3,11 +3,13 @@ require 'resource'
require 'checksum'
require 'version'
require 'build_options'
+require 'dependency_collector'
class SoftwareSpec
extend Forwardable
attr_reader :build, :resources, :owner
+ attr_reader :dependency_collector
def_delegators :@resource, :stage, :fetch
def_delegators :@resource, :download_strategy, :verify_download_integrity
@@ -18,6 +20,7 @@ class SoftwareSpec
@resource = Resource.new(:default, url, version)
@resources = {}
@build = BuildOptions.new(ARGV.options_only)
+ @dependency_collector = DependencyCollector.new
end
def owner= owner
@@ -44,6 +47,19 @@ class SoftwareSpec
raise "Options should not start with dashes." if name[0, 1] == "-"
build.add(name, description)
end
+
+ def depends_on spec
+ dep = dependency_collector.add(spec)
+ build.add_dep_option(dep) if dep
+ end
+
+ def deps
+ dependency_collector.deps
+ end
+
+ def requirements
+ dependency_collector.requirements
+ end
end
class HeadSoftwareSpec < SoftwareSpec
diff --git a/Library/Homebrew/test/test_formula.rb b/Library/Homebrew/test/test_formula.rb
index 037a8f9be..1591b425b 100644
--- a/Library/Homebrew/test/test_formula.rb
+++ b/Library/Homebrew/test/test_formula.rb
@@ -208,25 +208,4 @@ class FormulaTests < Test::Unit::TestCase
ensure
path.unlink
end
-
- def test_dependency_option_integration
- f = formula do
- url 'foo-1.0'
- depends_on 'foo' => :optional
- depends_on 'bar' => :recommended
- end
-
- assert f.build.has_option?('with-foo')
- assert f.build.has_option?('without-bar')
- end
-
- def test_explicit_options_override_default_dep_option_description
- f = formula do
- url 'foo-1.0'
- option 'with-foo', 'blah'
- depends_on 'foo' => :optional
- end
-
- assert_equal 'blah', f.build.first.description
- end
end
diff --git a/Library/Homebrew/test/test_software_spec.rb b/Library/Homebrew/test/test_software_spec.rb
index c534cd008..66ac7feb6 100644
--- a/Library/Homebrew/test/test_software_spec.rb
+++ b/Library/Homebrew/test/test_software_spec.rb
@@ -47,6 +47,24 @@ class SoftwareSpecTests < Test::Unit::TestCase
@spec.option(:foo)
assert @spec.build.has_option? 'foo'
end
+
+ def test_depends_on
+ @spec.depends_on('foo')
+ assert_equal 'foo', @spec.deps.first.name
+ end
+
+ def test_dependency_option_integration
+ @spec.depends_on 'foo' => :optional
+ @spec.depends_on 'bar' => :recommended
+ assert @spec.build.has_option?('with-foo')
+ assert @spec.build.has_option?('without-bar')
+ end
+
+ def test_explicit_options_override_default_dep_option_description
+ @spec.option('with-foo', 'blah')
+ @spec.depends_on('foo' => :optional)
+ assert_equal 'blah', @spec.build.first.description
+ end
end
class HeadSoftwareSpecTests < Test::Unit::TestCase