From da9e42f3125d191ef73eabc0db03868229904231 Mon Sep 17 00:00:00 2001 From: Bo Anderson Date: Wed, 17 Feb 2021 15:14:16 +0000 Subject: [PATCH 1/2] formulary: remove consts on cache clear --- Library/Homebrew/formulary.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 6714dc70f3..3540949ab0 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -33,6 +33,19 @@ module Formulary cache.fetch(path) end + def self.clear_cache + cache.each do |key, klass| + next if key == :formulary_factory + + namespace = klass.name.deconstantize + next if namespace.deconstantize != name + + remove_const(namespace.demodulize) + end + + super + end + def self.load_formula(name, path, contents, namespace, flags:) raise "Formula loading disabled by HOMEBREW_DISABLE_LOAD_FORMULA!" if Homebrew::EnvConfig.disable_load_formula? From 90e9d177894f76b5f5081d3be2a92245b2aafeda Mon Sep 17 00:00:00 2001 From: Bo Anderson Date: Wed, 17 Feb 2021 17:38:16 +0000 Subject: [PATCH 2/2] formulary: remove consts if loading failed --- Library/Homebrew/formulary.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 3540949ab0..52734a8d0c 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -60,6 +60,7 @@ module Formulary mod.const_set(:BUILD_FLAGS, flags) mod.module_eval(contents, path) rescue NameError, ArgumentError, ScriptError, MethodDeprecatedError => e + remove_const(namespace) raise FormulaUnreadableError.new(name, e) end class_name = class_s(name) @@ -71,6 +72,7 @@ module Formulary .map { |const_name| mod.const_get(const_name) } .select { |const| const.is_a?(Class) } new_exception = FormulaClassUnavailableError.new(name, path, class_name, class_list) + remove_const(namespace) raise new_exception, "", e.backtrace end end