diff --git a/Library/Homebrew/dev-cmd/bump.rb b/Library/Homebrew/dev-cmd/bump.rb index 0da3372b6a..77d1d37e9d 100644 --- a/Library/Homebrew/dev-cmd/bump.rb +++ b/Library/Homebrew/dev-cmd/bump.rb @@ -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 diff --git a/Library/Homebrew/extend/kernel.rb b/Library/Homebrew/extend/kernel.rb index 0b7d12ac9f..90d0988643 100644 --- a/Library/Homebrew/extend/kernel.rb +++ b/Library/Homebrew/extend/kernel.rb @@ -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 diff --git a/Library/Homebrew/style.rb b/Library/Homebrew/style.rb index eda23c283c..f9049d7fb0 100644 --- a/Library/Homebrew/style.rb +++ b/Library/Homebrew/style.rb @@ -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 diff --git a/Library/Homebrew/utils/git.rb b/Library/Homebrew/utils/git.rb index 994ae07ca2..4eeca69d1d 100644 --- a/Library/Homebrew/utils/git.rb +++ b/Library/Homebrew/utils/git.rb @@ -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 diff --git a/Library/Homebrew/utils/pypi.rb b/Library/Homebrew/utils/pypi.rb index cb3279ad6d..ec3cad9409 100644 --- a/Library/Homebrew/utils/pypi.rb +++ b/Library/Homebrew/utils/pypi.rb @@ -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