Ensure we require "formula" before doing ensure_formula_installed!

This is needed to avoid Sorbet runtime errors. See #20352.
This commit is contained in:
Carlo Cabrera 2025-08-02 02:34:56 +08:00 committed by Carlo Cabrera
parent cf6c5acce0
commit cc5df09845
No known key found for this signature in database
GPG Key ID: C74D447FC549A1D0
5 changed files with 17 additions and 3 deletions

View File

@ -135,7 +135,10 @@ module Homebrew
if args.repology? && !Utils::Curl.curl_supports_tls13?
begin
ensure_formula_installed!("curl", reason: "Repology queries") unless HOMEBREW_BREWED_CURL_PATH.exist?
unless HOMEBREW_BREWED_CURL_PATH.exist?
require "formula"
ensure_formula_installed!("curl", reason: "Repology queries")
end
rescue FormulaUnavailableError
opoo "A newer `curl` is required for Repology queries."
end

View File

@ -441,6 +441,8 @@ module Kernel
# Ensure the given formula is installed
# This is useful for installing a utility formula (e.g. `shellcheck` for `brew style`)
# NOTE: One must `require "formula"` before using this method. Doing `require "formula"` inside the method
# doesn't help, and therefore is useless to add.
sig {
params(formula_name: String, reason: String, latest: T::Boolean, output_to_stderr: T::Boolean,
quiet: T::Boolean).returns(Formula)
@ -460,8 +462,8 @@ module Kernel
end
end
require "formula"
# Do not `require "formula"` here. It will mask misuse of this method when
# it is called without doing `require "formula"` first.
formula = Formula[formula_name]
reason = " for #{reason}" if reason.present?
@ -493,6 +495,7 @@ module Kernel
].compact.first
return executable if executable.exist?
require "formula"
ensure_formula_installed!(formula_name, reason:, latest:).opt_bin/name
end

View File

@ -321,22 +321,26 @@ module Homebrew
end
def self.rubocop
require "formula"
ensure_formula_installed!("rubocop", latest: true,
reason: "Ruby style checks").opt_bin/"rubocop"
end
def self.shellcheck
require "formula"
ensure_formula_installed!("shellcheck", latest: true,
reason: "shell style checks").opt_bin/"shellcheck"
end
def self.shfmt
require "formula"
ensure_formula_installed!("shfmt", latest: true,
reason: "formatting shell scripts")
HOMEBREW_LIBRARY/"Homebrew/utils/shfmt.sh"
end
def self.actionlint
require "formula"
ensure_formula_installed!("actionlint", latest: true,
reason: "GitHub Actions checks").opt_bin/"actionlint"
end

View File

@ -103,6 +103,7 @@ module Utils
# and will also likely fail due to `OS::Linux` and `OS::Mac` being undefined.
raise "Refusing to install Git on a generic OS." if ENV["HOMEBREW_TEST_GENERIC_OS"]
require "formula"
ensure_formula_installed!("git")
clear_available_cache
rescue

View File

@ -152,6 +152,7 @@ module PyPI
@extras ||= T.let([], T.nilable(T::Array[String]))
@version ||= T.let(match[2], T.nilable(String))
elsif @is_url
require "formula"
ensure_formula_installed!(@python_name)
# The URL might be a source distribution hosted somewhere;
@ -260,6 +261,7 @@ module PyPI
missing_msg = "formulae required to update \"#{formula.name}\" resources: #{missing_dependencies.join(", ")}"
odie "Missing #{missing_msg}" unless install_dependencies
ohai "Installing #{missing_msg}"
require "formula"
missing_dependencies.each(&:ensure_formula_installed!)
end
@ -334,6 +336,7 @@ module PyPI
end
end
require "formula"
ensure_formula_installed!(python_name)
# Resolve the dependency tree of all input packages