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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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