diff --git a/Library/Homebrew/dependency.rb b/Library/Homebrew/dependency.rb index 6f3b88c8a2..8896435b67 100644 --- a/Library/Homebrew/dependency.rb +++ b/Library/Homebrew/dependency.rb @@ -230,6 +230,7 @@ end class UsesFromMacOSDependency < Dependency attr_reader :bounds + sig { params(name: String, tags: T::Array[Symbol], bounds: T::Hash[Symbol, Symbol]).void } def initialize(name, tags = [], bounds:) super(name, tags) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index f5a60ca97f..17c7f2ee77 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -3374,6 +3374,12 @@ 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}. + sig { + params( + dep: T.any(String, T::Hash[T.any(String, Symbol), T.any(Symbol, T::Array[Symbol])]), + bounds: T::Hash[Symbol, Symbol], + ).void + } def uses_from_macos(dep, bounds = {}) specs.each { |spec| spec.uses_from_macos(dep, bounds) } end diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 74ba8e75a4..978f06fde8 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -234,7 +234,7 @@ 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) diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb index 788bacfc32..8dd3630877 100644 --- a/Library/Homebrew/software_spec.rb +++ b/Library/Homebrew/software_spec.rb @@ -46,7 +46,6 @@ class SoftwareSpec @deprecated_options = [] @build = BuildOptions.new(Options.create(@flags), options) @compiler_failures = [] - @uses_from_macos_elements = [] end def initialize_dup(other) @@ -62,7 +61,6 @@ class SoftwareSpec @deprecated_options = @deprecated_options.dup @build = @build.dup @compiler_failures = @compiler_failures.dup - @uses_from_macos_elements = @uses_from_macos_elements.dup end def freeze @@ -77,7 +75,6 @@ class SoftwareSpec @deprecated_options.freeze @build.freeze @compiler_failures.freeze - @uses_from_macos_elements.freeze super end @@ -189,33 +186,36 @@ 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: T.any(String, T::Hash[T.any(String, Symbol), T.any(Symbol, T::Array[Symbol])]), + bounds: T::Hash[Symbol, Symbol], + ).void + } + def uses_from_macos(dep, bounds = {}) + if dep.is_a?(Hash) + bounds = dep.dup + dep, tags = bounds.shift + dep = T.cast(dep, String) + tags = [*tags] + bounds = T.cast(bounds, T::Hash[Symbol, Symbol]) + else + tags = [] end - spec, tags = deps.is_a?(Hash) ? deps.first : deps - raise TypeError, "Dependency name must be a string!" unless spec.is_a?(String) - - @uses_from_macos_elements << deps - - depends_on UsesFromMacOSDependency.new(spec, Array(tags), bounds: bounds) + depends_on UsesFromMacOSDependency.new(dep, tags, bounds: bounds) end # @deprecated def uses_from_macos_elements - # TODO: remove all @uses_from_macos_elements when removing this method - # Also remember to remove the delegate from formula.rb + # TODO: Remember to remove the delegate from `Formula`. odisabled "#uses_from_macos_elements", "#declared_deps" - @uses_from_macos_elements end # @deprecated def uses_from_macos_names - # TODO: Remember to remove the delegate from formula.rb + # TODO: Remember to remove the delegate from `Formula`. odisabled "#uses_from_macos_names", "#declared_deps" - uses_from_macos_elements.flat_map { |e| e.is_a?(Hash) ? e.keys : e } end def deps