From 9156d6def4b55acf6e9796f144f7af7551edecad Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Wed, 9 Jan 2019 17:03:02 +0000 Subject: [PATCH] config: better handle missing variables. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We don’t really have a better solution than this because of how the auto-updater’s Bash code worked on the version they are updating from. Users will never hit this more than once. Fixes #5513 --- Library/Homebrew/config.rb | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/Library/Homebrew/config.rb b/Library/Homebrew/config.rb index 3d1f3208cd..6d8f25efb4 100644 --- a/Library/Homebrew/config.rb +++ b/Library/Homebrew/config.rb @@ -1,18 +1,27 @@ -unless ENV["HOMEBREW_BREW_FILE"] - raise "HOMEBREW_BREW_FILE was not exported! Please call bin/brew directly!" +def get_env_or_raise(env, message = nil) + message ||= <<~EOS + don't worry, you likely hit a bug auto-updating from an old version. + Rerun your command, everything is up-to-date and fine now + EOS + unless ENV[env] + abort <<~EOS + Error: #{env} was not exported!\nPlease #{message.chomp}. + EOS + end + ENV[env] end # Path to `bin/brew` main executable in `HOMEBREW_PREFIX` -HOMEBREW_BREW_FILE = Pathname.new(ENV["HOMEBREW_BREW_FILE"]) +HOMEBREW_BREW_FILE = Pathname.new(get_env_or_raise("HOMEBREW_BREW_FILE", "call bin/brew directly")) # Where we link under -HOMEBREW_PREFIX = Pathname.new(ENV["HOMEBREW_PREFIX"]) +HOMEBREW_PREFIX = Pathname.new(get_env_or_raise("HOMEBREW_PREFIX")) # Where `.git` is found -HOMEBREW_REPOSITORY = Pathname.new(ENV["HOMEBREW_REPOSITORY"]) +HOMEBREW_REPOSITORY = Pathname.new(get_env_or_raise("HOMEBREW_REPOSITORY")) # Where we store most of Homebrew, taps, and various metadata -HOMEBREW_LIBRARY = Pathname.new(ENV["HOMEBREW_LIBRARY"]) +HOMEBREW_LIBRARY = Pathname.new(get_env_or_raise("HOMEBREW_LIBRARY")) # Where shim scripts for various build and SCM tools are stored HOMEBREW_SHIMS_PATH = HOMEBREW_LIBRARY/"Homebrew/shims" @@ -27,20 +36,20 @@ HOMEBREW_PINNED_KEGS = HOMEBREW_PREFIX/"var/homebrew/pinned" HOMEBREW_LOCKS = HOMEBREW_PREFIX/"var/homebrew/locks" # Where we store built products -HOMEBREW_CELLAR = Pathname.new(ENV["HOMEBREW_CELLAR"]) +HOMEBREW_CELLAR = Pathname.new(get_env_or_raise("HOMEBREW_CELLAR")) # Where downloads (bottles, source tarballs, etc.) are cached -HOMEBREW_CACHE = Pathname.new(ENV["HOMEBREW_CACHE"]) +HOMEBREW_CACHE = Pathname.new(get_env_or_raise("HOMEBREW_CACHE")) # Where brews installed via URL are cached HOMEBREW_CACHE_FORMULA = HOMEBREW_CACHE/"Formula" # Where build, postinstall, and test logs of formulae are written to -HOMEBREW_LOGS = Pathname.new(ENV["HOMEBREW_LOGS"]).expand_path +HOMEBREW_LOGS = Pathname.new(get_env_or_raise("HOMEBREW_LOGS")).expand_path # Must use `/tmp` instead of `TMPDIR` because long paths break Unix domain sockets HOMEBREW_TEMP = begin - tmp = Pathname.new(ENV["HOMEBREW_TEMP"]) + tmp = Pathname.new(get_env_or_raise("HOMEBREW_TEMP")) tmp.mkpath unless tmp.exist? tmp.realpath end