Simulate all OS/arch combinations in brew readall

This commit is contained in:
Rylan Polster 2022-10-10 22:59:07 -04:00
parent f30f68be7d
commit 174087958b
No known key found for this signature in database
GPG Key ID: 46A744940CFF4D64
9 changed files with 53 additions and 10 deletions

View File

@ -150,6 +150,9 @@ module Homebrew
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def syntax?; end def syntax?; end
sig { returns(T::Boolean) }
def no_simulate?; end
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def ignore_non_pypi_packages?; end def ignore_non_pypi_packages?; end

View File

@ -26,6 +26,8 @@ module Homebrew
switch "--eval-all", switch "--eval-all",
description: "Evaluate all available formulae and casks, whether installed or not. " \ description: "Evaluate all available formulae and casks, whether installed or not. " \
"Implied if HOMEBREW_EVAL_ALL is set." "Implied if HOMEBREW_EVAL_ALL is set."
switch "--no-simulate",
description: "Don't simulate other system configurations when checking formulae and casks."
named_args :tap named_args :tap
end end
@ -41,7 +43,7 @@ module Homebrew
Homebrew.failed = true unless Readall.valid_ruby_syntax?(ruby_files) Homebrew.failed = true unless Readall.valid_ruby_syntax?(ruby_files)
end end
options = { aliases: args.aliases? } options = { aliases: args.aliases?, no_simulate: args.no_simulate? }
taps = if args.no_named? taps = if args.no_named?
if !args.eval_all? && !Homebrew::EnvConfig.eval_all? if !args.eval_all? && !Homebrew::EnvConfig.eval_all?
odeprecated "brew readall", "brew readall --eval-all or HOMEBREW_EVAL_ALL" odeprecated "brew readall", "brew readall --eval-all or HOMEBREW_EVAL_ALL"

View File

@ -3,7 +3,7 @@
module Readall module Readall
class << self class << self
def valid_casks?(_casks) def valid_casks?(_casks, bottle_tag: nil)
true true
end end
end end

View File

@ -39,28 +39,39 @@ module Readall
!failed !failed
end end
def valid_formulae?(formulae) def valid_formulae?(formulae, bottle_tag: nil)
success = T.let(true, T::Boolean) success = T.let(true, T::Boolean)
formulae.each do |file| formulae.each do |file|
Formulary.factory(file) base = Formulary.factory(file)
next if bottle_tag.blank? || !base.path.exist? || !base.class.on_system_blocks_exist?
formula_contents = base.path.read
readall_namespace = Formulary.class_s("Readall#{bottle_tag.to_sym.capitalize}")
readall_formula_class = Formulary.load_formula(base.name, base.path, formula_contents, readall_namespace,
flags: base.class.build_flags, ignore_errors: true)
readall_formula_class.new(base.name, base.path, :stable,
alias_path: base.alias_path, force_bottle: base.force_bottle)
rescue Interrupt rescue Interrupt
raise raise
rescue Exception => e # rubocop:disable Lint/RescueException rescue Exception => e # rubocop:disable Lint/RescueException
onoe "Invalid formula: #{file}" onoe "Invalid formula (#{bottle_tag}): #{file}"
$stderr.puts e $stderr.puts e
success = false success = false
end end
success success
end end
def valid_casks?(casks) def valid_casks?(casks, bottle_tag: nil)
return true if bottle_tag.present? && bottle_tag.system == :linux
success = T.let(true, T::Boolean) success = T.let(true, T::Boolean)
casks.each do |file| casks.each do |file|
Cask::CaskLoader.load(file) Cask::CaskLoader.load(file)
rescue Interrupt rescue Interrupt
raise raise
rescue Exception => e # rubocop:disable Lint/RescueException rescue Exception => e # rubocop:disable Lint/RescueException
onoe "Invalid cask: #{file}" onoe "Invalid cask (#{bottle_tag}): #{file}"
$stderr.puts e $stderr.puts e
success = false success = false
end end
@ -73,9 +84,27 @@ module Readall
valid_aliases = valid_aliases?(tap.alias_dir, tap.formula_dir) valid_aliases = valid_aliases?(tap.alias_dir, tap.formula_dir)
success = false unless valid_aliases success = false unless valid_aliases
end end
valid_formulae = valid_formulae?(tap.formula_files) if options[:no_simulate]
valid_casks = valid_casks?(tap.cask_files) success = false unless valid_formulae?(tap.formula_files)
success = false if !valid_formulae || !valid_casks success = false unless valid_casks?(tap.cask_files)
else
arches = [:arm, :intel]
os_names = [*MacOSVersions::SYMBOLS.keys, :linux]
arches.each do |arch|
os_names.each do |os_name|
bottle_tag = Utils::Bottles::Tag.new(system: os_name, arch: arch)
next unless bottle_tag.valid_combination?
Homebrew::SimulateSystem.arch = arch
Homebrew::SimulateSystem.os = os_name
success = false unless valid_formulae?(tap.formula_files, bottle_tag: bottle_tag)
success = false unless valid_casks?(tap.cask_files, bottle_tag: bottle_tag)
Homebrew::SimulateSystem.clear
end
end
end
success success
end end

