From 039eb1adffdff15fccb461d9e3aa4b8e450bc1e1 Mon Sep 17 00:00:00 2001 From: apainintheneck Date: Sun, 17 Mar 2024 13:55:57 -0700 Subject: [PATCH] Update formula internal json v3 to improve dependencies readability This improves the readability of dependencies in the json we produce for this internally. --- Library/Homebrew/formula.rb | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 24cc6f75a2..c70f79e923 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -2361,13 +2361,6 @@ class Formula "ruby_source_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? @@ -2389,6 +2382,14 @@ class Formula api_hash["versioned_formulae"] = versioned_formulae_list.map(&:name) end + if (dependencies = dependencies_list(:stable).presence) + api_hash["dependencies"] = dependencies + end + + if (head_dependencies = dependencies_list(:head).presence) + api_hash["head_dependencies"] = head_dependencies + end + if (requirements_array = serialized_requirements.presence) api_hash["requirements"] = requirements_array end @@ -2608,6 +2609,19 @@ class Formula hash end + def dependencies_list(spec_symbol) + return if spec_symbol != :stable && spec_symbol != :head + + send(spec_symbol)&.declared_deps&.each_with_object({}) do |dep, dep_hash| + next if dep.implicit? # Remove all implicit deps + + dep_hash[dep.name] = {}.tap do |info| + info[:tags] = dep.tags if dep.tags.present? + info[:uses_from_macos] = dep.bounds.presence if dep.uses_from_macos? + end.presence + end + end + def on_system_blocks_exist? self.class.on_system_blocks_exist? || @on_system_blocks_exist end