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,64 +2214,52 @@ class Formula
|
|||||||
|
|
||||||
# @private
|
# @private
|
||||||
def to_hash
|
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 = {
|
hsh = {
|
||||||
"name" => name,
|
"name" => name,
|
||||||
"full_name" => full_name,
|
"full_name" => full_name,
|
||||||
"tap" => tap&.name,
|
"tap" => tap&.name,
|
||||||
"oldname" => oldnames.first, # deprecated
|
"oldname" => oldnames.first, # deprecated
|
||||||
"oldnames" => oldnames,
|
"oldnames" => oldnames,
|
||||||
"aliases" => aliases.sort,
|
"aliases" => aliases.sort,
|
||||||
"versioned_formulae" => versioned_formulae.map(&:name),
|
"versioned_formulae" => versioned_formulae.map(&:name),
|
||||||
"desc" => desc,
|
"desc" => desc,
|
||||||
"license" => SPDX.license_expression_to_string(license),
|
"license" => SPDX.license_expression_to_string(license),
|
||||||
"homepage" => homepage,
|
"homepage" => homepage,
|
||||||
"versions" => {
|
"versions" => {
|
||||||
"stable" => stable&.version&.to_s,
|
"stable" => stable&.version&.to_s,
|
||||||
"head" => head&.version&.to_s,
|
"head" => head&.version&.to_s,
|
||||||
"bottle" => bottle_defined?,
|
"bottle" => bottle_defined?,
|
||||||
},
|
},
|
||||||
"urls" => urls_hash,
|
"urls" => urls_hash,
|
||||||
"revision" => revision,
|
"revision" => revision,
|
||||||
"version_scheme" => version_scheme,
|
"version_scheme" => version_scheme,
|
||||||
"bottle" => {},
|
"bottle" => {},
|
||||||
"pour_bottle_only_if" => self.class.pour_bottle_only_if&.to_s,
|
"pour_bottle_only_if" => self.class.pour_bottle_only_if&.to_s,
|
||||||
"keg_only" => keg_only?,
|
"keg_only" => keg_only?,
|
||||||
"keg_only_reason" => keg_only_reason&.to_hash,
|
"keg_only_reason" => keg_only_reason&.to_hash,
|
||||||
"options" => [],
|
"options" => [],
|
||||||
"build_dependencies" => [],
|
**dependencies_hash,
|
||||||
"dependencies" => [],
|
"requirements" => serialized_requirements,
|
||||||
"test_dependencies" => [],
|
"conflicts_with" => conflicts.map(&:name),
|
||||||
"recommended_dependencies" => [],
|
"conflicts_with_reasons" => conflicts.map(&:reason),
|
||||||
"optional_dependencies" => [],
|
"link_overwrite" => self.class.link_overwrite_paths.to_a,
|
||||||
"uses_from_macos" => [],
|
"caveats" => caveats&.gsub(HOMEBREW_PREFIX, HOMEBREW_PREFIX_PLACEHOLDER)
|
||||||
"uses_from_macos_bounds" => [],
|
&.gsub(HOMEBREW_CELLAR, HOMEBREW_CELLAR_PLACEHOLDER),
|
||||||
"requirements" => serialized_requirements,
|
"installed" => [],
|
||||||
"conflicts_with" => conflicts.map(&:name),
|
"linked_keg" => linked_version&.to_s,
|
||||||
"conflicts_with_reasons" => conflicts.map(&:reason),
|
"pinned" => pinned?,
|
||||||
"link_overwrite" => self.class.link_overwrite_paths.to_a,
|
"outdated" => outdated?,
|
||||||
"caveats" => caveats&.gsub(HOMEBREW_PREFIX, HOMEBREW_PREFIX_PLACEHOLDER)
|
"deprecated" => deprecated?,
|
||||||
&.gsub(HOMEBREW_CELLAR, HOMEBREW_CELLAR_PLACEHOLDER),
|
"deprecation_date" => deprecation_date,
|
||||||
"installed" => [],
|
"deprecation_reason" => deprecation_reason,
|
||||||
"linked_keg" => linked_version&.to_s,
|
"disabled" => disabled?,
|
||||||
"pinned" => pinned?,
|
"disable_date" => disable_date,
|
||||||
"outdated" => outdated?,
|
"disable_reason" => disable_reason,
|
||||||
"deprecated" => deprecated?,
|
"post_install_defined" => post_install_defined?,
|
||||||
"deprecation_date" => deprecation_date,
|
"service" => (service.serialize if service?),
|
||||||
"deprecation_reason" => deprecation_reason,
|
"tap_git_head" => tap_git_head,
|
||||||
"disabled" => disabled?,
|
"ruby_source_path" => ruby_source_path,
|
||||||
"disable_date" => disable_date,
|
"ruby_source_checksum" => {},
|
||||||
"disable_reason" => disable_reason,
|
|
||||||
"post_install_defined" => post_install_defined?,
|
|
||||||
"service" => (service.serialize if service?),
|
|
||||||
"tap_git_head" => tap_git_head,
|
|
||||||
"ruby_source_path" => ruby_source_path,
|
|
||||||
"ruby_source_checksum" => {},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hsh["bottle"]["stable"] = bottle_hash if stable && bottle_defined?
|
hsh["bottle"]["stable"] = bottle_hash if stable && bottle_defined?
|
||||||
@ -2280,54 +2268,6 @@ class Formula
|
|||||||
{ "option" => opt.flag, "description" => opt.description }
|
{ "option" => opt.flag, "description" => opt.description }
|
||||||
end
|
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|
|
hsh["installed"] = installed_kegs.sort_by(&:version).map do |keg|
|
||||||
tab = Tab.for_keg keg
|
tab = Tab.for_keg keg
|
||||||
{
|
{
|
||||||
@ -2354,20 +2294,22 @@ class Formula
|
|||||||
# @private
|
# @private
|
||||||
def to_api_hash
|
def to_api_hash
|
||||||
api_hash = {
|
api_hash = {
|
||||||
"desc" => desc,
|
"desc" => desc,
|
||||||
"license" => SPDX.license_expression_to_string(license),
|
"license" => SPDX.license_expression_to_string(license),
|
||||||
"homepage" => homepage,
|
"homepage" => homepage,
|
||||||
"urls" => urls_hash.transform_values(&:compact),
|
"urls" => urls_hash.transform_values(&:compact),
|
||||||
"build_dependencies" => [],
|
"post_install_defined" => post_install_defined?,
|
||||||
"dependencies" => [],
|
"ruby_source_path" => ruby_source_path,
|
||||||
"test_dependencies" => [],
|
"ruby_source_checksum" => { "sha256" => ruby_source_checksum&.hexdigest },
|
||||||
"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.
|
# Exclude default values.
|
||||||
api_hash["revision"] = revision unless revision.zero?
|
api_hash["revision"] = revision unless revision.zero?
|
||||||
api_hash["version_scheme"] = version_scheme unless version_scheme.zero?
|
api_hash["version_scheme"] = version_scheme unless version_scheme.zero?
|
||||||
@ -2550,6 +2492,67 @@ class Formula
|
|||||||
end
|
end
|
||||||
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
|
# @private
|
||||||
def on_system_blocks_exist?
|
def on_system_blocks_exist?
|
||||||
self.class.on_system_blocks_exist? || @on_system_blocks_exist
|
self.class.on_system_blocks_exist? || @on_system_blocks_exist
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user