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