Unverified Commit 6913c7c8 authored by Mike McQuaid's avatar Mike McQuaid
Browse files

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.
parent 778de69b
......@@ -230,7 +230,16 @@ EOS
# exceeds 3 seconds.
update-preinstall-timer() {
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.
......
......@@ -162,10 +162,21 @@ module Homebrew
cleanup.periodic_clean!
elsif f.latest_version_installed? && !cleanup.skip_clean_formula?(f)
ohai "Running `brew cleanup #{f}`..."
puts_no_install_cleanup_disable_message_if_not_already!
cleanup.cleanup_formula(f)
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)
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..."
end
Cleanup.puts_no_install_cleanup_disable_message_if_not_already!
return if dry_run?
clean!(quiet: true, periodic: true)
......
......@@ -257,6 +257,10 @@ module Homebrew
"\n\n *Note:* Will only try to print emoji on OS X Lion or newer.",
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: {
description: "If set, do not use the GitHub API, e.g. for searches or fetching relevant issues " \
"after a failed install.",
......
......@@ -235,6 +235,16 @@ module Homebrew
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(
formulae,
flags:,
......@@ -249,7 +259,13 @@ module Homebrew
quiet: 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
return if installed_formulae.empty?
......@@ -286,6 +302,7 @@ module Homebrew
plural = "dependent".pluralize(upgradeable_dependents.count)
verb = dry_run ? "Would upgrade" : "Upgrading"
ohai "#{verb} #{upgradeable_dependents.count} #{plural}:"
Upgrade.puts_no_installed_dependents_check_disable_message_if_not_already!
formulae_upgrades = upgradeable_dependents.map do |f|
name = f.full_specified_name
if f.optlinked?
......@@ -317,7 +334,10 @@ module Homebrew
installed_formulae = FormulaInstaller.installed.to_a
# 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)
if broken_dependents.blank?
......@@ -356,6 +376,7 @@ module Homebrew
count = reinstallable_broken_dependents.count
plural = "dependent".pluralize(reinstallable_broken_dependents.count)
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)
.join(", ")
end
......
......@@ -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.
- `HOMEBREW_NO_ENV_HINTS`
<br>If set, do not print any hints about changing Homebrew's behaviour with environment variables.
- `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.
......
......@@ -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\.
.
.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
.
.br
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment