Pass args
in Install
and Messages
instead of using global args
.
This commit is contained in:
parent
2b33f995f3
commit
f8934c0255
@ -8,6 +8,8 @@ require "socket"
|
|||||||
require "cli/parser"
|
require "cli/parser"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
|
extend Install
|
||||||
|
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
def gist_logs_args
|
def gist_logs_args
|
||||||
@ -142,8 +144,8 @@ module Homebrew
|
|||||||
def gist_logs
|
def gist_logs
|
||||||
gist_logs_args.parse
|
gist_logs_args.parse
|
||||||
|
|
||||||
Install.perform_preinstall_checks(all_fatal: true)
|
perform_preinstall_checks(all_fatal: true)
|
||||||
Install.perform_build_from_source_checks(all_fatal: true)
|
perform_build_from_source_checks(all_fatal: true)
|
||||||
gistify_logs(args.resolved_formulae.first)
|
gistify_logs(args.resolved_formulae.first)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -10,10 +10,11 @@ require "cli/parser"
|
|||||||
require "upgrade"
|
require "upgrade"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
module_function
|
extend Install
|
||||||
|
|
||||||
extend Search
|
extend Search
|
||||||
|
|
||||||
|
module_function
|
||||||
|
|
||||||
def install_args
|
def install_args
|
||||||
Homebrew::CLI::Parser.new do
|
Homebrew::CLI::Parser.new do
|
||||||
usage_banner <<~EOS
|
usage_banner <<~EOS
|
||||||
@ -255,17 +256,17 @@ module Homebrew
|
|||||||
|
|
||||||
return if formulae.empty?
|
return if formulae.empty?
|
||||||
|
|
||||||
Install.perform_preinstall_checks
|
perform_preinstall_checks
|
||||||
|
|
||||||
formulae.each do |f|
|
formulae.each do |f|
|
||||||
Migrator.migrate_if_needed(f)
|
Migrator.migrate_if_needed(f, force: args.force?)
|
||||||
install_formula(f)
|
install_formula(f)
|
||||||
Cleanup.install_formula_clean!(f)
|
Cleanup.install_formula_clean!(f)
|
||||||
end
|
end
|
||||||
|
|
||||||
check_installed_dependents(args: args)
|
check_installed_dependents(args: args)
|
||||||
|
|
||||||
Homebrew.messages.display_messages
|
Homebrew.messages.display_messages(display_times: args.display_times?)
|
||||||
rescue FormulaUnreadableError, FormulaClassUnavailableError,
|
rescue FormulaUnreadableError, FormulaClassUnavailableError,
|
||||||
TapFormulaUnreadableError, TapFormulaClassUnavailableError => e
|
TapFormulaUnreadableError, TapFormulaClassUnavailableError => e
|
||||||
# Need to rescue before `FormulaUnavailableError` (superclass of this)
|
# Need to rescue before `FormulaUnavailableError` (superclass of this)
|
||||||
|
@ -24,7 +24,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
def migrate
|
def migrate
|
||||||
migrate_args.parse
|
args = migrate_args.parse
|
||||||
|
|
||||||
args.resolved_formulae.each do |f|
|
args.resolved_formulae.each do |f|
|
||||||
if f.oldname
|
if f.oldname
|
||||||
@ -34,7 +34,7 @@ module Homebrew
|
|||||||
raise "#{rack} is a symlink" if rack.symlink?
|
raise "#{rack} is a symlink" if rack.symlink?
|
||||||
end
|
end
|
||||||
|
|
||||||
migrator = Migrator.new(f)
|
migrator = Migrator.new(f, force: args.force?)
|
||||||
migrator.migrate
|
migrator.migrate
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
require "formula_installer"
|
require "formula_installer"
|
||||||
require "development_tools"
|
require "development_tools"
|
||||||
require "messages"
|
require "messages"
|
||||||
|
require "install"
|
||||||
require "reinstall"
|
require "reinstall"
|
||||||
require "cli/parser"
|
require "cli/parser"
|
||||||
require "cleanup"
|
require "cleanup"
|
||||||
@ -12,6 +13,8 @@ require "cask/macos"
|
|||||||
require "upgrade"
|
require "upgrade"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
|
extend Install
|
||||||
|
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
def reinstall_args
|
def reinstall_args
|
||||||
@ -58,7 +61,7 @@ module Homebrew
|
|||||||
|
|
||||||
FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed?
|
FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed?
|
||||||
|
|
||||||
Install.perform_preinstall_checks
|
perform_preinstall_checks
|
||||||
|
|
||||||
resolved_formulae, casks = args.resolved_formulae_casks
|
resolved_formulae, casks = args.resolved_formulae_casks
|
||||||
resolved_formulae.each do |f|
|
resolved_formulae.each do |f|
|
||||||
@ -66,14 +69,14 @@ module Homebrew
|
|||||||
onoe "#{f.full_name} is pinned. You must unpin it to reinstall."
|
onoe "#{f.full_name} is pinned. You must unpin it to reinstall."
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
Migrator.migrate_if_needed(f)
|
Migrator.migrate_if_needed(f, force: args.force?)
|
||||||
reinstall_formula(f, args: args)
|
reinstall_formula(f, args: args)
|
||||||
Cleanup.install_formula_clean!(f)
|
Cleanup.install_formula_clean!(f)
|
||||||
end
|
end
|
||||||
|
|
||||||
check_installed_dependents(args: args)
|
check_installed_dependents(args: args)
|
||||||
|
|
||||||
Homebrew.messages.display_messages
|
Homebrew.messages.display_messages(display_times: args.display_times?)
|
||||||
|
|
||||||
return if casks.blank?
|
return if casks.blank?
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
def update_report
|
def update_report
|
||||||
update_report_args.parse
|
args = update_report_args.parse
|
||||||
|
|
||||||
if !Utils::Analytics.messages_displayed? &&
|
if !Utils::Analytics.messages_displayed? &&
|
||||||
!Utils::Analytics.disabled? &&
|
!Utils::Analytics.disabled? &&
|
||||||
@ -122,7 +122,7 @@ module Homebrew
|
|||||||
else
|
else
|
||||||
hub.dump(updated_formula_report: !args.preinstall?)
|
hub.dump(updated_formula_report: !args.preinstall?)
|
||||||
hub.reporters.each(&:migrate_tap_migration)
|
hub.reporters.each(&:migrate_tap_migration)
|
||||||
hub.reporters.each(&:migrate_formula_rename)
|
hub.reporters.each { |r| r.migrate_formula_rename(force: args.force?) }
|
||||||
CacheStoreDatabase.use(:descriptions) do |db|
|
CacheStoreDatabase.use(:descriptions) do |db|
|
||||||
DescriptionCacheStore.new(db)
|
DescriptionCacheStore.new(db)
|
||||||
.update_from_report!(hub)
|
.update_from_report!(hub)
|
||||||
@ -373,7 +373,7 @@ class Reporter
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def migrate_formula_rename
|
def migrate_formula_rename(force:)
|
||||||
Formula.installed.each do |formula|
|
Formula.installed.each do |formula|
|
||||||
next unless Migrator.needs_migration?(formula)
|
next unless Migrator.needs_migration?(formula)
|
||||||
|
|
||||||
@ -397,7 +397,7 @@ class Reporter
|
|||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
Migrator.migrate_if_needed(f)
|
Migrator.migrate_if_needed(f, force: force)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -9,6 +9,8 @@ require "cask/utils"
|
|||||||
require "cask/macos"
|
require "cask/macos"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
|
extend Install
|
||||||
|
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
def upgrade_args
|
def upgrade_args
|
||||||
@ -77,7 +79,7 @@ module Homebrew
|
|||||||
def upgrade_outdated_formulae(formulae)
|
def upgrade_outdated_formulae(formulae)
|
||||||
FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed?
|
FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed?
|
||||||
|
|
||||||
Install.perform_preinstall_checks
|
perform_preinstall_checks
|
||||||
|
|
||||||
if formulae.blank?
|
if formulae.blank?
|
||||||
outdated = Formula.installed.select do |f|
|
outdated = Formula.installed.select do |f|
|
||||||
@ -129,7 +131,7 @@ module Homebrew
|
|||||||
|
|
||||||
check_installed_dependents(args: args)
|
check_installed_dependents(args: args)
|
||||||
|
|
||||||
Homebrew.messages.display_messages
|
Homebrew.messages.display_messages(display_times: args.display_times?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def upgrade_outdated_casks(casks)
|
def upgrade_outdated_casks(casks)
|
||||||
|
@ -21,6 +21,7 @@ require "cmd/install"
|
|||||||
require "find"
|
require "find"
|
||||||
|
|
||||||
class FormulaInstaller
|
class FormulaInstaller
|
||||||
|
include Homebrew::Install
|
||||||
include FormulaCellarChecks
|
include FormulaCellarChecks
|
||||||
extend Predicable
|
extend Predicable
|
||||||
|
|
||||||
@ -239,9 +240,7 @@ class FormulaInstaller
|
|||||||
lock
|
lock
|
||||||
|
|
||||||
start_time = Time.now
|
start_time = Time.now
|
||||||
if !formula.bottle_unneeded? && !pour_bottle? && DevelopmentTools.installed?
|
perform_build_from_source_checks if !formula.bottle_unneeded? && !pour_bottle? && DevelopmentTools.installed?
|
||||||
Homebrew::Install.perform_build_from_source_checks
|
|
||||||
end
|
|
||||||
|
|
||||||
# not in initialize so upgrade can unlink the active keg before calling this
|
# not in initialize so upgrade can unlink the active keg before calling this
|
||||||
# function but after instantiating this class so that it can avoid having to
|
# function but after instantiating this class so that it can avoid having to
|
||||||
|
@ -7,8 +7,6 @@ require "development_tools"
|
|||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
module Install
|
module Install
|
||||||
module_function
|
|
||||||
|
|
||||||
def check_cpu
|
def check_cpu
|
||||||
return if Hardware::CPU.intel? && Hardware::CPU.is_64_bit?
|
return if Hardware::CPU.intel? && Hardware::CPU.is_64_bit?
|
||||||
|
|
||||||
@ -40,11 +38,11 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
def check_cc_argv
|
def check_cc_argv
|
||||||
return unless Homebrew.args.cc
|
return unless (cc = args.cc)
|
||||||
|
|
||||||
@checks ||= Diagnostic::Checks.new
|
@checks ||= Diagnostic::Checks.new
|
||||||
opoo <<~EOS
|
opoo <<~EOS
|
||||||
You passed `--cc=#{Homebrew.args.cc}`.
|
You passed `--cc=#{cc}`.
|
||||||
#{@checks.please_create_pull_requests}
|
#{@checks.please_create_pull_requests}
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
@ -20,9 +20,9 @@ class Messages
|
|||||||
@install_times.push(formula: f.name, time: elapsed_time)
|
@install_times.push(formula: f.name, time: elapsed_time)
|
||||||
end
|
end
|
||||||
|
|
||||||
def display_messages
|
def display_messages(display_times: false)
|
||||||
display_caveats
|
display_caveats
|
||||||
display_install_times if Homebrew.args.display_times?
|
display_install_times if display_times
|
||||||
end
|
end
|
||||||
|
|
||||||
def display_caveats
|
def display_caveats
|
||||||
|
@ -97,18 +97,18 @@ class Migrator
|
|||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.migrate_if_needed(formula)
|
def self.migrate_if_needed(formula, force:)
|
||||||
return unless Migrator.needs_migration?(formula)
|
return unless Migrator.needs_migration?(formula)
|
||||||
|
|
||||||
begin
|
begin
|
||||||
migrator = Migrator.new(formula)
|
migrator = Migrator.new(formula, force: force)
|
||||||
migrator.migrate
|
migrator.migrate
|
||||||
rescue => e
|
rescue => e
|
||||||
onoe e
|
onoe e
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(formula, force: Homebrew.args.force?)
|
def initialize(formula, force: false)
|
||||||
@oldname = formula.oldname
|
@oldname = formula.oldname
|
||||||
@newname = formula.name
|
@newname = formula.name
|
||||||
raise MigratorNoOldnameError, formula unless oldname
|
raise MigratorNoOldnameError, formula unless oldname
|
||||||
|
@ -72,27 +72,20 @@ describe Messages do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Homebrew.args OpenStruct usage cannot use verified doubles.
|
context "when the `display_times` argument is true" do
|
||||||
# rubocop:disable RSpec/VerifiedDoubles
|
context "when `install_times` is empty" do
|
||||||
context "when the --display-times argument is present" do
|
it "doesn't print anything" do
|
||||||
before do
|
expect { messages.display_messages(display_times: true) }.not_to output.to_stdout
|
||||||
allow(Homebrew).to receive(:args).and_return \
|
|
||||||
double(display_times?: true, flags_only: ["--display-times"])
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when install_times is empty" do
|
|
||||||
it "doesn't print any output" do
|
|
||||||
expect { messages.display_messages }.not_to output.to_stdout
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when install_times is present" do
|
context "when `install_times` is present" do
|
||||||
before do
|
before do
|
||||||
messages.formula_installed(test_formula, elapsed_time)
|
messages.formula_installed(test_formula, elapsed_time)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "prints installation times" do
|
it "prints installation times" do
|
||||||
expect { messages.display_messages }.to output(
|
expect { messages.display_messages(display_times: true) }.to output(
|
||||||
<<~EOS,
|
<<~EOS,
|
||||||
==> Installation times
|
==> Installation times
|
||||||
foo 1.100 s
|
foo 1.100 s
|
||||||
@ -102,15 +95,10 @@ describe Messages do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when the --display-times argument isn't present" do
|
context "when the `display_times` argument isn't specified" do
|
||||||
before do
|
|
||||||
allow(Homebrew).to receive(:args).and_return(double(display_times?: false))
|
|
||||||
end
|
|
||||||
|
|
||||||
it "doesn't print installation times" do
|
it "doesn't print installation times" do
|
||||||
expect { messages.display_messages }.not_to output.to_stdout
|
expect { messages.display_messages }.not_to output.to_stdout
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# rubocop:enable RSpec/VerifiedDoubles
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -26,7 +26,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
formulae_to_install.each do |f|
|
formulae_to_install.each do |f|
|
||||||
Migrator.migrate_if_needed(f)
|
Migrator.migrate_if_needed(f, force: args.force?)
|
||||||
begin
|
begin
|
||||||
upgrade_formula(f, args: args)
|
upgrade_formula(f, args: args)
|
||||||
Cleanup.install_formula_clean!(f)
|
Cleanup.install_formula_clean!(f)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user