Add deprecated_option to software_spec.
Allows remapping one option name to another and updates build options and flags accordingly.
This commit is contained in:
parent
da0a65356d
commit
02e10beb7c
@ -47,6 +47,11 @@ class DeprecatedOption
|
||||
def current_flag
|
||||
"--#{current}"
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
instance_of?(other.class) && old == other.old && current == other.current
|
||||
end
|
||||
alias_method :eql?, :==
|
||||
end
|
||||
|
||||
class Options
|
||||
|
||||
@ -20,6 +20,7 @@ class SoftwareSpec
|
||||
|
||||
attr_reader :name, :owner
|
||||
attr_reader :build, :resources, :patches, :options
|
||||
attr_reader :deprecated_flags, :deprecated_options
|
||||
attr_reader :dependency_collector
|
||||
attr_reader :bottle_specification
|
||||
attr_reader :compiler_failures
|
||||
@ -36,7 +37,10 @@ class SoftwareSpec
|
||||
@bottle_specification = BottleSpecification.new
|
||||
@patches = []
|
||||
@options = Options.new
|
||||
@build = BuildOptions.new(Options.create(ARGV.flags_only), options)
|
||||
@flags = ARGV.flags_only
|
||||
@deprecated_flags = []
|
||||
@deprecated_options = []
|
||||
@build = BuildOptions.new(Options.create(@flags), options)
|
||||
@compiler_failures = []
|
||||
end
|
||||
|
||||
@ -99,6 +103,26 @@ class SoftwareSpec
|
||||
options << opt
|
||||
end
|
||||
|
||||
def deprecated_option hash
|
||||
raise ArgumentError, "deprecated_option hash must not be empty" if hash.empty?
|
||||
hash.each do |old_options, new_options|
|
||||
Array(old_options).each do |old_option|
|
||||
Array(new_options).each do |new_option|
|
||||
deprecated_option = DeprecatedOption.new(old_option, new_option)
|
||||
deprecated_options << deprecated_option
|
||||
|
||||
old_flag = deprecated_option.old_flag
|
||||
new_flag = deprecated_option.current_flag
|
||||
next unless @flags.include? old_flag
|
||||
@flags -= [old_flag]
|
||||
@flags |= [new_flag]
|
||||
@deprecated_flags << deprecated_option
|
||||
end
|
||||
end
|
||||
end
|
||||
@build = BuildOptions.new(Options.create(@flags), options)
|
||||
end
|
||||
|
||||
def depends_on spec
|
||||
dep = dependency_collector.add(spec)
|
||||
add_dep_option(dep) if dep
|
||||
|
||||
@ -37,6 +37,23 @@ class DeprecatedOptionTests < Homebrew::TestCase
|
||||
def test_current
|
||||
assert_equal "bar", @deprecated_option.current
|
||||
end
|
||||
|
||||
def test_old
|
||||
assert_equal "--foo", @deprecated_option.old_flag
|
||||
end
|
||||
|
||||
def test_current
|
||||
assert_equal "--bar", @deprecated_option.current_flag
|
||||
end
|
||||
|
||||
def test_equality
|
||||
foobar = DeprecatedOption.new("foo", "bar")
|
||||
boofar = DeprecatedOption.new("boo", "far")
|
||||
assert_equal foobar, @deprecated_option
|
||||
refute_equal boofar, @deprecated_option
|
||||
assert_eql @deprecated_option, foobar
|
||||
refute_eql @deprecated_option, boofar
|
||||
end
|
||||
end
|
||||
|
||||
class OptionsTests < Homebrew::TestCase
|
||||
|
||||
@ -72,6 +72,30 @@ class SoftwareSpecTests < Homebrew::TestCase
|
||||
assert_equal "", @spec.options.first.description
|
||||
end
|
||||
|
||||
def test_deprecated_option
|
||||
@spec.deprecated_option('foo' => 'bar')
|
||||
assert @spec.deprecated_options.any?
|
||||
assert_equal "foo", @spec.deprecated_options.first.old
|
||||
assert_equal "bar", @spec.deprecated_options.first.current
|
||||
end
|
||||
|
||||
def test_deprecated_options
|
||||
@spec.deprecated_option(['foo1', 'foo2'] => 'bar1', 'foo3' => ['bar2', 'bar3'])
|
||||
refute_empty @spec.deprecated_options
|
||||
assert_equal "foo1", @spec.deprecated_options.first.old
|
||||
assert_equal "bar1", @spec.deprecated_options.first.current
|
||||
assert_equal "foo2", @spec.deprecated_options[1].old
|
||||
assert_equal "bar1", @spec.deprecated_options[1].current
|
||||
assert_equal "foo3", @spec.deprecated_options[2].old
|
||||
assert_equal "bar2", @spec.deprecated_options[2].current
|
||||
assert_equal "foo3", @spec.deprecated_options.last.old
|
||||
assert_equal "bar3", @spec.deprecated_options.last.current
|
||||
end
|
||||
|
||||
def test_deprecated_option_raises_when_empty
|
||||
assert_raises(ArgumentError) { @spec.deprecated_option({}) }
|
||||
end
|
||||
|
||||
def test_depends_on
|
||||
@spec.depends_on('foo')
|
||||
assert_equal 'foo', @spec.deps.first.name
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user