Merge pull request #10449 from iMichka/bottle-write
cellars: write tag specific cellars
This commit is contained in:
commit
61e38654ed
@ -353,6 +353,7 @@ Layout/LineLength:
|
||||
' name "',
|
||||
' pkg "',
|
||||
' pkgutil: "',
|
||||
' sha256 "',
|
||||
"#{language}",
|
||||
"#{version.",
|
||||
' "/Library/Application Support/',
|
||||
|
||||
@ -20,19 +20,11 @@ BOTTLE_ERB = <<-EOS
|
||||
HOMEBREW_LINUX_DEFAULT_PREFIX].include?(prefix) %>
|
||||
prefix "<%= prefix %>"
|
||||
<% 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? %>
|
||||
rebuild <%= rebuild %>
|
||||
<% end %>
|
||||
<% checksums.each do |checksum_value| %>
|
||||
<% checksum, macos = checksum_value.shift %>
|
||||
sha256 "<%= checksum %>" => :<%= macos %>
|
||||
<% sha256_lines.each do |line| %>
|
||||
<%= line %>
|
||||
<% end %>
|
||||
end
|
||||
EOS
|
||||
@ -202,9 +194,29 @@ module Homebrew
|
||||
!absolute_symlinks_start_with_string.empty?
|
||||
end
|
||||
|
||||
def generate_sha256_line(tag, digest, cellar)
|
||||
default_cellars = [
|
||||
Homebrew::DEFAULT_MACOS_CELLAR,
|
||||
Homebrew::DEFAULT_MACOS_ARM_CELLAR,
|
||||
Homebrew::DEFAULT_LINUX_CELLAR,
|
||||
]
|
||||
if cellar.is_a?(Symbol)
|
||||
%Q(sha256 cellar: :#{cellar}, #{tag}: "#{digest}")
|
||||
elsif cellar.present? && default_cellars.exclude?(cellar)
|
||||
%Q(sha256 cellar: "#{cellar}", #{tag}: "#{digest}")
|
||||
else
|
||||
%Q(sha256 #{tag}: "#{digest}")
|
||||
end
|
||||
end
|
||||
|
||||
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.result(bottle.instance_eval { binding }).gsub(/^\s*$\n/, "")
|
||||
erb.result(erb_binding).gsub(/^\s*$\n/, "")
|
||||
end
|
||||
|
||||
def sudo_purge
|
||||
@ -451,19 +463,14 @@ module Homebrew
|
||||
|
||||
def merge_json_files(json_files)
|
||||
json_files.reduce({}) do |hash, json_file|
|
||||
hash.deep_merge(json_file) do |key, first, second|
|
||||
if key == "cellar"
|
||||
# Prioritize HOMEBREW_CELLAR over :any over :any_skip_relocation
|
||||
cellars = [first, second]
|
||||
next HOMEBREW_CELLAR if cellars.include?(HOMEBREW_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")
|
||||
json_file.each_value do |json_hash|
|
||||
json_bottle = json_hash["bottle"]
|
||||
cellar = json_bottle.delete("cellar")
|
||||
json_bottle["tags"].each_value do |json_platform|
|
||||
json_platform["cellar"] ||= cellar
|
||||
end
|
||||
|
||||
second
|
||||
end
|
||||
hash.deep_merge(json_file)
|
||||
end
|
||||
end
|
||||
|
||||
@ -476,13 +483,13 @@ module Homebrew
|
||||
|
||||
bottle = BottleSpecification.new
|
||||
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.rebuild bottle_hash["bottle"]["rebuild"]
|
||||
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 = { cellar: cellar, tag.to_sym => tag_hash["sha256"] }
|
||||
bottle.sha256 sha256_hash
|
||||
end
|
||||
|
||||
if args.write?
|
||||
@ -533,16 +540,16 @@ module Homebrew
|
||||
new_values = {
|
||||
root_url: new_bottle_hash["root_url"],
|
||||
prefix: new_bottle_hash["prefix"],
|
||||
cellar: new_bottle_hash["cellar"],
|
||||
rebuild: new_bottle_hash["rebuild"],
|
||||
}
|
||||
|
||||
skip_keys = [:sha256, :cellar]
|
||||
old_keys.each do |key|
|
||||
next if key == :sha256
|
||||
next if skip_keys.include?(key)
|
||||
|
||||
old_value = old_bottle_spec.send(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
|
||||
|
||||
mismatches << "#{key}: old: #{old_value.inspect}, new: #{new_value.inspect}"
|
||||
@ -551,12 +558,14 @@ module Homebrew
|
||||
return [mismatches, checksums] if old_keys.exclude? :sha256
|
||||
|
||||
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)
|
||||
if new_value.present?
|
||||
mismatches << "sha256 => #{tag}"
|
||||
else
|
||||
checksums << { old_value => tag }
|
||||
checksums << { cellar: old_cellar, tag => old_hexdigest }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -442,8 +442,9 @@ class BottleSpecification
|
||||
end
|
||||
tags.reverse.map do |tag|
|
||||
{
|
||||
collector[tag][:checksum] => tag,
|
||||
cellar: collector[tag][:cellar],
|
||||
"tag" => tag,
|
||||
"digest" => collector[tag][:checksum],
|
||||
"cellar" => collector[tag][:cellar],
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
@ -149,24 +149,26 @@ describe Homebrew do
|
||||
)
|
||||
|
||||
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"]["local_filename"]).to eq("hello--1.0.big_sur.bottle.tar.gz")
|
||||
expect(hello_hash["bottle"]["tags"]["big_sur"]["sha256"]).to eq(
|
||||
"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"]["local_filename"]).to eq("hello--1.0.catalina.bottle.tar.gz")
|
||||
expect(hello_hash["bottle"]["tags"]["catalina"]["sha256"]).to eq(
|
||||
"5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac",
|
||||
)
|
||||
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"]["local_filename"]).to eq("unzip--2.0.big_sur.bottle.tar.gz")
|
||||
expect(unzip_hash["bottle"]["tags"]["big_sur"]["sha256"]).to eq(
|
||||
"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"]["local_filename"]).to eq("unzip--2.0.catalina.bottle.tar.gz")
|
||||
expect(unzip_hash["bottle"]["tags"]["catalina"]["sha256"]).to eq(
|
||||
@ -202,16 +204,6 @@ describe Homebrew do
|
||||
]
|
||||
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
|
||||
old_spec = BottleSpecification.new
|
||||
old_spec.rebuild(1)
|
||||
@ -224,18 +216,54 @@ describe Homebrew do
|
||||
|
||||
it "checks for conflicting checksums" do
|
||||
old_spec = BottleSpecification.new
|
||||
old_spec.sha256("109c0cb581a7b5d84da36d84b221fb9dd0f8a927b3044d82611791c9907e202e" => :catalina)
|
||||
old_spec.sha256("7571772bf7a0c9fe193e70e521318b53993bee6f351976c9b6e01e00d13d6c3f" => :mojave)
|
||||
old_spec.sha256(catalina: "109c0cb581a7b5d84da36d84b221fb9dd0f8a927b3044d82611791c9907e202e")
|
||||
old_spec.sha256(mojave: "7571772bf7a0c9fe193e70e521318b53993bee6f351976c9b6e01e00d13d6c3f")
|
||||
new_hash = { "tags" => { "catalina" => "ec6d7f08412468f28dee2be17ad8cd8b883b16b34329efcecce019b8c9736428" } }
|
||||
expected_checksum_hash = { mojave: "7571772bf7a0c9fe193e70e521318b53993bee6f351976c9b6e01e00d13d6c3f" }
|
||||
expected_checksum_hash[:cellar] = Homebrew::DEFAULT_CELLAR
|
||||
expect(homebrew.merge_bottle_spec([:sha256], old_spec, new_hash)).to eq [
|
||||
["sha256 => catalina"],
|
||||
[{ "7571772bf7a0c9fe193e70e521318b53993bee6f351976c9b6e01e00d13d6c3f" => :mojave }],
|
||||
[expected_checksum_hash],
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
describe "::generate_sha256_line" do
|
||||
it "generates a string without cellar" do
|
||||
expect(homebrew.generate_sha256_line(:catalina, "deadbeef", nil)).to eq(
|
||||
<<~RUBY.chomp,
|
||||
sha256 catalina: "deadbeef"
|
||||
RUBY
|
||||
)
|
||||
end
|
||||
|
||||
it "generates a string with cellar symbol" do
|
||||
expect(homebrew.generate_sha256_line(:catalina, "deadbeef", :any)).to eq(
|
||||
<<~RUBY.chomp,
|
||||
sha256 cellar: :any, catalina: "deadbeef"
|
||||
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 catalina: "deadbeef"
|
||||
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 cellar: "/home/test", catalina: "deadbeef"
|
||||
RUBY
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "brew bottle --merge", :integration_test, :needs_linux do
|
||||
describe "brew bottle --merge", :integration_test do
|
||||
let(:core_tap) { CoreTap.new }
|
||||
let(:tarball) do
|
||||
if OS.linux?
|
||||
@ -292,9 +320,8 @@ describe "brew bottle --merge", :integration_test, :needs_linux do
|
||||
==> testball
|
||||
bottle do
|
||||
root_url "#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}"
|
||||
cellar :any_skip_relocation
|
||||
sha256 "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f" => :big_sur
|
||||
sha256 "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" => :catalina
|
||||
sha256 cellar: :any_skip_relocation, big_sur: "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f"
|
||||
sha256 cellar: :any_skip_relocation, catalina: "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac"
|
||||
end
|
||||
EOS
|
||||
|
||||
@ -307,9 +334,8 @@ describe "brew bottle --merge", :integration_test, :needs_linux do
|
||||
|
||||
bottle do
|
||||
root_url "#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}"
|
||||
cellar :any_skip_relocation
|
||||
sha256 "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f" => :big_sur
|
||||
sha256 "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" => :catalina
|
||||
sha256 cellar: :any_skip_relocation, big_sur: "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f"
|
||||
sha256 cellar: :any_skip_relocation, catalina: "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac"
|
||||
end
|
||||
|
||||
option "with-foo", "Build with foo"
|
||||
@ -339,8 +365,8 @@ describe "brew bottle --merge", :integration_test, :needs_linux do
|
||||
bottle do
|
||||
root_url "#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}"
|
||||
cellar :any_skip_relocation
|
||||
sha256 "6b276491297d4052538bd2fd22d5129389f27d90a98f831987236a5b90511b98" => :big_sur
|
||||
sha256 "16cf230afdfcb6306c208d169549cf8773c831c8653d2c852315a048960d7e72" => :catalina
|
||||
sha256 big_sur: "6b276491297d4052538bd2fd22d5129389f27d90a98f831987236a5b90511b98"
|
||||
sha256 catalina: "16cf230afdfcb6306c208d169549cf8773c831c8653d2c852315a048960d7e72"
|
||||
end
|
||||
EOS
|
||||
system "git", "add", "--all"
|
||||
@ -357,9 +383,8 @@ describe "brew bottle --merge", :integration_test, :needs_linux do
|
||||
==> testball
|
||||
bottle do
|
||||
root_url "#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}"
|
||||
cellar :any_skip_relocation
|
||||
sha256 "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f" => :big_sur
|
||||
sha256 "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" => :catalina
|
||||
sha256 cellar: :any_skip_relocation, big_sur: "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f"
|
||||
sha256 cellar: :any_skip_relocation, catalina: "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac"
|
||||
end
|
||||
EOS
|
||||
|
||||
@ -374,9 +399,8 @@ describe "brew bottle --merge", :integration_test, :needs_linux do
|
||||
|
||||
bottle do
|
||||
root_url "#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}"
|
||||
cellar :any_skip_relocation
|
||||
sha256 "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f" => :big_sur
|
||||
sha256 "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" => :catalina
|
||||
sha256 cellar: :any_skip_relocation, big_sur: "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f"
|
||||
sha256 cellar: :any_skip_relocation, catalina: "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac"
|
||||
end
|
||||
|
||||
def install
|
||||
@ -421,7 +445,7 @@ describe "brew bottle --merge", :integration_test, :needs_linux do
|
||||
|
||||
bottle do
|
||||
root_url "#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}"
|
||||
cellar :any_skip_relocation
|
||||
cellar :any
|
||||
sha256 "6971b6eebf4c00eaaed72a1104a49be63861eabc95d679a0c84040398e320059" => :high_sierra
|
||||
end
|
||||
EOS
|
||||
@ -440,10 +464,9 @@ describe "brew bottle --merge", :integration_test, :needs_linux do
|
||||
==> testball
|
||||
bottle do
|
||||
root_url "#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}"
|
||||
cellar :any_skip_relocation
|
||||
sha256 "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f" => :big_sur
|
||||
sha256 "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" => :catalina
|
||||
sha256 "6971b6eebf4c00eaaed72a1104a49be63861eabc95d679a0c84040398e320059" => :high_sierra
|
||||
sha256 cellar: :any_skip_relocation, big_sur: "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f"
|
||||
sha256 cellar: :any_skip_relocation, catalina: "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac"
|
||||
sha256 cellar: :any, high_sierra: "6971b6eebf4c00eaaed72a1104a49be63861eabc95d679a0c84040398e320059"
|
||||
end
|
||||
EOS
|
||||
|
||||
@ -458,10 +481,9 @@ describe "brew bottle --merge", :integration_test, :needs_linux do
|
||||
|
||||
bottle do
|
||||
root_url "#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}"
|
||||
cellar :any_skip_relocation
|
||||
sha256 "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f" => :big_sur
|
||||
sha256 "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" => :catalina
|
||||
sha256 "6971b6eebf4c00eaaed72a1104a49be63861eabc95d679a0c84040398e320059" => :high_sierra
|
||||
sha256 cellar: :any_skip_relocation, big_sur: "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f"
|
||||
sha256 cellar: :any_skip_relocation, catalina: "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac"
|
||||
sha256 cellar: :any, high_sierra: "6971b6eebf4c00eaaed72a1104a49be63861eabc95d679a0c84040398e320059"
|
||||
end
|
||||
|
||||
def install
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user