Use Homebrew::EnvConfig.

This commit is contained in:
Mike McQuaid 2020-04-05 15:44:50 +01:00
parent fb0052068f
commit 3381cbf5c7
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70
52 changed files with 184 additions and 265 deletions

View File

@ -28,10 +28,10 @@ class BottlePublisher
end end
def publish_changed_formula_bottles def publish_changed_formula_bottles
raise "Need to load formulae to publish them!" if ENV["HOMEBREW_DISABLE_LOAD_FORMULA"] raise "Need to load formulae to publish them!" if Homebrew::EnvConfig.disable_load_formula?
published = [] published = []
bintray_creds = { user: ENV["HOMEBREW_BINTRAY_USER"], key: ENV["HOMEBREW_BINTRAY_KEY"] } bintray_creds = { user: Homebrew::EnvConfig.bintray_user, key: Homebrew::EnvConfig.bintray_key }
if bintray_creds[:user] && bintray_creds[:key] if bintray_creds[:user] && bintray_creds[:key]
@changed_formulae_names.each do |name| @changed_formulae_names.each do |name|
f = Formula[name] f = Formula[name]
@ -82,7 +82,7 @@ class BottlePublisher
def verify_bintray_published(formulae_names) def verify_bintray_published(formulae_names)
return if formulae_names.empty? return if formulae_names.empty?
raise "Need to load formulae to verify their publication!" if ENV["HOMEBREW_DISABLE_LOAD_FORMULA"] raise "Need to load formulae to verify their publication!" if Homebrew::EnvConfig.disable_load_formula?
ohai "Verifying bottles published on Bintray" ohai "Verifying bottles published on Bintray"
formulae = formulae_names.map { |n| Formula[n] } formulae = formulae_names.map { |n| Formula[n] }

View File

@ -76,7 +76,7 @@ begin
internal_cmd = Commands.valid_internal_cmd?(cmd) internal_cmd = Commands.valid_internal_cmd?(cmd)
internal_cmd ||= begin internal_cmd ||= begin
internal_dev_cmd = Commands.valid_internal_dev_cmd?(cmd) internal_dev_cmd = Commands.valid_internal_dev_cmd?(cmd)
if internal_dev_cmd && !ARGV.homebrew_developer? if internal_dev_cmd && !Homebrew::EnvConfig.developer?
if (HOMEBREW_REPOSITORY/".git/config").exist? if (HOMEBREW_REPOSITORY/".git/config").exist?
system "git", "config", "--file=#{HOMEBREW_REPOSITORY}/.git/config", system "git", "config", "--file=#{HOMEBREW_REPOSITORY}/.git/config",
"--replace-all", "homebrew.devcmdrun", "true" "--replace-all", "homebrew.devcmdrun", "true"
@ -172,7 +172,7 @@ rescue MethodDeprecatedError => e
rescue Exception => e # rubocop:disable Lint/RescueException rescue Exception => e # rubocop:disable Lint/RescueException
onoe e onoe e
if internal_cmd && defined?(OS::ISSUES_URL) && if internal_cmd && defined?(OS::ISSUES_URL) &&
!ENV["HOMEBREW_NO_AUTO_UPDATE"] !Homebrew::EnvConfig.no_auto_update?
$stderr.puts "#{Tty.bold}Please report this issue:#{Tty.reset}" $stderr.puts "#{Tty.bold}Please report this issue:#{Tty.reset}"
$stderr.puts " #{Formatter.url(OS::ISSUES_URL)}" $stderr.puts " #{Formatter.url(OS::ISSUES_URL)}"
end end

View File

@ -136,9 +136,9 @@ then
HOMEBREW_FORCE_BREWED_GIT="1" HOMEBREW_FORCE_BREWED_GIT="1"
fi fi
HOMEBREW_CACHE="${HOMEBREW_CACHE:-${HOME}/Library/Caches/Homebrew}" HOMEBREW_DEFAULT_CACHE="${HOME}/Library/Caches/Homebrew"
HOMEBREW_LOGS="${HOMEBREW_LOGS:-${HOME}/Library/Logs/Homebrew}" HOMEBREW_DEFAULT_LOGS="${HOME}/Library/Logs/Homebrew"
HOMEBREW_SYSTEM_TEMP="/private/tmp" HOMEBREW_DEFAULT_TEMP="/private/tmp"
# Set a variable when the macOS system Ruby is new enough to avoid spawning # Set a variable when the macOS system Ruby is new enough to avoid spawning
# a Ruby process unnecessarily. # a Ruby process unnecessarily.
@ -180,9 +180,9 @@ else
fi fi
CACHE_HOME="${XDG_CACHE_HOME:-${HOME}/.cache}" CACHE_HOME="${XDG_CACHE_HOME:-${HOME}/.cache}"
HOMEBREW_CACHE="${HOMEBREW_CACHE:-${CACHE_HOME}/Homebrew}" HOMEBREW_DEFAULT_CACHE="${CACHE_HOME}/Homebrew"
HOMEBREW_LOGS="${HOMEBREW_LOGS:-${CACHE_HOME}/Homebrew/Logs}" HOMEBREW_DEFAULT_LOGS="${CACHE_HOME}/Homebrew/Logs"
HOMEBREW_SYSTEM_TEMP="/tmp" HOMEBREW_DEFAULT_TEMP="/tmp"
unset HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH unset HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH
fi fi
@ -194,7 +194,9 @@ else
HOMEBREW_BOTTLE_DEFAULT_DOMAIN="https://linuxbrew.bintray.com" HOMEBREW_BOTTLE_DEFAULT_DOMAIN="https://linuxbrew.bintray.com"
fi fi
HOMEBREW_TEMP="${HOMEBREW_TEMP:-${HOMEBREW_SYSTEM_TEMP}}" HOMEBREW_CACHE="${HOMEBREW_CACHE:-${HOMEBREW_DEFAULT_CACHE}}"
HOMEBREW_LOGS="${HOMEBREW_LOGS:-${HOMEBREW_DEFAULT_LOGS}}"
HOMEBREW_TEMP="${HOMEBREW_TEMP:-${HOMEBREW_DEFAULT_TEMP}}"
if [[ -n "$HOMEBREW_FORCE_BREWED_CURL" && if [[ -n "$HOMEBREW_FORCE_BREWED_CURL" &&
-x "$HOMEBREW_PREFIX/opt/curl/bin/curl" ]] && -x "$HOMEBREW_PREFIX/opt/curl/bin/curl" ]] &&
@ -230,13 +232,15 @@ export HOMEBREW_BREW_FILE
export HOMEBREW_PREFIX export HOMEBREW_PREFIX
export HOMEBREW_REPOSITORY export HOMEBREW_REPOSITORY
export HOMEBREW_LIBRARY export HOMEBREW_LIBRARY
export HOMEBREW_SYSTEM_TEMP
export HOMEBREW_TEMP
# Declared in brew.sh # Declared in brew.sh
export HOMEBREW_VERSION export HOMEBREW_VERSION
export HOMEBREW_DEFAULT_CACHE
export HOMEBREW_CACHE export HOMEBREW_CACHE
export HOMEBREW_DEFAULT_LOGS
export HOMEBREW_LOGS export HOMEBREW_LOGS
export HOMEBREW_DEFAULT_TEMP
export HOMEBREW_TEMP
export HOMEBREW_CELLAR export HOMEBREW_CELLAR
export HOMEBREW_SYSTEM export HOMEBREW_SYSTEM
export HOMEBREW_CURL export HOMEBREW_CURL
@ -374,23 +378,24 @@ then
export HOMEBREW_BOTTLE_DOMAIN="$HOMEBREW_BOTTLE_DEFAULT_DOMAIN" export HOMEBREW_BOTTLE_DOMAIN="$HOMEBREW_BOTTLE_DEFAULT_DOMAIN"
fi fi
HOMEBREW_DEFAULT_BREW_GIT_REMOTE="https://github.com/Homebrew/brew" export HOMEBREW_BREW_DEFAULT_GIT_REMOTE="https://github.com/Homebrew/brew"
if [[ -z "$HOMEBREW_BREW_GIT_REMOTE" ]] if [[ -z "$HOMEBREW_BREW_GIT_REMOTE" ]]
then then
HOMEBREW_BREW_GIT_REMOTE="$HOMEBREW_DEFAULT_BREW_GIT_REMOTE" HOMEBREW_BREW_GIT_REMOTE="$HOMEBREW_BREW_DEFAULT_GIT_REMOTE"
fi fi
export HOMEBREW_BREW_GIT_REMOTE export HOMEBREW_BREW_GIT_REMOTE
if [[ -n "$HOMEBREW_MACOS" ]] || [[ -n "$HOMEBREW_FORCE_HOMEBREW_ON_LINUX" ]] if [[ -n "$HOMEBREW_MACOS" ]] || [[ -n "$HOMEBREW_FORCE_HOMEBREW_ON_LINUX" ]]
then then
HOMEBREW_DEFAULT_CORE_GIT_REMOTE="https://github.com/Homebrew/homebrew-core" HOMEBREW_CORE_DEFAULT_GIT_REMOTE="https://github.com/Homebrew/homebrew-core"
else else
HOMEBREW_DEFAULT_CORE_GIT_REMOTE="https://github.com/Homebrew/linuxbrew-core" HOMEBREW_CORE_DEFAULT_GIT_REMOTE="https://github.com/Homebrew/linuxbrew-core"
fi fi
export HOMEBREW_CORE_DEFAULT_GIT_REMOTE
if [[ -z "$HOMEBREW_CORE_GIT_REMOTE" ]] if [[ -z "$HOMEBREW_CORE_GIT_REMOTE" ]]
then then
HOMEBREW_CORE_GIT_REMOTE="$HOMEBREW_DEFAULT_CORE_GIT_REMOTE" HOMEBREW_CORE_GIT_REMOTE="$HOMEBREW_CORE_DEFAULT_GIT_REMOTE"
fi fi
export HOMEBREW_CORE_GIT_REMOTE export HOMEBREW_CORE_GIT_REMOTE

