From 174087958b7cd31ae2eee0236313e0239dc68835 Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Mon, 10 Oct 2022 22:59:07 -0400 Subject: [PATCH] Simulate all OS/arch combinations in `brew readall` --- Library/Homebrew/cli/args.rbi | 3 ++ Library/Homebrew/cmd/readall.rb | 4 +- Library/Homebrew/extend/os/linux/readall.rb | 2 +- Library/Homebrew/readall.rb | 45 +++++++++++++++++---- completions/bash/brew | 1 + completions/fish/brew.fish | 1 + completions/zsh/_brew | 1 + docs/Manpage.md | 2 + manpages/brew.1 | 4 ++ 9 files changed, 53 insertions(+), 10 deletions(-) diff --git a/Library/Homebrew/cli/args.rbi b/Library/Homebrew/cli/args.rbi index cf4265879b..b9768725ab 100644 --- a/Library/Homebrew/cli/args.rbi +++ b/Library/Homebrew/cli/args.rbi @@ -150,6 +150,9 @@ module Homebrew sig { returns(T::Boolean) } def syntax?; end + sig { returns(T::Boolean) } + def no_simulate?; end + sig { returns(T::Boolean) } def ignore_non_pypi_packages?; end diff --git a/Library/Homebrew/cmd/readall.rb b/Library/Homebrew/cmd/readall.rb index 6413166dda..2c7bd4d0af 100644 --- a/Library/Homebrew/cmd/readall.rb +++ b/Library/Homebrew/cmd/readall.rb @@ -26,6 +26,8 @@ module Homebrew switch "--eval-all", description: "Evaluate all available formulae and casks, whether installed or not. " \ "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 end @@ -41,7 +43,7 @@ module Homebrew Homebrew.failed = true unless Readall.valid_ruby_syntax?(ruby_files) end - options = { aliases: args.aliases? } + options = { aliases: args.aliases?, no_simulate: args.no_simulate? } taps = if args.no_named? if !args.eval_all? && !Homebrew::EnvConfig.eval_all? odeprecated "brew readall", "brew readall --eval-all or HOMEBREW_EVAL_ALL" diff --git a/Library/Homebrew/extend/os/linux/readall.rb b/Library/Homebrew/extend/os/linux/readall.rb index 891761f26e..bc2366b642 100644 --- a/Library/Homebrew/extend/os/linux/readall.rb +++ b/Library/Homebrew/extend/os/linux/readall.rb @@ -3,7 +3,7 @@ module Readall class << self - def valid_casks?(_casks) + def valid_casks?(_casks, bottle_tag: nil) true end end diff --git a/Library/Homebrew/readall.rb b/Library/Homebrew/readall.rb index c61f0c2027..77ecc59aa7 100644 --- a/Library/Homebrew/readall.rb +++ b/Library/Homebrew/readall.rb @@ -39,28 +39,39 @@ module Readall !failed end - def valid_formulae?(formulae) + def valid_formulae?(formulae, bottle_tag: nil) success = T.let(true, T::Boolean) 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 raise rescue Exception => e # rubocop:disable Lint/RescueException - onoe "Invalid formula: #{file}" + onoe "Invalid formula (#{bottle_tag}): #{file}" $stderr.puts e success = false end success 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) casks.each do |file| Cask::CaskLoader.load(file) rescue Interrupt raise rescue Exception => e # rubocop:disable Lint/RescueException - onoe "Invalid cask: #{file}" + onoe "Invalid cask (#{bottle_tag}): #{file}" $stderr.puts e success = false end @@ -73,9 +84,27 @@ module Readall valid_aliases = valid_aliases?(tap.alias_dir, tap.formula_dir) success = false unless valid_aliases end - valid_formulae = valid_formulae?(tap.formula_files) - valid_casks = valid_casks?(tap.cask_files) - success = false if !valid_formulae || !valid_casks + if options[:no_simulate] + success = false unless valid_formulae?(tap.formula_files) + 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 end diff --git a/completions/bash/brew b/completions/bash/brew index 7c789ac9b0..9f381e02cb 100644 --- a/completions/bash/brew +++ b/completions/bash/brew @@ -1710,6 +1710,7 @@ _brew_readall() { --debug --eval-all --help + --no-simulate --quiet --syntax --verbose diff --git a/completions/fish/brew.fish b/completions/fish/brew.fish index 15ce52a09d..bf74278870 100644 --- a/completions/fish/brew.fish +++ b/completions/fish/brew.fish @@ -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 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 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 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' diff --git a/completions/zsh/_brew b/completions/zsh/_brew index 933a44e42a..0bf2b57618 100644 --- a/completions/zsh/_brew +++ b/completions/zsh/_brew @@ -1439,6 +1439,7 @@ _brew_readall() { '--debug[Display any debugging information]' \ '--eval-all[Evaluate all available formulae and casks, whether installed or not. Implied if HOMEBREW_EVAL_ALL is set]' \ '--help[Show this message]' \ + '--no-simulate[Don'\''t simulate other system configurations when checking formulae and casks]' \ '--quiet[Make some output more quiet]' \ '--syntax[Syntax-check all of Homebrew'\''s Ruby files (if no `tap` is passed)]' \ '--verbose[Make some output more verbose]' \ diff --git a/docs/Manpage.md b/docs/Manpage.md index 1f49c87d84..1b24d36d2a 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -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). * `--eval-all`: 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`* [...] diff --git a/manpages/brew.1 b/manpages/brew.1 index 0806010f50..e9bdea52a9 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -731,6 +731,10 @@ Syntax\-check all of Homebrew\'s Ruby files (if no \fB\fR is passed)\. \fB\-\-eval\-all\fR 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 [\.\.\.]" 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\. .