Refactor and add type signature for uses_from_macos.

This commit is contained in:
Markus Reiter 2024-02-12 23:45:03 +01:00
parent 4762f644cb
commit d9712f4d50
No known key found for this signature in database
GPG Key ID: 245293B51702655B
3 changed files with 27 additions and 13 deletions

View File

@ -3369,8 +3369,14 @@ class Formula
# On macOS this is a no-op (as we use the provided system libraries) unless # On macOS this is a no-op (as we use the provided system libraries) unless
# `:since` specifies a minimum macOS version. # `:since` specifies a minimum macOS version.
# On Linux this will act as {.depends_on}. # On Linux this will act as {.depends_on}.
def uses_from_macos(dep, bounds = {}) sig {
specs.each { |spec| spec.uses_from_macos(dep, bounds) } 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 end
# @!attribute [w] option # @!attribute [w] option

View File

@ -234,12 +234,13 @@ module Formulary
dep_json["uses_from_macos"]&.each_with_index do |dep, index| dep_json["uses_from_macos"]&.each_with_index do |dep, index|
bounds = dep_json.fetch("uses_from_macos_bounds", [])[index].dup || {} bounds = dep_json.fetch("uses_from_macos_bounds", [])[index].dup || {}
bounds.deep_transform_keys!(&:to_sym) 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) 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 else
uses_from_macos dep, bounds uses_from_macos dep, **bounds
end end
end end
end end

View File

@ -186,16 +186,23 @@ class SoftwareSpec
add_dep_option(dep) if dep add_dep_option(dep) if dep
end end
def uses_from_macos(deps, bounds = {}) sig {
if deps.is_a?(Hash) params(
bounds = deps.dup dep: String,
deps = [T.unsafe(bounds).shift].to_h 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 end
spec, tags = deps.is_a?(Hash) ? deps.first : deps depends_on UsesFromMacOSDependency.new(dep, tags, bounds: bounds)
raise TypeError, "Dependency name must be a string!" unless spec.is_a?(String)
depends_on UsesFromMacOSDependency.new(spec, Array(tags), bounds: bounds)
end end
# @deprecated # @deprecated