View File

@ -140,7 +140,7 @@ module Cask
def summary def summary
s = +"" s = +""
s << "#{Emoji.install_badge} " if Emoji.enabled? s << "#{Homebrew::EnvConfig.install_badge} " unless Homebrew::EnvConfig.no_emoji?
s << "#{@cask} was successfully #{upgrade? ? "upgraded" : "installed"}!" s << "#{@cask} was successfully #{upgrade? ? "upgraded" : "installed"}!"
s.freeze s.freeze
end end

View File

@ -138,7 +138,7 @@ module Homebrew
end end
def self.install_formula_clean!(f) def self.install_formula_clean!(f)
return if ENV["HOMEBREW_NO_INSTALL_CLEANUP"] return if Homebrew::EnvConfig.no_install_cleanup?
cleanup = Cleanup.new cleanup = Cleanup.new
if cleanup.periodic_clean_due? if cleanup.periodic_clean_due?
@ -149,7 +149,7 @@ module Homebrew
end end
def periodic_clean_due? def periodic_clean_due?
return false if ENV["HOMEBREW_NO_INSTALL_CLEANUP"] return false if Homebrew::EnvConfig.no_install_cleanup?
return true unless PERIODIC_CLEAN_FILE.exist? return true unless PERIODIC_CLEAN_FILE.exist?
PERIODIC_CLEAN_FILE.mtime < CLEANUP_DEFAULT_DAYS.days.ago PERIODIC_CLEAN_FILE.mtime < CLEANUP_DEFAULT_DAYS.days.ago
@ -337,7 +337,7 @@ module Homebrew
.chomp .chomp
use_system_ruby = ( use_system_ruby = (
Gem::Version.new(system_ruby_version) >= Gem::Version.new(RUBY_VERSION) Gem::Version.new(system_ruby_version) >= Gem::Version.new(RUBY_VERSION)
) && ENV["HOMEBREW_FORCE_VENDOR_RUBY"].nil? ) && !Homebrew::EnvConfig.force_vendor_ruby?
vendor_path = HOMEBREW_LIBRARY/"Homebrew/vendor" vendor_path = HOMEBREW_LIBRARY/"Homebrew/vendor"
portable_ruby_version_file = vendor_path/"portable-ruby-version" portable_ruby_version_file = vendor_path/"portable-ruby-version"
portable_ruby_version = if portable_ruby_version_file.exist? portable_ruby_version = if portable_ruby_version_file.exist?

View File

@ -83,7 +83,11 @@ module Homebrew
alias switch_option switch alias switch_option switch
def env?(env) def env?(env)
env.present? && ENV["HOMEBREW_#{env.to_s.upcase}"].present? return false if env.blank?
Homebrew::EnvConfig.send("#{env}?")
rescue NoMethodError
false
end end
def usage_banner(text) def usage_banner(text)

View File

@ -20,10 +20,10 @@ module Homebrew
cat_args.parse cat_args.parse
cd HOMEBREW_REPOSITORY cd HOMEBREW_REPOSITORY
pager = if ENV["HOMEBREW_BAT"].nil? pager = if Homebrew::EnvConfig.bat?
"cat"
else
"#{HOMEBREW_PREFIX}/bin/bat" "#{HOMEBREW_PREFIX}/bin/bat"
else
"cat"
end end
safe_system pager, args.formulae.first.path, *args.passthrough safe_system pager, args.formulae.first.path, *args.passthrough
end end

View File

@ -68,7 +68,7 @@ module Homebrew
rescue Interrupt rescue Interrupt
raise raise
rescue => e rescue => e
raise if ARGV.homebrew_developer? raise if Homebrew::EnvConfig.developer?
fetched_bottle = false fetched_bottle = false
onoe e.message onoe e.message

View File

@ -98,7 +98,7 @@ module Homebrew
puts "#{n} symlinks created" puts "#{n} symlinks created"
end end
puts_keg_only_path_message(keg) if keg_only && !ARGV.homebrew_developer? puts_keg_only_path_message(keg) if keg_only && !Homebrew::EnvConfig.developer?
end end
end end
end end

View File

@ -110,7 +110,7 @@ module Homebrew
def check_for_dependents(kegs) def check_for_dependents(kegs)
return false unless result = Keg.find_some_installed_dependents(kegs) return false unless result = Keg.find_some_installed_dependents(kegs)
if ARGV.homebrew_developer? if Homebrew::EnvConfig.developer?
DeveloperDependentsMessage.new(*result).output DeveloperDependentsMessage.new(*result).output
else else
NondeveloperDependentsMessage.new(*result).output NondeveloperDependentsMessage.new(*result).output

View File

@ -97,7 +97,7 @@ module Homebrew
begin begin
reporter = Reporter.new(tap) reporter = Reporter.new(tap)
rescue Reporter::ReporterRevisionUnsetError => e rescue Reporter::ReporterRevisionUnsetError => e
onoe "#{e.message}\n#{e.backtrace.join "\n"}" if ARGV.homebrew_developer? onoe "#{e.message}\n#{e.backtrace.join "\n"}" if Homebrew::EnvConfig.developer?
next next
end end
if reporter.updated? if reporter.updated?
@ -225,7 +225,7 @@ class Reporter
# Don't care if the formula isn't available right now. # Don't care if the formula isn't available right now.
nil nil
rescue Exception => e # rubocop:disable Lint/RescueException rescue Exception => e # rubocop:disable Lint/RescueException
onoe "#{e.message}\n#{e.backtrace.join "\n"}" if ARGV.homebrew_developer? onoe "#{e.message}\n#{e.backtrace.join "\n"}" if Homebrew::EnvConfig.developer?
end end
@report[:M] << tap.formula_file_to_name(src) @report[:M] << tap.formula_file_to_name(src)
when /^R\d{0,3}/ when /^R\d{0,3}/
@ -316,7 +316,7 @@ class Reporter
system HOMEBREW_BREW_FILE, "link", new_full_name, "--overwrite" system HOMEBREW_BREW_FILE, "link", new_full_name, "--overwrite"
end end
rescue Exception => e # rubocop:disable Lint/RescueException rescue Exception => e # rubocop:disable Lint/RescueException
onoe "#{e.message}\n#{e.backtrace.join "\n"}" if ARGV.homebrew_developer? onoe "#{e.message}\n#{e.backtrace.join "\n"}" if Homebrew::EnvConfig.developer?
end end
next next
end end
@ -380,7 +380,7 @@ class Reporter
begin begin
f = Formulary.factory(new_full_name) f = Formulary.factory(new_full_name)
rescue Exception => e # rubocop:disable Lint/RescueException rescue Exception => e # rubocop:disable Lint/RescueException
onoe "#{e.message}\n#{e.backtrace.join "\n"}" if ARGV.homebrew_developer? onoe "#{e.message}\n#{e.backtrace.join "\n"}" if Homebrew::EnvConfig.developer?
next next
end end

View File

