From eb16e10902565f113034fe42793865cc2e3ced90 Mon Sep 17 00:00:00 2001 From: FnControlOption <70830482+FnControlOption@users.noreply.github.com> Date: Thu, 2 Sep 2021 08:42:48 -0700 Subject: [PATCH] messages: record cask installations. This is used to record installation times and also to determine whether to display caveats. --- Library/Homebrew/cask/cmd/upgrade.rb | 4 ++++ Library/Homebrew/cask/installer.rb | 3 +++ Library/Homebrew/cmd/install.rb | 2 +- Library/Homebrew/cmd/upgrade.rb | 10 ++++------ Library/Homebrew/formula_installer.rb | 2 +- Library/Homebrew/messages.rb | 16 ++++++++-------- Library/Homebrew/test/messages_spec.rb | 24 ++++++++++++------------ 7 files changed, 33 insertions(+), 28 deletions(-) diff --git a/Library/Homebrew/cask/cmd/upgrade.rb b/Library/Homebrew/cask/cmd/upgrade.rb index e0c0aad719..89215e94c5 100644 --- a/Library/Homebrew/cask/cmd/upgrade.rb +++ b/Library/Homebrew/cask/cmd/upgrade.rb @@ -166,6 +166,7 @@ module Cask ) require "cask/installer" + start_time = Time.now odebug "Started upgrade process for Cask #{old_cask}" old_config = old_cask.config @@ -228,6 +229,9 @@ module Cask old_cask_installer.revert_upgrade if started_upgrade raise e end + + end_time = Time.now + Homebrew.messages.package_installed(new_cask.token, end_time - start_time) end end end diff --git a/Library/Homebrew/cask/installer.rb b/Library/Homebrew/cask/installer.rb index 9377f89958..863880fd54 100644 --- a/Library/Homebrew/cask/installer.rb +++ b/Library/Homebrew/cask/installer.rb @@ -88,6 +88,7 @@ module Cask end def install + start_time = Time.now odebug "Cask::Installer#install" old_config = @cask.config @@ -115,6 +116,8 @@ module Cask purge_backed_up_versioned_files puts summary + end_time = Time.now + Homebrew.messages.package_installed(@cask.token, end_time - start_time) rescue restore_backup raise diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 5a0129dad8..023c207bf2 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -95,7 +95,7 @@ module Homebrew }], [:switch, "--display-times", { env: :display_install_times, - description: "Print install times for each formula at the end of the run.", + description: "Print install times for each package at the end of the run.", }], [:switch, "-i", "--interactive", { description: "Download and patch , then open a shell. This allows the user to " \ diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index 9418d34305..8182bb8e87 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -67,7 +67,7 @@ module Homebrew }], [:switch, "--display-times", { env: :display_install_times, - description: "Print install times for each formula at the end of the run.", + description: "Print install times for each package at the end of the run.", }], ].each do |options| send(*options) @@ -104,12 +104,10 @@ module Homebrew only_upgrade_formulae = formulae.present? && casks.blank? only_upgrade_casks = casks.present? && formulae.blank? - display_messages = !only_upgrade_casks && upgrade_outdated_formulae(formulae, args: args) - force_caveats = !only_upgrade_formulae && upgrade_outdated_casks(casks, args: args) + upgrade_outdated_formulae(formulae, args: args) unless only_upgrade_casks + upgrade_outdated_casks(casks, args: args) unless only_upgrade_formulae - return unless display_messages - - Homebrew.messages.display_messages(force_caveats: force_caveats, display_times: args.display_times?) + Homebrew.messages.display_messages(display_times: args.display_times?) end sig { params(formulae: T::Array[Formula], args: CLI::Args).returns(T::Boolean) } diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index b19c82bea8..8b0206c994 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -441,7 +441,7 @@ class FormulaInstaller opoo "Nothing was installed to #{formula.prefix}" unless formula.latest_version_installed? end_time = Time.now - Homebrew.messages.formula_installed(formula, end_time - start_time) + Homebrew.messages.package_installed(formula.name, end_time - start_time) end def check_conflicts diff --git a/Library/Homebrew/messages.rb b/Library/Homebrew/messages.rb index 6cc2cbcad6..89e03b551a 100644 --- a/Library/Homebrew/messages.rb +++ b/Library/Homebrew/messages.rb @@ -6,12 +6,12 @@ class Messages extend T::Sig - attr_reader :caveats, :formula_count, :install_times + attr_reader :caveats, :package_count, :install_times sig { void } def initialize @caveats = [] - @formula_count = 0 + @package_count = 0 @install_times = [] end @@ -19,9 +19,9 @@ class Messages @caveats.push(package: package, caveats: caveats) end - def formula_installed(f, elapsed_time) - @formula_count += 1 - @install_times.push(formula: f.name, time: elapsed_time) + def package_installed(package, elapsed_time) + @package_count += 1 + @install_times.push(package: package, time: elapsed_time) end def display_messages(force_caveats: false, display_times: false) @@ -30,8 +30,8 @@ class Messages end def display_caveats(force: false) - return if @formula_count.zero? - return if @formula_count == 1 && !force + return if @package_count.zero? + return if @package_count == 1 && !force return if @caveats.empty? oh1 "Caveats" @@ -45,7 +45,7 @@ class Messages oh1 "Installation times" install_times.each do |t| - puts format("%-20s %