Skip to content

Commit

Permalink
Merge pull request #16768 from Homebrew/parse-source-checksum-correct…
Browse files Browse the repository at this point in the history
…ly-in-json-v3

internal json v3: parse ruby source checksum correctly
  • Loading branch information
MikeMcQuaid authored Feb 29, 2024
2 parents 136c50a + cd5b93a commit 2aa8040
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
1 change: 1 addition & 0 deletions Library/Homebrew/dev-cmd/tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ def self.setup_environment!(args)

# 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

Expand Down
7 changes: 4 additions & 3 deletions Library/Homebrew/formulary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,11 @@ def ruby_source_path
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

Expand Down
26 changes: 16 additions & 10 deletions Library/Homebrew/test/api/internal_tap_json/formula_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,19 @@
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

Expand All @@ -112,6 +115,9 @@
"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

Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/test/formulary_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ def formula_json_contents(extra_items = {})
"working_dir" => "/$HOME",
},
"ruby_source_path" => "Formula/#{formula_name}.rb",
"ruby_source_checksum" => { "sha256" => "ABCDEFGHIJKLMNOPQRSTUVWXYZ" },
}.merge(extra_items),
}
end
Expand Down Expand Up @@ -419,6 +420,8 @@ def formula_json_contents(extra_items = {})
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.")
Expand Down

0 comments on commit 2aa8040

Please sign in to comment.