@ -30,7 +30,7 @@ git_init_if_necessary() {
trap '{ rm -rf .git; exit 1; }' EXIT trap '{ rm -rf .git; exit 1; }' EXIT
git init git init
git config --bool core.autocrlf false git config --bool core.autocrlf false
if [[ "$HOMEBREW_DEFAULT_BREW_GIT_REMOTE" != "$HOMEBREW_BREW_GIT_REMOTE" ]] if [[ "$HOMEBREW_BREW_DEFAULT_GIT_REMOTE" != "$HOMEBREW_BREW_GIT_REMOTE" ]]
then then
echo "HOMEBREW_BREW_GIT_REMOTE set: using $HOMEBREW_BREW_GIT_REMOTE for Homebrew/brew Git remote URL." echo "HOMEBREW_BREW_GIT_REMOTE set: using $HOMEBREW_BREW_GIT_REMOTE for Homebrew/brew Git remote URL."
fi fi
@ -52,7 +52,7 @@ git_init_if_necessary() {
trap '{ rm -rf .git; exit 1; }' EXIT trap '{ rm -rf .git; exit 1; }' EXIT
git init git init
git config --bool core.autocrlf false git config --bool core.autocrlf false
if [[ "$HOMEBREW_DEFAULT_CORE_GIT_REMOTE" != "$HOMEBREW_CORE_GIT_REMOTE" ]] if [[ "$HOMEBREW_CORE_DEFAULT_GIT_REMOTE" != "$HOMEBREW_CORE_GIT_REMOTE" ]]
then then
echo "HOMEBREW_CORE_GIT_REMOTE set: using $HOMEBREW_CORE_GIT_REMOTE for Homebrew/core Git remote URL." echo "HOMEBREW_CORE_GIT_REMOTE set: using $HOMEBREW_CORE_GIT_REMOTE for Homebrew/core Git remote URL."
fi fi
@ -414,7 +414,7 @@ EOS
git_init_if_necessary git_init_if_necessary
if [[ "$HOMEBREW_DEFAULT_BREW_GIT_REMOTE" != "$HOMEBREW_BREW_GIT_REMOTE" ]] if [[ "$HOMEBREW_BREW_DEFAULT_GIT_REMOTE" != "$HOMEBREW_BREW_GIT_REMOTE" ]]
then then
safe_cd "$HOMEBREW_REPOSITORY" safe_cd "$HOMEBREW_REPOSITORY"
echo "HOMEBREW_BREW_GIT_REMOTE set: using $HOMEBREW_BREW_GIT_REMOTE for Homebrew/brew Git remote." echo "HOMEBREW_BREW_GIT_REMOTE set: using $HOMEBREW_BREW_GIT_REMOTE for Homebrew/brew Git remote."
@ -424,7 +424,7 @@ EOS
git fetch --force origin --shallow-since="$latest_tag" git fetch --force origin --shallow-since="$latest_tag"
fi fi
if [[ "$HOMEBREW_DEFAULT_CORE_GIT_REMOTE" != "$HOMEBREW_CORE_GIT_REMOTE" ]] && if [[ "$HOMEBREW_CORE_DEFAULT_GIT_REMOTE" != "$HOMEBREW_CORE_GIT_REMOTE" ]] &&
[[ -d "$HOMEBREW_LIBRARY/Taps/homebrew/homebrew-core" ]] [[ -d "$HOMEBREW_LIBRARY/Taps/homebrew/homebrew-core" ]]
then then
safe_cd "$HOMEBREW_LIBRARY/Taps/homebrew/homebrew-core" safe_cd "$HOMEBREW_LIBRARY/Taps/homebrew/homebrew-core"

View File

@ -114,7 +114,7 @@ module Homebrew
ENV["PATH"] = ENV["HOMEBREW_PATH"] ENV["PATH"] = ENV["HOMEBREW_PATH"]
# Use the user's browser, too. # Use the user's browser, too.
ENV["BROWSER"] = ENV["HOMEBREW_BROWSER"] ENV["BROWSER"] = Homebrew::EnvConfig.browser
formula = args.formulae.first formula = args.formulae.first

View File

@ -108,7 +108,7 @@ module Homebrew
end end
destination_tap = Tap.fetch(args.named.second) destination_tap = Tap.fetch(args.named.second)
unless ARGV.homebrew_developer? unless Homebrew::EnvConfig.developer?
odie "Cannot extract formula to homebrew/core!" if destination_tap.core_tap? odie "Cannot extract formula to homebrew/core!" if destination_tap.core_tap?
odie "Cannot extract formula to the same tap!" if destination_tap == source_tap odie "Cannot extract formula to the same tap!" if destination_tap == source_tap
end end

View File

@ -22,8 +22,8 @@ module Homebrew
def mirror def mirror
mirror_args.parse mirror_args.parse
bintray_user = ENV["HOMEBREW_BINTRAY_USER"] bintray_user = Homebrew::EnvConfig.bintray_user
bintray_key = ENV["HOMEBREW_BINTRAY_KEY"] bintray_key = Homebrew::EnvConfig.bintray_key
raise "Missing HOMEBREW_BINTRAY_USER or HOMEBREW_BINTRAY_KEY variables!" if !bintray_user || !bintray_key raise "Missing HOMEBREW_BINTRAY_USER or HOMEBREW_BINTRAY_KEY variables!" if !bintray_user || !bintray_key
args.formulae.each do |f| args.formulae.each do |f|

View File

@ -72,8 +72,7 @@ module Homebrew
pull_args.parse pull_args.parse
# Passthrough Git environment variables for e.g. git am # Passthrough Git environment variables for e.g. git am
ENV["GIT_COMMITTER_NAME"] = ENV["HOMEBREW_GIT_NAME"] if ENV["HOMEBREW_GIT_NAME"] Utils.set_git_name_email!(author: false, committer: true)
ENV["GIT_COMMITTER_EMAIL"] = ENV["HOMEBREW_GIT_EMAIL"] if ENV["HOMEBREW_GIT_EMAIL"]
# Depending on user configuration, git may try to invoke gpg. # Depending on user configuration, git may try to invoke gpg.
if Utils.popen_read("git config --get --bool commit.gpgsign").chomp == "true" if Utils.popen_read("git config --get --bool commit.gpgsign").chomp == "true"
@ -168,7 +167,7 @@ module Homebrew
fetch_bottles = false fetch_bottles = false
changed_formulae_names.each do |name| changed_formulae_names.each do |name|
next if ENV["HOMEBREW_DISABLE_LOAD_FORMULA"] next if Homebrew::EnvConfig.disable_load_formula?
begin begin
f = Formula[name] f = Formula[name]
@ -213,7 +212,7 @@ module Homebrew
end end
is_bumpable = false if args.clean? is_bumpable = false if args.clean?
is_bumpable = false if ENV["HOMEBREW_DISABLE_LOAD_FORMULA"] is_bumpable = false if Homebrew::EnvConfig.disable_load_formula?
if is_bumpable if is_bumpable
formula = Formula[changed_formulae_names.first] formula = Formula[changed_formulae_names.first]

View File

@ -538,11 +538,11 @@ module Homebrew
end end
def check_brew_git_origin def check_brew_git_origin
examine_git_origin(HOMEBREW_REPOSITORY, HOMEBREW_BREW_GIT_REMOTE) examine_git_origin(HOMEBREW_REPOSITORY, Homebrew::EnvConfig.brew_git_remote)
end end
def check_coretap_git_origin def check_coretap_git_origin
examine_git_origin(CoreTap.instance.path, HOMEBREW_CORE_GIT_REMOTE) examine_git_origin(CoreTap.instance.path, Homebrew::EnvConfig.core_git_remote)
end end
def check_casktap_git_origin def check_casktap_git_origin

View File

@ -345,8 +345,8 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
@resolved_info_cache ||= {} @resolved_info_cache ||= {}
return @resolved_info_cache[url] if @resolved_info_cache.include?(url) return @resolved_info_cache[url] if @resolved_info_cache.include?(url)
if ENV["HOMEBREW_ARTIFACT_DOMAIN"] if (domain = Homebrew::EnvConfig.artifact_domain)
url = url.sub(%r{^((ht|f)tps?://)?}, ENV["HOMEBREW_ARTIFACT_DOMAIN"].chomp("/") + "/") url = url.sub(%r{^((ht|f)tps?://)?}, domain.chomp("/") + "/")
end end
out, _, status= curl_output("--location", "--silent", "--head", "--request", "GET", url.to_s) out, _, status= curl_output("--location", "--silent", "--head", "--request", "GET", url.to_s)
@ -402,7 +402,7 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
def _fetch(url:, resolved_url:) def _fetch(url:, resolved_url:)
ohai "Downloading from #{resolved_url}" if url != resolved_url ohai "Downloading from #{resolved_url}" if url != resolved_url
if ENV["HOMEBREW_NO_INSECURE_REDIRECT"] && if Homebrew::EnvConfig.no_insecure_redirect? &&
url.start_with?("https://") && !resolved_url.start_with?("https://") url.start_with?("https://") && !resolved_url.start_with?("https://")
$stderr.puts "HTTPS to HTTP redirect detected & HOMEBREW_NO_INSECURE_REDIRECT is set." $stderr.puts "HTTPS to HTTP redirect detected & HOMEBREW_NO_INSECURE_REDIRECT is set."
raise CurlDownloadStrategyError, url raise CurlDownloadStrategyError, url
@ -784,7 +784,7 @@ class GitDownloadStrategy < VCSDownloadStrategy
git_dir = dot_git.read.chomp[/^gitdir: (.*)$/, 1] git_dir = dot_git.read.chomp[/^gitdir: (.*)$/, 1]
if git_dir.nil? if git_dir.nil?
onoe "Failed to parse '#{dot_git}'." if ARGV.homebrew_developer? onoe "Failed to parse '#{dot_git}'." if Homebrew::EnvConfig.developer?
next next
end end
@ -809,7 +809,7 @@ class GitHubGitDownloadStrategy < GitDownloadStrategy
end end
def github_last_commit def github_last_commit
return if ENV["HOMEBREW_NO_GITHUB_API"] return if Homebrew::EnvConfig.no_github_api?
output, _, status = curl_output( output, _, status = curl_output(
"--silent", "--head", "--location", "--silent", "--head", "--location",
@ -825,7 +825,7 @@ class GitHubGitDownloadStrategy < GitDownloadStrategy
end end
def multiple_short_commits_exist?(commit) def multiple_short_commits_exist?(commit)
return if ENV["HOMEBREW_NO_GITHUB_API"] return if Homebrew::EnvConfig.no_github_api?
output, _, status = curl_output( output, _, status = curl_output(
"--silent", "--head", "--location", "--silent", "--head", "--location",

View File

@ -1,13 +0,0 @@
# frozen_string_literal: true
module Emoji
class << self
def install_badge
ENV["HOMEBREW_INSTALL_BADGE"] || "🍺"
end
def enabled?
!ENV["HOMEBREW_NO_EMOJI"]
end
end
end

View File

@ -31,18 +31,6 @@ module HomebrewArgvExtension
flag?("--debug") || !ENV["HOMEBREW_DEBUG"].nil? flag?("--debug") || !ENV["HOMEBREW_DEBUG"].nil?
end end
def homebrew_developer?
!ENV["HOMEBREW_DEVELOPER"].nil?
end
def skip_or_later_bottles?
homebrew_developer? && !ENV["HOMEBREW_SKIP_OR_LATER_BOTTLES"].nil?
end
def no_sandbox?
include?("--no-sandbox") || !ENV["HOMEBREW_NO_SANDBOX"].nil?
end
def build_bottle? def build_bottle?
include?("--build-bottle") include?("--build-bottle")
end end

View File

@ -169,7 +169,7 @@ module Stdenv
# Sets architecture-specific flags for every environment variable # Sets architecture-specific flags for every environment variable
# given in the list `flags`. # given in the list `flags`.
# @private # @private
def set_cpu_flags(flags, map = Hardware::CPU.optimization_flags) # rubocop:disable Naming/AccessorMethodName def set_cpu_flags(flags, map = Hardware::CPU.optimization_flags)
cflags =~ /(-Xarch_#{Hardware::CPU.arch_32_bit} )-march=/ cflags =~ /(-Xarch_#{Hardware::CPU.arch_32_bit} )-march=/
xarch = Regexp.last_match(1).to_s xarch = Regexp.last_match(1).to_s
remove flags, /(-Xarch_#{Hardware::CPU.arch_32_bit} )?-march=\S*/ remove flags, /(-Xarch_#{Hardware::CPU.arch_32_bit} )?-march=\S*/
@ -188,12 +188,7 @@ module Stdenv
end end
def make_jobs def make_jobs
# '-j' requires a positive integral argument Homebrew::EnvConfig.make_jobs
if (jobs = self["HOMEBREW_MAKE_JOBS"].to_i).positive?
jobs
else
Hardware::CPU.cores
end
end end
# This method does nothing in stdenv since there's no arg refurbishment # This method does nothing in stdenv since there's no arg refurbishment

View File

@ -217,11 +217,7 @@ module Superenv
end end
def determine_make_jobs def determine_make_jobs
if (j = self["HOMEBREW_MAKE_JOBS"].to_i) < 1 Homebrew::EnvConfig.make_jobs
Hardware::CPU.cores
else
j
end
end end
def determine_optflags def determine_optflags

View File

@ -3,9 +3,8 @@
module Hardware module Hardware
class CPU class CPU
class << self class << self
native_arch = (ENV["HOMEBREW_ARCH"] || "native").freeze
OPTIMIZATION_FLAGS_LINUX = { OPTIMIZATION_FLAGS_LINUX = {
native: "-march=#{native_arch}", native: "-march=#{Homebrew::EnvConfig.arch}",
nehalem: "-march=nehalem", nehalem: "-march=nehalem",
core2: "-march=core2", core2: "-march=core2",
core: "-march=prescott", core: "-march=prescott",

View File

@ -93,7 +93,7 @@ class Keg
@bottle_dependencies ||= begin @bottle_dependencies ||= begin
formulae = relocation_formulae formulae = relocation_formulae
gcc = Formula["gcc"] gcc = Formula["gcc"]
if !ENV["HOMEBREW_FORCE_HOMEBREW_ON_LINUX"] && if !Homebrew::EnvConfig.force_homebrew_on_linux? &&
DevelopmentTools.non_apple_gcc_version("gcc") < gcc.version.to_i DevelopmentTools.non_apple_gcc_version("gcc") < gcc.version.to_i
formulae += gcc.recursive_dependencies.map(&:name) formulae += gcc.recursive_dependencies.map(&:name)
formulae << gcc.name formulae << gcc.name

View File

@ -4,6 +4,6 @@ class CoreTap < Tap
# @private # @private
def initialize def initialize
super "Homebrew", "core" super "Homebrew", "core"
@full_name = "Homebrew/linuxbrew-core" unless ENV["HOMEBREW_FORCE_HOMEBREW_ON_LINUX"] @full_name = "Homebrew/linuxbrew-core" unless Homebrew::EnvConfig.force_homebrew_on_linux?
end end
end end

View File

@ -4,13 +4,13 @@ module Utils
module Analytics module Analytics
class << self class << self
def formula_path def formula_path
return generic_formula_path if ENV["HOMEBREW_FORCE_HOMEBREW_ON_LINUX"] return generic_formula_path if Homebrew::EnvConfig.force_homebrew_on_linux?
"formula-linux" "formula-linux"
end end
def analytics_path def analytics_path
return generic_analytics_path if ENV["HOMEBREW_FORCE_HOMEBREW_ON_LINUX"] return generic_analytics_path if Homebrew::EnvConfig.force_homebrew_on_linux?
"analytics-linux" "analytics-linux"
end end

View File

@ -45,7 +45,7 @@ module Homebrew
end end
def check_for_unsupported_macos def check_for_unsupported_macos
return if ARGV.homebrew_developer? return if Homebrew::EnvConfig.developer?
who = +"We" who = +"We"
if OS::Mac.prerelease? if OS::Mac.prerelease?
@ -141,7 +141,7 @@ module Homebrew
def check_ruby_version def check_ruby_version
ruby_version = "2.6.3" ruby_version = "2.6.3"
return if RUBY_VERSION == ruby_version return if RUBY_VERSION == ruby_version
return if ARGV.homebrew_developer? && OS::Mac.prerelease? return if Homebrew::EnvConfig.developer? && OS::Mac.prerelease?
<<~EOS <<~EOS
Ruby version #{RUBY_VERSION} is unsupported on #{MacOS.version}. Homebrew Ruby version #{RUBY_VERSION} is unsupported on #{MacOS.version}. Homebrew

View File

@ -17,7 +17,8 @@ module Utils
def find_matching_tag(tag) def find_matching_tag(tag)
# Used primarily by developers testing beta macOS releases. # Used primarily by developers testing beta macOS releases.
if OS::Mac.prerelease? && ARGV.skip_or_later_bottles? if OS::Mac.prerelease? && Homebrew::EnvConfig.developer? &&
Homebrew::EnvConfig.skip_or_later_bottles?
generic_find_matching_tag(tag) generic_find_matching_tag(tag)
else else
generic_find_matching_tag(tag) || generic_find_matching_tag(tag) ||

View File

@ -1891,7 +1891,7 @@ class Formula
# system "make", "install"</pre> # system "make", "install"</pre>
def system(cmd, *args) def system(cmd, *args)
verbose = Homebrew.args.verbose? verbose = Homebrew.args.verbose?
verbose_using_dots = !ENV["HOMEBREW_VERBOSE_USING_DOTS"].nil? verbose_using_dots = Homebrew::EnvConfig.verbose_using_dots?
# remove "boring" arguments so that the important ones are more likely to # remove "boring" arguments so that the important ones are more likely to
# be shown considering that we trim long ohai lines to the terminal width # be shown considering that we trim long ohai lines to the terminal width
@ -1962,8 +1962,7 @@ class Formula
$stdout.flush $stdout.flush
unless $CHILD_STATUS.success? unless $CHILD_STATUS.success?
log_lines = ENV["HOMEBREW_FAIL_LOG_LINES"] log_lines = Homebrew::EnvConfig.fail_log_lines
log_lines ||= "15"
log.flush log.flush
if !verbose || verbose_using_dots if !verbose || verbose_using_dots

View File

@ -11,7 +11,6 @@ require "formula_cellar_checks"
require "install_renamed" require "install_renamed"
require "debrew" require "debrew"
require "sandbox" require "sandbox"
require "emoji"
require "development_tools" require "development_tools"
require "cache_store" require "cache_store"
require "linkage_checker" require "linkage_checker"
@ -306,9 +305,9 @@ class FormulaInstaller
end end
formula.rack.rmdir_if_possible formula.rack.rmdir_if_possible
end end
raise if ARGV.homebrew_developer? || raise if Homebrew::EnvConfig.developer? ||
e.is_a?(Interrupt) || Homebrew::EnvConfig.no_bottle_source_fallback? ||
ENV["HOMEBREW_NO_BOTTLE_SOURCE_FALLBACK"] e.is_a?(Interrupt)
@pour_failed = true @pour_failed = true
onoe e.message onoe e.message
@ -372,7 +371,7 @@ class FormulaInstaller
'conflicts_with \"#{c.name}\"' should be removed from #{formula.path.basename}. 'conflicts_with \"#{c.name}\"' should be removed from #{formula.path.basename}.
EOS EOS
raise if ARGV.homebrew_developer? raise if Homebrew::EnvConfig.developer?
$stderr.puts "Please report this issue to the #{formula.tap} tap (not Homebrew/brew or Homebrew/core)!" $stderr.puts "Please report this issue to the #{formula.tap} tap (not Homebrew/brew or Homebrew/core)!"
false false
@ -621,7 +620,7 @@ class FormulaInstaller
def caveats def caveats
return if only_deps? return if only_deps?
audit_installed if ARGV.homebrew_developer? audit_installed if Homebrew::EnvConfig.developer?
caveats = Caveats.new(formula) caveats = Caveats.new(formula)
@ -684,7 +683,7 @@ class FormulaInstaller
def summary def summary
s = +"" s = +""
s << "#{Emoji.install_badge} " if Emoji.enabled? s << "#{Homebrew::EnvConfig.install_badge} " unless Homebrew::EnvConfig.no_emoji?
s << "#{formula.prefix.resolved_path}: #{formula.prefix.abv}" s << "#{formula.prefix.resolved_path}: #{formula.prefix.abv}"
s << ", built in #{pretty_duration build_time}" if build_time s << ", built in #{pretty_duration build_time}" if build_time
s.freeze s.freeze
@ -943,7 +942,7 @@ class FormulaInstaller
rescue Exception => e # rubocop:disable Lint/RescueException rescue Exception => e # rubocop:disable Lint/RescueException
opoo "The post-install step did not complete successfully" opoo "The post-install step did not complete successfully"
puts "You can try again using `brew postinstall #{formula.full_name}`" puts "You can try again using `brew postinstall #{formula.full_name}`"
ohai e, e.backtrace if debug? || ARGV.homebrew_developer? ohai e, e.backtrace if debug? || Homebrew::EnvConfig.developer?
Homebrew.failed = true Homebrew.failed = true
@show_summary_heading = true @show_summary_heading = true
end end

View File

@ -26,7 +26,7 @@ module Formulary
end end
def self.load_formula(name, path, contents, namespace) def self.load_formula(name, path, contents, namespace)
raise "Formula loading disabled by HOMEBREW_DISABLE_LOAD_FORMULA!" if ENV["HOMEBREW_DISABLE_LOAD_FORMULA"] raise "Formula loading disabled by HOMEBREW_DISABLE_LOAD_FORMULA!" if Homebrew::EnvConfig.disable_load_formula?
mod = Module.new mod = Module.new
const_set(namespace, mod) const_set(namespace, mod)

View File

@ -25,6 +25,14 @@ ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.irregular "it", "they" inflect.irregular "it", "they"
end end
HOMEBREW_BOTTLE_DEFAULT_DOMAIN = ENV["HOMEBREW_BOTTLE_DEFAULT_DOMAIN"]
HOMEBREW_BREW_DEFAULT_GIT_REMOTE = ENV["HOMEBREW_BREW_DEFAULT_GIT_REMOTE"]
HOMEBREW_CORE_DEFAULT_GIT_REMOTE = ENV["HOMEBREW_CORE_DEFAULT_GIT_REMOTE"]
HOMEBREW_DEFAULT_CACHE = ENV["HOMEBREW_DEFAULT_CACHE"]
HOMEBREW_DEFAULT_LOGS = ENV["HOMEBREW_DEFAULT_LOGS"]
HOMEBREW_DEFAULT_TEMP = ENV["HOMEBREW_DEFAULT_TEMP"]
require "env_config"
require "config" require "config"
require "os" require "os"
require "extend/ARGV" require "extend/ARGV"
@ -51,12 +59,6 @@ HOMEBREW_USER_AGENT_FAKE_SAFARI =
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/602.4.8 " \ "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/602.4.8 " \
"(KHTML, like Gecko) Version/10.0.3 Safari/602.4.8" "(KHTML, like Gecko) Version/10.0.3 Safari/602.4.8"
HOMEBREW_BOTTLE_DEFAULT_DOMAIN = ENV["HOMEBREW_BOTTLE_DEFAULT_DOMAIN"]
HOMEBREW_BOTTLE_DOMAIN = ENV["HOMEBREW_BOTTLE_DOMAIN"]
HOMEBREW_BREW_GIT_REMOTE = ENV["HOMEBREW_BREW_GIT_REMOTE"]
HOMEBREW_CORE_GIT_REMOTE = ENV["HOMEBREW_CORE_GIT_REMOTE"]
HOMEBREW_DEFAULT_PREFIX = "/usr/local" HOMEBREW_DEFAULT_PREFIX = "/usr/local"
LINUXBREW_DEFAULT_PREFIX = "/home/linuxbrew/.linuxbrew" LINUXBREW_DEFAULT_PREFIX = "/home/linuxbrew/.linuxbrew"
@ -134,4 +136,4 @@ require "official_taps"
require "tap" require "tap"
require "tap_constants" require "tap_constants"
require "compat" if !ARGV.include?("--no-compat") && !ENV["HOMEBREW_NO_COMPAT"] require "compat" unless Homebrew::EnvConfig.no_compat?

View File

@ -1,5 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
require "utils/popen"
module Hardware module Hardware
class CPU class CPU
INTEL_32BIT_ARCHS = [:i386].freeze INTEL_32BIT_ARCHS = [:i386].freeze

View File

@ -83,7 +83,7 @@ module Homebrew
output ||= comment_help(path) output ||= comment_help(path)
output ||= if output.blank? output ||= if output.blank?
opoo "No help text in: #{path}" if ARGV.homebrew_developer? opoo "No help text in: #{path}" if Homebrew::EnvConfig.developer?
HOMEBREW_HELP HOMEBREW_HELP
end end

View File

@ -10,7 +10,7 @@ module Language
# e.g. `resource "github.com/foo/bar"` # e.g. `resource "github.com/foo/bar"`
def self.stage_deps(resources, target) def self.stage_deps(resources, target)
if resources.empty? if resources.empty?
if ARGV.homebrew_developer? if Homebrew::EnvConfig.developer?
odie "tried to stage empty Language::Go resources array" odie "tried to stage empty Language::Go resources array"
else else
opoo "tried to stage empty Language::Go resources array" opoo "tried to stage empty Language::Go resources array"

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
module Homebrew module Homebrew
DEFAULT_PREFIX ||= if ENV["HOMEBREW_FORCE_HOMEBREW_ON_LINUX"] DEFAULT_PREFIX ||= if Homebrew::EnvConfig.force_homebrew_on_linux?
HOMEBREW_DEFAULT_PREFIX HOMEBREW_DEFAULT_PREFIX
else else
LINUXBREW_DEFAULT_PREFIX LINUXBREW_DEFAULT_PREFIX

View File

@ -50,7 +50,7 @@ module MachOShim
rescue rescue
# ... but complain about other (parse) errors for further investigation. # ... but complain about other (parse) errors for further investigation.
onoe "Failed to read Mach-O binary: #{self}" onoe "Failed to read Mach-O binary: #{self}"
raise if ARGV.homebrew_developer? raise if Homebrew::EnvConfig.developer?
[] []
end end

View File

@ -10,16 +10,16 @@ class Sandbox
OS.mac? && File.executable?(SANDBOX_EXEC) OS.mac? && File.executable?(SANDBOX_EXEC)
end end
def self.formula?(_formula) def self.formula?(_)
return false unless available? return false unless available?
!ARGV.no_sandbox? !Homebrew.args.no_sandbox?
end end
def self.test? def self.test?
return false unless available? return false unless available?
!ARGV.no_sandbox? !Homebrew.args.no_sandbox?
end end
def initialize def initialize
@ -127,7 +127,7 @@ class Sandbox
end end
end end
if @failed && ENV["HOMEBREW_VERBOSE"].present? if @failed && Homebrew::EnvConfig.verbose?
ohai "Sandbox log" ohai "Sandbox log"
puts logs puts logs
$stdout.flush # without it, brew test-bot would fail to catch the log $stdout.flush # without it, brew test-bot would fail to catch the log

View File

@ -30,7 +30,7 @@ module Homebrew
results = { formulae: [], casks: [] } results = { formulae: [], casks: [] }
return results if ENV["HOMEBREW_NO_GITHUB_API"] return results if Homebrew::EnvConfig.no_github_api?
unless silent unless silent
# Use stderr to avoid breaking parsed output # Use stderr to avoid breaking parsed output

View File

@ -346,7 +346,7 @@ class BottleSpecification
def root_url(var = nil, specs = {}) def root_url(var = nil, specs = {})
if var.nil? if var.nil?
@root_url ||= "#{HOMEBREW_BOTTLE_DOMAIN}/#{Utils::Bottles::Bintray.repository(tap)}" @root_url ||= "#{Homebrew::EnvConfig.bottle_domain}/#{Utils::Bottles::Bintray.repository(tap)}"
else else
@root_url = var @root_url = var
@root_url_specs.merge!(specs) @root_url_specs.merge!(specs)

View File

@ -119,67 +119,37 @@ class SystemConfig
else else
f.puts "Core tap: N/A" f.puts "Core tap: N/A"
end end
defaults_hash = {
HOMEBREW_PREFIX: Homebrew::DEFAULT_PREFIX,
HOMEBREW_REPOSITORY: Homebrew::DEFAULT_REPOSITORY,
HOMEBREW_CELLAR: Homebrew::DEFAULT_CELLAR,
HOMEBREW_CACHE: "#{ENV["HOME"]}/Library/Caches/Homebrew",
HOMEBREW_LOGS: "#{ENV["HOME"]}/Library/Logs/Homebrew",
HOMEBREW_TEMP: ENV["HOMEBREW_SYSTEM_TEMP"],
HOMEBREW_RUBY_WARNINGS: "-W0",
}.freeze
boring_keys = %w[
HOMEBREW_BROWSER
HOMEBREW_EDITOR
HOMEBREW_ANALYTICS_ID
HOMEBREW_ANALYTICS_USER_UUID
HOMEBREW_AUTO_UPDATE_CHECKED
HOMEBREW_BOTTLE_DEFAULT_DOMAIN
HOMEBREW_BOTTLE_DOMAIN
HOMEBREW_BREW_FILE
HOMEBREW_BREW_GIT_REMOTE
HOMEBREW_COMMAND_DEPTH
HOMEBREW_CORE_GIT_REMOTE
HOMEBREW_CURL
HOMEBREW_DISPLAY
HOMEBREW_GIT
HOMEBREW_GIT_CONFIG_FILE
HOMEBREW_LIBRARY
HOMEBREW_MACOS_VERSION
HOMEBREW_MACOS_VERSION_NUMERIC
HOMEBREW_MINIMUM_GIT_VERSION
HOMEBREW_RUBY_PATH
HOMEBREW_SYSTEM
HOMEBREW_SYSTEM_TEMP
HOMEBREW_OS_VERSION
HOMEBREW_PATH
HOMEBREW_PROCESSOR
HOMEBREW_PRODUCT
HOMEBREW_USER_AGENT
HOMEBREW_USER_AGENT_CURL
HOMEBREW_VERSION
].freeze
f.puts "HOMEBREW_PREFIX: #{HOMEBREW_PREFIX}" f.puts "HOMEBREW_PREFIX: #{HOMEBREW_PREFIX}"
[:HOMEBREW_CELLAR, :HOMEBREW_CACHE, :HOMEBREW_LOGS, :HOMEBREW_REPOSITORY, {
:HOMEBREW_TEMP].each do |key| HOMEBREW_REPOSITORY: Homebrew::DEFAULT_REPOSITORY,
HOMEBREW_CELLAR: Homebrew::DEFAULT_CELLAR,
}.freeze.each do |key, default|
value = Object.const_get(key) value = Object.const_get(key)
f.puts "#{key}: #{value}" if defaults_hash[key] != value.to_s f.puts "#{key}: #{value}" if value.to_s != default.to_s
end end
if defaults_hash[:HOMEBREW_RUBY_WARNINGS] != ENV["HOMEBREW_RUBY_WARNINGS"].to_s
f.puts "HOMEBREW_RUBY_WARNINGS: #{ENV["HOMEBREW_RUBY_WARNINGS"]}"
end
unless ENV["HOMEBREW_ENV"]
ENV.sort.each do |key, value|
next unless key.start_with?("HOMEBREW_")
next if key.start_with?("HOMEBREW_BUNDLE_")
next if boring_keys.include?(key)
next if defaults_hash[key.to_sym]
value = "set" if ENV.sensitive?(key) Homebrew::EnvConfig::ENVS.each do |env, hash|
f.puts "#{key}: #{value}" method_name = Homebrew::EnvConfig.env_method_name(env, hash)
if hash[:boolean]
f.puts "#{env}: set" if Homebrew::EnvConfig.send(method_name)
next
end
value = Homebrew::EnvConfig.send(method_name)
next unless value
if (default = hash[:default].presence)
next if value.to_s == default.to_s
end
if ENV.sensitive?(env)
f.puts "#{env}: set"
else
f.puts "#{env}: #{value}"
end end
end end
f.puts hardware if hardware f.puts hardware if hardware
f.puts "Homebrew Ruby: #{describe_homebrew_ruby}" f.puts "Homebrew Ruby: #{describe_homebrew_ruby}"
f.print "Clang: " f.print "Clang: "

View File

@ -272,7 +272,7 @@ class Tap
begin begin
safe_system "git", *args safe_system "git", *args
unless Readall.valid_tap?(self, aliases: true) unless Readall.valid_tap?(self, aliases: true)
raise "Cannot tap #{name}: invalid syntax in tap!" unless ARGV.homebrew_developer? raise "Cannot tap #{name}: invalid syntax in tap!" unless Homebrew::EnvConfig.developer?
end end
rescue Interrupt, RuntimeError rescue Interrupt, RuntimeError
ignore_interrupts do ignore_interrupts do
@ -641,12 +641,9 @@ class CoreTap < Tap
end end
def install(full_clone: true, quiet: false, clone_target: nil, force_auto_update: nil) def install(full_clone: true, quiet: false, clone_target: nil, force_auto_update: nil)
if HOMEBREW_CORE_GIT_REMOTE != default_remote remote = Homebrew::EnvConfig.core_git_remote
puts "HOMEBREW_CORE_GIT_REMOTE set: using #{HOMEBREW_CORE_GIT_REMOTE} " \ puts "HOMEBREW_CORE_GIT_REMOTE set: using #{remote} for Homebrew/core Git remote URL." if remote != default_remote
"for Homebrew/core Git remote URL." super(full_clone: full_clone, quiet: quiet, clone_target: remote, force_auto_update: force_auto_update)
clone_target ||= HOMEBREW_CORE_GIT_REMOTE
end
super(full_clone: full_clone, quiet: quiet, clone_target: clone_target, force_auto_update: force_auto_update)
end end
# @private # @private

View File

@ -13,8 +13,7 @@ describe Homebrew::CLI::Parser do
} }
before do before do
allow(ENV).to receive(:[]) allow(Homebrew::EnvConfig).to receive(:pry?).and_return(true)
allow(ENV).to receive(:[]).with("HOMEBREW_PRY").and_return("1")
end end
it "parses short option" do it "parses short option" do
@ -181,18 +180,16 @@ describe Homebrew::CLI::Parser do
end end
it "prioritizes cli arguments over env vars when they conflict" do it "prioritizes cli arguments over env vars when they conflict" do
allow(ENV).to receive(:[]) allow(Homebrew::EnvConfig).to receive(:switch_a?).and_return(true)
allow(ENV).to receive(:[]).with("HOMEBREW_SWITCH_A").and_return("1") allow(Homebrew::EnvConfig).to receive(:switch_b?).and_return(false)
allow(ENV).to receive(:[]).with("HOMEBREW_SWITCH_B").and_return(nil)
parser.parse(["--switch-b"]) parser.parse(["--switch-b"])
expect(Homebrew.args.switch_a).to be_falsy expect(Homebrew.args.switch_a).to be_falsy
expect(Homebrew.args).to be_switch_b expect(Homebrew.args).to be_switch_b
end end
it "raises an exception on constraint violation when both are env vars" do it "raises an exception on constraint violation when both are env vars" do
allow(ENV).to receive(:[]) allow(Homebrew::EnvConfig).to receive(:switch_a?).and_return(true)
allow(ENV).to receive(:[]).with("HOMEBREW_SWITCH_A").and_return("1") allow(Homebrew::EnvConfig).to receive(:switch_b?).and_return(true)
allow(ENV).to receive(:[]).with("HOMEBREW_SWITCH_B").and_return("1")
expect { parser.parse([]) }.to raise_error(Homebrew::CLI::OptionConflictError) expect { parser.parse([]) }.to raise_error(Homebrew::CLI::OptionConflictError)
end end
end end

View File

@ -1,22 +0,0 @@
# frozen_string_literal: true
require "emoji"
describe Emoji do
describe "#install_badge" do
subject { described_class.install_badge }
before do
ENV.delete("HOMEBREW_INSTALL_BADGE")
end
it "returns 🍺 by default" do
expect(subject).to eq "🍺"
end
it "returns the contents of HOMEBREW_INSTALL_BADGE if set" do
ENV["HOMEBREW_INSTALL_BADGE"] = "foo"
expect(subject).to eq "foo"
end
end
end

View File

@ -26,7 +26,8 @@ describe Utils::Bottles::Collector do
end end
it "does not use older tags when requested not to", :needs_macos do it "does not use older tags when requested not to", :needs_macos do
allow(ARGV).to receive(:skip_or_later_bottles?).and_return(true) allow(Homebrew::EnvConfig).to receive(:developer?).and_return(true)
allow(Homebrew::EnvConfig).to receive(:skip_or_later_bottles?).and_return(true)
allow(OS::Mac).to receive(:prerelease?).and_return(true) allow(OS::Mac).to receive(:prerelease?).and_return(true)
subject[:mavericks] = "foo" subject[:mavericks] = "foo"
expect(subject.send(:find_matching_tag, :mavericks)).to eq(:mavericks) expect(subject.send(:find_matching_tag, :mavericks)).to eq(:mavericks)

View File

@ -1,6 +1,5 @@
# frozen_string_literal: true # frozen_string_literal: true
require "emoji"
require "utils/analytics" require "utils/analytics"
require "utils/curl" require "utils/curl"
require "utils/fork" require "utils/fork"
@ -177,7 +176,7 @@ module Kernel
message << tap_message if tap_message message << tap_message if tap_message
message.freeze message.freeze
if ARGV.homebrew_developer? || disable || Homebrew.raise_deprecation_exceptions? if Homebrew::EnvConfig.developer? || disable || Homebrew.raise_deprecation_exceptions?
exception = MethodDeprecatedError.new(message) exception = MethodDeprecatedError.new(message)
exception.set_backtrace(backtrace) exception.set_backtrace(backtrace)
raise exception raise exception
@ -194,20 +193,20 @@ module Kernel
def pretty_installed(f) def pretty_installed(f)
if !$stdout.tty? if !$stdout.tty?
f.to_s f.to_s
elsif Emoji.enabled? elsif Homebrew::EnvConfig.no_emoji?
"#{Tty.bold}#{f} #{Formatter.success("")}#{Tty.reset}"
else
Formatter.success("#{Tty.bold}#{f} (installed)#{Tty.reset}") Formatter.success("#{Tty.bold}#{f} (installed)#{Tty.reset}")
else
"#{Tty.bold}#{f} #{Formatter.success("")}#{Tty.reset}"
end end
end end
def pretty_uninstalled(f) def pretty_uninstalled(f)
if !$stdout.tty? if !$stdout.tty?
f.to_s f.to_s
elsif Emoji.enabled? elsif Homebrew::EnvConfig.no_emoji?
"#{Tty.bold}#{f} #{Formatter.error("")}#{Tty.reset}"
else
Formatter.error("#{Tty.bold}#{f} (uninstalled)#{Tty.reset}") Formatter.error("#{Tty.bold}#{f} (uninstalled)#{Tty.reset}")
else
"#{Tty.bold}#{f} #{Formatter.error("")}#{Tty.reset}"
end end
end end
@ -304,10 +303,7 @@ module Kernel
end end
def which_editor def which_editor
editor = ENV.values_at("HOMEBREW_EDITOR", "HOMEBREW_VISUAL") editor = Homebrew::EnvConfig.editor
.compact
.reject(&:empty?)
.first
return editor if editor return editor if editor
# Find Atom, Sublime Text, Textmate, BBEdit / TextWrangler, or vim # Find Atom, Sublime Text, Textmate, BBEdit / TextWrangler, or vim
@ -331,11 +327,11 @@ module Kernel
end end
def exec_browser(*args) def exec_browser(*args)
browser = ENV["HOMEBREW_BROWSER"] browser = Homebrew::EnvConfig.browser
browser ||= OS::PATH_OPEN if defined?(OS::PATH_OPEN) browser ||= OS::PATH_OPEN if defined?(OS::PATH_OPEN)
return unless browser return unless browser
ENV["DISPLAY"] = ENV["HOMEBREW_DISPLAY"] ENV["DISPLAY"] = Homebrew::EnvConfig.display
safe_system(browser, *args) safe_system(browser, *args)
end end

View File

@ -12,7 +12,7 @@ module Utils
args = [] args = []
# do not load .curlrc unless requested (must be the first argument) # do not load .curlrc unless requested (must be the first argument)
args << "--disable" unless ENV["HOMEBREW_CURLRC"] args << "--disable" unless Homebrew::EnvConfig.curlrc?
args += %W[ args += %W[
--max-time 3 --max-time 3
@ -78,7 +78,7 @@ module Utils
end end
def disabled? def disabled?
return true if ENV["HOMEBREW_NO_ANALYTICS"] return true if Homebrew::EnvConfig.no_analytics?
config_true?(:analyticsdisabled) config_true?(:analyticsdisabled)
end end
@ -308,7 +308,7 @@ module Utils
end end
def formulae_api_json(endpoint) def formulae_api_json(endpoint)
return if ENV["HOMEBREW_NO_ANALYTICS"] || ENV["HOMEBREW_NO_GITHUB_API"] return if Homebrew::EnvConfig.no_analytics? || Homebrew::EnvConfig.no_github_api?
output, = curl_output("--max-time", "5", output, = curl_output("--max-time", "5",
"https://formulae.brew.sh/api/#{endpoint}") "https://formulae.brew.sh/api/#{endpoint}")

View File

@ -17,7 +17,7 @@ def curl_args(*extra_args, show_output: false, user_agent: :default)
args = [] args = []
# do not load .curlrc unless requested (must be the first argument) # do not load .curlrc unless requested (must be the first argument)
args << "--disable" unless ENV["HOMEBREW_CURLRC"] args << "--disable" unless Homebrew::EnvConfig.curlrc?
args << "--globoff" args << "--globoff"
@ -35,12 +35,11 @@ def curl_args(*extra_args, show_output: false, user_agent: :default)
unless show_output unless show_output
args << "--fail" args << "--fail"
args << "--progress-bar" unless Homebrew.args.verbose? args << "--progress-bar" unless Homebrew.args.verbose?
args << "--verbose" if ENV["HOMEBREW_CURL_VERBOSE"] args << "--verbose" if Homebrew::EnvConfig.curl_verbose?
args << "--silent" unless $stdout.tty? args << "--silent" unless $stdout.tty?
end end
# When changing the default value, the manpage has to be updated. args << "--retry" << Homebrew::EnvConfig.curl_retries
args << "--retry" << (ENV["HOMEBREW_CURL_RETRIES"] || "3")
args + extra_args args + extra_args
end end
@ -128,7 +127,7 @@ def curl_check_http_content(url, user_agents: [:default], check_content: false,
return "The URL #{url} is not reachable (HTTP status code #{details[:status]})" return "The URL #{url} is not reachable (HTTP status code #{details[:status]})"
end end
if url.start_with?("https://") && ENV["HOMEBREW_NO_INSECURE_REDIRECT"] && if url.start_with?("https://") && Homebrew::EnvConfig.no_insecure_redirect? &&
!details[:final_url].start_with?("https://") !details[:final_url].start_with?("https://")
return "The URL #{url} redirects back to HTTP" return "The URL #{url} redirects back to HTTP"
end end

View File

@ -103,11 +103,15 @@ module Utils
quiet_system "git", "ls-remote", url quiet_system "git", "ls-remote", url
end end
def self.set_git_name_email! def self.set_git_name_email!(author: true, committer: true)
return unless ENV["HOMEBREW_GIT_NAME"] if Homebrew::EnvConfig.git_name
return unless ENV["HOMEBREW_GIT_EMAIL"] ENV["GIT_AUTHOR_NAME"] = Homebrew::EnvConfig.git_name if author
ENV["GIT_COMMITTER_NAME"] = Homebrew::EnvConfig.git_name if committer
end
ENV["GIT_AUTHOR_NAME"] = ENV["GIT_COMMITTER_NAME"] = ENV["HOMEBREW_GIT_NAME"] return unless Homebrew::EnvConfig.git_email
ENV["GIT_AUTHOR_EMAIL"] = ENV["GIT_COMMITTER_EMAIL"] = ENV["HOMEBREW_GIT_EMAIL"]
ENV["GIT_AUTHOR_EMAIL"] = Homebrew::EnvConfig.git_email if author
ENV["GIT_COMMITTER_EMAIL"] = Homebrew::EnvConfig.git_email if committer
end end
end end

View File

@ -49,7 +49,7 @@ module GitHub
def initialize(github_message) def initialize(github_message)
@github_message = github_message @github_message = github_message
message = +"GitHub #{github_message}:" message = +"GitHub #{github_message}:"
message << if ENV["HOMEBREW_GITHUB_API_TOKEN"] message << if Homebrew::EnvConfig.github_api_token
<<~EOS <<~EOS
HOMEBREW_GITHUB_API_TOKEN may be invalid or expired; check: HOMEBREW_GITHUB_API_TOKEN may be invalid or expired; check:
#{Formatter.url("https://github.com/settings/tokens")} #{Formatter.url("https://github.com/settings/tokens")}
@ -80,15 +80,11 @@ module GitHub
end end
end end
def env_token
ENV["HOMEBREW_GITHUB_API_TOKEN"].presence
end
def env_username_password def env_username_password
return if ENV["HOMEBREW_GITHUB_API_USERNAME"].blank? return unless Homebrew::EnvConfig.github_api_username
return if ENV["HOMEBREW_GITHUB_API_PASSWORD"].blank? return unless Homebrew::EnvConfig.github_api_password
[ENV["HOMEBREW_GITHUB_API_PASSWORD"], ENV["HOMEBREW_GITHUB_API_USERNAME"]] [Homebrew::EnvConfig.github_api_password, Homebrew::EnvConfig.github_api_username]
end end
def keychain_username_password def keychain_username_password
@ -117,12 +113,12 @@ module GitHub
def api_credentials def api_credentials
@api_credentials ||= begin @api_credentials ||= begin
env_token || env_username_password || keychain_username_password Homebrew::EnvConfig.github_api_token || env_username_password || keychain_username_password
end end
end end
def api_credentials_type def api_credentials_type
if env_token if Homebrew::EnvConfig.github_api_token
:env_token :env_token
elsif env_username_password elsif env_username_password
:env_username_password :env_username_password
@ -174,7 +170,7 @@ module GitHub
def open_api(url, data: nil, request_method: nil, scopes: [].freeze, parse_json: true) def open_api(url, data: nil, request_method: nil, scopes: [].freeze, parse_json: true)
# This is a no-op if the user is opting out of using the GitHub API. # This is a no-op if the user is opting out of using the GitHub API.
return block_given? ? yield({}) : {} if ENV["HOMEBREW_NO_GITHUB_API"] return block_given? ? yield({}) : {} if Homebrew::EnvConfig.no_github_api?
args = ["--header", "Accept: application/vnd.github.v3+json", "--write-out", "\n%\{http_code}"] args = ["--header", "Accept: application/vnd.github.v3+json", "--write-out", "\n%\{http_code}"]
args += ["--header", "Accept: application/vnd.github.antiope-preview+json"] args += ["--header", "Accept: application/vnd.github.antiope-preview+json"]

View File

@ -72,8 +72,8 @@ module Tty
end end
def color? def color?
return false if ENV["HOMEBREW_NO_COLOR"] return false if Homebrew::EnvConfig.no_color?
return true if ENV["HOMEBREW_COLOR"] return true if Homebrew::EnvConfig.color?
$stdout.tty? $stdout.tty?
end end

View File

@ -62,8 +62,7 @@ HOMEBREW_LIBRARY="$HOMEBREW_REPOSITORY/Library"
# Whitelist and copy to HOMEBREW_* all variables previously mentioned in # Whitelist and copy to HOMEBREW_* all variables previously mentioned in
# manpage or used elsewhere by Homebrew. # manpage or used elsewhere by Homebrew.
for VAR in AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY BINTRAY_USER BINTRAY_KEY \ for VAR in BROWSER DISPLAY EDITOR NO_COLOR PATH
BROWSER DISPLAY EDITOR GIT NO_COLOR PATH VISUAL
do do
# Skip if variable value is empty. # Skip if variable value is empty.
[[ -z "${!VAR}" ]] && continue [[ -z "${!VAR}" ]] && continue
@ -74,6 +73,12 @@ do
export "$VAR_NEW"="${!VAR}" export "$VAR_NEW"="${!VAR}"
done done
# Use VISUAL if HOMEBREW_EDITOR and EDITOR are unset.
if [[ -z "$HOMEBREW_EDITOR" && -n "$VISUAL" ]]
then
export HOMEBREW_EDITOR="$VISUAL"
fi
# Set CI variable for GitHub Actions, Azure Pipelines, Jenkins # Set CI variable for GitHub Actions, Azure Pipelines, Jenkins
# (Set by default on Circle and Travis CI) # (Set by default on Circle and Travis CI)
if [[ -n "$GITHUB_ACTIONS" || -n "$TF_BUILD" || -n "$JENKINS_HOME" ]] if [[ -n "$GITHUB_ACTIONS" || -n "$TF_BUILD" || -n "$JENKINS_HOME" ]]
@ -90,7 +95,7 @@ then
# Filter all but the specific variables. # Filter all but the specific variables.
for VAR in HOME SHELL PATH TERM TERMINFO COLUMNS DISPLAY LOGNAME USER CI SSH_AUTH_SOCK SUDO_ASKPASS \ for VAR in HOME SHELL PATH TERM TERMINFO COLUMNS DISPLAY LOGNAME USER CI SSH_AUTH_SOCK SUDO_ASKPASS \
http_proxy https_proxy ftp_proxy no_proxy all_proxy HTTPS_PROXY FTP_PROXY ALL_PROXY \ http_proxy https_proxy ftp_proxy no_proxy all_proxy HTTPS_PROXY FTP_PROXY ALL_PROXY \
"${!HOMEBREW_@}" "${!TRAVIS_@}" "${!HOMEBREW_@}"
do do
# Skip if variable value is empty. # Skip if variable value is empty.
[[ -z "${!VAR}" ]] && continue [[ -z "${!VAR}" ]] && continue