Better handle missing environment variables when updating
Try to re-exec the Homebrew binary to get the environment variables we need and give up if that doesn't work.
This commit is contained in:
parent
11c5c3eaec
commit
63cfb0ff61
@ -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
|
||||
|
||||
@ -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"))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user