requirement: get formula from satisfy.

If satisfy returns a `Pathname` from `which` then we can use that to
infer a formula dependency from that `Requirement`.
This commit is contained in:
Mike McQuaid 2017-01-09 22:44:01 +00:00
parent ebf3d939d1
commit fe117bf79b

View File

@ -15,6 +15,7 @@ class Requirement
@default_formula = self.class.default_formula @default_formula = self.class.default_formula
@cask ||= self.class.cask @cask ||= self.class.cask
@download ||= self.class.download @download ||= self.class.download
@formula = nil
tags.each do |tag| tags.each do |tag|
next unless tag.is_a? Hash next unless tag.is_a? Hash
@cask ||= tag[:cask] @cask ||= tag[:cask]
@ -56,7 +57,14 @@ class Requirement
def satisfied? def satisfied?
result = self.class.satisfy.yielder { |p| instance_eval(&p) } result = self.class.satisfy.yielder { |p| instance_eval(&p) }
@satisfied_result = result @satisfied_result = result
result ? true : false return false unless result
if parent = satisfied_result_parent
parent.to_s =~ %r{(#{Regexp.escape(HOMEBREW_CELLAR)}|#{Regexp.escape(HOMEBREW_PREFIX)}/opt)/([\w+-.@]+)}
@formula = $2
end
true
end end
# Overriding #fatal? is deprecated. # Overriding #fatal? is deprecated.
@ -69,6 +77,11 @@ class Requirement
self.class.default_formula || false self.class.default_formula || false
end end
def satisfied_result_parent
return unless @satisfied_result.is_a?(Pathname)
@satisfied_result.resolved_path.parent
end
# Overriding #modify_build_environment is deprecated. # Overriding #modify_build_environment is deprecated.
# Pass a block to the env DSL method instead. # Pass a block to the env DSL method instead.
# Note: #satisfied? should be called before invoking this method # Note: #satisfied? should be called before invoking this method
@ -81,11 +94,8 @@ class Requirement
# satisfy { which("executable") } # satisfy { which("executable") }
# work, even under superenv where "executable" wouldn't normally be on the # work, even under superenv where "executable" wouldn't normally be on the
# PATH. # PATH.
# This is undocumented magic and it should be removed, but we need to add parent = satisfied_result_parent
# a way to declare path-based requirements that work with superenv first. return unless parent
return unless @satisfied_result.is_a?(Pathname)
parent = @satisfied_result.parent
return if ENV["PATH"].split(File::PATH_SEPARATOR).include?(parent.to_s) return if ENV["PATH"].split(File::PATH_SEPARATOR).include?(parent.to_s)
ENV.append_path("PATH", parent) ENV.append_path("PATH", parent)
end end
@ -111,13 +121,15 @@ class Requirement
"#<#{self.class.name}: #{name.inspect} #{tags.inspect}>" "#<#{self.class.name}: #{name.inspect} #{tags.inspect}>"
end end
def formula
@formula || self.class.default_formula
end
def to_dependency def to_dependency
f = self.class.default_formula if formula =~ HOMEBREW_TAP_FORMULA_REGEX
raise "No default formula defined for #{inspect}" if f.nil? TapDependency.new(formula, tags, method(:modify_build_environment), name)
if f =~ HOMEBREW_TAP_FORMULA_REGEX elsif formula
TapDependency.new(f, tags, method(:modify_build_environment), name) Dependency.new(formula, tags, method(:modify_build_environment), name)
else
Dependency.new(f, tags, method(:modify_build_environment), name)
end end
end end