mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Use predefined options for universal, cxx11, and 32-bit options
:universal and :cxx11 are now handled directly, so we don't need to always convert symbols to strings in this method. Symbols should be reserved for future use.
This commit is contained in:
parent
efd63447d8
commit
0c51cf1245
@ -11,6 +11,12 @@ require 'patch'
|
|||||||
class SoftwareSpec
|
class SoftwareSpec
|
||||||
extend Forwardable
|
extend Forwardable
|
||||||
|
|
||||||
|
PREDEFINED_OPTIONS = {
|
||||||
|
:universal => Option.new("universal", "Build a universal binary"),
|
||||||
|
:cxx11 => Option.new("c++11", "Build using C++11 mode"),
|
||||||
|
"32-bit" => Option.new("32-bit", "Build 32-bit only"),
|
||||||
|
}
|
||||||
|
|
||||||
attr_reader :name, :owner
|
attr_reader :name, :owner
|
||||||
attr_reader :build, :resources, :patches, :options
|
attr_reader :build, :resources, :patches, :options
|
||||||
attr_reader :dependency_collector
|
attr_reader :dependency_collector
|
||||||
@ -75,20 +81,18 @@ class SoftwareSpec
|
|||||||
options.include?(name)
|
options.include?(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def option name, description=nil
|
def option(name, description="")
|
||||||
name = 'c++11' if name == :cxx11
|
opt = PREDEFINED_OPTIONS.fetch(name) do
|
||||||
name = name.to_s if Symbol === name
|
if Symbol === name
|
||||||
raise ArgumentError, "option name is required" if name.empty?
|
opoo "Passing arbitrary symbols to `option` is deprecated: #{name.inspect}"
|
||||||
raise ArgumentError, "options should not start with dashes" if name.start_with?("-")
|
puts "Symbols are reserved for future use, please pass a string instead"
|
||||||
|
name = name.to_s
|
||||||
description ||= case name
|
|
||||||
when "universal" then "Build a universal binary"
|
|
||||||
when "32-bit" then "Build 32-bit only"
|
|
||||||
when "c++11" then "Build using C++11 mode"
|
|
||||||
else ""
|
|
||||||
end
|
end
|
||||||
|
raise ArgumentError, "option name is required" if name.empty?
|
||||||
options << Option.new(name, description)
|
raise ArgumentError, "options should not start with dashes" if name.start_with?("-")
|
||||||
|
Option.new(name, description)
|
||||||
|
end
|
||||||
|
options << opt
|
||||||
end
|
end
|
||||||
|
|
||||||
def depends_on spec
|
def depends_on spec
|
||||||
|
@ -55,11 +55,6 @@ class SoftwareSpecTests < Homebrew::TestCase
|
|||||||
assert_raises(ArgumentError) { @spec.option("") }
|
assert_raises(ArgumentError) { @spec.option("") }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_option_accepts_symbols
|
|
||||||
@spec.option(:foo)
|
|
||||||
assert @spec.option_defined?("foo")
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_cxx11_option_special_case
|
def test_cxx11_option_special_case
|
||||||
@spec.option(:cxx11)
|
@spec.option(:cxx11)
|
||||||
assert @spec.option_defined?("c++11")
|
assert @spec.option_defined?("c++11")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user