Formula: add bottle disable DSL

This commit is contained in:
Xu Cheng 2015-09-14 19:51:04 +08:00
parent 5ec396ed38
commit b5032ad2cb
3 changed files with 61 additions and 4 deletions

View File

@ -216,6 +216,21 @@ class Formula
active_spec == head
end
# @private
def bottle_unneeded?
active_spec.bottle_unneeded?
end
# @private
def bottle_disabled?
active_spec.bottle_disabled?
end
# @private
def bottle_disable_reason
active_spec.bottle_disable_reason
end
# @private
def bottled?
active_spec.bottled?
@ -1592,8 +1607,14 @@ class Formula
# sha256 "53c234e5e8472b6ac51c1ae1cab3fe06fad053beb8ebfd8977b010655bfdd3c3" => :mavericks
# sha256 "1121cfccd5913f0a63fec40a6ffd44ea64f9dc135c66634ba001d10bcf4302a2" => :mountain_lion
# end</pre>
def bottle(*, &block)
stable.bottle(&block)
#
# For formulae which don't require compiling, you can tag them with:
# <pre>bottle :unneeded</pre>
#
# To disable bottle for other reasons.
# <pre>bottle :disable, "reasons"</pre>
def bottle(*args, &block)
stable.bottle(*args, &block)
end
# @private

View File

@ -55,3 +55,23 @@ EOS
end.strip
end
end
# Used to annotate formulae that don't require compiling or cannot build bottle.
class BottleDisableReason
def initialize(type, reason)
@type = type
@reason = reason
end
def unneeded?
@type == :unneeded
end
def to_s
if @type == :unneeded
"This formula doesn't require compiling."
else
@reason
end
end
end

View File

@ -63,13 +63,29 @@ class SoftwareSpec
dependency_collector.add(@resource)
end
def bottle_unneeded?
!!@bottle_disable_reason && @bottle_disable_reason.unneeded?
end
def bottle_disabled?
!!@bottle_disable_reason
end
def bottle_disable_reason
@bottle_disable_reason
end
def bottled?
bottle_specification.tag?(bottle_tag) && \
(bottle_specification.compatible_cellar? || ARGV.force_bottle?)
end
def bottle(&block)
bottle_specification.instance_eval(&block)
def bottle(disable_type = nil, disable_reason = nil, &block)
if disable_type
@bottle_disable_reason = BottleDisableReason.new(disable_type, disable_reason)
else
bottle_specification.instance_eval(&block)
end
end
def resource_defined?(name)