formula: add bottle_hash method.

Extract this method from `#to_hash` so it can be used in `brew bundle`.
This commit is contained in:
Mike McQuaid 2021-02-10 10:36:40 +00:00
parent 455af85235
commit 04804c6db5
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70

View File

@ -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)