Merge pull request #5529 from MikeMcQuaid/better-handle-update-env

Better handle missing environment variables when updating
This commit is contained in:
Mike McQuaid 2019-01-12 17:01:21 +00:00 committed by GitHub
commit bf4ac4bca3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 13 deletions

View File

@ -10,7 +10,21 @@ if RUBY_X < 2 || (RUBY_X == 2 && RUBY_Y < 3)
raise "Homebrew must be run under Ruby 2.3! You're running #{RUBY_VERSION}."
end
begin
require_relative "global"
rescue MissingEnvironmentVariables => e
raise e if ENV["HOMEBREW_MISSING_ENV_RETRY"]
if ENV["HOMEBREW_DEVELOPER"]
$stderr.puts <<~EOS
Warning: #{e.message}
Retrying with `exec #{ENV["HOMEBREW_BREW_FILE"]}`!
EOS
end
ENV["HOMEBREW_MISSING_ENV_RETRY"] = "1"
exec ENV["HOMEBREW_BREW_FILE"], *ARGV
end
begin
trap("INT", std_trap) # restore default CTRL-C handler

View File

@ -1,18 +1,18 @@
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]
unless ENV["HOMEBREW_BREW_FILE"]
raise "HOMEBREW_BREW_FILE was not exported! Please call bin/brew directly!"
end
# Path to `bin/brew` main executable in `HOMEBREW_PREFIX`
HOMEBREW_BREW_FILE = Pathname.new(get_env_or_raise("HOMEBREW_BREW_FILE", "call bin/brew directly"))
HOMEBREW_BREW_FILE = Pathname.new(ENV["HOMEBREW_BREW_FILE"])
class MissingEnvironmentVariables < RuntimeError; end
def get_env_or_raise(env)
unless ENV[env]
raise MissingEnvironmentVariables, "#{env} was not exported!"
end
ENV[env]
end
# Where we link under
HOMEBREW_PREFIX = Pathname.new(get_env_or_raise("HOMEBREW_PREFIX"))