From 2264c08cee95f0c829a6826d23c6285762e2d515 Mon Sep 17 00:00:00 2001 From: Michelle Nguyen Date: Wed, 4 Mar 2020 17:48:17 -0500 Subject: [PATCH 1/3] Fetch formula resources before unlinking during upgrade. Fixes #6374. --- Library/Homebrew/cask/installer.rb | 1 + Library/Homebrew/cmd/install.rb | 1 + Library/Homebrew/cmd/upgrade.rb | 2 ++ Library/Homebrew/formula.rb | 1 + Library/Homebrew/formula_installer.rb | 36 +++++++++++++++---- Library/Homebrew/reinstall.rb | 1 + Library/Homebrew/resource.rb | 2 +- .../test/formula_installer_bottle_spec.rb | 5 ++- .../Homebrew/test/formula_installer_spec.rb | 2 ++ Library/Homebrew/test/formulary_spec.rb | 2 ++ .../spec/shared_context/integration_test.rb | 1 + 11 files changed, 45 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/cask/installer.rb b/Library/Homebrew/cask/installer.rb index 212e40720a..369b05f1d0 100644 --- a/Library/Homebrew/cask/installer.rb +++ b/Library/Homebrew/cask/installer.rb @@ -369,6 +369,7 @@ module Cask fi.show_header = true fi.verbose = verbose? fi.prelude + fi.fetch fi.install fi.finish end diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 7d60894b9b..ef95b00c76 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -326,6 +326,7 @@ module Homebrew fi.interactive = args.interactive? fi.git = args.git? fi.prelude + fi.fetch fi.install fi.finish rescue FormulaInstallationAlreadyAttemptedError diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index 80841542a2..f417c7c54f 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -192,6 +192,8 @@ module Homebrew end oh1 "Upgrading #{Formatter.identifier(f.full_specified_name)} #{upgrade_version} #{fi.options.to_a.join(" ")}" + fi.fetch + # first we unlink the currently active keg for this formula otherwise it is # possible for the existing build to interfere with the build we are about to # do! Seriously, it happens! diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index f431b19dfa..499937efd3 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1160,6 +1160,7 @@ class Formula # @private def brew @prefix_returns_versioned_prefix = true + active_spec.fetch stage do |staging| staging.retain! if Homebrew.args.keep_tmp? prepare_patches diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index dcce9bbb84..7c5e82cba9 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -600,6 +600,7 @@ class FormulaInstaller fi.installed_as_dependency = true fi.installed_on_request = df.any_version_installed? && tab.installed_on_request fi.prelude + fi.fetch oh1 "Installing #{formula.full_name} dependency: #{Formatter.identifier(dep.name)}" fi.install fi.finish @@ -946,14 +947,35 @@ class FormulaInstaller @show_summary_heading = true end - def pour - if (bottle_path = formula.local_bottle_path) - downloader = LocalBottleDownloadStrategy.new(bottle_path) - else - downloader = formula.bottle - downloader.fetch - end + def fetch_dependencies + deps = compute_dependencies + return if deps.empty? || ignore_deps? + + deps.each do |dep, _| + dep.to_formula.resources.each(&:fetch) + end + end + + def fetch + fetch_dependencies + + return if only_deps? + + downloader.fetch + end + + def downloader + if (bottle_path = formula.local_bottle_path) + LocalBottleDownloadStrategy.new(bottle_path) + elsif pour_bottle? + formula.bottle + else + formula.downloader + end + end + + def pour HOMEBREW_CELLAR.cd do downloader.stage end diff --git a/Library/Homebrew/reinstall.rb b/Library/Homebrew/reinstall.rb index 8fc5ed649d..be7f9c847e 100644 --- a/Library/Homebrew/reinstall.rb +++ b/Library/Homebrew/reinstall.rb @@ -36,6 +36,7 @@ module Homebrew fi.installed_on_request = tab.installed_on_request end fi.prelude + fi.fetch oh1 "Reinstalling #{Formatter.identifier(f.full_name)} #{options.to_a.join " "}" diff --git a/Library/Homebrew/resource.rb b/Library/Homebrew/resource.rb index 920a787c3f..2d7d6f6d03 100644 --- a/Library/Homebrew/resource.rb +++ b/Library/Homebrew/resource.rb @@ -70,8 +70,8 @@ class Resource def stage(target = nil, &block) raise ArgumentError, "target directory or block is required" unless target || block - fetch prepare_patches + unpack(target, &block) end diff --git a/Library/Homebrew/test/formula_installer_bottle_spec.rb b/Library/Homebrew/test/formula_installer_bottle_spec.rb index d1a86b59c2..b5e715260f 100644 --- a/Library/Homebrew/test/formula_installer_bottle_spec.rb +++ b/Library/Homebrew/test/formula_installer_bottle_spec.rb @@ -23,7 +23,10 @@ describe FormulaInstaller do stub_formula_loader formula("gcc") { url "gcc-1.0" } stub_formula_loader formula("patchelf") { url "patchelf-1.0" } allow(Formula["patchelf"]).to receive(:latest_version_installed?).and_return(true) - described_class.new(formula).install + + fi = FormulaInstaller.new(formula) + fi.fetch + fi.install keg = Keg.new(formula.prefix) diff --git a/Library/Homebrew/test/formula_installer_spec.rb b/Library/Homebrew/test/formula_installer_spec.rb index d7dcd713c1..cd5856a0bf 100644 --- a/Library/Homebrew/test/formula_installer_spec.rb +++ b/Library/Homebrew/test/formula_installer_spec.rb @@ -21,6 +21,7 @@ describe FormulaInstaller do installer = described_class.new(formula) + installer.fetch installer.install keg = Keg.new(formula.prefix) @@ -158,6 +159,7 @@ describe FormulaInstaller do it "shows audit problems if HOMEBREW_DEVELOPER is set" do ENV["HOMEBREW_DEVELOPER"] = "1" + formula_installer.fetch formula_installer.install expect(formula_installer).to receive(:audit_installed).and_call_original formula_installer.caveats diff --git a/Library/Homebrew/test/formulary_spec.rb b/Library/Homebrew/test/formulary_spec.rb index 3170b71cb2..157b608050 100644 --- a/Library/Homebrew/test/formulary_spec.rb +++ b/Library/Homebrew/test/formulary_spec.rb @@ -149,6 +149,7 @@ describe Formulary do let(:installer) { FormulaInstaller.new(installed_formula) } it "returns a Formula when given a rack" do + installer.fetch installer.install f = described_class.from_rack(installed_formula.rack) @@ -156,6 +157,7 @@ describe Formulary do end it "returns a Formula when given a Keg" do + installer.fetch installer.install keg = Keg.new(installed_formula.prefix) diff --git a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb index 0a28b8b558..cbc933817d 100644 --- a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb +++ b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb @@ -177,6 +177,7 @@ RSpec.shared_context "integration test" do fi = FormulaInstaller.new(Formula[name]) fi.build_bottle = build_bottle fi.prelude + fi.fetch fi.install fi.finish end From 48918bb5e33440d97c7ce12186b97fb0026e4bbf Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sun, 3 May 2020 14:53:50 +0100 Subject: [PATCH 2/3] formula_installer: add fetch_dependency method. This uses `FormulaInstaller#fetch` to recursively fetch dependencies through the dependency tree and allows `install_dependency` to not do any fetching. --- Library/Homebrew/formula_installer.rb | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 7c5e82cba9..9dbb75674e 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -561,6 +561,18 @@ class FormulaInstaller @show_header = true unless deps.empty? end + def fetch_dependency(dep) + df = dep.to_formula + fi = FormulaInstaller.new(df) + + fi.build_from_source = Homebrew.args.build_formula_from_source?(df) + fi.force_bottle = false + fi.verbose = verbose? + fi.quiet = quiet? + fi.debug = debug? + fi.fetch + end + def install_dependency(dep, inherited_options) df = dep.to_formula tab = Tab.for_formula(df) @@ -600,7 +612,6 @@ class FormulaInstaller fi.installed_as_dependency = true fi.installed_on_request = df.any_version_installed? && tab.installed_on_request fi.prelude - fi.fetch oh1 "Installing #{formula.full_name} dependency: #{Formatter.identifier(dep.name)}" fi.install fi.finish @@ -952,9 +963,7 @@ class FormulaInstaller return if deps.empty? || ignore_deps? - deps.each do |dep, _| - dep.to_formula.resources.each(&:fetch) - end + deps.each { |dep, _options| fetch_dependency(dep) } end def fetch From 08a9f0e1c093a8de3acb31c5bc12664cfeecd102 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sun, 3 May 2020 14:54:31 +0100 Subject: [PATCH 3/3] Use FormulaInstaller#fetch before #prelude. --- Library/Homebrew/cask/installer.rb | 2 +- Library/Homebrew/cmd/install.rb | 2 +- Library/Homebrew/cmd/upgrade.rb | 2 +- Library/Homebrew/reinstall.rb | 2 +- .../test/support/helper/spec/shared_context/integration_test.rb | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/cask/installer.rb b/Library/Homebrew/cask/installer.rb index 369b05f1d0..503962e308 100644 --- a/Library/Homebrew/cask/installer.rb +++ b/Library/Homebrew/cask/installer.rb @@ -368,8 +368,8 @@ module Cask fi.installed_on_request = false fi.show_header = true fi.verbose = verbose? - fi.prelude fi.fetch + fi.prelude fi.install fi.finish end diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index ef95b00c76..03f373447d 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -325,8 +325,8 @@ module Homebrew fi.build_bottle = args.build_bottle? fi.interactive = args.interactive? fi.git = args.git? - fi.prelude fi.fetch + fi.prelude fi.install fi.finish rescue FormulaInstallationAlreadyAttemptedError diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index f417c7c54f..df2481fb10 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -183,7 +183,6 @@ module Homebrew fi.installed_as_dependency = tab.installed_as_dependency fi.installed_on_request ||= tab.installed_on_request end - fi.prelude upgrade_version = if f.optlinked? "#{Keg.new(f.opt_prefix).version} -> #{f.pkg_version}" @@ -193,6 +192,7 @@ module Homebrew oh1 "Upgrading #{Formatter.identifier(f.full_specified_name)} #{upgrade_version} #{fi.options.to_a.join(" ")}" fi.fetch + fi.prelude # first we unlink the currently active keg for this formula otherwise it is # possible for the existing build to interfere with the build we are about to diff --git a/Library/Homebrew/reinstall.rb b/Library/Homebrew/reinstall.rb index be7f9c847e..ff3c5707f2 100644 --- a/Library/Homebrew/reinstall.rb +++ b/Library/Homebrew/reinstall.rb @@ -35,8 +35,8 @@ module Homebrew fi.installed_as_dependency = tab.installed_as_dependency fi.installed_on_request = tab.installed_on_request end - fi.prelude fi.fetch + fi.prelude oh1 "Reinstalling #{Formatter.identifier(f.full_name)} #{options.to_a.join " "}" diff --git a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb index cbc933817d..3f4468a3a7 100644 --- a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb +++ b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb @@ -176,8 +176,8 @@ RSpec.shared_context "integration test" do setup_test_formula(name, content) fi = FormulaInstaller.new(Formula[name]) fi.build_bottle = build_bottle - fi.prelude fi.fetch + fi.prelude fi.install fi.finish end