diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index cd3f928829..d55b18a210 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -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) + 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) + 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 = { tag_hash["sha256"] => tag.to_sym, :cellar => cellar } + 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 << { old_hexdigest => tag, :cellar => old_cellar } end end diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb index ccfdd942a8..0794e77814 100644 --- a/Library/Homebrew/software_spec.rb +++ b/Library/Homebrew/software_spec.rb @@ -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 diff --git a/Library/Homebrew/test/dev-cmd/bottle_spec.rb b/Library/Homebrew/test/dev-cmd/bottle_spec.rb index 34d3bf8ccc..fdf5ad16c8 100644 --- a/Library/Homebrew/test/dev-cmd/bottle_spec.rb +++ b/Library/Homebrew/test/dev-cmd/bottle_spec.rb @@ -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) @@ -227,12 +219,48 @@ describe Homebrew do old_spec.sha256("109c0cb581a7b5d84da36d84b221fb9dd0f8a927b3044d82611791c9907e202e" => :catalina) old_spec.sha256("7571772bf7a0c9fe193e70e521318b53993bee6f351976c9b6e01e00d13d6c3f" => :mojave) 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 [ ["sha256 => catalina"], - [{ "7571772bf7a0c9fe193e70e521318b53993bee6f351976c9b6e01e00d13d6c3f" => :mojave }], + [expected_checksum_hash], ] 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 describe "brew bottle --merge", :integration_test, :needs_linux do @@ -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 "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f" => :big_sur, :cellar => :any_skip_relocation + sha256 "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" => :catalina, :cellar => :any_skip_relocation 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 "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f" => :big_sur, :cellar => :any_skip_relocation + sha256 "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" => :catalina, :cellar => :any_skip_relocation end option "with-foo", "Build with foo" @@ -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 "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f" => :big_sur, :cellar => :any_skip_relocation + sha256 "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" => :catalina, :cellar => :any_skip_relocation 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 "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f" => :big_sur, :cellar => :any_skip_relocation + sha256 "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" => :catalina, :cellar => :any_skip_relocation 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 "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f" => :big_sur, :cellar => :any_skip_relocation + sha256 "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" => :catalina, :cellar => :any_skip_relocation + sha256 "6971b6eebf4c00eaaed72a1104a49be63861eabc95d679a0c84040398e320059" => :high_sierra, :cellar => :any 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 "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f" => :big_sur, :cellar => :any_skip_relocation + sha256 "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac" => :catalina, :cellar => :any_skip_relocation + sha256 "6971b6eebf4c00eaaed72a1104a49be63861eabc95d679a0c84040398e320059" => :high_sierra, :cellar => :any end def install