From 578c935bcffe0fe1d03c86907026939e210f9481 Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Wed, 13 Sep 2023 13:23:35 -0400 Subject: [PATCH] Formula, BuildError: Update type signatures We're seeing type errors when building formulae that use something like `xcodebuild ..., "-arch", Hardware::CPU.arch`, since `CPU.arch` is a symbol. We've been addressing these issues by calling `#to_s` on the value but there was some talk about simply expanding the type signatures to accommodate anything that will be cast to a `String`. There's maybe still an argument to be made for doing string conversion in formulae but expanding the type signatures will resolve a number of existing type errors if we simply want to rely on implicit type casting. Past that, this also updates the type signature for `BuildError` to align with the `#system` signature changes, as we receive a type error otherwise. --- Library/Homebrew/exceptions.rb | 2 +- Library/Homebrew/formula.rb | 4 ++-- Library/Homebrew/test/exceptions_spec.rb | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb index 3845ce1d7c..662b9f200a 100644 --- a/Library/Homebrew/exceptions.rb +++ b/Library/Homebrew/exceptions.rb @@ -479,7 +479,7 @@ class BuildError < RuntimeError params( formula: T.nilable(Formula), cmd: T.any(String, Pathname), - args: T::Array[T.any(String, Pathname, Integer)], + args: T::Array[T.any(String, Integer, Pathname, Symbol)], env: T::Hash[String, T.untyped], ).void } diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index caffdb1c87..b764cfb5d9 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -2629,7 +2629,7 @@ class Formula # # # If there is a "make install" available, please use it! # system "make", "install" - sig { params(cmd: T.any(String, Pathname), args: T.any(String, Pathname, Integer)).void } + sig { params(cmd: T.any(String, Pathname), args: T.any(String, Integer, Pathname, Symbol)).void } def system(cmd, *args) verbose_using_dots = Homebrew::EnvConfig.verbose_using_dots? @@ -2794,7 +2794,7 @@ class Formula end # Runs `xcodebuild` without Homebrew's compiler environment variables set. - sig { params(args: T.any(String, Pathname)).void } + sig { params(args: T.any(String, Integer, Pathname, Symbol)).void } def xcodebuild(*args) removed = ENV.remove_cc_etc diff --git a/Library/Homebrew/test/exceptions_spec.rb b/Library/Homebrew/test/exceptions_spec.rb index 3921f2c2e4..a56fbb914c 100644 --- a/Library/Homebrew/test/exceptions_spec.rb +++ b/Library/Homebrew/test/exceptions_spec.rb @@ -141,11 +141,11 @@ describe "Exception" do end describe BuildError do - subject { described_class.new(formula, "badprg", %w[arg1 arg2], {}) } + subject { described_class.new(formula, "badprg", ["arg1", 2, Pathname.new("arg3"), :arg4], {}) } let(:formula) { instance_double(Formula, name: "foo") } - its(:to_s) { is_expected.to eq("Failed executing: badprg arg1 arg2") } + its(:to_s) { is_expected.to eq("Failed executing: badprg arg1 2 arg3 arg4") } end describe OperationInProgressError do