Formulary: use variations hash when installing from API

This commit is contained in:
Rylan Polster 2022-07-24 22:59:42 +02:00
parent 89cf96fffa
commit 7392f9811e
No known key found for this signature in database
GPG Key ID: 46A744940CFF4D64
2 changed files with 25 additions and 0 deletions

View File

@ -136,6 +136,11 @@ module Formulary
class_s = Formulary.class_s(name) class_s = Formulary.class_s(name)
json_formula = Homebrew::API::Formula.all_formulae[name] json_formula = Homebrew::API::Formula.all_formulae[name]
bottle_tag = Utils::Bottles.tag.to_s
if json_formula.key?("variations") && json_formula["variations"].key?(bottle_tag)
json_formula = json_formula.merge(json_formula["variations"][bottle_tag])
end
klass = Class.new(::Formula) do klass = Class.new(::Formula) do
desc json_formula["desc"] desc json_formula["desc"]
homepage json_formula["homepage"] homepage json_formula["homepage"]

View File

@ -260,6 +260,16 @@ describe Formulary do
} }
end end
let(:variations_json) do
{
"variations" => {
Utils::Bottles.tag.to_s => {
"dependencies" => ["dep", "variations_dep"],
},
},
}
end
before do before do
allow(described_class).to receive(:loader_for).and_return(described_class::FormulaAPILoader.new(formula_name)) allow(described_class).to receive(:loader_for).and_return(described_class::FormulaAPILoader.new(formula_name))
end end
@ -303,6 +313,16 @@ describe Formulary do
formula.install formula.install
}.to raise_error("Cannot build from source from abstract formula.") }.to raise_error("Cannot build from source from abstract formula.")
end end
it "returns a Formula with variations when given a name", :needs_macos do
allow(Homebrew::API::Formula).to receive(:all_formulae).and_return formula_json_contents(variations_json)
allow(Utils::Bottles).to receive(:tag).and_return(:arm64_monterey)
formula = described_class.factory(formula_name)
expect(formula).to be_kind_of(Formula)
expect(formula.deps.count).to eq 5
expect(formula.deps.map(&:name).include?("variations_dep")).to be true
end
end end
end end