diff --git a/Library/Homebrew/build.rb b/Library/Homebrew/build.rb index 98ad387ce2..c63f45f97e 100644 --- a/Library/Homebrew/build.rb +++ b/Library/Homebrew/build.rb @@ -114,7 +114,9 @@ class Build with_env(new_env) do formula.extend(Debrew::Formula) if ARGV.debug? - formula.brew do |_formula, staging| + formula.update_head_version + + formula.brew(fetch: false) do |_formula, staging| # For head builds, HOMEBREW_FORMULA_PREFIX should include the commit, # which is not known until after the formula has been staged. ENV["HOMEBREW_FORMULA_PREFIX"] = formula.prefix diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index faa86fceec..c33d151c9c 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1012,11 +1012,11 @@ class Formula self.build = Tab.for_formula(self) new_env = { - "TMPDIR" => HOMEBREW_TEMP, - "TEMP" => HOMEBREW_TEMP, - "TMP" => HOMEBREW_TEMP, - "HOMEBREW_PATH" => nil, - "PATH" => ENV["HOMEBREW_PATH"], + TMPDIR: HOMEBREW_TEMP, + TEMP: HOMEBREW_TEMP, + TMP: HOMEBREW_TEMP, + HOMEBREW_PATH: nil, + PATH: ENV["HOMEBREW_PATH"], } with_env(new_env) do @@ -1160,11 +1160,12 @@ class Formula # yields |self,staging| with current working directory set to the uncompressed tarball # where staging is a Mktemp staging context # @private - def brew + def brew(fetch: true) @prefix_returns_versioned_prefix = true + active_spec.fetch if fetch stage do |staging| staging.retain! if Homebrew.args.keep_tmp? - prepare_patches + fetch_patches if fetch begin yield self, staging @@ -2078,6 +2079,13 @@ class Formula ENV.update(removed) end + def fetch_patches + active_spec.add_legacy_patches(patches) if respond_to?(:patches) + + patchlist.grep(DATAPatch) { |p| p.path = path } + patchlist.select(&:external?).each(&:fetch) + end + private # Returns the prefix for a given formula version number. @@ -2147,13 +2155,6 @@ class Formula end end - def prepare_patches - active_spec.add_legacy_patches(patches) if respond_to?(:patches) - - patchlist.grep(DATAPatch) { |p| p.path = path } - patchlist.select(&:external?).each(&:fetch) - end - # The methods below define the formula DSL. class << self include BuildEnvironment::DSL diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index d51ad3780b..dcf57c4d66 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -977,6 +977,11 @@ class FormulaInstaller return if only_deps? + unless pour_bottle? + formula.fetch_patches + formula.resources.each(&:fetch) + end + downloader.fetch end @@ -986,7 +991,7 @@ class FormulaInstaller elsif pour_bottle? formula.bottle else - formula.downloader + formula end end diff --git a/Library/Homebrew/patch.rb b/Library/Homebrew/patch.rb index db49f65e79..1050e5bdf4 100644 --- a/Library/Homebrew/patch.rb +++ b/Library/Homebrew/patch.rb @@ -117,8 +117,8 @@ class ExternalPatch attr_reader :resource, :strip def_delegators :resource, - :url, :fetch, :patch_files, :verify_download_integrity, :cached_download, - :clear_cache + :url, :fetch, :patch_files, :verify_download_integrity, + :cached_download, :downloaded?, :clear_cache def initialize(strip, &block) @strip = strip diff --git a/Library/Homebrew/resource.rb b/Library/Homebrew/resource.rb index 1f245fd719..dec25c6de1 100644 --- a/Library/Homebrew/resource.rb +++ b/Library/Homebrew/resource.rb @@ -55,6 +55,10 @@ class Resource "#{owner.name}--#{escaped_name}" end + def downloaded? + cached_download.exist? + end + def cached_download downloader.cached_location end @@ -68,17 +72,19 @@ class Resource # directory. Subclasses that override stage should implement the tmp # dir using {Mktemp} so that works with all subtypes. def stage(target = nil, &block) - raise ArgumentError, "target directory or block is required" unless target || block + raise ArgumentError, "target directory or block is required" if target.blank? && block.blank? - fetch - prepare_patches + fetch_patches(skip_downloaded: true) + fetch unless downloaded? unpack(target, &block) end - def prepare_patches + def fetch_patches(skip_downloaded: false) patches.grep(DATAPatch) { |p| p.path = owner.owner.path } - patches.select(&:external?).each(&:fetch) + patches.select!(&:external?) + patches.reject!(&:downloaded?) if skip_downloaded + patches.each(&:fetch) end def apply_patches @@ -115,6 +121,8 @@ class Resource def fetch(verify_download_integrity: true) HOMEBREW_CACHE.mkpath + fetch_patches + begin downloader.fetch rescue ErrorDuringExecution, CurlDownloadStrategyError => e