From ddcbdbe0c0f138068cf35a015d98a868a5ffbd98 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Tue, 5 Nov 2019 20:34:06 +0000 Subject: [PATCH] formula: cache runtime_dependencies related stuff. --- Library/Homebrew/dev-cmd/bottle.rb | 1 + Library/Homebrew/formula.rb | 24 +++++++++++++----------- Library/Homebrew/formula_installer.rb | 2 +- Library/Homebrew/test/spec_helper.rb | 2 ++ 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index d94752fa91..3e600bc4a0 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -263,6 +263,7 @@ module Homebrew changed_files = keg.replace_locations_with_placeholders unless args.skip_relocation? + Formula.clear_cache Keg.clear_cache Tab.clear_cache tab = Tab.for_keg(keg) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 3be9be5850..2213f640d6 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -52,6 +52,7 @@ class Formula include Utils::Shell extend Enumerable extend Forwardable + extend Cachable # @!method inreplace(paths, before = nil, after = nil) # Actually implemented in {Utils::Inreplace.inreplace}. @@ -1528,7 +1529,8 @@ class Formula # If not, return nil. # @private def opt_or_installed_prefix_keg - if optlinked? && opt_prefix.exist? + Formula.cache[:opt_or_installed_prefix_keg] ||= {} + Formula.cache[:opt_or_installed_prefix_keg][name] ||= if optlinked? && opt_prefix.exist? Keg.new(opt_prefix) elsif installed_prefix.directory? Keg.new(installed_prefix) @@ -1538,27 +1540,27 @@ class Formula # Returns a list of Dependency objects that are required at runtime. # @private def runtime_dependencies(read_from_tab: true, undeclared: true) - if read_from_tab && - undeclared && - (keg = opt_or_installed_prefix_keg) && - (tab_deps = keg.runtime_dependencies) - return tab_deps.map do |d| + deps = if read_from_tab && undeclared && + (tab_deps = opt_or_installed_prefix_keg&.runtime_dependencies) + tab_deps.map do |d| full_name = d["full_name"] next unless full_name Dependency.new full_name end.compact end - - return declared_runtime_dependencies unless undeclared - - declared_runtime_dependencies | undeclared_runtime_dependencies + deps ||= declared_runtime_dependencies unless undeclared + deps ||= (declared_runtime_dependencies | undeclared_runtime_dependencies) + deps end # Returns a list of Formula objects that are required at runtime. # @private def runtime_formula_dependencies(read_from_tab: true, undeclared: true) - runtime_dependencies( + cache_key = "#{name}-#{read_from_tab}-#{undeclared}" + + Formula.cache[:runtime_formula_dependencies] ||= {} + Formula.cache[:runtime_formula_dependencies][cache_key] ||= runtime_dependencies( read_from_tab: read_from_tab, undeclared: undeclared, ).map do |d| diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 9c0092b37c..93468b1202 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -649,7 +649,6 @@ class FormulaInstaller # Update tab with actual runtime dependencies tab = Tab.for_keg(keg) - Keg.clear_cache Tab.clear_cache f_runtime_deps = formula.runtime_dependencies(read_from_tab: false) tab.runtime_dependencies = Tab.runtime_deps_hash(f_runtime_deps) @@ -783,6 +782,7 @@ class FormulaInstaller unless link_keg begin keg.optlink + Formula.clear_cache rescue Keg::LinkError => e onoe "Failed to create #{formula.opt_prefix}" puts "Things that depend on #{formula.full_name} will probably not build." diff --git a/Library/Homebrew/test/spec_helper.rb b/Library/Homebrew/test/spec_helper.rb index 74dd62adde..bf47e60694 100644 --- a/Library/Homebrew/test/spec_helper.rb +++ b/Library/Homebrew/test/spec_helper.rb @@ -145,6 +145,7 @@ RSpec.configure do |config| begin Homebrew.raise_deprecation_exceptions = true + Formula.clear_cache Keg.clear_cache Tap.clear_cache FormulaInstaller.clear_attempted @@ -178,6 +179,7 @@ RSpec.configure do |config| end Tab.clear_cache + Formula.clear_cache Keg.clear_cache FileUtils.rm_rf [