Browse files

factory: don't reload previously defined formulae

build.rb calls Formula.factory to get a usable Formula object to pass to
its install method. However, because the formula file is the actual
executing script, its class is already defined, and loading it again
causes the class to be re-evaluated, which, unfortunately, is not

This bug has existed for a very long time, and its side effects include
duplicate entries the deps array and mirrors array, among others.
Fortunately, the fix is very simple.

Signed-off-by: Jack Nagel <>
  • Loading branch information...
1 parent f33f3ea commit bbc167b9e724a1d875abecc175b46890800d5c8f @jacknagel jacknagel committed Aug 19, 2012
Showing with 5 additions and 3 deletions.
  1. +5 −3 Library/Homebrew/formula.rb
@@ -377,20 +377,22 @@ def self.factory name
name = Formula.canonical_name(name)
# If name was a path or mapped to a cached formula
- if name.include? "/"
- require name
+ if name.include? "/"
# require allows filenames to drop the .rb extension, but everything else
# in our codebase will require an exact and fullpath.
name = "#{name}.rb" unless name =~ /\.rb$/
path =
name = path.stem
+ require path unless Object.const_defined? self.class_s(name)
install_type = :from_path
target_file = path.to_s
# For names, map to the path and then require
- require Formula.path(name)
+ require Formula.path(name) unless Object.const_defined? self.class_s(name)
install_type = :from_name

0 comments on commit bbc167b

Please sign in to comment.