Merge pull request #20359 from Homebrew/replace-ensure_formula_installed!
Replace `ensure_formula_installed!` with `Formula#ensure_installed!`
This commit is contained in:
commit
a29a643c66
@ -354,9 +354,7 @@ module Homebrew
|
||||
end
|
||||
return if gnu_tar_formula.blank?
|
||||
|
||||
ensure_formula_installed!(gnu_tar_formula.name, reason: "bottling")
|
||||
|
||||
gnu_tar_formula
|
||||
gnu_tar_formula.ensure_installed!(reason: "bottling")
|
||||
end
|
||||
|
||||
sig { params(mtime: String, default_tar: T::Boolean).returns([String, T::Array[String]]) }
|
||||
|
@ -135,10 +135,7 @@ module Homebrew
|
||||
|
||||
if args.repology? && !Utils::Curl.curl_supports_tls13?
|
||||
begin
|
||||
unless HOMEBREW_BREWED_CURL_PATH.exist?
|
||||
require "formula"
|
||||
ensure_formula_installed!("curl", reason: "Repology queries")
|
||||
end
|
||||
Formula["curl"].ensure_installed!(reason: "Repology queries") unless HOMEBREW_BREWED_CURL_PATH.exist?
|
||||
rescue FormulaUnavailableError
|
||||
opoo "A newer `curl` is required for Repology queries."
|
||||
end
|
||||
|
@ -31,8 +31,7 @@ module Homebrew
|
||||
ENV["BAT_CONFIG_PATH"] = Homebrew::EnvConfig.bat_config_path
|
||||
ENV["BAT_THEME"] = Homebrew::EnvConfig.bat_theme
|
||||
require "formula"
|
||||
ensure_formula_installed!(
|
||||
"bat",
|
||||
Formula["bat"].ensure_installed!(
|
||||
reason: "displaying <formula>/<cask> source",
|
||||
# The user might want to capture the output of `brew cat ...`
|
||||
# Redirect stdout to stderr
|
||||
|
@ -449,6 +449,8 @@ module Kernel
|
||||
}
|
||||
def ensure_formula_installed!(formula_name, reason: "", latest: false,
|
||||
output_to_stderr: true, quiet: false)
|
||||
odeprecated "ensure_formula_installed!", "Formula[\"#{formula_name}\"].ensure_installed!"
|
||||
|
||||
if output_to_stderr || quiet
|
||||
file = if quiet
|
||||
File::NULL
|
||||
@ -496,7 +498,7 @@ module Kernel
|
||||
return executable if executable.exist?
|
||||
|
||||
require "formula"
|
||||
ensure_formula_installed!(formula_name, reason:, latest:).opt_bin/name
|
||||
Formula[formula_name].ensure_installed!(reason:, latest:).opt_bin/name
|
||||
end
|
||||
|
||||
sig { returns(T::Array[Pathname]) }
|
||||
|
@ -302,6 +302,44 @@ class Formula
|
||||
Requirement.clear_cache
|
||||
end
|
||||
|
||||
# Ensure the given formula is installed
|
||||
# This is useful for installing a utility formula (e.g. `shellcheck` for `brew style`)
|
||||
sig {
|
||||
params(
|
||||
reason: String,
|
||||
latest: T::Boolean,
|
||||
output_to_stderr: T::Boolean,
|
||||
quiet: T::Boolean,
|
||||
).returns(T.self_type)
|
||||
}
|
||||
def ensure_installed!(reason: "", latest: false, output_to_stderr: true, quiet: false)
|
||||
if output_to_stderr || quiet
|
||||
file = if quiet
|
||||
File::NULL
|
||||
else
|
||||
$stderr
|
||||
end
|
||||
# Call this method itself with redirected stdout
|
||||
redirect_stdout(file) do
|
||||
return ensure_installed!(latest:, reason:, output_to_stderr: false)
|
||||
end
|
||||
end
|
||||
|
||||
reason = " for #{reason}" if reason.present?
|
||||
|
||||
unless any_version_installed?
|
||||
ohai "Installing `#{name}`#{reason}..."
|
||||
safe_system HOMEBREW_BREW_FILE, "install", "--formula", full_name
|
||||
end
|
||||
|
||||
if latest && !latest_version_installed?
|
||||
ohai "Upgrading `#{name}`#{reason}..."
|
||||
safe_system HOMEBREW_BREW_FILE, "upgrade", "--formula", full_name
|
||||
end
|
||||
|
||||
self
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Allow full name logic to be re-used between names, aliases and installed aliases.
|
||||
|
@ -322,21 +322,18 @@ module Homebrew
|
||||
|
||||
def self.shellcheck
|
||||
require "formula"
|
||||
ensure_formula_installed!("shellcheck", latest: true,
|
||||
reason: "shell style checks").opt_bin/"shellcheck"
|
||||
Formula["shellcheck"].ensure_installed!(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")
|
||||
Formula["shfmt"].ensure_installed!(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"
|
||||
Formula["actionlint"].ensure_installed!(latest: true, reason: "GitHub Actions checks").opt_bin/"actionlint"
|
||||
end
|
||||
|
||||
# Collection of style offenses.
|
||||
|
@ -186,7 +186,10 @@ RSpec.describe Utils::Git do
|
||||
unless ENV["HOMEBREW_TEST_GENERIC_OS"]
|
||||
it "installs git" do
|
||||
expect(described_class).to receive(:available?).and_return(false)
|
||||
expect(described_class).to receive(:ensure_formula_installed!).with("git")
|
||||
allow(CoreTap.instance).to receive(:installed?).and_return(true)
|
||||
formula_double = instance_double(Formula)
|
||||
allow(Formula).to receive(:[]).with("git").and_return(formula_double)
|
||||
allow(formula_double).to receive(:ensure_installed!).and_return(formula_double)
|
||||
expect(described_class).to receive(:available?).and_return(true)
|
||||
|
||||
described_class.ensure_installed!
|
||||
|
@ -104,7 +104,7 @@ module Utils
|
||||
raise "Refusing to install Git on a generic OS." if ENV["HOMEBREW_TEST_GENERIC_OS"]
|
||||
|
||||
require "formula"
|
||||
ensure_formula_installed!("git")
|
||||
Formula["git"].ensure_installed!
|
||||
clear_available_cache
|
||||
rescue
|
||||
raise "Git is unavailable"
|
||||
|
@ -153,7 +153,7 @@ module PyPI
|
||||
@version ||= T.let(match[2], T.nilable(String))
|
||||
elsif @is_url
|
||||
require "formula"
|
||||
ensure_formula_installed!(@python_name)
|
||||
Formula[@python_name].ensure_installed!
|
||||
|
||||
# The URL might be a source distribution hosted somewhere;
|
||||
# try and use `pip install -q --no-deps --dry-run --report ...` to get its
|
||||
@ -262,7 +262,7 @@ module PyPI
|
||||
odie "Missing #{missing_msg}" unless install_dependencies
|
||||
ohai "Installing #{missing_msg}"
|
||||
require "formula"
|
||||
missing_dependencies.each(&:ensure_formula_installed!)
|
||||
missing_dependencies.each { |dep| Formula[dep].ensure_installed! }
|
||||
end
|
||||
|
||||
python_deps = formula.deps
|
||||
@ -337,7 +337,7 @@ module PyPI
|
||||
end
|
||||
|
||||
require "formula"
|
||||
ensure_formula_installed!(python_name)
|
||||
Formula[python_name].ensure_installed!
|
||||
|
||||
# Resolve the dependency tree of all input packages
|
||||
show_info = !print_only && !silent
|
||||
|
Loading…
x
Reference in New Issue
Block a user