Allow multiple option_names in dep/reqs.

This means that dependencies can be merged but still maintain all
their option names.

Closes Homebrew/homebrew#46916.

Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
This commit is contained in:
Mike McQuaid 2015-12-14 19:47:19 +00:00
parent 484c70d19f
commit e5ba31fcdc
7 changed files with 43 additions and 34 deletions

View File

@ -24,21 +24,23 @@ class BuildOptions
# args << "--with-example1"
# end</pre>
def with?(val)
name = val.respond_to?(:option_name) ? val.option_name : val
option_names = val.respond_to?(:option_names) ? val.option_names : [val]
if option_defined? "with-#{name}"
include? "with-#{name}"
elsif option_defined? "without-#{name}"
!include? "without-#{name}"
else
false
option_names.any? do |name|
if option_defined? "with-#{name}"
include? "with-#{name}"
elsif option_defined? "without-#{name}"
!include? "without-#{name}"
else
false
end
end
end
# True if a {Formula} is being built without a specific option.
# <pre>args << "--no-spam-plz" if build.without? "spam"
def without?(name)
!with? name
def without?(val)
!with?(val)
end
# True if a {Formula} is being built as a bottle (i.e. binary package).

View File

@ -4,15 +4,15 @@ require "dependable"
class Dependency
include Dependable
attr_reader :name, :tags, :env_proc, :option_name
attr_reader :name, :tags, :env_proc, :option_names
DEFAULT_ENV_PROC = proc {}
def initialize(name, tags = [], env_proc = DEFAULT_ENV_PROC, option_name = name)
def initialize(name, tags = [], env_proc = DEFAULT_ENV_PROC, option_names = [name])
@name = name
@tags = tags
@env_proc = env_proc
@option_name = option_name
@option_names = option_names
end
def to_s
@ -125,7 +125,8 @@ class Dependency
deps = grouped.fetch(name)
dep = deps.first
tags = deps.flat_map(&:tags).uniq
dep.class.new(name, tags, dep.env_proc)
option_names = deps.flat_map(&:option_names).uniq
dep.class.new(name, tags, dep.env_proc, option_names)
end
end
end
@ -134,9 +135,9 @@ end
class TapDependency < Dependency
attr_reader :tap
def initialize(name, tags = [], env_proc = DEFAULT_ENV_PROC, option_name = name.split("/").last)
def initialize(name, tags = [], env_proc = DEFAULT_ENV_PROC, option_names = [name.split("/").last])
@tap = name.rpartition("/").first
super(name, tags, env_proc, option_name)
super(name, tags, env_proc, option_names)
end
def installed?

View File

@ -10,7 +10,6 @@ class Requirement
include Dependable
attr_reader :tags, :name, :cask, :download, :default_formula
alias_method :option_name, :name
def initialize(tags = [])
@default_formula = self.class.default_formula
@ -26,6 +25,10 @@ class Requirement
@name ||= infer_name
end
def option_names
[name]
end
# The message to show when the requirement is not met.
def message
s = ""

View File

@ -185,12 +185,12 @@ class SoftwareSpec
end
def add_dep_option(dep)
name = dep.option_name
if dep.optional? && !option_defined?("with-#{name}")
options << Option.new("with-#{name}", "Build with #{name} support")
elsif dep.recommended? && !option_defined?("without-#{name}")
options << Option.new("without-#{name}", "Build without #{name} support")
dep.option_names.each do |name|
if dep.optional? && !option_defined?("with-#{name}")
options << Option.new("with-#{name}", "Build with #{name} support")
elsif dep.recommended? && !option_defined?("without-#{name}")
options << Option.new("without-#{name}", "Build without #{name} support")
end
end
end
end

View File

@ -147,12 +147,15 @@ class Tab < OpenStruct
end
def with?(val)
name = val.respond_to?(:option_name) ? val.option_name : val
include?("with-#{name}") || unused_options.include?("without-#{name}")
option_names = val.respond_to?(:option_names) ? val.option_names : [val]
option_names.any? do |name|
include?("with-#{name}") || unused_options.include?("without-#{name}")
end
end
def without?(name)
!with? name
def without?(val)
!with?(val)
end
def include?(opt)

View File

@ -49,13 +49,13 @@ class DependencyTests < Homebrew::TestCase
foo_named_dep = merged.find {|d| d.name == "foo"}
assert_equal [:build, "bar"], foo_named_dep.tags
assert_includes foo_named_dep.option_name, "foo"
assert_includes foo_named_dep.option_name, "foo2"
assert_includes foo_named_dep.option_names, "foo"
assert_includes foo_named_dep.option_names, "foo2"
xyz_named_dep = merged.find {|d| d.name == "xyz"}
assert_equal ["abc"], xyz_named_dep.tags
assert_includes xyz_named_dep.option_name, "foo"
refute_includes xyz_named_dep.option_name, "foo2"
assert_includes xyz_named_dep.option_names, "foo"
refute_includes xyz_named_dep.option_names, "foo2"
end
def test_equality
@ -73,8 +73,8 @@ class DependencyTests < Homebrew::TestCase
end
class TapDependencyTests < Homebrew::TestCase
def test_option_name
def test_option_names
dep = TapDependency.new("foo/bar/dog")
assert_equal "dog", dep.option_name
assert_equal %w[dog], dep.option_names
end
end

View File

@ -14,9 +14,9 @@ class RequirementTests < Homebrew::TestCase
assert_equal %w[bar baz].sort, dep.tags.sort
end
def test_option_name
def test_option_names
dep = TestRequirement.new
assert_equal "test", dep.option_name
assert_equal %w[test], dep.option_names
end
def test_preserves_symbol_tags