Skip to content

Commit 73b6439

Browse files
committed
Use existing Utils::Bottles::Collector#specification_for method
1 parent e83dc1c commit 73b6439

File tree

3 files changed

+9
-85
lines changed

3 files changed

+9
-85
lines changed

Library/Homebrew/dev-cmd/generate-formula-api.rb

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,14 @@ def run
7575
version = Version.new(formula.dig("versions", "stable"))
7676
pkg_version = PkgVersion.new(version, formula["revision"])
7777
rebuild = formula.dig("bottle", "stable", "rebuild") || 0
78-
sha256 = newest_bottle_sha256(formula, bottle_tag)
78+
79+
bottle_collector = Utils::Bottles::Collector.new
80+
formula.dig("bottle", "stable", "files")&.each do |tag, data|
81+
tag = Utils::Bottles::Tag.from_symbol(tag)
82+
bottle_collector.add tag, checksum: Checksum.new(data["sha256"]), cellar: :any
83+
end
84+
85+
sha256 = bottle_collector.specification_for(bottle_tag)&.checksum&.to_s
7986

8087
[name, [pkg_version.to_s, rebuild, sha256]]
8188
end
@@ -87,35 +94,6 @@ def run
8794
end
8895
end
8996

90-
sig {
91-
params(formula_json: T::Hash[String, T.untyped], bottle_tag: Utils::Bottles::Tag).returns(T.nilable(String))
92-
}
93-
def newest_bottle_sha256(formula_json, bottle_tag)
94-
available_tags = formula_json.dig("bottle", "stable", "files")&.keys&.map(&:to_sym)
95-
return unless available_tags
96-
97-
return formula_json.dig("bottle", "stable", "files", :all, "sha256") if available_tags.include? :all
98-
99-
if available_tags.include? bottle_tag.to_sym
100-
return formula_json.dig("bottle", "stable", "files", bottle_tag.to_sym, "sha256")
101-
end
102-
103-
return unless bottle_tag.macos?
104-
105-
# If the actual tag is not available, find the newest tag with matching arch that's older than the actual tag
106-
newest_viable_macos_tag = available_tags.filter_map do |tag_sym|
107-
tag = Utils::Bottles::Tag.from_symbol(tag_sym)
108-
next unless tag.macos?
109-
next if tag.arch != bottle_tag.arch
110-
next if tag.to_macos_version > bottle_tag.to_macos_version
111-
112-
tag
113-
end.max_by(&:to_macos_version)
114-
return unless newest_viable_macos_tag
115-
116-
formula_json.dig("bottle", "stable", "files", newest_viable_macos_tag.to_sym, "sha256")
117-
end
118-
11997
private
12098

12199
sig { params(title: String).returns(String) }

Library/Homebrew/extend/os/mac/utils/bottles.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def find_older_compatible_tag(tag)
4747
return if tag_version.blank?
4848

4949
tags.find do |candidate|
50-
next if candidate.arch != tag.arch
50+
next if candidate.standardized_arch != tag.standardized_arch
5151

5252
candidate.to_macos_version <= tag_version
5353
rescue MacOSVersion::Error

Library/Homebrew/test/dev-cmd/generate-formula-api_spec.rb

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -5,58 +5,4 @@
55

66
RSpec.describe Homebrew::DevCmd::GenerateFormulaApi do
77
it_behaves_like "parseable arguments"
8-
9-
describe "#newest_bottle_sha256" do
10-
subject(:generate_formula_api) { described_class.new [] }
11-
12-
def make_json(bottles)
13-
json = {
14-
"bottle" => {
15-
"stable" => {
16-
"files" => {},
17-
},
18-
},
19-
}
20-
bottles.each do |tag, sha256|
21-
json["bottle"]["stable"]["files"][tag] = { "sha256" => sha256 }
22-
end
23-
json
24-
end
25-
26-
expected_sha256s = {
27-
arm64_sequoia: "abc123",
28-
arm64_sonoma: "abc123",
29-
arm64_ventura: "ghi789",
30-
arm64_monterey: nil,
31-
sequoia: "jkl012",
32-
sonoma: "jkl012",
33-
ventura: "mno345",
34-
monterey: "mno345",
35-
x86_64_linux: "pqr678",
36-
arm64_linux: nil,
37-
}.transform_keys do |tag|
38-
Utils::Bottles::Tag.from_symbol(tag)
39-
end
40-
41-
let(:all_json) { make_json all: "abc123" }
42-
let(:standard_json) do
43-
make_json arm64_sonoma: "abc123",
44-
arm64_ventura: "ghi789",
45-
sonoma: "jkl012",
46-
big_sur: "mno345",
47-
x86_64_linux: "pqr678"
48-
end
49-
50-
it "returns the sha256 for the :all tag on all systems" do
51-
expected_sha256s.each_key do |tag|
52-
expect(generate_formula_api.newest_bottle_sha256(all_json, tag)).to eq("abc123")
53-
end
54-
end
55-
56-
expected_sha256s.each_key do |tag|
57-
it "returns the corrent sha256 for #{tag}" do
58-
expect(generate_formula_api.newest_bottle_sha256(standard_json, tag)).to eq(expected_sha256s[tag])
59-
end
60-
end
61-
end
628
end

0 commit comments

Comments
 (0)