From 04804c6db5ad4912efb946313930abee97d7fcf8 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Wed, 10 Feb 2021 10:36:40 +0000 Subject: [PATCH] formula: add bottle_hash method. Extract this method from `#to_hash` so it can be used in `brew bundle`. --- Library/Homebrew/formula.rb | 41 ++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 8e81d0b2ec..9ffd65f6f9 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1822,25 +1822,7 @@ class Formula "revision" => stable.specs[:revision], } - if bottle_defined? - bottle_spec = stable.bottle_specification - bottle_info = { - "rebuild" => bottle_spec.rebuild, - "cellar" => (cellar = bottle_spec.cellar).is_a?(Symbol) ? cellar.inspect : cellar, - "prefix" => bottle_spec.prefix, - "root_url" => bottle_spec.root_url, - } - bottle_info["files"] = {} - bottle_spec.collector.each_key do |os| - bottle_url = "#{bottle_spec.root_url}/#{Bottle::Filename.create(self, os, bottle_spec.rebuild).bintray}" - checksum = bottle_spec.collector[os][:checksum] - bottle_info["files"][os] = { - "url" => bottle_url, - "sha256" => checksum.hexdigest, - } - end - hsh["bottle"]["stable"] = bottle_info - end + hsh["bottle"]["stable"] = bottle_hash if bottle_defined? end hsh["options"] = options.map do |opt| @@ -1874,6 +1856,27 @@ class Formula hsh end + # Returns the bottle information for a formula + def bottle_hash + bottle_spec = stable.bottle_specification + hash = { + "rebuild" => bottle_spec.rebuild, + "cellar" => (cellar = bottle_spec.cellar).is_a?(Symbol) ? cellar.inspect : cellar, + "prefix" => bottle_spec.prefix, + "root_url" => bottle_spec.root_url, + "files" => {}, + } + bottle_spec.collector.each_key do |os| + bottle_url = "#{bottle_spec.root_url}/#{Bottle::Filename.create(self, os, bottle_spec.rebuild).bintray}" + checksum = bottle_spec.collector[os][:checksum] + hash["files"][os] = { + "url" => bottle_url, + "sha256" => checksum.hexdigest, + } + end + hash + end + # @private def fetch(verify_download_integrity: true) active_spec.fetch(verify_download_integrity: verify_download_integrity)