From 2af4a3cd202cc02fac3a9fe9e51423b0300eb9a6 Mon Sep 17 00:00:00 2001 From: apainintheneck Date: Sat, 3 Feb 2024 13:21:32 -0800 Subject: [PATCH] formula: change how `#to_hash` is defined for backwards compatibility Now the output of commands like `brew info --json=` and `brew generate-formula-api` should be the same as before along with the additional files for the internal API. Before this commit the hash key order had changed. --- Library/Homebrew/formula.rb | 90 ++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 41 deletions(-) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 6fb60ee81d8e12..9ced43938792de 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -2215,50 +2215,56 @@ def merge_spec_dependables(dependables) # @private def to_hash hsh = { - "name" => name, - "full_name" => full_name, - "tap" => tap&.name, - "oldname" => oldnames.first, # deprecated - "oldnames" => oldnames, - "aliases" => aliases.sort, - "versioned_formulae" => versioned_formulae.map(&:name), - "desc" => desc, - "license" => SPDX.license_expression_to_string(license), - "homepage" => homepage, - "versions" => { + "name" => name, + "full_name" => full_name, + "tap" => tap&.name, + "oldname" => oldnames.first, # deprecated + "oldnames" => oldnames, + "aliases" => aliases.sort, + "versioned_formulae" => versioned_formulae.map(&:name), + "desc" => desc, + "license" => SPDX.license_expression_to_string(license), + "homepage" => homepage, + "versions" => { "stable" => stable&.version&.to_s, "head" => head&.version&.to_s, "bottle" => bottle_defined?, }, - "urls" => urls_hash, - "revision" => revision, - "version_scheme" => version_scheme, - "bottle" => {}, - "pour_bottle_only_if" => self.class.pour_bottle_only_if&.to_s, - "keg_only" => keg_only?, - "keg_only_reason" => keg_only_reason&.to_hash, - "options" => [], - **dependencies_hash, - "requirements" => serialized_requirements, - "conflicts_with" => conflicts.map(&:name), - "conflicts_with_reasons" => conflicts.map(&:reason), - "link_overwrite" => self.class.link_overwrite_paths.to_a, - "caveats" => caveats_with_placeholders, - "installed" => [], - "linked_keg" => linked_version&.to_s, - "pinned" => pinned?, - "outdated" => outdated?, - "deprecated" => deprecated?, - "deprecation_date" => deprecation_date, - "deprecation_reason" => deprecation_reason, - "disabled" => disabled?, - "disable_date" => disable_date, - "disable_reason" => disable_reason, - "post_install_defined" => post_install_defined?, - "service" => (service.to_hash if service?), - "tap_git_head" => tap_git_head, - "ruby_source_path" => ruby_source_path, - "ruby_source_checksum" => {}, + "urls" => urls_hash, + "revision" => revision, + "version_scheme" => version_scheme, + "bottle" => {}, + "pour_bottle_only_if" => self.class.pour_bottle_only_if&.to_s, + "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" => [], + "requirements" => serialized_requirements, + "conflicts_with" => conflicts.map(&:name), + "conflicts_with_reasons" => conflicts.map(&:reason), + "link_overwrite" => self.class.link_overwrite_paths.to_a, + "caveats" => caveats_with_placeholders, + "installed" => [], + "linked_keg" => linked_version&.to_s, + "pinned" => pinned?, + "outdated" => outdated?, + "deprecated" => deprecated?, + "deprecation_date" => deprecation_date, + "deprecation_reason" => deprecation_reason, + "disabled" => disabled?, + "disable_date" => disable_date, + "disable_reason" => disable_reason, + "post_install_defined" => post_install_defined?, + "service" => (service.to_hash 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? @@ -2267,6 +2273,8 @@ def to_hash { "option" => opt.flag, "description" => opt.description } end + hsh.merge!(dependencies_hash) + hsh["installed"] = installed_kegs.sort_by(&:version).map do |keg| tab = Tab.for_keg keg { @@ -2307,7 +2315,7 @@ def to_api_hash .transform_values(&:presence) .compact - api_hash.merge(dep_hash) + api_hash.merge!(dep_hash) # Exclude default values. api_hash["revision"] = revision unless revision.zero?