Merge pull request #4290 from MikeMcQuaid/check-linkage

linkage_checker: fix cache invalidation.
This commit is contained in:
Mike McQuaid 2018-06-06 14:04:34 +01:00 committed by GitHub
commit 9c1a988c32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 14 deletions

View File

@ -607,7 +607,7 @@ class FormulaInstaller
# Updates the cache for a particular formula after doing an install # Updates the cache for a particular formula after doing an install
CacheStoreDatabase.use(:linkage) do |db| CacheStoreDatabase.use(:linkage) do |db|
break unless db.created? break unless db.created?
LinkageChecker.new(keg, formula, cache_db: db) LinkageChecker.new(keg, formula, cache_db: db, rebuild_cache: true)
end end
# Update tab with actual runtime dependencies # Update tab with actual runtime dependencies

View File

@ -272,6 +272,11 @@ class Keg
end end
def uninstall def uninstall
CacheStoreDatabase.use(:linkage) do |db|
break unless db.created?
LinkageCacheStore.new(path, db).flush_cache!
end
path.rmtree path.rmtree
path.parent.rmdir_if_possible path.parent.rmdir_if_possible
remove_opt_record if optlinked? remove_opt_record if optlinked?

View File

@ -6,19 +6,19 @@ require "cache_store"
# by the `brew linkage` command # by the `brew linkage` command
# #
class LinkageCacheStore < CacheStore class LinkageCacheStore < CacheStore
# @param [String] keg_name # @param [String] keg_path
# @param [CacheStoreDatabase] database # @param [CacheStoreDatabase] database
# @return [nil] # @return [nil]
def initialize(keg_name, database) def initialize(keg_path, database)
@keg_name = keg_name @keg_path = keg_path
super(database) super(database)
end end
# Returns `true` if the database has any value for the current `keg_name` # Returns `true` if the database has any value for the current `keg_path`
# #
# @return [Boolean] # @return [Boolean]
def keg_exists? def keg_exists?
!database.get(@keg_name).nil? !database.get(@keg_path).nil?
end end
# Inserts dylib-related information into the cache if it does not exist or # Inserts dylib-related information into the cache if it does not exist or
@ -35,7 +35,7 @@ class LinkageCacheStore < CacheStore
EOS EOS
end end
database.set @keg_name, ruby_hash_to_json_string(hash_values) database.set @keg_path, ruby_hash_to_json_string(hash_values)
end end
# @param [Symbol] the type to fetch from the `LinkageCacheStore` # @param [Symbol] the type to fetch from the `LinkageCacheStore`
@ -55,7 +55,7 @@ class LinkageCacheStore < CacheStore
# @return [nil] # @return [nil]
def flush_cache! def flush_cache!
database.delete(@keg_name) database.delete(@keg_path)
end end
private private
@ -65,7 +65,7 @@ class LinkageCacheStore < CacheStore
# @param [Symbol] type # @param [Symbol] type
# @return [Hash] # @return [Hash]
def fetch_hash_values(type) def fetch_hash_values(type)
keg_cache = database.get(@keg_name) keg_cache = database.get(@keg_path)
return {} unless keg_cache return {} unless keg_cache
json_string_to_ruby_hash(keg_cache)[type.to_s] json_string_to_ruby_hash(keg_cache)[type.to_s]
end end

View File

@ -6,10 +6,11 @@ class LinkageChecker
attr_reader :undeclared_deps attr_reader :undeclared_deps
def initialize(keg, formula = nil, cache_db:, def initialize(keg, formula = nil, cache_db:,
use_cache: !ENV["HOMEBREW_LINKAGE_CACHE"].nil?) use_cache: !ENV["HOMEBREW_LINKAGE_CACHE"].nil?,
rebuild_cache: false)
@keg = keg @keg = keg
@formula = formula || resolve_formula(keg) @formula = formula || resolve_formula(keg)
@store = LinkageCacheStore.new(keg.name, cache_db) if use_cache @store = LinkageCacheStore.new(keg.to_s, cache_db) if use_cache
@system_dylibs = Set.new @system_dylibs = Set.new
@broken_dylibs = Set.new @broken_dylibs = Set.new
@ -21,7 +22,7 @@ class LinkageChecker
@undeclared_deps = [] @undeclared_deps = []
@unnecessary_deps = [] @unnecessary_deps = []
check_dylibs check_dylibs(rebuild_cache: rebuild_cache)
end end
def display_normal_output def display_normal_output
@ -67,9 +68,16 @@ class LinkageChecker
Regexp.last_match(2) Regexp.last_match(2)
end end
def check_dylibs def check_dylibs(rebuild_cache:)
keg_files_dylibs_was_empty = false keg_files_dylibs = nil
if rebuild_cache
store&.flush_cache!
else
keg_files_dylibs = store&.fetch_type(:keg_files_dylibs) keg_files_dylibs = store&.fetch_type(:keg_files_dylibs)
end
keg_files_dylibs_was_empty = false
keg_files_dylibs ||= {} keg_files_dylibs ||= {}
if keg_files_dylibs.empty? if keg_files_dylibs.empty?
keg_files_dylibs_was_empty = true keg_files_dylibs_was_empty = true