Merge pull request #16647 from reitermarkus/uses_from_macos_sig
Refactor and add type signature for `uses_from_macos`.
This commit is contained in:
commit
1c4b06fce2
@ -230,6 +230,7 @@ end
|
|||||||
class UsesFromMacOSDependency < Dependency
|
class UsesFromMacOSDependency < Dependency
|
||||||
attr_reader :bounds
|
attr_reader :bounds
|
||||||
|
|
||||||
|
sig { params(name: String, tags: T::Array[Symbol], bounds: T::Hash[Symbol, Symbol]).void }
|
||||||
def initialize(name, tags = [], bounds:)
|
def initialize(name, tags = [], bounds:)
|
||||||
super(name, tags)
|
super(name, tags)
|
||||||
|
|
||||||
|
|||||||
@ -3374,6 +3374,12 @@ 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}.
|
||||||
|
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 = {})
|
def uses_from_macos(dep, bounds = {})
|
||||||
specs.each { |spec| spec.uses_from_macos(dep, bounds) }
|
specs.each { |spec| spec.uses_from_macos(dep, bounds) }
|
||||||
end
|
end
|
||||||
|
|||||||
@ -234,7 +234,7 @@ 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)
|
uses_from_macos dep.deep_transform_values(&:to_sym).merge(bounds)
|
||||||
|
|||||||
@ -46,7 +46,6 @@ class SoftwareSpec
|
|||||||
@deprecated_options = []
|
@deprecated_options = []
|
||||||
@build = BuildOptions.new(Options.create(@flags), options)
|
@build = BuildOptions.new(Options.create(@flags), options)
|
||||||
@compiler_failures = []
|
@compiler_failures = []
|
||||||
@uses_from_macos_elements = []
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize_dup(other)
|
def initialize_dup(other)
|
||||||
@ -62,7 +61,6 @@ class SoftwareSpec
|
|||||||
@deprecated_options = @deprecated_options.dup
|
@deprecated_options = @deprecated_options.dup
|
||||||
@build = @build.dup
|
@build = @build.dup
|
||||||
@compiler_failures = @compiler_failures.dup
|
@compiler_failures = @compiler_failures.dup
|
||||||
@uses_from_macos_elements = @uses_from_macos_elements.dup
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def freeze
|
def freeze
|
||||||
@ -77,7 +75,6 @@ class SoftwareSpec
|
|||||||
@deprecated_options.freeze
|
@deprecated_options.freeze
|
||||||
@build.freeze
|
@build.freeze
|
||||||
@compiler_failures.freeze
|
@compiler_failures.freeze
|
||||||
@uses_from_macos_elements.freeze
|
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -189,33 +186,36 @@ 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: T.any(String, T::Hash[T.any(String, Symbol), T.any(Symbol, T::Array[Symbol])]),
|
||||||
deps = [T.unsafe(bounds).shift].to_h
|
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
|
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)
|
|
||||||
|
|
||||||
@uses_from_macos_elements << deps
|
|
||||||
|
|
||||||
depends_on UsesFromMacOSDependency.new(spec, Array(tags), bounds: bounds)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# @deprecated
|
# @deprecated
|
||||||
def uses_from_macos_elements
|
def uses_from_macos_elements
|
||||||
# TODO: remove all @uses_from_macos_elements when removing this method
|
# TODO: Remember to remove the delegate from `Formula`.
|
||||||
# Also remember to remove the delegate from formula.rb
|
|
||||||
odisabled "#uses_from_macos_elements", "#declared_deps"
|
odisabled "#uses_from_macos_elements", "#declared_deps"
|
||||||
@uses_from_macos_elements
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# @deprecated
|
# @deprecated
|
||||||
def uses_from_macos_names
|
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"
|
odisabled "#uses_from_macos_names", "#declared_deps"
|
||||||
uses_from_macos_elements.flat_map { |e| e.is_a?(Hash) ? e.keys : e }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def deps
|
def deps
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user