Skip to content

Commit

Permalink
Refactor and add type signature for uses_from_macos.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed Feb 12, 2024
1 parent 4762f64 commit b160a13
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
10 changes: 8 additions & 2 deletions Library/Homebrew/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3369,8 +3369,14 @@ def depends_on(dep)
# 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::Hash[T.any(String, Symbol), 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
Expand Down
7 changes: 4 additions & 3 deletions Library/Homebrew/formulary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,13 @@ def self.load_formula_from_api(name, flags:)
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
Expand Down
23 changes: 15 additions & 8 deletions Library/Homebrew/software_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,23 @@ def depends_on(spec)
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)
if dep
tags = []
bounds = bounds.dup
else
bounds = bounds.dup
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
Expand Down

0 comments on commit b160a13

Please sign in to comment.