From 7392f9811e6c5a03038b336d9560c6fa1d76682d Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Sun, 24 Jul 2022 22:59:42 +0200 Subject: [PATCH] `Formulary`: use variations hash when installing from API --- Library/Homebrew/formulary.rb | 5 +++++ Library/Homebrew/test/formulary_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index df7bfff951..0ca6a8033e 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -136,6 +136,11 @@ module Formulary class_s = Formulary.class_s(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 desc json_formula["desc"] homepage json_formula["homepage"] diff --git a/Library/Homebrew/test/formulary_spec.rb b/Library/Homebrew/test/formulary_spec.rb index 6276ecf876..68eb82733e 100644 --- a/Library/Homebrew/test/formulary_spec.rb +++ b/Library/Homebrew/test/formulary_spec.rb @@ -260,6 +260,16 @@ describe Formulary do } end + let(:variations_json) do + { + "variations" => { + Utils::Bottles.tag.to_s => { + "dependencies" => ["dep", "variations_dep"], + }, + }, + } + end + before do allow(described_class).to receive(:loader_for).and_return(described_class::FormulaAPILoader.new(formula_name)) end @@ -303,6 +313,16 @@ describe Formulary do formula.install }.to raise_error("Cannot build from source from abstract formula.") 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