From 0a2d8c3d4dc24c3644e19be3e90424a3f8f71962 Mon Sep 17 00:00:00 2001 From: Andrew Janke Date: Wed, 20 Jun 2018 00:54:14 -0400 Subject: [PATCH] Add --display-times option to `install`, `reinstall`, and `upgrade` --- Library/Homebrew/cmd/install.rb | 5 ++++- Library/Homebrew/cmd/reinstall.rb | 5 ++++- Library/Homebrew/cmd/upgrade.rb | 5 ++++- Library/Homebrew/extend/ARGV.rb | 1 + Library/Homebrew/formula_installer.rb | 4 +++- Library/Homebrew/messages.rb | 15 +++++++++++++-- Library/Homebrew/test/messages_spec.rb | 20 +++++++++++++++++--- completions/bash/brew | 3 +++ completions/zsh/_brew | 3 +++ docs/Manpage.md | 15 ++++++++++++--- manpages/brew.1 | 15 ++++++++++++--- 11 files changed, 76 insertions(+), 15 deletions(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index a87284d834..6a35ad7fbe 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -1,4 +1,4 @@ -#: * `install` [`--debug`] [`--env=`(`std`|`super`)] [`--ignore-dependencies`|`--only-dependencies`] [`--cc=`] [`--build-from-source`|`--force-bottle`] [`--include-test`] [`--devel`|`--HEAD`] [`--keep-tmp`] [`--build-bottle`] [`--force`] [`--verbose`] [ ...]: +#: * `install` [`--debug`] [`--env=`(`std`|`super`)] [`--ignore-dependencies`|`--only-dependencies`] [`--cc=`] [`--build-from-source`|`--force-bottle`] [`--include-test`] [`--devel`|`--HEAD`] [`--keep-tmp`] [`--build-bottle`] [`--force`] [`--verbose`] [`--display-times`] [ ...]: #: Install . #: #: is usually the name of the formula to install, but it can be specified @@ -59,6 +59,9 @@ #: #: If `--verbose` (or `-v`) is passed, print the verification and postinstall steps. #: +#: If `--display-times` is passed, install times for each formula are printed +#: at the end of the run. +#: #: Installation options specific to may be appended to the command, #: and can be listed with `brew options` . #: diff --git a/Library/Homebrew/cmd/reinstall.rb b/Library/Homebrew/cmd/reinstall.rb index e32eb8c239..30495f1bfc 100644 --- a/Library/Homebrew/cmd/reinstall.rb +++ b/Library/Homebrew/cmd/reinstall.rb @@ -1,5 +1,8 @@ -#: * `reinstall` : +#: * `reinstall` [`--display-times`] : #: Uninstall and then install (with existing install options). +#: +#: If `--display-times` is passed, install times for each formula are printed +#: at the end of the run. require "formula_installer" require "development_tools" diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index c6e79ea9f4..765638be67 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -1,4 +1,4 @@ -#: * `upgrade` [] [`--cleanup`] [`--fetch-HEAD`] [`--ignore-pinned`] []: +#: * `upgrade` [] [`--cleanup`] [`--fetch-HEAD`] [`--ignore-pinned`] [`--display-times`] []: #: Upgrade outdated, unpinned brews (with existing install options). #: #: Options for the `install` command are also valid here. @@ -14,6 +14,9 @@ #: If `--ignore-pinned` is passed, set a 0 exit code even if pinned formulae #: are not upgraded. #: +#: If `--display-times` is passed, install times for each formula are printed +#: at the end of the run. +#: #: If are given, upgrade only the specified brews (unless they #: are pinned; see `pin`, `unpin`). diff --git a/Library/Homebrew/extend/ARGV.rb b/Library/Homebrew/extend/ARGV.rb index 0a66a0abe6..f214fb75ec 100644 --- a/Library/Homebrew/extend/ARGV.rb +++ b/Library/Homebrew/extend/ARGV.rb @@ -18,6 +18,7 @@ module HomebrewArgvExtension --include-test --verbose --force + --display-times -i -v -d diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index ed08c958ee..1494ffb74d 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -221,6 +221,7 @@ class FormulaInstaller end def install + start_time = Time.now if !formula.bottle_unneeded? && !pour_bottle? && DevelopmentTools.installed? Homebrew::Install.check_development_tools end @@ -349,7 +350,8 @@ class FormulaInstaller build_bottle_postinstall if build_bottle? opoo "Nothing was installed to #{formula.prefix}" unless formula.installed? - Homebrew.messages.formula_installed(formula) + end_time = Time.now + Homebrew.messages.formula_installed(formula, end_time - start_time) end def check_conflicts diff --git a/Library/Homebrew/messages.rb b/Library/Homebrew/messages.rb index bf56934c84..f76167e7a3 100644 --- a/Library/Homebrew/messages.rb +++ b/Library/Homebrew/messages.rb @@ -1,23 +1,26 @@ # A Messages object collects messages that may need to be displayed together # at the end of a multi-step `brew` command run class Messages - attr_reader :caveats, :formula_count + attr_reader :caveats, :formula_count, :install_times def initialize @caveats = [] @formula_count = 0 + @install_times = [] end def record_caveats(f, caveats) @caveats.push(formula: f.name, caveats: caveats) end - def formula_installed(_f) + def formula_installed(f, elapsed_time) @formula_count += 1 + @install_times.push(formula: f.name, time: elapsed_time) end def display_messages display_caveats + display_install_times if ARGV.include?("--display-times") end def display_caveats @@ -28,4 +31,12 @@ class Messages ohai c[:formula], c[:caveats] end end + + def display_install_times + return if install_times.empty? + oh1 "Installation times" + install_times.each do |t| + puts format("%-20s %10.3f s", t[:formula], t[:time]) + end + end end diff --git a/Library/Homebrew/test/messages_spec.rb b/Library/Homebrew/test/messages_spec.rb index baeed4f7d1..d368ef1402 100644 --- a/Library/Homebrew/test/messages_spec.rb +++ b/Library/Homebrew/test/messages_spec.rb @@ -13,11 +13,11 @@ describe Messages do f_baz = formula("baz") do url "http://example.com/baz-0.1.tgz" end - @m.formula_installed(f_foo) + @m.formula_installed(f_foo, 1.1) @m.record_caveats(f_foo, "Zsh completions were installed") - @m.formula_installed(f_bar) + @m.formula_installed(f_bar, 2.2) @m.record_caveats(f_bar, "Keg-only formula") - @m.formula_installed(f_baz) + @m.formula_installed(f_baz, 3.3) @m.record_caveats(f_baz, "A valid GOPATH is required to use the go command") end @@ -33,4 +33,18 @@ describe Messages do caveats_formula_order = @m.caveats.map { |x| x[:formula] } expect(caveats_formula_order).to eq(["foo", "bar", "baz"]) end + + it "has recorded installation times" do + expect(@m.install_times).to_not be_empty + end + + it "maintained the order of install times" do + formula_order = @m.install_times.map { |x| x[:formula] } + expect(formula_order).to eq(["foo", "bar", "baz"]) + end + + it "recorded the right install times" do + times = @m.install_times.map { |x| x[:time] } + expect(times).to eq([1.1, 2.2, 3.3]) + end end diff --git a/completions/bash/brew b/completions/bash/brew index 24046fbba4..681a6ff091 100644 --- a/completions/bash/brew +++ b/completions/bash/brew @@ -221,6 +221,7 @@ _brew_install() { --interactive --only-dependencies --verbose + --display-times $(brew options --compact "$prv" 2>/dev/null) " fi @@ -481,6 +482,7 @@ _brew_unpack() { esac __brew_complete_formulae } + _brew_update() { local cur="${COMP_WORDS[COMP_CWORD]}" case "$cur" in @@ -504,6 +506,7 @@ _brew_upgrade() { --debug --verbose --fetch-HEAD + --display-times " return ;; diff --git a/completions/zsh/_brew b/completions/zsh/_brew index 760291e1c8..29d0945983 100644 --- a/completions/zsh/_brew +++ b/completions/zsh/_brew @@ -419,6 +419,7 @@ _brew_install() { '(--build-from-source -s)'{--build-from-source,-s}'[compile the specified formula from source even if a bottle is provided]' \ '(--devel --HEAD)'{--devel,--HEAD}'[install the development / HEAD version]' \ '--keep-tmp[don''t delete temporary files created during installation]' \ + '--display-times[display installation times at end of run]' \ '*: : __brew_formulae' \ - interactive-install \ '--interactive[download and patch formula, then open a shell]' \ @@ -554,6 +555,7 @@ _brew_readall() { # brew reinstall formulae: _brew_reinstall() { _arguments \ + '--display-times[display installation times at end of run]' \ '*::formula:__brew_installed_formulae' } @@ -752,6 +754,7 @@ _brew_upgrade() { '(--build-from-source -s)'{--build-from-source,-s}'[compile the specified formula from source even if a bottle is provided]' \ '(--devel --HEAD)'{--devel,--HEAD}'[install the development / HEAD version]' \ '--keep-tmp[don''t delete temporary files created during installation]' \ + '--display-times[display installation times at end of run]' \ '*: : __brew_outdated_formulae' \ - interactive-install \ '--interactive[download and patch formula, then open a shell]' \ diff --git a/docs/Manpage.md b/docs/Manpage.md index 43979377c9..f41954f240 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -216,7 +216,7 @@ With `--verbose` or `-v`, many commands print extra debugging information. Note See the docs for examples of using the JSON output: - * `install` [`--debug`] [`--env=`(`std`|`super`)] [`--ignore-dependencies`|`--only-dependencies`] [`--cc=``compiler`] [`--build-from-source`|`--force-bottle`] [`--include-test`] [`--devel`|`--HEAD`] [`--keep-tmp`] [`--build-bottle`] [`--force`] [`--verbose`] `formula` [`options` ...]: + * `install` [`--debug`] [`--env=`(`std`|`super`)] [`--ignore-dependencies`|`--only-dependencies`] [`--cc=``compiler`] [`--build-from-source`|`--force-bottle`] [`--include-test`] [`--devel`|`--HEAD`] [`--keep-tmp`] [`--build-bottle`] [`--force`] [`--verbose`] [`--display-times`] `formula` [`options` ...]: Install `formula`. `formula` is usually the name of the formula to install, but it can be specified @@ -277,6 +277,9 @@ With `--verbose` or `-v`, many commands print extra debugging information. Note If `--verbose` (or `-v`) is passed, print the verification and postinstall steps. + If `--display-times` is passed, install times for each formula are printed + at the end of the run. + Installation options specific to `formula` may be appended to the command, and can be listed with `brew options` `formula`. @@ -400,9 +403,12 @@ With `--verbose` or `-v`, many commands print extra debugging information. Note If `--syntax` is passed, also syntax-check all of Homebrew's Ruby files. - * `reinstall` `formula`: + * `reinstall` [`--display-times`] `formula`: Uninstall and then install `formula` (with existing install options). + If `--display-times` is passed, install times for each formula are printed + at the end of the run. + * `search`, `-S`: Display all locally available formulae (including tapped ones). No online search is performed. @@ -563,7 +569,7 @@ With `--verbose` or `-v`, many commands print extra debugging information. Note their latest `origin/master`. Note this will destroy all your uncommitted or committed changes. - * `upgrade` [`install-options`] [`--cleanup`] [`--fetch-HEAD`] [`--ignore-pinned`] [`formulae`]: + * `upgrade` [`install-options`] [`--cleanup`] [`--fetch-HEAD`] [`--ignore-pinned`] [`--display-times`] [`formulae`]: Upgrade outdated, unpinned brews (with existing install options). Options for the `install` command are also valid here. @@ -579,6 +585,9 @@ With `--verbose` or `-v`, many commands print extra debugging information. Note If `--ignore-pinned` is passed, set a 0 exit code even if pinned formulae are not upgraded. + If `--display-times` is passed, install times for each formula are printed + at the end of the run. + If `formulae` are given, upgrade only the specified brews (unless they are pinned; see `pin`, `unpin`). diff --git a/manpages/brew.1 b/manpages/brew.1 index 917bb0ce1e..d084f3b709 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -206,7 +206,7 @@ Pass \fB\-\-all\fR to get information on all formulae, or \fB\-\-installed\fR to See the docs for examples of using the JSON output: \fIhttps://docs\.brew\.sh/Querying\-Brew\fR . .IP "\(bu" 4 -\fBinstall\fR [\fB\-\-debug\fR] [\fB\-\-env=\fR(\fBstd\fR|\fBsuper\fR)] [\fB\-\-ignore\-dependencies\fR|\fB\-\-only\-dependencies\fR] [\fB\-\-cc=\fR\fIcompiler\fR] [\fB\-\-build\-from\-source\fR|\fB\-\-force\-bottle\fR] [\fB\-\-include\-test\fR] [\fB\-\-devel\fR|\fB\-\-HEAD\fR] [\fB\-\-keep\-tmp\fR] [\fB\-\-build\-bottle\fR] [\fB\-\-force\fR] [\fB\-\-verbose\fR] \fIformula\fR [\fIoptions\fR \.\.\.]: Install \fIformula\fR\. +\fBinstall\fR [\fB\-\-debug\fR] [\fB\-\-env=\fR(\fBstd\fR|\fBsuper\fR)] [\fB\-\-ignore\-dependencies\fR|\fB\-\-only\-dependencies\fR] [\fB\-\-cc=\fR\fIcompiler\fR] [\fB\-\-build\-from\-source\fR|\fB\-\-force\-bottle\fR] [\fB\-\-include\-test\fR] [\fB\-\-devel\fR|\fB\-\-HEAD\fR] [\fB\-\-keep\-tmp\fR] [\fB\-\-build\-bottle\fR] [\fB\-\-force\fR] [\fB\-\-verbose\fR] [\fB\-\-display\-times\fR] \fIformula\fR [\fIoptions\fR \.\.\.]: Install \fIformula\fR\. . .IP \fIformula\fR is usually the name of the formula to install, but it can be specified in several different ways\. See \fISPECIFYING FORMULAE\fR\. @@ -260,6 +260,9 @@ If \fB\-\-force\fR (or \fB\-f\fR) is passed, install without checking for previo If \fB\-\-verbose\fR (or \fB\-v\fR) is passed, print the verification and postinstall steps\. . .IP +If \fB\-\-display\-times\fR is passed, install times for each formula are printed at the end of the run\. +. +.IP Installation options specific to \fIformula\fR may be appended to the command, and can be listed with \fBbrew options\fR \fIformula\fR\. . .IP "\(bu" 4 @@ -371,7 +374,10 @@ If \fB\-\-aliases\fR is passed, also verify any alias symlinks in each tap\. If \fB\-\-syntax\fR is passed, also syntax\-check all of Homebrew\'s Ruby files\. . .IP "\(bu" 4 -\fBreinstall\fR \fIformula\fR: Uninstall and then install \fIformula\fR (with existing install options)\. +\fBreinstall\fR [\fB\-\-display\-times\fR] \fIformula\fR: Uninstall and then install \fIformula\fR (with existing install options)\. +. +.IP +If \fB\-\-display\-times\fR is passed, install times for each formula are printed at the end of the run\. . .IP "\(bu" 4 \fBsearch\fR, \fB\-S\fR: Display all locally available formulae (including tapped ones)\. No online search is performed\. @@ -512,7 +518,7 @@ If \fB\-\-force\fR (or \fB\-f\fR) is specified then always do a slower, full upd \fBupdate\-reset\fR: Fetches and resets Homebrew and all tap repositories using \fBgit\fR(1) to their latest \fBorigin/master\fR\. Note this will destroy all your uncommitted or committed changes\. . .IP "\(bu" 4 -\fBupgrade\fR [\fIinstall\-options\fR] [\fB\-\-cleanup\fR] [\fB\-\-fetch\-HEAD\fR] [\fB\-\-ignore\-pinned\fR] [\fIformulae\fR]: Upgrade outdated, unpinned brews (with existing install options)\. +\fBupgrade\fR [\fIinstall\-options\fR] [\fB\-\-cleanup\fR] [\fB\-\-fetch\-HEAD\fR] [\fB\-\-ignore\-pinned\fR] [\fB\-\-display\-times\fR] [\fIformulae\fR]: Upgrade outdated, unpinned brews (with existing install options)\. . .IP Options for the \fBinstall\fR command are also valid here\. @@ -527,6 +533,9 @@ If \fB\-\-fetch\-HEAD\fR is passed, fetch the upstream repository to detect if t If \fB\-\-ignore\-pinned\fR is passed, set a 0 exit code even if pinned formulae are not upgraded\. . .IP +If \fB\-\-display\-times\fR is passed, install times for each formula are printed at the end of the run\. +. +.IP If \fIformulae\fR are given, upgrade only the specified brews (unless they are pinned; see \fBpin\fR, \fBunpin\fR)\. . .IP "\(bu" 4