Skip to content

Commit

Permalink
software_spec: reverse tag/digest for new bottles.
Browse files Browse the repository at this point in the history
This new format was agreed in Homebrew#10377
  • Loading branch information
MikeMcQuaid committed Jan 28, 2021
1 parent 5f66e15 commit fc1c142
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
25 changes: 18 additions & 7 deletions Library/Homebrew/software_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -403,17 +403,28 @@ def tag?(tag)
# 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

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 = hash[:cellar] || all_tags_cellar

cellar ||= all_tags_cellar
collector[tag] = { checksum: Checksum.new(digest), cellar: cellar }
end

Expand Down
10 changes: 5 additions & 5 deletions Library/Homebrew/test/software_spec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,14 @@

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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def initialize(name = "testball_bottle", path = Pathname.new(__FILE__).expand_pa
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
Expand Down

0 comments on commit fc1c142

Please sign in to comment.