software_spec: reverse tag/digest for new bottles.

This new format was agreed in #10377
This commit is contained in:
Mike McQuaid 2021-01-28 12:26:57 +00:00
parent 5f66e15602
commit fc1c142ebd
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70
3 changed files with 24 additions and 13 deletions

View File

@ -403,17 +403,28 @@ class BottleSpecification
# a Hash, which indicates the platform the checksum applies on.
# Example bottle block syntax:
# bottle do
# sha256 "69489ae397e4645..." => :big_sur, :cellar => :any_skip_relocation
# sha256 "449de5ea35d0e94..." => :catalina, :cellar => :any
# sha256 cellar: :any_skip_relocation, big_sur: "69489ae397e4645..."
# sha256 cellar: :any, catalina: "449de5ea35d0e94..."
# end
# Example args:
# {"69489ae397e4645..."=> :big_sur, :cellar=>:any_skip_relocation}
def sha256(hash)
sha256_regex = /^[a-f0-9]{64}$/i
digest, tag = hash.find do |key, value|
key.is_a?(String) && value.is_a?(Symbol) && key.match?(sha256_regex)
# find new `sha256 big_sur: "69489ae397e4645..."` format
tag, digest = hash.find do |key, value|
key.is_a?(Symbol) && value.is_a?(String) && value.match?(sha256_regex)
end
cellar = hash[:cellar] || all_tags_cellar
if digest && tag
# the cellar hash key only exists on the new format
cellar = hash[:cellar]
else
# otherwise, find old `sha256 "69489ae397e4645..." => :big_sur` format
digest, tag = hash.find do |key, value|
key.is_a?(String) && value.is_a?(Symbol) && key.match?(sha256_regex)
end
end
cellar ||= all_tags_cellar
collector[tag] = { checksum: Checksum.new(digest), cellar: cellar }
end

View File

@ -201,14 +201,14 @@ describe BottleSpecification do
it "works with cellar" do
checksums = [
{ digest: "deadbeef" * 8, tag: :snow_leopard_32, cellar: :any_skip_relocation },
{ digest: "faceb00c" * 8, tag: :snow_leopard, cellar: :any },
{ digest: "baadf00d" * 8, tag: :lion, cellar: "/usr/local/Cellar" },
{ digest: "8badf00d" * 8, tag: :mountain_lion, cellar: Homebrew::DEFAULT_CELLAR },
{ cellar: :any_skip_relocation, tag: :snow_leopard_32, digest: "deadbeef" * 8 },
{ cellar: :any, tag: :snow_leopard, digest: "faceb00c" * 8 },
{ cellar: "/usr/local/Cellar", tag: :lion, digest: "baadf00d" * 8 },
{ cellar: Homebrew::DEFAULT_CELLAR, tag: :mountain_lion, digest: "8badf00d" * 8 },
]
checksums.each do |checksum|
subject.sha256(checksum[:digest] => checksum[:tag], cellar: checksum[:cellar])
subject.sha256(checksum[:tag] => checksum[:digest], cellar: checksum[:cellar])
digest, tag, cellar = subject.checksum_for(checksum[:tag])
expect(Checksum.new(checksum[:digest])).to eq(digest)
expect(checksum[:tag]).to eq(tag)

View File

@ -10,7 +10,7 @@ class TestballBottleCellar < Formula
hexdigest = "8f9aecd233463da6a4ea55f5f88fc5841718c013f3e2a7941350d6130f1dc149"
stable.bottle do
root_url "file://#{TEST_FIXTURE_DIR}/bottles"
sha256 hexdigest => Utils::Bottles.tag, :cellar => :any_skip_relocation
sha256 cellar: :any_skip_relocation, Utils::Bottles.tag => hexdigest
end
cxxstdlib_check :skip
end