Scope HOMEBREW_NO_INSTALL_FROM_API to core formulae in brew audit

This commit is contained in:
Bo Anderson 2023-02-24 12:29:36 +00:00
parent 041545db2c
commit 559bec95bc
No known key found for this signature in database
GPG Key ID: 3DB94E204E137D65
2 changed files with 41 additions and 27 deletions

View File

@ -790,7 +790,6 @@ then
if [[ -z "${HOMEBREW_NO_INSTALL_FROM_API}" ]]
then
NO_INSTALL_FROM_API_COMMANDS=(
audit
bottle
bump-cask-pr
bump-formula-pr

View File

@ -122,7 +122,8 @@ module Homebrew
ENV.activate_extensions!
ENV.setup_build_environment
audit_formulae, audit_casks = if args.tap
audit_formulae, audit_casks = without_api do # audit requires full Ruby source
if args.tap
Tap.fetch(args.tap).then do |tap|
[
tap.formula_names.map { |name| Formula[name] },
@ -148,6 +149,7 @@ module Homebrew
args.named.to_formulae_and_casks
.partition { |formula_or_cask| formula_or_cask.is_a?(Formula) }
end
end
if audit_formulae.empty? && audit_casks.empty?
ofail "No matching formulae or casks to audit!"
@ -209,8 +211,15 @@ module Homebrew
display_cop_names: args.display_cop_names?,
}.compact
fa = FormulaAuditor.new(f, **options)
fa.audit
audit_proc = proc { FormulaAuditor.new(f, **options).tap(&:audit) }
# Audit requires full Ruby source so disable API.
# We shouldn't do this for taps however so that we don't unnecessarily require a full Homebrew/core clone.
fa = if f.core_formula?
without_api(&audit_proc)
else
audit_proc.call
end
if fa.problems.any? || fa.new_formula_problems.any?
formula_count += 1
@ -316,4 +325,10 @@ module Homebrew
def format_problem(message, location)
"* #{location&.to_s&.dup&.concat(": ")}#{message.chomp.gsub("\n", "\n ")}"
end
def without_api(&block)
return yield unless Homebrew::EnvConfig.install_from_api?
with_env(HOMEBREW_NO_INSTALL_FROM_API: "1", HOMEBREW_AUTOMATICALLY_SET_NO_INSTALL_FROM_API: "1", &block)
end
end