Merge pull request #4359 from apjanke/display-build-times

Add --display-times option to `install`, `upgrade`, and `reinstall`
This commit is contained in:
Mike McQuaid 2018-07-15 11:30:22 +01:00 committed by GitHub
commit af204c843d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 76 additions and 15 deletions

View File

@ -1,4 +1,4 @@
#: * `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>. #: Install <formula>.
#: #:
#: <formula> is usually the name of the formula to install, but it can be specified #: <formula> 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 `--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, #: Installation options specific to <formula> may be appended to the command,
#: and can be listed with `brew options` <formula>. #: and can be listed with `brew options` <formula>.
#: #:

View File

@ -1,5 +1,8 @@
#: * `reinstall` <formula>: #: * `reinstall` [`--display-times`] <formula>:
#: Uninstall and then install <formula> (with existing install options). #: 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.
require "formula_installer" require "formula_installer"
require "development_tools" require "development_tools"

View File

@ -1,4 +1,4 @@
#: * `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). #: Upgrade outdated, unpinned brews (with existing install options).
#: #:
#: Options for the `install` command are also valid here. #: 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 #: If `--ignore-pinned` is passed, set a 0 exit code even if pinned formulae
#: are not upgraded. #: 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 #: If <formulae> are given, upgrade only the specified brews (unless they
#: are pinned; see `pin`, `unpin`). #: are pinned; see `pin`, `unpin`).

View File

@ -18,6 +18,7 @@ module HomebrewArgvExtension
--include-test --include-test
--verbose --verbose
--force --force
--display-times
-i -i
-v -v
-d -d

View File

@ -221,6 +221,7 @@ class FormulaInstaller
end end
def install def install
start_time = Time.now
if !formula.bottle_unneeded? && !pour_bottle? && DevelopmentTools.installed? if !formula.bottle_unneeded? && !pour_bottle? && DevelopmentTools.installed?
Homebrew::Install.check_development_tools Homebrew::Install.check_development_tools
end end
@ -349,7 +350,8 @@ class FormulaInstaller
build_bottle_postinstall if build_bottle? build_bottle_postinstall if build_bottle?
opoo "Nothing was installed to #{formula.prefix}" unless formula.installed? 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 end
def check_conflicts def check_conflicts

View File

@ -1,23 +1,26 @@
# A Messages object collects messages that may need to be displayed together # A Messages object collects messages that may need to be displayed together
# at the end of a multi-step `brew` command run # at the end of a multi-step `brew` command run
class Messages class Messages
attr_reader :caveats, :formula_count attr_reader :caveats, :formula_count, :install_times
def initialize def initialize
@caveats = [] @caveats = []
@formula_count = 0 @formula_count = 0
@install_times = []
end end
def record_caveats(f, caveats) def record_caveats(f, caveats)
@caveats.push(formula: f.name, caveats: caveats) @caveats.push(formula: f.name, caveats: caveats)
end end
def formula_installed(_f) def formula_installed(f, elapsed_time)
@formula_count += 1 @formula_count += 1
@install_times.push(formula: f.name, time: elapsed_time)
end end
def display_messages def display_messages
display_caveats display_caveats
display_install_times if ARGV.include?("--display-times")
end end
def display_caveats def display_caveats
@ -28,4 +31,12 @@ class Messages
ohai c[:formula], c[:caveats] ohai c[:formula], c[:caveats]
end end
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 end

View File

@ -13,11 +13,11 @@ describe Messages do
f_baz = formula("baz") do f_baz = formula("baz") do
url "http://example.com/baz-0.1.tgz" url "http://example.com/baz-0.1.tgz"
end end
@m.formula_installed(f_foo) @m.formula_installed(f_foo, 1.1)
@m.record_caveats(f_foo, "Zsh completions were installed") @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.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") @m.record_caveats(f_baz, "A valid GOPATH is required to use the go command")
end end
@ -33,4 +33,18 @@ describe Messages do
caveats_formula_order = @m.caveats.map { |x| x[:formula] } caveats_formula_order = @m.caveats.map { |x| x[:formula] }
expect(caveats_formula_order).to eq(["foo", "bar", "baz"]) expect(caveats_formula_order).to eq(["foo", "bar", "baz"])
end 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 end

View File

