From 18f8adbd5c70d38b9eae10da2455ccb09b79427b Mon Sep 17 00:00:00 2001 From: Jarek Wojciechowski Date: Sat, 20 Oct 2018 19:34:26 -0400 Subject: [PATCH 1/3] test and add HOMEBREW_INSTALL_CLEANUP to upgrade --- Library/Homebrew/cmd/upgrade.rb | 4 ++-- Library/Homebrew/test/cmd/upgrade_spec.rb | 15 ++++++++++++++- docs/Manpage.md | 3 +++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index 7b4b8c5c96..71d702f642 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -3,7 +3,7 @@ #: #: Options for the `install` command are also valid here. #: -#: If `--cleanup` is specified or `HOMEBREW_UPGRADE_CLEANUP` is set then remove +#: If `--cleanup` is specified, `HOMEBREW_INSTALL_CLEANUP` or `HOMEBREW_UPGRADE_CLEANUP` is set then remove #: previously installed version(s) of upgraded . #: #: If `--fetch-HEAD` is passed, fetch the upstream repository to detect if @@ -107,7 +107,7 @@ module Homebrew Migrator.migrate_if_needed(f) begin upgrade_formula(f) - next if !ARGV.include?("--cleanup") && !ENV["HOMEBREW_UPGRADE_CLEANUP"] + next if !ARGV.include?("--cleanup") && !ENV["HOMEBREW_UPGRADE_CLEANUP"] && !ENV["HOMEBREW_INSTALL_CLEANUP"] next unless f.installed? Cleanup.new.cleanup_formula(f) diff --git a/Library/Homebrew/test/cmd/upgrade_spec.rb b/Library/Homebrew/test/cmd/upgrade_spec.rb index cb6934d4c3..60ef9b25ca 100644 --- a/Library/Homebrew/test/cmd/upgrade_spec.rb +++ b/Library/Homebrew/test/cmd/upgrade_spec.rb @@ -8,7 +8,7 @@ describe "brew upgrade", :integration_test do expect(HOMEBREW_CELLAR/"testball/0.1").to be_a_directory end - it "upgrades a Formula and cleans up old versions" do + it "upgrades a Formula and cleans up old versions when `--cleanup` is passed" do setup_test_formula "testball" (HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath @@ -17,4 +17,17 @@ describe "brew upgrade", :integration_test do expect(HOMEBREW_CELLAR/"testball/0.1").to be_a_directory expect(HOMEBREW_CELLAR/"testball/0.0.1").not_to exist end + + it "upgrades a Formula and cleans up old versions when `HOMEBREW_INSTALL_CLEANUP` is set" do + setup_test_formula "testball" + # allow(ENV).to receive(:[]).and_call_original + # allow(ENV).to receive(:[]).with("HOMEBREW_INSTALL_CLEANUP").and_return("1") + ENV["HOMEBREW_INSTALL_CLEANUP"] = "1" + (HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath + + expect { brew "upgrade" }.to be_a_success + + expect(HOMEBREW_CELLAR/"testball/0.1").to be_a_directory + expect(HOMEBREW_CELLAR/"testball/0.0.1").not_to exist + end end diff --git a/docs/Manpage.md b/docs/Manpage.md index 5d8387d9c1..1d6ba4da8a 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -1246,6 +1246,9 @@ Note that environment variables must have a value set to be detected. For exampl * `HOMEBREW_UPGRADE_CLEANUP`: If set, `brew upgrade` always assumes `--cleanup` has been passed. + * `HOMEBREW_INSTALL_CLEANUP`: + If set, `brew upgrade` always assumes `--cleanup` has been passed. + * `HOMEBREW_VERBOSE`: If set, Homebrew always assumes `--verbose` when running commands. From 51ca60d6d5faf97f74774ee8366785a6a8d1e168 Mon Sep 17 00:00:00 2001 From: Jarek Wojciechowski Date: Mon, 29 Oct 2018 11:23:32 -0400 Subject: [PATCH 2/3] add formula cleanup to install and reinstall --- Library/Homebrew/cmd/install.rb | 4 ++++ Library/Homebrew/cmd/reinstall.rb | 4 ++++ Library/Homebrew/cmd/upgrade.rb | 2 +- Library/Homebrew/test/cmd/upgrade_spec.rb | 13 ------------- docs/Manpage.md | 5 ++--- 5 files changed, 11 insertions(+), 17 deletions(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index d14eb80c6b..26ef6655e4 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -73,6 +73,9 @@ #: #: If `--git` (or `-g`) is passed, Homebrew will create a Git repository, useful for #: creating patches to the software. +#: +#: If `HOMEBREW_INSTALL_CLEANUP` is set then remove previously installed versions +#: of upgraded . require "missing_formula" require "formula_installer" @@ -254,6 +257,7 @@ module Homebrew formulae.each do |f| Migrator.migrate_if_needed(f) install_formula(f) + Cleanup.new.cleanup_formula(f) if ENV["HOMEBREW_INSTALL_CLEANUP"] end Homebrew.messages.display_messages rescue FormulaUnreadableError, FormulaClassUnavailableError, diff --git a/Library/Homebrew/cmd/reinstall.rb b/Library/Homebrew/cmd/reinstall.rb index 8f73846cb0..38adf73e0f 100644 --- a/Library/Homebrew/cmd/reinstall.rb +++ b/Library/Homebrew/cmd/reinstall.rb @@ -3,6 +3,9 @@ #: #: If `--display-times` is passed, install times for each formula are printed #: at the end of the run. +#: +#: If `HOMEBREW_INSTALL_CLEANUP` is set then remove previously installed versions +#: of upgraded . require "formula_installer" require "development_tools" @@ -24,6 +27,7 @@ module Homebrew end Migrator.migrate_if_needed(f) reinstall_formula(f) + Cleanup.new.cleanup_formula(f) if ENV["HOMEBREW_INSTALL_CLEANUP"] end Homebrew.messages.display_messages end diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index 71d702f642..a12ca439e9 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -3,7 +3,7 @@ #: #: Options for the `install` command are also valid here. #: -#: If `--cleanup` is specified, `HOMEBREW_INSTALL_CLEANUP` or `HOMEBREW_UPGRADE_CLEANUP` is set then remove +#: If `--cleanup` is specified or `HOMEBREW_INSTALL_CLEANUP` is set then remove #: previously installed version(s) of upgraded . #: #: If `--fetch-HEAD` is passed, fetch the upstream repository to detect if diff --git a/Library/Homebrew/test/cmd/upgrade_spec.rb b/Library/Homebrew/test/cmd/upgrade_spec.rb index 60ef9b25ca..83afb0cff1 100644 --- a/Library/Homebrew/test/cmd/upgrade_spec.rb +++ b/Library/Homebrew/test/cmd/upgrade_spec.rb @@ -17,17 +17,4 @@ describe "brew upgrade", :integration_test do expect(HOMEBREW_CELLAR/"testball/0.1").to be_a_directory expect(HOMEBREW_CELLAR/"testball/0.0.1").not_to exist end - - it "upgrades a Formula and cleans up old versions when `HOMEBREW_INSTALL_CLEANUP` is set" do - setup_test_formula "testball" - # allow(ENV).to receive(:[]).and_call_original - # allow(ENV).to receive(:[]).with("HOMEBREW_INSTALL_CLEANUP").and_return("1") - ENV["HOMEBREW_INSTALL_CLEANUP"] = "1" - (HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath - - expect { brew "upgrade" }.to be_a_success - - expect(HOMEBREW_CELLAR/"testball/0.1").to be_a_directory - expect(HOMEBREW_CELLAR/"testball/0.0.1").not_to exist - end end diff --git a/docs/Manpage.md b/docs/Manpage.md index 1d6ba4da8a..5031083f0f 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -1243,11 +1243,10 @@ Note that environment variables must have a value set to be detected. For exampl This issue typically occurs when using FileVault or custom SSD configurations. - * `HOMEBREW_UPGRADE_CLEANUP`: - If set, `brew upgrade` always assumes `--cleanup` has been passed. - * `HOMEBREW_INSTALL_CLEANUP`: If set, `brew upgrade` always assumes `--cleanup` has been passed. + Additionally, `brew install` and `brew reinstall` will clean up associated + formulae. * `HOMEBREW_VERBOSE`: If set, Homebrew always assumes `--verbose` when running commands. From 6c2f41b90cc77349f594be555aed7d01d5a9f3db Mon Sep 17 00:00:00 2001 From: Jarek Wojciechowski Date: Tue, 30 Oct 2018 10:19:45 -0400 Subject: [PATCH 3/3] Update docs and manpage for HOMEBREW_INSTALL_CLEANUP --- Library/Homebrew/cmd/install.rb | 2 +- Library/Homebrew/cmd/reinstall.rb | 2 +- docs/Manpage.md | 12 ++++++++---- manpages/brew.1 | 8 +++++++- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 26ef6655e4..f7c233b923 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -75,7 +75,7 @@ #: creating patches to the software. #: #: If `HOMEBREW_INSTALL_CLEANUP` is set then remove previously installed versions -#: of upgraded . +#: of upgraded as well as the HOMEBREW_CACHE for that formula. require "missing_formula" require "formula_installer" diff --git a/Library/Homebrew/cmd/reinstall.rb b/Library/Homebrew/cmd/reinstall.rb index 38adf73e0f..6bd1f41f88 100644 --- a/Library/Homebrew/cmd/reinstall.rb +++ b/Library/Homebrew/cmd/reinstall.rb @@ -5,7 +5,7 @@ #: at the end of the run. #: #: If `HOMEBREW_INSTALL_CLEANUP` is set then remove previously installed versions -#: of upgraded . +#: of upgraded as well as the HOMEBREW_CACHE for that formula. require "formula_installer" require "development_tools" diff --git a/docs/Manpage.md b/docs/Manpage.md index 6264439cd4..d033dec5f2 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -311,6 +311,9 @@ With `--verbose` or `-v`, many commands print extra debugging information. Note If `--git` (or `-g`) is passed, Homebrew will create a Git repository, useful for creating patches to the software. + If `HOMEBREW_INSTALL_CLEANUP` is set then remove previously installed versions + of upgraded *`formulae`* as well as the HOMEBREW_CACHE for that formula. + * `leaves`: Show installed formulae that are not dependencies of another installed formula. @@ -428,6 +431,9 @@ With `--verbose` or `-v`, many commands print extra debugging information. Note If `--display-times` is passed, install times for each formula are printed at the end of the run. + If `HOMEBREW_INSTALL_CLEANUP` is set then remove previously installed versions + of upgraded *`formulae`* as well as the HOMEBREW_CACHE for that formula. + * `search`, `-S`: Display all locally available formulae (including tapped ones). No online search is performed. @@ -601,7 +607,7 @@ With `--verbose` or `-v`, many commands print extra debugging information. Note Options for the `install` command are also valid here. - If `--cleanup` is specified or `HOMEBREW_UPGRADE_CLEANUP` is set then remove + If `--cleanup` is specified or `HOMEBREW_INSTALL_CLEANUP` is set then remove previously installed version(s) of upgraded *`formulae`*. If `--fetch-HEAD` is passed, fetch the upstream repository to detect if @@ -1255,10 +1261,8 @@ Note that environment variables must have a value set to be detected. For exampl This issue typically occurs when using FileVault or custom SSD configurations. - * `HOMEBREW_INSTALL_CLEANUP`: + * `HOMEBREW_UPGRADE_CLEANUP`: If set, `brew upgrade` always assumes `--cleanup` has been passed. - Additionally, `brew install` and `brew reinstall` will clean up associated - formulae. * `HOMEBREW_VERBOSE`: If set, Homebrew always assumes `--verbose` when running commands. diff --git a/manpages/brew.1 b/manpages/brew.1 index 48c71f5902..540edab73a 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -315,6 +315,9 @@ If \fB\-\-interactive\fR (or \fB\-i\fR) is passed, download and patch \fIformula .IP If \fB\-\-git\fR (or \fB\-g\fR) is passed, Homebrew will create a Git repository, useful for creating patches to the software\. . +.IP +If \fBHOMEBREW_INSTALL_CLEANUP\fR is set then remove previously installed versions of upgraded \fIformulae\fR as well as the HOMEBREW_CACHE for that formula\. +. .TP \fBleaves\fR Show installed formulae that are not dependencies of another installed formula\. @@ -438,6 +441,9 @@ 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 +If \fBHOMEBREW_INSTALL_CLEANUP\fR is set then remove previously installed versions of upgraded \fIformulae\fR as well as the HOMEBREW_CACHE for that formula\. +. .TP \fBsearch\fR, \fB\-S\fR Display all locally available formulae (including tapped ones)\. No online search is performed\. @@ -614,7 +620,7 @@ Upgrade outdated, unpinned brews (with existing install options)\. Options for the \fBinstall\fR command are also valid here\. . .IP -If \fB\-\-cleanup\fR is specified or \fBHOMEBREW_UPGRADE_CLEANUP\fR is set then remove previously installed version(s) of upgraded \fIformulae\fR\. +If \fB\-\-cleanup\fR is specified or \fBHOMEBREW_INSTALL_CLEANUP\fR is set then remove previously installed version(s) of upgraded \fIformulae\fR\. . .IP If \fB\-\-fetch\-HEAD\fR is passed, fetch the upstream repository to detect if the HEAD installation of the formula is outdated\. Otherwise, the repository\'s HEAD will be checked for updates when a new stable or devel version has been released\.