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}."
|
raise "Homebrew must be run under Ruby 2.3! You're running #{RUBY_VERSION}."
|
||||||
end
|
end
|
||||||
|
|
||||||
require_relative "global"
|
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
|
begin
|
||||||
trap("INT", std_trap) # restore default CTRL-C handler
|
trap("INT", std_trap) # restore default CTRL-C handler
|
||||||
|
|||||||
@ -1,18 +1,18 @@
|
|||||||
def get_env_or_raise(env, message = nil)
|
unless ENV["HOMEBREW_BREW_FILE"]
|
||||||
message ||= <<~EOS
|
raise "HOMEBREW_BREW_FILE was not exported! Please call bin/brew directly!"
|
||||||
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
|
end
|
||||||
|
|
||||||
# Path to `bin/brew` main executable in `HOMEBREW_PREFIX`
|
# 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
|
# Where we link under
|
||||||
HOMEBREW_PREFIX = Pathname.new(get_env_or_raise("HOMEBREW_PREFIX"))
|
HOMEBREW_PREFIX = Pathname.new(get_env_or_raise("HOMEBREW_PREFIX"))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user