formula: share dependencies serialization logic
Note: This changes where the "head_dependencies" key in the hash shows up but not the hash's contents. "head_dependencies" now shows up directly after all of the other dependency keys. Before it was always at the end of the hash after variations.
This commit is contained in:
parent
d2dd80b0d6
commit
69609731d9
@ -2214,12 +2214,6 @@ class Formula
|
||||
|
||||
# @private
|
||||
def to_hash
|
||||
# Create a hash of spec names (stable/head) to the list of dependencies under each
|
||||
dependencies = self.class.spec_syms.to_h do |sym|
|
||||
[sym, send(sym)&.declared_deps]
|
||||
end
|
||||
dependencies.transform_values! { |deps| deps&.reject(&:implicit?) } # Remove all implicit deps from all lists
|
||||
|
||||
hsh = {
|
||||
"name" => name,
|
||||
"full_name" => full_name,
|
||||
@ -2244,13 +2238,7 @@ class Formula
|
||||
"keg_only" => keg_only?,
|
||||
"keg_only_reason" => keg_only_reason&.to_hash,
|
||||
"options" => [],
|
||||
"build_dependencies" => [],
|
||||
"dependencies" => [],
|
||||
"test_dependencies" => [],
|
||||
"recommended_dependencies" => [],
|
||||
"optional_dependencies" => [],
|
||||
"uses_from_macos" => [],
|
||||
"uses_from_macos_bounds" => [],
|
||||
**dependencies_hash,
|
||||
"requirements" => serialized_requirements,
|
||||
"conflicts_with" => conflicts.map(&:name),
|
||||
"conflicts_with_reasons" => conflicts.map(&:reason),
|
||||
@ -2280,54 +2268,6 @@ class Formula
|
||||
{ "option" => opt.flag, "description" => opt.description }
|
||||
end
|
||||
|
||||
dependencies.each do |spec_sym, spec_deps|
|
||||
next if spec_deps.nil?
|
||||
|
||||
dep_hash = if spec_sym == :stable
|
||||
hsh
|
||||
else
|
||||
next if spec_deps == dependencies[:stable]
|
||||
|
||||
hsh["#{spec_sym}_dependencies"] ||= {}
|
||||
end
|
||||
|
||||
dep_hash["build_dependencies"] = spec_deps.select(&:build?)
|
||||
.reject(&:uses_from_macos?)
|
||||
.map(&:name)
|
||||
.uniq
|
||||
dep_hash["dependencies"] = spec_deps.reject(&:optional?)
|
||||
.reject(&:recommended?)
|
||||
.reject(&:build?)
|
||||
.reject(&:test?)
|
||||
.reject(&:uses_from_macos?)
|
||||
.map(&:name)
|
||||
.uniq
|
||||
dep_hash["test_dependencies"] = spec_deps.select(&:test?)
|
||||
.reject(&:uses_from_macos?)
|
||||
.map(&:name)
|
||||
.uniq
|
||||
dep_hash["recommended_dependencies"] = spec_deps.select(&:recommended?)
|
||||
.reject(&:uses_from_macos?)
|
||||
.map(&:name)
|
||||
.uniq
|
||||
dep_hash["optional_dependencies"] = spec_deps.select(&:optional?)
|
||||
.reject(&:uses_from_macos?)
|
||||
.map(&:name)
|
||||
.uniq
|
||||
|
||||
uses_from_macos_deps = spec_deps.select(&:uses_from_macos?).uniq
|
||||
dep_hash["uses_from_macos"] = uses_from_macos_deps.map do |dep|
|
||||
if dep.tags.length >= 2
|
||||
{ dep.name => dep.tags }
|
||||
elsif dep.tags.present?
|
||||
{ dep.name => dep.tags.first }
|
||||
else
|
||||
dep.name
|
||||
end
|
||||
end
|
||||
dep_hash["uses_from_macos_bounds"] = uses_from_macos_deps.map(&:bounds)
|
||||
end
|
||||
|
||||
hsh["installed"] = installed_kegs.sort_by(&:version).map do |keg|
|
||||
tab = Tab.for_keg keg
|
||||
{
|
||||
@ -2358,16 +2298,18 @@ class Formula
|
||||
"license" => SPDX.license_expression_to_string(license),
|
||||
"homepage" => homepage,
|
||||
"urls" => urls_hash.transform_values(&:compact),
|
||||
"build_dependencies" => [],
|
||||
"dependencies" => [],
|
||||
"test_dependencies" => [],
|
||||
"uses_from_macos" => [],
|
||||
"uses_from_macos_bounds" => [],
|
||||
"post_install_defined" => post_install_defined?,
|
||||
"ruby_source_path" => ruby_source_path,
|
||||
"ruby_source_checksum" => { "sha256" => ruby_source_checksum&.hexdigest },
|
||||
}
|
||||
|
||||
dep_hash = dependencies_hash
|
||||
.except("recommended_dependencies", "optional_dependencies")
|
||||
.transform_values(&:presence)
|
||||
.compact
|
||||
|
||||
api_hash.merge(dep_hash)
|
||||
|
||||
# Exclude default values.
|
||||
api_hash["revision"] = revision unless revision.zero?
|
||||
api_hash["version_scheme"] = version_scheme unless version_scheme.zero?
|
||||
@ -2550,6 +2492,67 @@ class Formula
|
||||
end
|
||||
end
|
||||
|
||||
# @private
|
||||
def dependencies_hash
|
||||
# Create a hash of spec names (stable/head) to the list of dependencies under each
|
||||
dependencies = self.class.spec_syms.to_h do |sym|
|
||||
[sym, send(sym)&.declared_deps]
|
||||
end
|
||||
dependencies.transform_values! { |deps| deps&.reject(&:implicit?) } # Remove all implicit deps from all lists
|
||||
|
||||
hash = {}
|
||||
|
||||
dependencies.each do |spec_sym, spec_deps|
|
||||
next if spec_deps.nil?
|
||||
|
||||
dep_hash = if spec_sym == :stable
|
||||
hash
|
||||
else
|
||||
next if spec_deps == dependencies[:stable]
|
||||
|
||||
hash["#{spec_sym}_dependencies"] ||= {}
|
||||
end
|
||||
|
||||
dep_hash["build_dependencies"] = spec_deps.select(&:build?)
|
||||
.reject(&:uses_from_macos?)
|
||||
.map(&:name)
|
||||
.uniq
|
||||
dep_hash["dependencies"] = spec_deps.reject(&:optional?)
|
||||
.reject(&:recommended?)
|
||||
.reject(&:build?)
|
||||
.reject(&:test?)
|
||||
.reject(&:uses_from_macos?)
|
||||
.map(&:name)
|
||||
.uniq
|
||||
dep_hash["test_dependencies"] = spec_deps.select(&:test?)
|
||||
.reject(&:uses_from_macos?)
|
||||
.map(&:name)
|
||||
.uniq
|
||||
dep_hash["recommended_dependencies"] = spec_deps.select(&:recommended?)
|
||||
.reject(&:uses_from_macos?)
|
||||
.map(&:name)
|
||||
.uniq
|
||||
dep_hash["optional_dependencies"] = spec_deps.select(&:optional?)
|
||||
.reject(&:uses_from_macos?)
|
||||
.map(&:name)
|
||||
.uniq
|
||||
|
||||
uses_from_macos_deps = spec_deps.select(&:uses_from_macos?).uniq
|
||||
dep_hash["uses_from_macos"] = uses_from_macos_deps.map do |dep|
|
||||
if dep.tags.length >= 2
|
||||
{ dep.name => dep.tags }
|
||||
elsif dep.tags.present?
|
||||
{ dep.name => dep.tags.first }
|
||||
else
|
||||
dep.name
|
||||
end
|
||||
end
|
||||
dep_hash["uses_from_macos_bounds"] = uses_from_macos_deps.map(&:bounds)
|
||||
end
|
||||
|
||||
hash
|
||||
end
|
||||
|
||||
# @private
|
||||
def on_system_blocks_exist?
|
||||
self.class.on_system_blocks_exist? || @on_system_blocks_exist
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user