Move dependencies to SoftwareSpec
This commit is contained in:
parent
a8d3aca169
commit
5511a8b3f5
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user