Improve performance of brew readall

This commit is contained in:
Bo Anderson 2023-09-28 14:05:09 +01:00
parent eadbe0f184
commit e4623cc8f4
No known key found for this signature in database
GPG Key ID: 3DB94E204E137D65
4 changed files with 36 additions and 18 deletions

View File

@ -3,7 +3,7 @@
module Readall module Readall
class << self class << self
def valid_casks?(casks, os_name: nil, arch: Hardware::CPU.type) def valid_casks?(tap, os_name: nil, arch: Hardware::CPU.type)
return true if os_name == :linux return true if os_name == :linux
current_macos_version = if os_name.is_a?(Symbol) current_macos_version = if os_name.is_a?(Symbol)
@ -13,7 +13,7 @@ module Readall
end end
success = T.let(true, T::Boolean) success = T.let(true, T::Boolean)
casks.each do |file| tap.cask_files.each do |file|
cask = Cask::CaskLoader.load(file) cask = Cask::CaskLoader.load(file)
# Fine to have missing URLs for unsupported macOS # Fine to have missing URLs for unsupported macOS

View File

@ -2398,7 +2398,7 @@ class Formula
variations = {} variations = {}
if path.exist? && (self.class.on_system_blocks_exist? || @on_system_blocks_exist) if path.exist? && on_system_blocks_exist?
formula_contents = path.read formula_contents = path.read
OnSystem::ALL_OS_ARCH_COMBINATIONS.each do |os, arch| OnSystem::ALL_OS_ARCH_COMBINATIONS.each do |os, arch|
bottle_tag = Utils::Bottles::Tag.new(system: os, arch: arch) bottle_tag = Utils::Bottles::Tag.new(system: os, arch: arch)
@ -2452,6 +2452,11 @@ class Formula
hash hash
end end
# @private
def on_system_blocks_exist?
self.class.on_system_blocks_exist? || @on_system_blocks_exist
end
# @private # @private
def fetch(verify_download_integrity: true) def fetch(verify_download_integrity: true)
active_spec.fetch(verify_download_integrity: verify_download_integrity) active_spec.fetch(verify_download_integrity: verify_download_integrity)

View File

@ -9,6 +9,10 @@ require "cask/cask_loader"
# @api private # @api private
module Readall module Readall
class << self class << self
include Cachable
private :cache
def valid_ruby_syntax?(ruby_files) def valid_ruby_syntax?(ruby_files)
failed = T.let(false, T::Boolean) failed = T.let(false, T::Boolean)
ruby_files.each do |ruby_file| ruby_files.each do |ruby_file|
@ -39,19 +43,26 @@ module Readall
!failed !failed
end end
def valid_formulae?(formulae, bottle_tag: nil) def valid_formulae?(tap, bottle_tag: nil)
cache[:valid_formulae] ||= {}
success = T.let(true, T::Boolean) success = T.let(true, T::Boolean)
formulae.each do |file| tap.formula_files.each do |file|
base = Formulary.factory(file) valid = cache[:valid_formulae][file]
next if bottle_tag.blank? || !base.path.exist? || !base.class.on_system_blocks_exist? next if valid == true || valid&.include?(bottle_tag)
formula_contents = base.path.read formula_name = file.basename(".rb").to_s
formula_contents = file.read(encoding: "UTF-8")
readall_namespace = Formulary.class_s("Readall#{bottle_tag.to_sym.capitalize}") readall_namespace = "ReadallNamespace"
readall_formula_class = Formulary.load_formula(base.name, base.path, formula_contents, readall_namespace, readall_formula_class = Formulary.load_formula(formula_name, file, formula_contents, readall_namespace,
flags: base.class.build_flags, ignore_errors: true) flags: [], ignore_errors: false)
readall_formula_class.new(base.name, base.path, :stable, readall_formula = readall_formula_class.new(formula_name, file, :stable, tap: tap)
alias_path: base.alias_path, force_bottle: base.force_bottle) cache[:valid_formulae][file] = if readall_formula.on_system_blocks_exist?
[bottle_tag, *cache[:valid_formulae][file]]
else
true
end
rescue Interrupt rescue Interrupt
raise raise
rescue Exception => e # rubocop:disable Lint/RescueException rescue Exception => e # rubocop:disable Lint/RescueException
@ -62,7 +73,7 @@ module Readall
success success
end end
def valid_casks?(_casks, os_name: nil, arch: nil) def valid_casks?(_tap, os_name: nil, arch: nil)
true true
end end
@ -75,16 +86,16 @@ module Readall
end end
if no_simulate if no_simulate
success = false unless valid_formulae?(tap.formula_files) success = false unless valid_formulae?(tap)
success = false unless valid_casks?(tap.cask_files) success = false unless valid_casks?(tap)
else else
os_arch_combinations.each do |os, arch| os_arch_combinations.each do |os, arch|
bottle_tag = Utils::Bottles::Tag.new(system: os, arch: arch) bottle_tag = Utils::Bottles::Tag.new(system: os, arch: arch)
next unless bottle_tag.valid_combination? next unless bottle_tag.valid_combination?
Homebrew::SimulateSystem.with os: os, arch: arch do Homebrew::SimulateSystem.with os: os, arch: arch do
success = false unless valid_formulae?(tap.formula_files, bottle_tag: bottle_tag) success = false unless valid_formulae?(tap, bottle_tag: bottle_tag)
success = false unless valid_casks?(tap.cask_files, os_name: os, arch: arch) success = false unless valid_casks?(tap, os_name: os, arch: arch)
end end
end end
end end

View File

@ -196,6 +196,7 @@ RSpec.configure do |config|
Tab.clear_cache Tab.clear_cache
Dependency.clear_cache Dependency.clear_cache
Requirement.clear_cache Requirement.clear_cache
Readall.clear_cache if defined?(Readall)
FormulaInstaller.clear_attempted FormulaInstaller.clear_attempted
FormulaInstaller.clear_installed FormulaInstaller.clear_installed
FormulaInstaller.clear_fetched FormulaInstaller.clear_fetched
@ -251,6 +252,7 @@ RSpec.configure do |config|
Tab.clear_cache Tab.clear_cache
Dependency.clear_cache Dependency.clear_cache
Requirement.clear_cache Requirement.clear_cache
Readall.clear_cache if defined?(Readall)
FileUtils.rm_rf [ FileUtils.rm_rf [
*TEST_DIRECTORIES, *TEST_DIRECTORIES,