From 3cf86dad30d60452e14f360d7c16c3bb78c70fe4 Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Thu, 16 Jun 2022 16:14:39 -0400 Subject: [PATCH 1/3] Handle deprecate/disable symbols when loading from the API --- Library/Homebrew/formulary.rb | 12 ++++++++++-- Library/Homebrew/test/formulary_spec.rb | 13 ++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 4bc7f65c8b..86ce3d1451 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -167,11 +167,13 @@ module Formulary end if (deprecation_date = json_formula["deprecation_date"]).present? - deprecate! date: deprecation_date, because: json_formula["deprecation_reason"] + reason = Formulary.convert_to_deprecate_disable_reason_string_or_symbol json_formula["deprecation_reason"] + deprecate! date: deprecation_date, because: reason end if (disable_date = json_formula["disable_date"]).present? - disable! date: disable_date, because: json_formula["disable_reason"] + reason = Formulary.convert_to_deprecate_disable_reason_string_or_symbol json_formula["disable_reason"] + disable! date: disable_date, because: reason end json_formula["build_dependencies"].each do |dep| @@ -261,6 +263,12 @@ module Formulary string end + def self.convert_to_deprecate_disable_reason_string_or_symbol(string) + return string unless DeprecateDisable::DEPRECATE_DISABLE_REASONS.keys.map(&:to_s).include?(string) + + string.to_sym + end + # A {FormulaLoader} returns instances of formulae. # Subclasses implement loaders for particular sources of formulae. class FormulaLoader diff --git a/Library/Homebrew/test/formulary_spec.rb b/Library/Homebrew/test/formulary_spec.rb index b371c84c26..4fdd65e4c3 100644 --- a/Library/Homebrew/test/formulary_spec.rb +++ b/Library/Homebrew/test/formulary_spec.rb @@ -256,7 +256,7 @@ describe Formulary do let(:disable_json) do { "disable_date" => "2022-06-15", - "disable_reason" => "repo_archived", + "disable_reason" => "requires something else", } end @@ -344,4 +344,15 @@ describe Formulary do .to eq(Pathname.new("#{HOMEBREW_LIBRARY}/Taps/homebrew/homebrew-core/Formula/#{name}.rb")) end end + + describe "::convert_to_deprecate_disable_reason_string_or_symbol" do + it "returns the original string if it isn't a preset reason" do + expect(described_class.convert_to_deprecate_disable_reason_string_or_symbol("foo")).to eq "foo" + end + + it "returns a symbol if the original string is a preset reason" do + expect(described_class.convert_to_deprecate_disable_reason_string_or_symbol("does_not_build")) + .to eq :does_not_build + end + end end From 0ea9f5ec808c2ee843bf0cd84e061d9aaed8df8e Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Thu, 16 Jun 2022 16:45:38 -0400 Subject: [PATCH 2/3] Add tests for convert_to_string_or_symbol --- Library/Homebrew/test/formulary_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Library/Homebrew/test/formulary_spec.rb b/Library/Homebrew/test/formulary_spec.rb index 4fdd65e4c3..a631cf491a 100644 --- a/Library/Homebrew/test/formulary_spec.rb +++ b/Library/Homebrew/test/formulary_spec.rb @@ -345,6 +345,16 @@ describe Formulary do end end + describe "::convert_to_string_or_symbol" do + it "returns the original string if it doesn't start with a colon" do + expect(described_class.convert_to_string_or_symbol("foo")).to eq "foo" + end + + it "returns a symbol if the original string starts with a colon" do + expect(described_class.convert_to_string_or_symbol(":foo")).to eq :foo + end + end + describe "::convert_to_deprecate_disable_reason_string_or_symbol" do it "returns the original string if it isn't a preset reason" do expect(described_class.convert_to_deprecate_disable_reason_string_or_symbol("foo")).to eq "foo" From 15cf890ed747babbcc32a1ac9283ea2f56e3a019 Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Thu, 16 Jun 2022 19:36:32 -0400 Subject: [PATCH 3/3] Fix caveats when loading from the API --- Library/Homebrew/formulary.rb | 2 +- Library/Homebrew/test/formulary_spec.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 86ce3d1451..1a8afb24a9 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -203,7 +203,7 @@ module Formulary @caveats_string = json_formula["caveats"] def caveats - @caveats_string + self.class.instance_variable_get(:@caveats_string) end end diff --git a/Library/Homebrew/test/formulary_spec.rb b/Library/Homebrew/test/formulary_spec.rb index a631cf491a..6276ecf876 100644 --- a/Library/Homebrew/test/formulary_spec.rb +++ b/Library/Homebrew/test/formulary_spec.rb @@ -241,7 +241,7 @@ describe Formulary do "recommended_dependencies" => ["recommended_dep"], "optional_dependencies" => ["optional_dep"], "uses_from_macos" => ["uses_from_macos_dep"], - "caveats" => "", + "caveats" => "example caveat string", }.merge(extra_items), } end @@ -276,6 +276,7 @@ describe Formulary do expect(formula.deps.count).to eq 5 end expect(formula.uses_from_macos_elements).to eq ["uses_from_macos_dep"] + expect(formula.caveats).to eq "example caveat string" expect { formula.install }.to raise_error("Cannot build from source from abstract formula.")