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_support'
|
||||||
require 'formula_lock'
|
require 'formula_lock'
|
||||||
require 'formula_pin'
|
require 'formula_pin'
|
||||||
@ -105,6 +104,14 @@ class Formula
|
|||||||
active_spec.resources.values
|
active_spec.resources.values
|
||||||
end
|
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
|
# if the dir is there, but it's empty we consider it not installed
|
||||||
def installed?
|
def installed?
|
||||||
(dir = installed_prefix).directory? && dir.children.length > 0
|
(dir = installed_prefix).directory? && dir.children.length > 0
|
||||||
@ -442,9 +449,6 @@ class Formula
|
|||||||
Pathname.new("#{HOMEBREW_REPOSITORY}/Library/Formula/#{name.downcase}.rb")
|
Pathname.new("#{HOMEBREW_REPOSITORY}/Library/Formula/#{name.downcase}.rb")
|
||||||
end
|
end
|
||||||
|
|
||||||
def deps; self.class.dependencies.deps; end
|
|
||||||
def requirements; self.class.dependencies.requirements; end
|
|
||||||
|
|
||||||
def env
|
def env
|
||||||
@env ||= self.class.env
|
@env ||= self.class.env
|
||||||
end
|
end
|
||||||
@ -719,13 +723,8 @@ class Formula
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def dependencies
|
|
||||||
@dependencies ||= DependencyCollector.new
|
|
||||||
end
|
|
||||||
|
|
||||||
def depends_on dep
|
def depends_on dep
|
||||||
d = dependencies.add(dep)
|
specs.each { |spec| spec.depends_on(dep) }
|
||||||
build.add_dep_option(d) unless d.nil?
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def option name, description=nil
|
def option name, description=nil
|
||||||
|
|||||||
@ -3,11 +3,13 @@ require 'resource'
|
|||||||
require 'checksum'
|
require 'checksum'
|
||||||
require 'version'
|
require 'version'
|
||||||
require 'build_options'
|
require 'build_options'
|
||||||
|
require 'dependency_collector'
|
||||||
|
|
||||||
class SoftwareSpec
|
class SoftwareSpec
|
||||||
extend Forwardable
|
extend Forwardable
|
||||||
|
|
||||||
attr_reader :build, :resources, :owner
|
attr_reader :build, :resources, :owner
|
||||||
|
attr_reader :dependency_collector
|
||||||
|
|
||||||
def_delegators :@resource, :stage, :fetch
|
def_delegators :@resource, :stage, :fetch
|
||||||
def_delegators :@resource, :download_strategy, :verify_download_integrity
|
def_delegators :@resource, :download_strategy, :verify_download_integrity
|
||||||
@ -18,6 +20,7 @@ class SoftwareSpec
|
|||||||
@resource = Resource.new(:default, url, version)
|
@resource = Resource.new(:default, url, version)
|
||||||
@resources = {}
|
@resources = {}
|
||||||
@build = BuildOptions.new(ARGV.options_only)
|
@build = BuildOptions.new(ARGV.options_only)
|
||||||
|
@dependency_collector = DependencyCollector.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def owner= owner
|
def owner= owner
|
||||||
@ -44,6 +47,19 @@ class SoftwareSpec
|
|||||||
raise "Options should not start with dashes." if name[0, 1] == "-"
|
raise "Options should not start with dashes." if name[0, 1] == "-"
|
||||||
build.add(name, description)
|
build.add(name, description)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
class HeadSoftwareSpec < SoftwareSpec
|
class HeadSoftwareSpec < SoftwareSpec
|
||||||
|
|||||||
@ -208,25 +208,4 @@ class FormulaTests < Test::Unit::TestCase
|
|||||||
ensure
|
ensure
|
||||||
path.unlink
|
path.unlink
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@ -47,6 +47,24 @@ class SoftwareSpecTests < Test::Unit::TestCase
|
|||||||
@spec.option(:foo)
|
@spec.option(:foo)
|
||||||
assert @spec.build.has_option? 'foo'
|
assert @spec.build.has_option? 'foo'
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
class HeadSoftwareSpecTests < Test::Unit::TestCase
|
class HeadSoftwareSpecTests < Test::Unit::TestCase
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user