From 96ee0e90ccaccb9a91dfbe53919998a0adc68cbd Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Fri, 27 Jul 2012 02:50:29 -0500 Subject: [PATCH] Deduplicate requirements Because of some quirks in how formulae are loaded, DSL methods invoked in the class definition are called multiple times. This results in, for example, duplicate dependencies and requirements. Code that iterates over requirements and takes some action for each can thus repeat things that shouldn't be repeated, like appending to environment variables. Make DependencyCollector's external_deps a Set, and define eql? and hash on Requirement to prevent these duplicates. Signed-off-by: Jack Nagel --- Library/Homebrew/dependencies.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/dependencies.rb b/Library/Homebrew/dependencies.rb index 6a4c3e2286..43596ad6c7 100644 --- a/Library/Homebrew/dependencies.rb +++ b/Library/Homebrew/dependencies.rb @@ -1,3 +1,5 @@ +require 'set' + ## This file defines dependencies and requirements. ## ## A dependency is a formula that another formula needs to install. @@ -21,7 +23,7 @@ class DependencyCollector def initialize @deps = Dependencies.new - @external_deps = [] + @external_deps = Set.new end def add spec @@ -119,6 +121,14 @@ class Requirement def fatal?; false; end def message; ""; end def modify_build_environment; nil end + + def eql?(other) + other.is_a? self.class and hash == other.hash + end + + def hash + @message.hash + end end