diff options
| author | Mike McQuaid | 2017-01-09 22:44:01 +0000 |
|---|---|---|
| committer | Mike McQuaid | 2017-01-11 12:01:08 -0800 |
| commit | fe117bf79b244c42b7e4049d353c3c003eae4880 (patch) | |
| tree | 50a9f9af9440f14eb8088e2c584bb78105cdc2fb /Library | |
| parent | ebf3d939d1d63ea2cf8b8185e1c36a6e4a066d48 (diff) | |
| download | brew-fe117bf79b244c42b7e4049d353c3c003eae4880.tar.bz2 | |
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`.
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/requirement.rb | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/Library/Homebrew/requirement.rb b/Library/Homebrew/requirement.rb index fe1a3c020..49108ca75 100644 --- a/Library/Homebrew/requirement.rb +++ b/Library/Homebrew/requirement.rb @@ -15,6 +15,7 @@ class Requirement @default_formula = self.class.default_formula @cask ||= self.class.cask @download ||= self.class.download + @formula = nil tags.each do |tag| next unless tag.is_a? Hash @cask ||= tag[:cask] @@ -56,7 +57,14 @@ class Requirement def satisfied? result = self.class.satisfy.yielder { |p| instance_eval(&p) } @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 # Overriding #fatal? is deprecated. @@ -69,6 +77,11 @@ class Requirement self.class.default_formula || false end + def satisfied_result_parent + return unless @satisfied_result.is_a?(Pathname) + @satisfied_result.resolved_path.parent + end + # Overriding #modify_build_environment is deprecated. # Pass a block to the env DSL method instead. # Note: #satisfied? should be called before invoking this method @@ -81,11 +94,8 @@ class Requirement # satisfy { which("executable") } # work, even under superenv where "executable" wouldn't normally be on the # PATH. - # This is undocumented magic and it should be removed, but we need to add - # a way to declare path-based requirements that work with superenv first. - return unless @satisfied_result.is_a?(Pathname) - parent = @satisfied_result.parent - + parent = satisfied_result_parent + return unless parent return if ENV["PATH"].split(File::PATH_SEPARATOR).include?(parent.to_s) ENV.append_path("PATH", parent) end @@ -111,13 +121,15 @@ class Requirement "#<#{self.class.name}: #{name.inspect} #{tags.inspect}>" end + def formula + @formula || self.class.default_formula + end + def to_dependency - f = self.class.default_formula - raise "No default formula defined for #{inspect}" if f.nil? - if f =~ HOMEBREW_TAP_FORMULA_REGEX - TapDependency.new(f, tags, method(:modify_build_environment), name) - else - Dependency.new(f, tags, method(:modify_build_environment), name) + if formula =~ HOMEBREW_TAP_FORMULA_REGEX + TapDependency.new(formula, tags, method(:modify_build_environment), name) + elsif formula + Dependency.new(formula, tags, method(:modify_build_environment), name) end end |
