diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb index 6512856afa..ccfdd942a8 100644 --- a/Library/Homebrew/software_spec.rb +++ b/Library/Homebrew/software_spec.rb @@ -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 diff --git a/Library/Homebrew/test/software_spec_spec.rb b/Library/Homebrew/test/software_spec_spec.rb index 088fa2ff6a..1cfd058adb 100644 --- a/Library/Homebrew/test/software_spec_spec.rb +++ b/Library/Homebrew/test/software_spec_spec.rb @@ -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) diff --git a/Library/Homebrew/test/support/fixtures/testball_bottle_cellar.rb b/Library/Homebrew/test/support/fixtures/testball_bottle_cellar.rb index feae788169..c647c97971 100644 --- a/Library/Homebrew/test/support/fixtures/testball_bottle_cellar.rb +++ b/Library/Homebrew/test/support/fixtures/testball_bottle_cellar.rb @@ -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