From cd5b93a2f2f2f0e774547fba9398485af9a3b282 Mon Sep 17 00:00:00 2001 From: apainintheneck Date: Wed, 28 Feb 2024 21:06:10 -0800 Subject: [PATCH] internal json v3: parse ruby source checksum correctly Currently we are including this in the API but not actually parsing and loading it correctly from the JSON. I think this was an oversight when addressing feedback and refactoring the JSON shape. Not a big deal, of course, because I'm the only person using it right now. I found this out while testing installs using the API and I got this error while running `brew reinstall tree`. ``` Warning: Cannot verify integrity of '60fc4212023d3fef00e6de4b9f3f0d63402cf3eca00778d09f4f2d3481b524a1--tree.rb'. No checksum was provided. ``` --- Library/Homebrew/dev-cmd/tests.rb | 1 + Library/Homebrew/formulary.rb | 7 ++--- .../api/internal_tap_json/formula_spec.rb | 26 ++++++++++++------- Library/Homebrew/test/formulary_spec.rb | 3 +++ 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/Library/Homebrew/dev-cmd/tests.rb b/Library/Homebrew/dev-cmd/tests.rb index 005764c3cc..d13fe70134 100644 --- a/Library/Homebrew/dev-cmd/tests.rb +++ b/Library/Homebrew/dev-cmd/tests.rb @@ -240,6 +240,7 @@ module Homebrew # TODO: remove this and fix tests when possible. ENV["HOMEBREW_NO_INSTALL_FROM_API"] = "1" + ENV.delete("HOMEBREW_INTERNAL_JSON_V3") ENV["USER"] ||= system_command!("id", args: ["-nu"]).stdout.chomp diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 0681db1951..1a882e18d2 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -411,10 +411,11 @@ module Formulary self.class.instance_variable_get(:@ruby_source_path_string) end - @ruby_source_checksum_hash = json_formula["ruby_source_checksum"] + @ruby_source_checksum_string = json_formula.dig("ruby_source_checksum", "sha256") + @ruby_source_checksum_string ||= json_formula["ruby_source_sha256"] def ruby_source_checksum - checksum_hash = self.class.instance_variable_get(:@ruby_source_checksum_hash) - Checksum.new(checksum_hash["sha256"]) if checksum_hash&.key?("sha256") + checksum = self.class.instance_variable_get(:@ruby_source_checksum_string) + Checksum.new(checksum) if checksum end end diff --git a/Library/Homebrew/test/api/internal_tap_json/formula_spec.rb b/Library/Homebrew/test/api/internal_tap_json/formula_spec.rb index 076f6bd673..550036d6e0 100644 --- a/Library/Homebrew/test/api/internal_tap_json/formula_spec.rb +++ b/Library/Homebrew/test/api/internal_tap_json/formula_spec.rb @@ -85,16 +85,19 @@ RSpec.describe "Internal Tap JSON -- Formula" do context "when loading formulae" do let(:fennel_metadata) do { - "dependencies" => ["lua"], - "desc" => "Lua Lisp Language", - "full_name" => "fennel", - "homepage" => "https://fennel-lang.org", - "license" => "MIT", - "name" => "fennel", - "ruby_source_path" => "Formula/f/fennel.rb", - "tap" => "homebrew/core", - "tap_git_head" => tap_git_head, - "versions" => { "bottle"=>true, "head"=>nil, "stable"=>"1.4.0" }, + "dependencies" => ["lua"], + "desc" => "Lua Lisp Language", + "full_name" => "fennel", + "homepage" => "https://fennel-lang.org", + "license" => "MIT", + "name" => "fennel", + "ruby_source_path" => "Formula/f/fennel.rb", + "tap" => "homebrew/core", + "tap_git_head" => tap_git_head, + "versions" => { "bottle"=>true, "head"=>nil, "stable"=>"1.4.0" }, + "ruby_source_checksum" => { + "sha256" => "5856e655fd1cea11496d67bc27fb14fee5cfbdea63c697c3773c7f247581197d", + }, } end @@ -112,6 +115,9 @@ RSpec.describe "Internal Tap JSON -- Formula" do "uses_from_macos" => [{ "llvm"=>[:build, :test] }, "zlib"], "uses_from_macos_bounds" => [{}, {}], "versions" => { "bottle"=>true, "head"=>nil, "stable"=>"0.58.1" }, + "ruby_source_checksum" => { + "sha256" => "81d51c25d18710191beb62f9f380bae3d878aad815a65ec1ee2a3b132c1fadb3", + }, } end diff --git a/Library/Homebrew/test/formulary_spec.rb b/Library/Homebrew/test/formulary_spec.rb index 91c79174fa..cd4dec18c3 100644 --- a/Library/Homebrew/test/formulary_spec.rb +++ b/Library/Homebrew/test/formulary_spec.rb @@ -331,6 +331,7 @@ RSpec.describe Formulary do "working_dir" => "/$HOME", }, "ruby_source_path" => "Formula/#{formula_name}.rb", + "ruby_source_checksum" => { "sha256" => "ABCDEFGHIJKLMNOPQRSTUVWXYZ" }, }.merge(extra_items), } end @@ -419,6 +420,8 @@ RSpec.describe Formulary do expect(formula.plist_name).to eq("custom.launchd.name") expect(formula.service_name).to eq("custom.systemd.name") + expect(formula.ruby_source_checksum.hexdigest).to eq("abcdefghijklmnopqrstuvwxyz") + expect do formula.install end.to raise_error("Cannot build from source from abstract formula.")