utils: add method ensure_formula_installed!
This commit is contained in:
parent
9be410b348
commit
3376479e95
@ -108,10 +108,7 @@ module Homebrew
|
||||
|
||||
def ensure_relocation_formulae_installed!
|
||||
Keg.relocation_formulae.each do |f|
|
||||
next if Formula[f].latest_version_installed?
|
||||
|
||||
ohai "Installing #{f}..."
|
||||
safe_system HOMEBREW_BREW_FILE, "install", f
|
||||
ensure_formula_installed!(f, latest: true)
|
||||
end
|
||||
end
|
||||
|
||||
@ -263,10 +260,7 @@ module Homebrew
|
||||
return default_tar_args
|
||||
end
|
||||
|
||||
unless gnu_tar.any_version_installed?
|
||||
ohai "Installing `gnu-tar` for bottling..."
|
||||
safe_system HOMEBREW_BREW_FILE, "install", "--formula", gnu_tar.full_name
|
||||
end
|
||||
ensure_formula_installed!(gnu_tar, "for bottling")
|
||||
|
||||
["#{gnu_tar.opt_bin}/gtar", gnutar_args].freeze
|
||||
end
|
||||
|
@ -59,8 +59,7 @@ module Homebrew
|
||||
unless Utils::Curl.curl_supports_tls13?
|
||||
begin
|
||||
unless Pathname.new(ENV["HOMEBREW_BREWED_CURL_PATH"]).exist?
|
||||
ohai "Installing `curl` for Repology queries..."
|
||||
safe_system HOMEBREW_BREW_FILE, "install", "--formula", Formula["curl"].full_name
|
||||
ensure_formula_installed!("curl", "for Repology queries")
|
||||
end
|
||||
rescue FormulaUnavailableError
|
||||
opoo "A `curl` with TLS 1.3 support is required for Repology queries."
|
||||
|
@ -31,18 +31,14 @@ module Homebrew
|
||||
|
||||
cd HOMEBREW_REPOSITORY
|
||||
pager = if Homebrew::EnvConfig.bat?
|
||||
require "formula"
|
||||
|
||||
unless Formula["bat"].any_version_installed?
|
||||
ENV["BAT_CONFIG_PATH"] = Homebrew::EnvConfig.bat_config_path
|
||||
ensure_formula_installed!(
|
||||
"bat",
|
||||
"for displaying <formula>/<cask> source",
|
||||
# The user might want to capture the output of `brew cat ...`
|
||||
# Redirect stdout to stderr
|
||||
redirect_stdout($stderr) do
|
||||
ohai "Installing `bat` for displaying <formula>/<cask> source..."
|
||||
safe_system HOMEBREW_BREW_FILE, "install", "bat"
|
||||
end
|
||||
end
|
||||
ENV["BAT_CONFIG_PATH"] = Homebrew::EnvConfig.bat_config_path
|
||||
Formula["bat"].opt_bin/"bat"
|
||||
output_to_stderr: true,
|
||||
).opt_bin/"bat"
|
||||
else
|
||||
"cat"
|
||||
end
|
||||
|
@ -48,11 +48,9 @@ module Homebrew
|
||||
def run_buildpulse
|
||||
require "formula"
|
||||
|
||||
unless Formula["buildpulse-test-reporter"].any_version_installed?
|
||||
ohai "Installing `buildpulse-test-reporter` for reporting test flakiness..."
|
||||
with_env(HOMEBREW_NO_AUTO_UPDATE: "1", HOMEBREW_NO_BOOTSNAP: "1") do
|
||||
safe_system HOMEBREW_BREW_FILE, "install", "buildpulse-test-reporter"
|
||||
end
|
||||
with_env(HOMEBREW_NO_AUTO_UPDATE: "1", HOMEBREW_NO_BOOTSNAP: "1") do
|
||||
ensure_formula_installed!("buildpulse-test-reporter",
|
||||
"for reporting test flakiness")
|
||||
end
|
||||
|
||||
ENV["BUILDPULSE_ACCESS_KEY_ID"] = ENV["HOMEBREW_BUILDPULSE_ACCESS_KEY_ID"]
|
||||
|
@ -53,11 +53,7 @@ class GitHubPackages
|
||||
which("skopeo", ENV["HOMEBREW_PATH"]),
|
||||
HOMEBREW_PREFIX/"bin/skopeo",
|
||||
].compact.first
|
||||
unless skopeo.exist?
|
||||
ohai "Installing `skopeo` for upload..."
|
||||
safe_system HOMEBREW_BREW_FILE, "install", "--formula", "skopeo"
|
||||
skopeo = Formula["skopeo"].opt_bin/"skopeo"
|
||||
end
|
||||
skopeo = ensure_formula_installed!("skopeo", "for upload").opt_bin/"skopeo" unless skopeo.exist?
|
||||
|
||||
require "json_schemer"
|
||||
|
||||
|
@ -278,31 +278,12 @@ module Homebrew
|
||||
|
||||
def shellcheck
|
||||
# Always use the latest brewed shellcheck
|
||||
unless Formula["shellcheck"].latest_version_installed?
|
||||
if Formula["shellcheck"].any_version_installed?
|
||||
ohai "Upgrading `shellcheck` for shell style checks..."
|
||||
safe_system HOMEBREW_BREW_FILE, "upgrade", "shellcheck"
|
||||
else
|
||||
ohai "Installing `shellcheck` for shell style checks..."
|
||||
safe_system HOMEBREW_BREW_FILE, "install", "shellcheck"
|
||||
end
|
||||
end
|
||||
|
||||
Formula["shellcheck"].opt_bin/"shellcheck"
|
||||
ensure_formula_installed!("shellcheck", "for shell style checks", latest: true).opt_bin/"shellcheck"
|
||||
end
|
||||
|
||||
def shfmt
|
||||
# Always use the latest brewed shfmt
|
||||
unless Formula["shfmt"].latest_version_installed?
|
||||
if Formula["shfmt"].any_version_installed?
|
||||
ohai "Upgrading `shfmt` to format shell scripts..."
|
||||
safe_system HOMEBREW_BREW_FILE, "upgrade", "shfmt"
|
||||
else
|
||||
ohai "Installing `shfmt` to format shell scripts..."
|
||||
safe_system HOMEBREW_BREW_FILE, "install", "shfmt"
|
||||
end
|
||||
end
|
||||
|
||||
ensure_formula_installed!("shfmt", "to format shell scripts", latest: true)
|
||||
HOMEBREW_LIBRARY/"Homebrew/utils/shfmt.sh"
|
||||
end
|
||||
|
||||
|
@ -454,6 +454,47 @@ module Kernel
|
||||
out.close
|
||||
end
|
||||
|
||||
# Ensure the given formula is installed
|
||||
# This is useful for installing a utility formula (e.g. `shellcheck` for `brew style`)
|
||||
def ensure_formula_installed!(formula_or_name, reason = "", latest: false, linked: false,
|
||||
output_to_stderr: false, 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_formula_installed!(formula_or_name, reason, latest: latest, linked: linked)
|
||||
end
|
||||
end
|
||||
|
||||
require "formula"
|
||||
|
||||
formula = if formula_or_name.is_a?(Formula)
|
||||
formula_or_name
|
||||
else
|
||||
Formula[formula_or_name]
|
||||
end
|
||||
|
||||
reason = " #{reason}" if reason.present? # add a whitespace
|
||||
|
||||
unless formula.any_version_installed?
|
||||
ohai "Installing `#{formula.name}`#{reason}..."
|
||||
safe_system HOMEBREW_BREW_FILE, "install", "--formula", formula.full_name
|
||||
end
|
||||
|
||||
if latest && !formula.latest_version_installed?
|
||||
ohai "Upgrading `#{formula.name}`#{reason}..."
|
||||
safe_system HOMEBREW_BREW_FILE, "upgrade", "--formula", formula.full_name
|
||||
end
|
||||
|
||||
safe_system HOMEBREW_BREW_FILE, "link", formula.full_name if linked && !formula.linked?
|
||||
|
||||
formula
|
||||
end
|
||||
|
||||
def paths
|
||||
@paths ||= PATH.new(ENV["HOMEBREW_PATH"]).map do |p|
|
||||
File.expand_path(p).chomp("/")
|
||||
|
@ -100,7 +100,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"]
|
||||
|
||||
safe_system HOMEBREW_BREW_FILE, "install", "git"
|
||||
ensure_formula_installed!("git")
|
||||
clear_available_cache
|
||||
rescue
|
||||
raise "Git is unavailable"
|
||||
|
Loading…
x
Reference in New Issue
Block a user