diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 3cce9ccb3f..9120a5cd8d 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -3369,8 +3369,14 @@ class Formula # On macOS this is a no-op (as we use the provided system libraries) unless # `:since` specifies a minimum macOS version. # On Linux this will act as {.depends_on}. - def uses_from_macos(dep, bounds = {}) - specs.each { |spec| spec.uses_from_macos(dep, bounds) } + sig { + params( + dep: String, + bounds: T.any(Symbol, T::Array[Symbol]), + ).void + } + def uses_from_macos(dep = T.unsafe(nil), **bounds) + specs.each { |spec| spec.uses_from_macos(*dep, **bounds) } end # @!attribute [w] option diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 13dccfb851..2cfe6b8f0e 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -234,12 +234,13 @@ module Formulary dep_json["uses_from_macos"]&.each_with_index do |dep, index| bounds = dep_json.fetch("uses_from_macos_bounds", [])[index].dup || {} bounds.deep_transform_keys!(&:to_sym) - bounds.deep_transform_values! { |val| val.is_a?(String) ? val.to_sym : val } + bounds.deep_transform_values!(&:to_sym) if dep.is_a?(Hash) - uses_from_macos dep.deep_transform_values(&:to_sym).merge(bounds) + dep.deep_transform_values!(&:to_sym) + uses_from_macos(**T.unsafe(dep.merge(bounds))) else - uses_from_macos dep, bounds + uses_from_macos dep, **bounds end end end diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb index 1afb7884bc..a6e9776aa2 100644 --- a/Library/Homebrew/software_spec.rb +++ b/Library/Homebrew/software_spec.rb @@ -186,16 +186,23 @@ class SoftwareSpec add_dep_option(dep) if dep end - def uses_from_macos(deps, bounds = {}) - if deps.is_a?(Hash) - bounds = deps.dup - deps = [T.unsafe(bounds).shift].to_h + sig { + params( + dep: String, + bounds: T.any(Symbol, T::Array[Symbol]), + ).void + } + def uses_from_macos(dep = T.unsafe(nil), **bounds) + bounds = bounds.dup + + if dep + tags = [] + else + dep, tags = bounds.shift + tags = [*tags] end - spec, tags = deps.is_a?(Hash) ? deps.first : deps - raise TypeError, "Dependency name must be a string!" unless spec.is_a?(String) - - depends_on UsesFromMacOSDependency.new(spec, Array(tags), bounds: bounds) + depends_on UsesFromMacOSDependency.new(dep, tags, bounds: bounds) end # @deprecated