Output environment variable hints.

Output hints for disabling automatic `brew update`, `brew cleanup` and
`brew upgrade`/`brew reinstall` of dependents. Also provide a
`HOMEBREW_NO_ENV_HINTS` to disable this messaging.
This commit is contained in:
Mike McQuaid 2021-11-26 13:14:10 +00:00
parent 778de69b08
commit 6913c7c84e
No known key found for this signature in database
GPG Key ID: 3338A31AFDB1D829
6 changed files with 58 additions and 3 deletions

View File

@ -230,7 +230,16 @@ EOS
# exceeds 3 seconds. # exceeds 3 seconds.
update-preinstall-timer() { update-preinstall-timer() {
sleep 3 sleep 3
echo 'Updating Homebrew...' >&2 # Outputting a command but don't want to run it, hence single quotes.
# shellcheck disable=SC2016
echo 'Running `brew update --preinstall`...' >&2
if [[ -z "${HOMEBREW_NO_ENV_HINTS}" && -z "${HOMEBREW_AUTO_UPDATE_SECS}" ]]
then
# shellcheck disable=SC2016
echo 'Adjust how often this is run with HOMEBREW_AUTO_UPDATE_SECS or disable with' >&2
# shellcheck disable=SC2016
echo 'HOMEBREW_NO_AUTO_UPDATE. Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).' >&2
fi
} }
# These variables are set from various Homebrew scripts. # These variables are set from various Homebrew scripts.

View File

@ -162,10 +162,21 @@ module Homebrew
cleanup.periodic_clean! cleanup.periodic_clean!
elsif f.latest_version_installed? && !cleanup.skip_clean_formula?(f) elsif f.latest_version_installed? && !cleanup.skip_clean_formula?(f)
ohai "Running `brew cleanup #{f}`..." ohai "Running `brew cleanup #{f}`..."
puts_no_install_cleanup_disable_message_if_not_already!
cleanup.cleanup_formula(f) cleanup.cleanup_formula(f)
end end
end end
def self.puts_no_install_cleanup_disable_message_if_not_already!
return if Homebrew::EnvConfig.no_env_hints?
return if Homebrew::EnvConfig.no_install_cleanup?
return if @puts_no_install_cleanup_disable_message_if_not_already
puts "Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP."
puts "Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`)."
@puts_no_install_cleanup_disable_message_if_not_already = true
end
def skip_clean_formula?(f) def skip_clean_formula?(f)
return false if Homebrew::EnvConfig.no_cleanup_formulae.blank? return false if Homebrew::EnvConfig.no_cleanup_formulae.blank?
@ -194,6 +205,7 @@ module Homebrew
ohai "`brew cleanup` has not been run in the last #{CLEANUP_DEFAULT_DAYS} days, running now..." ohai "`brew cleanup` has not been run in the last #{CLEANUP_DEFAULT_DAYS} days, running now..."
end end
Cleanup.puts_no_install_cleanup_disable_message_if_not_already!
return if dry_run? return if dry_run?
clean!(quiet: true, periodic: true) clean!(quiet: true, periodic: true)

View File

