cellars: write tag specific cellars

With #10186 now merged, the tag specific cellar information is being read by brew.
This PR (once merged) will start adding the cellar information for each tag instead
of having a single cellar line on the top of the bottle block.

Each new CI build in homebrew-core will slowly start migrating the cellar lines to
the right place. If keep-old is used, the old "all tag" cellar line is removed and
added to each tag.
This commit is contained in:
Michka Popoff 2021-01-20 23:26:41 +01:00 committed by Mike McQuaid
parent fc1c142ebd
commit de2e309d50
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70
3 changed files with 99 additions and 67 deletions

View File

@ -20,19 +20,11 @@ BOTTLE_ERB = <<-EOS
HOMEBREW_LINUX_DEFAULT_PREFIX].include?(prefix) %> HOMEBREW_LINUX_DEFAULT_PREFIX].include?(prefix) %>
prefix "<%= prefix %>" prefix "<%= prefix %>"
<% end %> <% end %>
<% if cellar.is_a? Symbol %>
cellar :<%= cellar %>
<% elsif ![Homebrew::DEFAULT_MACOS_CELLAR,
Homebrew::DEFAULT_MACOS_ARM_CELLAR,
Homebrew::DEFAULT_LINUX_CELLAR].include?(cellar) %>
cellar "<%= cellar %>"
<% end %>
<% if rebuild.positive? %> <% if rebuild.positive? %>
rebuild <%= rebuild %> rebuild <%= rebuild %>
<% end %> <% end %>
<% checksums.each do |checksum_value| %> <% sha256_lines.each do |line| %>
<% checksum, macos = checksum_value.shift %> <%= line %>
sha256 "<%= checksum %>" => :<%= macos %>
<% end %> <% end %>
end end
EOS EOS
@ -202,9 +194,29 @@ module Homebrew
!absolute_symlinks_start_with_string.empty? !absolute_symlinks_start_with_string.empty?
end end
def generate_sha256_line(tag, digest, cellar)
line = %Q(sha256 "#{digest}" => :#{tag})
return line if cellar.blank?
return "#{line}, :cellar => :#{cellar}" if cellar.is_a? Symbol
default_cellars = [
Homebrew::DEFAULT_MACOS_CELLAR,
Homebrew::DEFAULT_MACOS_ARM_CELLAR,
Homebrew::DEFAULT_LINUX_CELLAR,
]
return %Q(#{line}, :cellar => "#{cellar}") if default_cellars.exclude?(cellar)
line
end
def bottle_output(bottle) def bottle_output(bottle)
sha256_lines = bottle.checksums.map do |checksum|
generate_sha256_line(checksum["tag"], checksum["digest"], checksum["cellar"])
end
erb_binding = bottle.instance_eval { binding }
erb_binding.local_variable_set(:sha256_lines, sha256_lines)
erb = ERB.new BOTTLE_ERB erb = ERB.new BOTTLE_ERB
erb.result(bottle.instance_eval { binding }).gsub(/^\s*$\n/, "") erb.result(erb_binding).gsub(/^\s*$\n/, "")
end end
def sudo_purge def sudo_purge
@ -451,19 +463,14 @@ module Homebrew
def merge_json_files(json_files) def merge_json_files(json_files)
json_files.reduce({}) do |hash, json_file| json_files.reduce({}) do |hash, json_file|
hash.deep_merge(json_file) do |key, first, second| json_file.each_value do |json_hash|
if key == "cellar" json_bottle = json_hash["bottle"]
# Prioritize HOMEBREW_CELLAR over :any over :any_skip_relocation cellar = json_bottle.delete("cellar")
cellars = [first, second] json_bottle["tags"].each_value do |json_platform|
next HOMEBREW_CELLAR if cellars.include?(HOMEBREW_CELLAR) json_platform["cellar"] ||= cellar
next first if first.start_with?("/")
next second if second.start_with?("/")
next "any" if cellars.include?("any")
next "any_skip_relocation" if cellars.include?("any_skip_relocation")
end end
second
end end
hash.deep_merge(json_file)
end end
end end
@ -476,13 +483,13 @@ module Homebrew
bottle = BottleSpecification.new bottle = BottleSpecification.new
bottle.root_url bottle_hash["bottle"]["root_url"] bottle.root_url bottle_hash["bottle"]["root_url"]
cellar = bottle_hash["bottle"]["cellar"]
cellar = cellar.to_sym if any_cellars.include?(cellar)
bottle.cellar cellar
bottle.prefix bottle_hash["bottle"]["prefix"] bottle.prefix bottle_hash["bottle"]["prefix"]
bottle.rebuild bottle_hash["bottle"]["rebuild"] bottle.rebuild bottle_hash["bottle"]["rebuild"]
bottle_hash["bottle"]["tags"].each do |tag, tag_hash| bottle_hash["bottle"]["tags"].each do |tag, tag_hash|
bottle.sha256 tag_hash["sha256"] => tag.to_sym cellar = tag_hash["cellar"]
cellar = cellar.to_sym if any_cellars.include?(cellar)
sha256_hash = { tag_hash["sha256"] => tag.to_sym, :cellar => cellar }
bottle.sha256 sha256_hash
end end
if args.write? if args.write?
@ -533,16 +540,16 @@ module Homebrew
new_values = { new_values = {
root_url: new_bottle_hash["root_url"], root_url: new_bottle_hash["root_url"],
prefix: new_bottle_hash["prefix"], prefix: new_bottle_hash["prefix"],
cellar: new_bottle_hash["cellar"],
rebuild: new_bottle_hash["rebuild"], rebuild: new_bottle_hash["rebuild"],
} }
skip_keys = [:sha256, :cellar]
old_keys.each do |key| old_keys.each do |key|
next if key == :sha256 next if skip_keys.include?(key)
old_value = old_bottle_spec.send(key).to_s old_value = old_bottle_spec.send(key).to_s
new_value = new_values[key].to_s new_value = new_values[key].to_s
next if key == :cellar && old_value == "any" && new_value == "any_skip_relocation"
next if old_value.present? && new_value == old_value next if old_value.present? && new_value == old_value
mismatches << "#{key}: old: #{old_value.inspect}, new: #{new_value.inspect}" mismatches << "#{key}: old: #{old_value.inspect}, new: #{new_value.inspect}"
@ -551,12 +558,14 @@ module Homebrew
return [mismatches, checksums] if old_keys.exclude? :sha256 return [mismatches, checksums] if old_keys.exclude? :sha256
old_bottle_spec.collector.each_key do |tag| old_bottle_spec.collector.each_key do |tag|
old_value = old_bottle_spec.collector[tag][:checksum].hexdigest old_checksum_hash = old_bottle_spec.collector[tag]
old_hexdigest = old_checksum_hash[:checksum].hexdigest
old_cellar = old_checksum_hash[:cellar]
new_value = new_bottle_hash.dig("tags", tag.to_s) new_value = new_bottle_hash.dig("tags", tag.to_s)
if new_value.present? if new_value.present?
mismatches << "sha256 => #{tag}" mismatches << "sha256 => #{tag}"
else else
checksums << { old_value => tag } checksums << { old_hexdigest => tag, :cellar => old_cellar }
end end
end end

View File

@ -442,8 +442,9 @@ class BottleSpecification
end end
tags.reverse.map do |tag| tags.reverse.map do |tag|
{ {
collector[tag][:checksum] => tag, "tag" => tag,
cellar: collector[tag][:cellar], "digest" => collector[tag][:checksum],
"cellar" => collector[tag][:cellar],
} }
end end
end end

View File

@ -149,24 +149,26 @@ describe Homebrew do
) )
hello_hash = bottles_hash["hello"] hello_hash = bottles_hash["hello"]
expect(hello_hash["bottle"]["cellar"]).to eq("any_skip_relocation") expect(hello_hash["bottle"]["tags"]["big_sur"]["cellar"]).to eq("any_skip_relocation")
expect(hello_hash["bottle"]["tags"]["big_sur"]["filename"]).to eq("hello-1.0.big_sur.bottle.tar.gz") expect(hello_hash["bottle"]["tags"]["big_sur"]["filename"]).to eq("hello-1.0.big_sur.bottle.tar.gz")
expect(hello_hash["bottle"]["tags"]["big_sur"]["local_filename"]).to eq("hello--1.0.big_sur.bottle.tar.gz") expect(hello_hash["bottle"]["tags"]["big_sur"]["local_filename"]).to eq("hello--1.0.big_sur.bottle.tar.gz")
expect(hello_hash["bottle"]["tags"]["big_sur"]["sha256"]).to eq( expect(hello_hash["bottle"]["tags"]["big_sur"]["sha256"]).to eq(
"a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f", "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f",
) )
expect(hello_hash["bottle"]["tags"]["catalina"]["cellar"]).to eq("any_skip_relocation")
expect(hello_hash["bottle"]["tags"]["catalina"]["filename"]).to eq("hello-1.0.catalina.bottle.tar.gz") expect(hello_hash["bottle"]["tags"]["catalina"]["filename"]).to eq("hello-1.0.catalina.bottle.tar.gz")
expect(hello_hash["bottle"]["tags"]["catalina"]["local_filename"]).to eq("hello--1.0.catalina.bottle.tar.gz") expect(hello_hash["bottle"]["tags"]["catalina"]["local_filename"]).to eq("hello--1.0.catalina.bottle.tar.gz")
expect(hello_hash["bottle"]["tags"]["catalina"]["sha256"]).to eq( expect(hello_hash["bottle"]["tags"]["catalina"]["sha256"]).to eq(
"5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac", "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac",
) )
unzip_hash = bottles_hash["unzip"] unzip_hash = bottles_hash["unzip"]
expect(unzip_hash["bottle"]["cellar"]).to eq("any") expect(unzip_hash["bottle"]["tags"]["big_sur"]["cellar"]).to eq("any_skip_relocation")
expect(unzip_hash["bottle"]["tags"]["big_sur"]["filename"]).to eq("unzip-2.0.big_sur.bottle.tar.gz") expect(unzip_hash["bottle"]["tags"]["big_sur"]["filename"]).to eq("unzip-2.0.big_sur.bottle.tar.gz")
expect(unzip_hash["bottle"]["tags"]["big_sur"]["local_filename"]).to eq("unzip--2.0.big_sur.bottle.tar.gz") expect(unzip_hash["bottle"]["tags"]["big_sur"]["local_filename"]).to eq("unzip--2.0.big_sur.bottle.tar.gz")
expect(unzip_hash["bottle"]["tags"]["big_sur"]["sha256"]).to eq( expect(unzip_hash["bottle"]["tags"]["big_sur"]["sha256"]).to eq(
"16cf230afdfcb6306c208d169549cf8773c831c8653d2c852315a048960d7e72", "16cf230afdfcb6306c208d169549cf8773c831c8653d2c852315a048960d7e72",
) )
expect(unzip_hash["bottle"]["tags"]["catalina"]["cellar"]).to eq("any")
expect(unzip_hash["bottle"]["tags"]["catalina"]["filename"]).to eq("unzip-2.0.catalina.bottle.tar.gz") expect(unzip_hash["bottle"]["tags"]["catalina"]["filename"]).to eq("unzip-2.0.catalina.bottle.tar.gz")
expect(unzip_hash["bottle"]["tags"]["catalina"]["local_filename"]).to eq("unzip--2.0.catalina.bottle.tar.gz") expect(unzip_hash["bottle"]["tags"]["catalina"]["local_filename"]).to eq("unzip--2.0.catalina.bottle.tar.gz")
expect(unzip_hash["bottle"]["tags"]["catalina"]["sha256"]).to eq( expect(unzip_hash["bottle"]["tags"]["catalina"]["sha256"]).to eq(
@ -202,16 +204,6 @@ describe Homebrew do
] ]
end end
it "checks for conflicting cellar" do
old_spec = BottleSpecification.new
old_spec.cellar("/opt/failbrew/Cellar")
new_hash = { "cellar" => "/opt/testbrew/Cellar" }
expect(homebrew.merge_bottle_spec([:cellar], old_spec, new_hash)).to eq [
['cellar: old: "/opt/failbrew/Cellar", new: "/opt/testbrew/Cellar"'],
[],
]
end
it "checks for conflicting rebuild number" do it "checks for conflicting rebuild number" do
old_spec = BottleSpecification.new old_spec = BottleSpecification.new
old_spec.rebuild(1) old_spec.rebuild(1)
@ -227,12 +219,48 @@ describe Homebrew do
old_spec.sha256("109c0cb581a7b5d84da36d84b221fb9dd0f8a927b3044d82611791c9907e202e" => :catalina) old_spec.sha256("109c0cb581a7b5d84da36d84b221fb9dd0f8a927b3044d82611791c9907e202e" => :catalina)
old_spec.sha256("7571772bf7a0c9fe193e70e521318b53993bee6f351976c9b6e01e00d13d6c3f" => :mojave) old_spec.sha256("7571772bf7a0c9fe193e70e521318b53993bee6f351976c9b6e01e00d13d6c3f" => :mojave)
new_hash = { "tags" => { "catalina" => "ec6d7f08412468f28dee2be17ad8cd8b883b16b34329efcecce019b8c9736428" } } new_hash = { "tags" => { "catalina" => "ec6d7f08412468f28dee2be17ad8cd8b883b16b34329efcecce019b8c9736428" } }
expected_checksum_hash = { "7571772bf7a0c9fe193e70e521318b53993bee6f351976c9b6e01e00d13d6c3f" => :mojave }
expected_checksum_hash[:cellar] = Homebrew::DEFAULT_CELLAR
expect(homebrew.merge_bottle_spec([:sha256], old_spec, new_hash)).to eq [ expect(homebrew.merge_bottle_spec([:sha256], old_spec, new_hash)).to eq [
["sha256 => catalina"], ["sha256 => catalina"],
[{ "7571772bf7a0c9fe193e70e521318b53993bee6f351976c9b6e01e00d13d6c3f" => :mojave }], [expected_checksum_hash],
] ]
end end
end end
describe "::generate_sha256_line", :needs_linux do
it "generates a string without cellar" do
expect(homebrew.generate_sha256_line(:catalina, "deadbeef", nil)).to eq(
<<~RUBY.chomp,
sha256 "deadbeef" => :catalina
RUBY
)
end
it "generates a string with cellar symbol" do
expect(homebrew.generate_sha256_line(:catalina, "deadbeef", :any)).to eq(
<<~RUBY.chomp,
sha256 "deadbeef" => :catalina, :cellar => :any
RUBY
)
end
it "generates a string with default cellar path" do
expect(homebrew.generate_sha256_line(:catalina, "deadbeef", Homebrew::DEFAULT_LINUX_CELLAR)).to eq(
<<~RUBY.chomp,
sha256 "deadbeef" => :catalina
RUBY
)
end
it "generates a string with non-default cellar path" do
expect(homebrew.generate_sha256_line(:catalina, "deadbeef", "/home/test")).to eq(
<<~RUBY.chomp,
sha256 "deadbeef" => :catalina, :cellar => "/home/test"
RUBY
)
end
end
end end
describe "brew bottle --merge", :integration_test, :needs_linux do describe "brew bottle --merge", :integration_test, :needs_linux do
@ -292,9 +320,8 @@ describe "brew bottle --merge", :integration_test, :needs_linux do
==> testball ==> testball
bottle do bottle do
root_url "#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}" root_url "#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}"
cellar :any_skip_relocation sha256 "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f" => :big_sur, :cellar => :any_skip_relocation
sha256 "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f" => :big_sur sha256 "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" => :catalina, :cellar => :any_skip_relocation
sha256 "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" => :catalina
end end
EOS EOS
@ -307,9 +334,8 @@ describe "brew bottle --merge", :integration_test, :needs_linux do
bottle do bottle do
root_url "#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}" root_url "#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}"
cellar :any_skip_relocation sha256 "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f" => :big_sur, :cellar => :any_skip_relocation
sha256 "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f" => :big_sur sha256 "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" => :catalina, :cellar => :any_skip_relocation
sha256 "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" => :catalina
end end
option "with-foo", "Build with foo" option "with-foo", "Build with foo"
@ -357,9 +383,8 @@ describe "brew bottle --merge", :integration_test, :needs_linux do
==> testball ==> testball
bottle do bottle do
root_url "#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}" root_url "#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}"
cellar :any_skip_relocation sha256 "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f" => :big_sur, :cellar => :any_skip_relocation
sha256 "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f" => :big_sur sha256 "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" => :catalina, :cellar => :any_skip_relocation
sha256 "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" => :catalina
end end
EOS EOS
@ -374,9 +399,8 @@ describe "brew bottle --merge", :integration_test, :needs_linux do
bottle do bottle do
root_url "#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}" root_url "#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}"
cellar :any_skip_relocation sha256 "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f" => :big_sur, :cellar => :any_skip_relocation
sha256 "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f" => :big_sur sha256 "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" => :catalina, :cellar => :any_skip_relocation
sha256 "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" => :catalina
end end
def install def install
@ -421,7 +445,7 @@ describe "brew bottle --merge", :integration_test, :needs_linux do
bottle do bottle do
root_url "#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}" root_url "#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}"
cellar :any_skip_relocation cellar :any
sha256 "6971b6eebf4c00eaaed72a1104a49be63861eabc95d679a0c84040398e320059" => :high_sierra sha256 "6971b6eebf4c00eaaed72a1104a49be63861eabc95d679a0c84040398e320059" => :high_sierra
end end
EOS EOS
@ -440,10 +464,9 @@ describe "brew bottle --merge", :integration_test, :needs_linux do
==> testball ==> testball
bottle do bottle do
root_url "#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}" root_url "#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}"
cellar :any_skip_relocation sha256 "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f" => :big_sur, :cellar => :any_skip_relocation
sha256 "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f" => :big_sur sha256 "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" => :catalina, :cellar => :any_skip_relocation
sha256 "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" => :catalina sha256 "6971b6eebf4c00eaaed72a1104a49be63861eabc95d679a0c84040398e320059" => :high_sierra, :cellar => :any
sha256 "6971b6eebf4c00eaaed72a1104a49be63861eabc95d679a0c84040398e320059" => :high_sierra
end end
EOS EOS
@ -458,10 +481,9 @@ describe "brew bottle --merge", :integration_test, :needs_linux do
bottle do bottle do
root_url "#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}" root_url "#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}"
cellar :any_skip_relocation sha256 "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f" => :big_sur, :cellar => :any_skip_relocation
sha256 "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f" => :big_sur sha256 "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" => :catalina, :cellar => :any_skip_relocation
sha256 "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" => :catalina sha256 "6971b6eebf4c00eaaed72a1104a49be63861eabc95d679a0c84040398e320059" => :high_sierra, :cellar => :any
sha256 "6971b6eebf4c00eaaed72a1104a49be63861eabc95d679a0c84040398e320059" => :high_sierra
end end
def install def install