View File

@ -1710,6 +1710,7 @@ _brew_readall() {
--debug --debug
--eval-all --eval-all
--help --help
--no-simulate
--quiet --quiet
--syntax --syntax
--verbose --verbose

View File

@ -1180,6 +1180,7 @@ __fish_brew_complete_arg 'readall' -l aliases -d 'Verify any alias symlinks in e
__fish_brew_complete_arg 'readall' -l debug -d 'Display any debugging information' __fish_brew_complete_arg 'readall' -l debug -d 'Display any debugging information'
__fish_brew_complete_arg 'readall' -l eval-all -d 'Evaluate all available formulae and casks, whether installed or not. Implied if HOMEBREW_EVAL_ALL is set' __fish_brew_complete_arg 'readall' -l eval-all -d 'Evaluate all available formulae and casks, whether installed or not. Implied if HOMEBREW_EVAL_ALL is set'
__fish_brew_complete_arg 'readall' -l help -d 'Show this message' __fish_brew_complete_arg 'readall' -l help -d 'Show this message'
__fish_brew_complete_arg 'readall' -l no-simulate -d 'Don\'t simulate other system configurations when checking formulae and casks'
__fish_brew_complete_arg 'readall' -l quiet -d 'Make some output more quiet' __fish_brew_complete_arg 'readall' -l quiet -d 'Make some output more quiet'
__fish_brew_complete_arg 'readall' -l syntax -d 'Syntax-check all of Homebrew\'s Ruby files (if no `tap` is passed)' __fish_brew_complete_arg 'readall' -l syntax -d 'Syntax-check all of Homebrew\'s Ruby files (if no `tap` is passed)'
__fish_brew_complete_arg 'readall' -l verbose -d 'Make some output more verbose' __fish_brew_complete_arg 'readall' -l verbose -d 'Make some output more verbose'

View File

@ -1439,6 +1439,7 @@ _brew_readall() {
'--debug[Display any debugging information]' \ '--debug[Display any debugging information]' \
'--eval-all[Evaluate all available formulae and casks, whether installed or not. Implied if HOMEBREW_EVAL_ALL is set]' \ '--eval-all[Evaluate all available formulae and casks, whether installed or not. Implied if HOMEBREW_EVAL_ALL is set]' \
'--help[Show this message]' \ '--help[Show this message]' \
'--no-simulate[Don'\''t simulate other system configurations when checking formulae and casks]' \
'--quiet[Make some output more quiet]' \ '--quiet[Make some output more quiet]' \
'--syntax[Syntax-check all of Homebrew'\''s Ruby files (if no `tap` is passed)]' \ '--syntax[Syntax-check all of Homebrew'\''s Ruby files (if no `tap` is passed)]' \
'--verbose[Make some output more verbose]' \ '--verbose[Make some output more verbose]' \

View File

@ -528,6 +528,8 @@ all items or checking if any current formulae/casks have Ruby issues.
Syntax-check all of Homebrew's Ruby files (if no `*`tap`*` is passed). Syntax-check all of Homebrew's Ruby files (if no `*`tap`*` is passed).
* `--eval-all`: * `--eval-all`:
Evaluate all available formulae and casks, whether installed or not. Implied if HOMEBREW_EVAL_ALL is set. Evaluate all available formulae and casks, whether installed or not. Implied if HOMEBREW_EVAL_ALL is set.
* `--no-simulate`:
Don't simulate other system configurations when checking formulae and casks.
### `reinstall` [*`options`*] *`formula`*|*`cask`* [...] ### `reinstall` [*`options`*] *`formula`*|*`cask`* [...]

View File

@ -731,6 +731,10 @@ Syntax\-check all of Homebrew\'s Ruby files (if no \fB<tap>\fR is passed)\.
\fB\-\-eval\-all\fR \fB\-\-eval\-all\fR
Evaluate all available formulae and casks, whether installed or not\. Implied if HOMEBREW_EVAL_ALL is set\. Evaluate all available formulae and casks, whether installed or not\. Implied if HOMEBREW_EVAL_ALL is set\.
. .
.TP
\fB\-\-no\-simulate\fR
Don\'t simulate other system configurations when checking formulae and casks\.
.
.SS "\fBreinstall\fR [\fIoptions\fR] \fIformula\fR|\fIcask\fR [\.\.\.]" .SS "\fBreinstall\fR [\fIoptions\fR] \fIformula\fR|\fIcask\fR [\.\.\.]"
Uninstall and then reinstall a \fIformula\fR or \fIcask\fR using the same options it was originally installed with, plus any appended options specific to a \fIformula\fR\. Uninstall and then reinstall a \fIformula\fR or \fIcask\fR using the same options it was originally installed with, plus any appended options specific to a \fIformula\fR\.
. .