2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-02-19 13:11:32 +00:00
|
|
|
raise "HOMEBREW_BREW_FILE was not exported! Please call bin/brew directly!" unless ENV["HOMEBREW_BREW_FILE"]
|
2016-08-24 14:46:05 +01:00
|
|
|
|
2012-08-22 15:50:27 -04:00
|
|
|
std_trap = trap("INT") { exit! 130 } # no backtrace thanks
|
|
|
|
|
2016-08-18 14:35:39 +08:00
|
|
|
# check ruby version before requiring any modules.
|
2018-09-17 19:44:12 +02:00
|
|
|
RUBY_X, RUBY_Y, = RUBY_VERSION.split(".").map(&:to_i)
|
2019-11-04 21:06:27 +11:00
|
|
|
if RUBY_X < 2 || (RUBY_X == 2 && RUBY_Y < 6)
|
|
|
|
raise "Homebrew must be run under Ruby 2.6! You're running #{RUBY_VERSION}."
|
2017-09-29 19:53:15 +01:00
|
|
|
end
|
2016-08-18 14:35:39 +08:00
|
|
|
|
2019-02-20 12:29:31 +00:00
|
|
|
# Load Bundler first of all if it's needed to avoid Gem version conflicts.
|
|
|
|
if ENV["HOMEBREW_INSTALL_BUNDLER_GEMS_FIRST"]
|
|
|
|
require_relative "utils/gems"
|
|
|
|
Homebrew.install_bundler_gems!
|
|
|
|
end
|
|
|
|
|
2019-01-23 15:40:44 +00:00
|
|
|
# Also define here so we can rescue regardless of location.
|
|
|
|
class MissingEnvironmentVariables < RuntimeError; end
|
|
|
|
|
2019-01-12 15:59:08 +00:00
|
|
|
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
|
2009-08-10 16:48:30 +01:00
|
|
|
|
2009-06-02 13:39:39 +01:00
|
|
|
begin
|
2012-08-22 15:50:27 -04:00
|
|
|
trap("INT", std_trap) # restore default CTRL-C handler
|
|
|
|
|
2014-06-25 09:45:01 +01:00
|
|
|
empty_argv = ARGV.empty?
|
2016-04-17 04:07:36 +02:00
|
|
|
help_flag_list = %w[-h --help --usage -?]
|
2016-10-01 18:17:52 +03:00
|
|
|
help_flag = !ENV["HOMEBREW_HELP"].nil?
|
2020-07-31 17:37:36 +02:00
|
|
|
help_cmd_index = nil
|
2014-06-25 09:45:01 +01:00
|
|
|
cmd = nil
|
|
|
|
|
2020-05-23 19:39:11 +01:00
|
|
|
ARGV.each_with_index do |arg, i|
|
2016-09-22 20:12:28 +02:00
|
|
|
break if help_flag && cmd
|
|
|
|
|
2016-10-01 18:17:52 +03:00
|
|
|
if arg == "help" && !cmd
|
2016-04-17 04:07:36 +02:00
|
|
|
# Command-style help: `help <cmd>` is fine, but `<cmd> help` is not.
|
2014-06-25 09:45:01 +01:00
|
|
|
help_flag = true
|
2020-07-31 17:37:36 +02:00
|
|
|
help_cmd_index = i
|
2016-10-01 18:17:52 +03:00
|
|
|
elsif !cmd && !help_flag_list.include?(arg)
|
2014-06-25 09:45:01 +01:00
|
|
|
cmd = ARGV.delete_at(i)
|
2020-06-22 10:23:00 +05:30
|
|
|
cmd = Commands::HOMEBREW_INTERNAL_COMMAND_ALIASES.fetch(cmd, cmd)
|
2014-06-25 09:45:01 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-31 17:37:36 +02:00
|
|
|
ARGV.delete_at(help_cmd_index) if help_cmd_index
|
|
|
|
|
2020-08-02 02:52:24 +02:00
|
|
|
args = Homebrew::CLI::Parser.new.parse(ARGV.dup.freeze, ignore_invalid_options: true)
|
|
|
|
Homebrew.args = args
|
2020-08-02 14:32:31 +02:00
|
|
|
Context.current = args.context
|
2020-07-30 18:40:10 +02:00
|
|
|
|
2017-04-27 10:44:44 +02:00
|
|
|
path = PATH.new(ENV["PATH"])
|
2017-06-02 18:44:39 +01:00
|
|
|
homebrew_path = PATH.new(ENV["HOMEBREW_PATH"])
|
2017-04-27 10:44:44 +02:00
|
|
|
|
2014-09-24 21:35:07 -07:00
|
|
|
# Add SCM wrappers.
|
2018-10-24 18:20:17 -04:00
|
|
|
path.prepend(HOMEBREW_SHIMS_PATH/"scm")
|
|
|
|
homebrew_path.prepend(HOMEBREW_SHIMS_PATH/"scm")
|
2017-04-27 10:44:44 +02:00
|
|
|
|
|
|
|
ENV["PATH"] = path
|
2014-09-24 21:35:07 -07:00
|
|
|
|
2020-02-02 17:05:45 +01:00
|
|
|
require "commands"
|
2015-09-10 21:20:34 +08:00
|
|
|
|
2020-02-02 17:05:45 +01:00
|
|
|
if cmd
|
|
|
|
internal_cmd = Commands.valid_internal_cmd?(cmd)
|
|
|
|
internal_cmd ||= begin
|
|
|
|
internal_dev_cmd = Commands.valid_internal_dev_cmd?(cmd)
|
2020-04-05 15:44:50 +01:00
|
|
|
if internal_dev_cmd && !Homebrew::EnvConfig.developer?
|
2018-09-15 05:18:24 +02:00
|
|
|
if (HOMEBREW_REPOSITORY/".git/config").exist?
|
|
|
|
system "git", "config", "--file=#{HOMEBREW_REPOSITORY}/.git/config",
|
2019-04-30 08:44:35 +01:00
|
|
|
"--replace-all", "homebrew.devcmdrun", "true"
|
2018-09-15 05:18:24 +02:00
|
|
|
end
|
2016-09-05 21:32:25 +01:00
|
|
|
ENV["HOMEBREW_DEV_CMD_RUN"] = "1"
|
|
|
|
end
|
2020-02-02 17:05:45 +01:00
|
|
|
internal_dev_cmd
|
2015-09-10 21:20:34 +08:00
|
|
|
end
|
|
|
|
end
|
2014-06-25 09:45:01 +01:00
|
|
|
|
2017-11-18 17:04:54 -08:00
|
|
|
unless internal_cmd
|
|
|
|
# Add contributed commands to PATH before checking.
|
|
|
|
homebrew_path.append(Tap.cmd_directories)
|
|
|
|
|
|
|
|
# External commands expect a normal PATH
|
|
|
|
ENV["PATH"] = homebrew_path
|
|
|
|
end
|
|
|
|
|
2014-06-25 09:45:01 +01:00
|
|
|
# Usage instructions should be displayed if and only if one of:
|
2016-10-01 18:25:16 +01:00
|
|
|
# - a help flag is passed AND a command is matched
|
2014-06-26 09:27:22 +01:00
|
|
|
# - a help flag is passed AND there is no command specified
|
2014-06-25 09:45:01 +01:00
|
|
|
# - no arguments are passed
|
2017-10-24 10:17:11 -03:00
|
|
|
# - if cmd is Cask, let Cask handle the help command instead
|
|
|
|
if (empty_argv || help_flag) && cmd != "cask"
|
2018-06-05 23:19:18 -04:00
|
|
|
require "help"
|
2020-02-01 19:05:03 +01:00
|
|
|
Homebrew::Help.help cmd, empty_argv: empty_argv
|
2020-02-02 11:32:50 +01:00
|
|
|
# `Homebrew.help` never returns, except for unknown commands.
|
2014-06-25 09:45:01 +01:00
|
|
|
end
|
|
|
|
|
2020-02-02 17:05:45 +01:00
|
|
|
if internal_cmd || Commands.external_ruby_v2_cmd_path(cmd)
|
|
|
|
Homebrew.send Commands.method_name(cmd)
|
|
|
|
elsif (path = Commands.external_ruby_cmd_path(cmd))
|
|
|
|
require?(path)
|
|
|
|
exit Homebrew.failed? ? 1 : 0
|
|
|
|
elsif Commands.external_cmd_path(cmd)
|
2017-11-05 15:37:57 +00:00
|
|
|
%w[CACHE LIBRARY_PATH].each do |env|
|
|
|
|
ENV["HOMEBREW_#{env}"] = Object.const_get("HOMEBREW_#{env}").to_s
|
2010-02-27 13:29:49 +00:00
|
|
|
end
|
2010-09-11 20:22:54 +01:00
|
|
|
exec "brew-#{cmd}", *ARGV
|
2009-09-24 19:19:57 +01:00
|
|
|
else
|
2016-07-04 17:05:37 +01:00
|
|
|
possible_tap = OFFICIAL_CMD_TAPS.find { |_, cmds| cmds.include?(cmd) }
|
|
|
|
possible_tap = Tap.fetch(possible_tap.first) if possible_tap
|
2015-11-07 16:52:01 +08:00
|
|
|
|
2017-09-24 20:12:58 +01:00
|
|
|
odie "Unknown command: #{cmd}" if !possible_tap || possible_tap.installed?
|
|
|
|
|
2017-10-18 08:47:52 -03:00
|
|
|
# Unset HOMEBREW_HELP to avoid confusing the tap
|
2020-07-30 18:40:10 +02:00
|
|
|
with_env HOMEBREW_HELP: nil do
|
|
|
|
tap_commands = []
|
|
|
|
cgroup = Utils.popen_read("cat", "/proc/1/cgroup")
|
|
|
|
if %w[azpl_job actions_job docker garden kubepods].none? { |container| cgroup.include?(container) }
|
|
|
|
brew_uid = HOMEBREW_BREW_FILE.stat.uid
|
|
|
|
tap_commands += %W[/usr/bin/sudo -u ##{brew_uid}] if Process.uid.zero? && !brew_uid.zero?
|
|
|
|
end
|
|
|
|
tap_commands += %W[#{HOMEBREW_BREW_FILE} tap #{possible_tap.name}]
|
|
|
|
safe_system(*tap_commands)
|
2019-04-18 07:48:05 +02:00
|
|
|
end
|
2020-07-30 18:40:10 +02:00
|
|
|
|
2017-09-24 20:12:58 +01:00
|
|
|
exec HOMEBREW_BREW_FILE, cmd, *ARGV
|
2009-06-02 13:39:39 +01:00
|
|
|
end
|
2016-04-19 08:11:17 +02:00
|
|
|
rescue UsageError => e
|
2018-06-05 23:19:18 -04:00
|
|
|
require "help"
|
|
|
|
Homebrew::Help.help cmd, usage_error: e.message
|
2015-12-21 08:44:41 +00:00
|
|
|
rescue SystemExit => e
|
2020-08-02 02:53:08 +02:00
|
|
|
onoe "Kernel.exit" if args.debug? && !e.success?
|
|
|
|
$stderr.puts e.backtrace if args.debug?
|
2009-11-11 18:51:05 +00:00
|
|
|
raise
|
2017-05-05 10:50:26 +02:00
|
|
|
rescue Interrupt
|
2016-01-30 23:09:45 -08:00
|
|
|
$stderr.puts # seemingly a newline is typical
|
2009-08-10 16:48:30 +01:00
|
|
|
exit 130
|
2009-11-12 01:33:14 +00:00
|
|
|
rescue BuildError => e
|
2017-06-07 16:34:54 +01:00
|
|
|
Utils::Analytics.report_build_error(e)
|
2020-08-02 02:52:24 +02:00
|
|
|
e.dump(verbose: args.verbose?)
|
2020-03-30 20:44:01 +01:00
|
|
|
|
2020-07-26 11:53:05 +02:00
|
|
|
if e.formula.head? || e.formula.deprecated? || e.formula.disabled?
|
|
|
|
$stderr.puts <<~EOS
|
|
|
|
Please create pull requests instead of asking for help on Homebrew's GitHub,
|
|
|
|
Discourse, Twitter or IRC.
|
|
|
|
EOS
|
|
|
|
end
|
2020-03-30 20:44:01 +01:00
|
|
|
|
2009-11-12 01:33:14 +00:00
|
|
|
exit 1
|
|
|
|
rescue RuntimeError, SystemCallError => e
|
2012-08-28 20:14:44 -04:00
|
|
|
raise if e.message.empty?
|
2018-09-17 02:45:00 +02:00
|
|
|
|
2009-11-12 01:33:14 +00:00
|
|
|
onoe e
|
2020-08-02 02:53:08 +02:00
|
|
|
$stderr.puts e.backtrace if args.debug?
|
2020-03-30 20:44:01 +01:00
|
|
|
|
2009-11-12 01:33:14 +00:00
|
|
|
exit 1
|
2016-12-10 13:04:14 +00:00
|
|
|
rescue MethodDeprecatedError => e
|
|
|
|
onoe e
|
|
|
|
if e.issues_url
|
|
|
|
$stderr.puts "If reporting this issue please do so at (not Homebrew/brew or Homebrew/core):"
|
|
|
|
$stderr.puts " #{Formatter.url(e.issues_url)}"
|
|
|
|
end
|
2020-08-02 02:53:08 +02:00
|
|
|
$stderr.puts e.backtrace if args.debug?
|
2016-12-10 13:04:14 +00:00
|
|
|
exit 1
|
2017-10-07 00:31:28 +02:00
|
|
|
rescue Exception => e # rubocop:disable Lint/RescueException
|
2009-11-11 18:38:50 +00:00
|
|
|
onoe e
|
2017-06-07 16:37:39 +01:00
|
|
|
if internal_cmd && defined?(OS::ISSUES_URL) &&
|
2020-04-05 15:44:50 +01:00
|
|
|
!Homebrew::EnvConfig.no_auto_update?
|
2020-03-11 10:57:36 +00:00
|
|
|
$stderr.puts "#{Tty.bold}Please report this issue:#{Tty.reset}"
|
2016-08-30 21:38:13 +02:00
|
|
|
$stderr.puts " #{Formatter.url(OS::ISSUES_URL)}"
|
2015-07-23 23:57:11 +02:00
|
|
|
end
|
2016-01-30 23:09:45 -08:00
|
|
|
$stderr.puts e.backtrace
|
2009-09-23 09:32:04 +01:00
|
|
|
exit 1
|
2012-03-15 10:57:34 +13:00
|
|
|
else
|
|
|
|
exit 1 if Homebrew.failed?
|
2009-07-31 02:51:17 +01:00
|
|
|
end
|