@ -257,6 +257,10 @@ module Homebrew
"\n\n *Note:* Will only try to print emoji on OS X Lion or newer.", "\n\n *Note:* Will only try to print emoji on OS X Lion or newer.",
boolean: true, boolean: true,
}, },
HOMEBREW_NO_ENV_HINTS: {
description: "If set, do not print any hints about changing Homebrew's behaviour with environment variables.",
boolean: true,
},
HOMEBREW_NO_GITHUB_API: { HOMEBREW_NO_GITHUB_API: {
description: "If set, do not use the GitHub API, e.g. for searches or fetching relevant issues " \ description: "If set, do not use the GitHub API, e.g. for searches or fetching relevant issues " \
"after a failed install.", "after a failed install.",

View File

@ -235,6 +235,16 @@ module Homebrew
end end
end end
def self.puts_no_installed_dependents_check_disable_message_if_not_already!
return if Homebrew::EnvConfig.no_env_hints?
return if Homebrew::EnvConfig.no_installed_dependents_check?
return if @puts_no_installed_dependents_check_disable_message_if_not_already
puts "Disable this behaviour by setting HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK."
puts "Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`)."
@puts_no_installed_dependents_check_disable_message_if_not_already = true
end
def check_installed_dependents( def check_installed_dependents(
formulae, formulae,
flags:, flags:,
@ -249,7 +259,13 @@ module Homebrew
quiet: false, quiet: false,
verbose: false verbose: false
) )
return if Homebrew::EnvConfig.no_installed_dependents_check? if Homebrew::EnvConfig.no_installed_dependents_check?
opoo <<~EOS
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK is set: not checking for outdated
dependents or dependents with broken linkage!
EOS
return
end
installed_formulae = dry_run ? formulae : FormulaInstaller.installed.to_a installed_formulae = dry_run ? formulae : FormulaInstaller.installed.to_a
return if installed_formulae.empty? return if installed_formulae.empty?
@ -286,6 +302,7 @@ module Homebrew
plural = "dependent".pluralize(upgradeable_dependents.count) plural = "dependent".pluralize(upgradeable_dependents.count)
verb = dry_run ? "Would upgrade" : "Upgrading" verb = dry_run ? "Would upgrade" : "Upgrading"
ohai "#{verb} #{upgradeable_dependents.count} #{plural}:" ohai "#{verb} #{upgradeable_dependents.count} #{plural}:"
Upgrade.puts_no_installed_dependents_check_disable_message_if_not_already!
formulae_upgrades = upgradeable_dependents.map do |f| formulae_upgrades = upgradeable_dependents.map do |f|
name = f.full_specified_name name = f.full_specified_name
if f.optlinked? if f.optlinked?
@ -317,7 +334,10 @@ module Homebrew
installed_formulae = FormulaInstaller.installed.to_a installed_formulae = FormulaInstaller.installed.to_a
# Assess the dependents tree again now we've upgraded. # Assess the dependents tree again now we've upgraded.
oh1 "Checking for dependents of upgraded formulae..." unless dry_run unless dry_run
oh1 "Checking for dependents of upgraded formulae..."
Upgrade.puts_no_installed_dependents_check_disable_message_if_not_already!
end
broken_dependents = check_broken_dependents(installed_formulae) broken_dependents = check_broken_dependents(installed_formulae)
if broken_dependents.blank? if broken_dependents.blank?
@ -356,6 +376,7 @@ module Homebrew
count = reinstallable_broken_dependents.count count = reinstallable_broken_dependents.count
plural = "dependent".pluralize(reinstallable_broken_dependents.count) plural = "dependent".pluralize(reinstallable_broken_dependents.count)
ohai "Reinstalling #{count} #{plural} with broken linkage from source:" ohai "Reinstalling #{count} #{plural} with broken linkage from source:"
Upgrade.puts_no_installed_dependents_check_disable_message_if_not_already!
puts reinstallable_broken_dependents.map(&:full_specified_name) puts reinstallable_broken_dependents.map(&:full_specified_name)
.join(", ") .join(", ")
end end

View File

@ -2095,6 +2095,9 @@ example, run `export HOMEBREW_NO_INSECURE_REDIRECT=1` rather than just
*Note:* Will only try to print emoji on OS X Lion or newer. *Note:* Will only try to print emoji on OS X Lion or newer.
- `HOMEBREW_NO_ENV_HINTS`
<br>If set, do not print any hints about changing Homebrew's behaviour with environment variables.
- `HOMEBREW_NO_GITHUB_API` - `HOMEBREW_NO_GITHUB_API`
<br>If set, do not use the GitHub API, e.g. for searches or fetching relevant issues after a failed install. <br>If set, do not use the GitHub API, e.g. for searches or fetching relevant issues after a failed install.

View File

@ -3041,6 +3041,12 @@ If set, do not print \fBHOMEBREW_INSTALL_BADGE\fR on a successful build\.
\fINote:\fR Will only try to print emoji on OS X Lion or newer\. \fINote:\fR Will only try to print emoji on OS X Lion or newer\.
. .
.TP .TP
\fBHOMEBREW_NO_ENV_HINTS\fR
.
.br
If set, do not print any hints about changing Homebrew\'s behaviour with environment variables\.
.
.TP
\fBHOMEBREW_NO_GITHUB_API\fR \fBHOMEBREW_NO_GITHUB_API\fR
. .
.br .br