@ -221,6 +221,7 @@ _brew_install() {
--interactive --interactive
--only-dependencies --only-dependencies
--verbose --verbose
--display-times
$(brew options --compact "$prv" 2>/dev/null) $(brew options --compact "$prv" 2>/dev/null)
" "
fi fi
@ -481,6 +482,7 @@ _brew_unpack() {
esac esac
__brew_complete_formulae __brew_complete_formulae
} }
_brew_update() { _brew_update() {
local cur="${COMP_WORDS[COMP_CWORD]}" local cur="${COMP_WORDS[COMP_CWORD]}"
case "$cur" in case "$cur" in
@ -504,6 +506,7 @@ _brew_upgrade() {
--debug --debug
--verbose --verbose
--fetch-HEAD --fetch-HEAD
--display-times
" "
return return
;; ;;

View File

@ -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]' \ '(--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]' \ '(--devel --HEAD)'{--devel,--HEAD}'[install the development / HEAD version]' \
'--keep-tmp[don''t delete temporary files created during installation]' \ '--keep-tmp[don''t delete temporary files created during installation]' \
'--display-times[display installation times at end of run]' \
'*: : __brew_formulae' \ '*: : __brew_formulae' \
- interactive-install \ - interactive-install \
'--interactive[download and patch formula, then open a shell]' \ '--interactive[download and patch formula, then open a shell]' \
@ -554,6 +555,7 @@ _brew_readall() {
# brew reinstall formulae: # brew reinstall formulae:
_brew_reinstall() { _brew_reinstall() {
_arguments \ _arguments \
'--display-times[display installation times at end of run]' \
'*::formula:__brew_installed_formulae' '*::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]' \ '(--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]' \ '(--devel --HEAD)'{--devel,--HEAD}'[install the development / HEAD version]' \
'--keep-tmp[don''t delete temporary files created during installation]' \ '--keep-tmp[don''t delete temporary files created during installation]' \
'--display-times[display installation times at end of run]' \
'*: : __brew_outdated_formulae' \ '*: : __brew_outdated_formulae' \
- interactive-install \ - interactive-install \
'--interactive[download and patch formula, then open a shell]' \ '--interactive[download and patch formula, then open a shell]' \

View File

@ -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: See the docs for examples of using the JSON output:
<https://docs.brew.sh/Querying-Brew> <https://docs.brew.sh/Querying-Brew>
* `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`. Install `formula`.
`formula` is usually the name of the formula to install, but it can be specified `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 `--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, Installation options specific to `formula` may be appended to the command,
and can be listed with `brew options` `formula`. 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. 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). 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`: * `search`, `-S`:
Display all locally available formulae (including tapped ones). Display all locally available formulae (including tapped ones).
No online search is performed. 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 their latest `origin/master`. Note this will destroy all your uncommitted
or committed changes. 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). Upgrade outdated, unpinned brews (with existing install options).
Options for the `install` command are also valid here. 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 If `--ignore-pinned` is passed, set a 0 exit code even if pinned formulae
are not upgraded. 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 If `formulae` are given, upgrade only the specified brews (unless they
are pinned; see `pin`, `unpin`). are pinned; see `pin`, `unpin`).

View File

@ -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 See the docs for examples of using the JSON output: \fIhttps://docs\.brew\.sh/Querying\-Brew\fR
. .
.IP "\(bu" 4 .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 .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\. \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\. If \fB\-\-verbose\fR (or \fB\-v\fR) is passed, print the verification and postinstall steps\.
. .
.IP .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\. 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 .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\. If \fB\-\-syntax\fR is passed, also syntax\-check all of Homebrew\'s Ruby files\.
. .
.IP "\(bu" 4 .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 .IP "\(bu" 4
\fBsearch\fR, \fB\-S\fR: Display all locally available formulae (including tapped ones)\. No online search is performed\. \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\. \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 .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 .IP
Options for the \fBinstall\fR command are also valid here\. 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\. If \fB\-\-ignore\-pinned\fR is passed, set a 0 exit code even if pinned formulae are not upgraded\.
. .
.IP .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)\. If \fIformulae\fR are given, upgrade only the specified brews (unless they are pinned; see \fBpin\fR, \fBunpin\fR)\.
. .
.IP "\(bu" 4 .IP "\(bu" 4