diff --git a/Library/Homebrew/api.rb b/Library/Homebrew/api.rb index c88ef32fb5..7dcc3c696d 100644 --- a/Library/Homebrew/api.rb +++ b/Library/Homebrew/api.rb @@ -184,11 +184,6 @@ module Homebrew Tap.fetch(org, repo) end - - sig { returns(T::Boolean) } - def self.internal_json_v3? - ENV["HOMEBREW_INTERNAL_JSON_V3"].present? - end end sig { params(block: T.proc.returns(T.untyped)).returns(T.untyped) } diff --git a/Library/Homebrew/api/formula.rb b/Library/Homebrew/api/formula.rb index d905bb4c85..1bcd622da4 100644 --- a/Library/Homebrew/api/formula.rb +++ b/Library/Homebrew/api/formula.rb @@ -11,7 +11,6 @@ module Homebrew extend Cachable DEFAULT_API_FILENAME = "formula.jws.json" - INTERNAL_V3_API_FILENAME = "internal/v3/homebrew-core.jws.json" private_class_method :cache @@ -43,33 +42,24 @@ module Homebrew sig { returns(Pathname) } def self.cached_json_file_path - if Homebrew::API.internal_json_v3? - HOMEBREW_CACHE_API/INTERNAL_V3_API_FILENAME - else - HOMEBREW_CACHE_API/DEFAULT_API_FILENAME - end + HOMEBREW_CACHE_API/DEFAULT_API_FILENAME end sig { returns(T::Boolean) } def self.download_and_cache_data! - if Homebrew::API.internal_json_v3? - json_formulae, updated = Homebrew::API.fetch_json_api_file INTERNAL_V3_API_FILENAME - overwrite_cache! T.cast(json_formulae, T::Hash[String, T.untyped]) - else - json_formulae, updated = Homebrew::API.fetch_json_api_file DEFAULT_API_FILENAME + json_formulae, updated = Homebrew::API.fetch_json_api_file DEFAULT_API_FILENAME - cache["aliases"] = {} - cache["renames"] = {} - cache["formulae"] = json_formulae.to_h do |json_formula| - json_formula["aliases"].each do |alias_name| - cache["aliases"][alias_name] = json_formula["name"] - end - (json_formula["oldnames"] || [json_formula["oldname"]].compact).each do |oldname| - cache["renames"][oldname] = json_formula["name"] - end - - [json_formula["name"], json_formula.except("name")] + cache["aliases"] = {} + cache["renames"] = {} + cache["formulae"] = json_formulae.to_h do |json_formula| + json_formula["aliases"].each do |alias_name| + cache["aliases"][alias_name] = json_formula["name"] end + (json_formula["oldnames"] || [json_formula["oldname"]].compact).each do |oldname| + cache["renames"][oldname] = json_formula["name"] + end + + [json_formula["name"], json_formula.except("name")] end updated diff --git a/Library/Homebrew/dev-cmd/tests.rb b/Library/Homebrew/dev-cmd/tests.rb index ac69184300..697a2a0684 100644 --- a/Library/Homebrew/dev-cmd/tests.rb +++ b/Library/Homebrew/dev-cmd/tests.rb @@ -219,7 +219,6 @@ module Homebrew # TODO: remove this and fix tests when possible. ENV["HOMEBREW_NO_INSTALL_FROM_API"] = "1" - ENV.delete("HOMEBREW_INTERNAL_JSON_V3") ENV["USER"] ||= system_command!("id", args: ["-nu"]).stdout.chomp diff --git a/Library/Homebrew/extend/cachable.rb b/Library/Homebrew/extend/cachable.rb index d3d2794bc3..b124c638e6 100644 --- a/Library/Homebrew/extend/cachable.rb +++ b/Library/Homebrew/extend/cachable.rb @@ -7,16 +7,8 @@ module Cachable @cache ||= T.let({}, T.nilable(T::Hash[T.untyped, T.untyped])) end - # NOTE: We overwrite here instead of using `Hash#clear` to handle frozen hashes. sig { void } def clear_cache - overwrite_cache!({}) - end - - private - - sig { params(hash: T::Hash[T.untyped, T.untyped]).void } - def overwrite_cache!(hash) - @cache = hash + cache.clear end end diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 0529671e9a..5dd9e2ec4c 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -213,71 +213,38 @@ module Formulary end end - add_deps = if Homebrew::API.internal_json_v3? - lambda do |deps| - T.bind(self, SoftwareSpec) + add_deps = lambda do |spec| + T.bind(self, SoftwareSpec) - deps&.each do |name, info| - tags = case info&.dig("tags") - in Array => tag_list - tag_list.map(&:to_sym) - in String => tag - tag.to_sym - else - nil - end + dep_json = json_formula.fetch("#{spec}_dependencies", json_formula) - if info&.key?("uses_from_macos") - bounds = info["uses_from_macos"].dup || {} - bounds.deep_transform_keys!(&:to_sym) - bounds.deep_transform_values!(&:to_sym) + dep_json["dependencies"]&.each do |dep| + # Backwards compatibility check - uses_from_macos used to be a part of dependencies on Linux + next if !json_formula.key?("uses_from_macos_bounds") && uses_from_macos_names.include?(dep) && + !Homebrew::SimulateSystem.simulating_or_running_on_macos? - if tags - uses_from_macos name => tags, **bounds - else - uses_from_macos name, **bounds - end - elsif tags - depends_on name => tags - else - depends_on name - end - end + depends_on dep end - else - lambda do |spec| - T.bind(self, SoftwareSpec) - dep_json = json_formula.fetch("#{spec}_dependencies", json_formula) - - dep_json["dependencies"]&.each do |dep| + [:build, :test, :recommended, :optional].each do |type| + dep_json["#{type}_dependencies"]&.each do |dep| # Backwards compatibility check - uses_from_macos used to be a part of dependencies on Linux next if !json_formula.key?("uses_from_macos_bounds") && uses_from_macos_names.include?(dep) && !Homebrew::SimulateSystem.simulating_or_running_on_macos? - depends_on dep + depends_on dep => type end + end - [:build, :test, :recommended, :optional].each do |type| - dep_json["#{type}_dependencies"]&.each do |dep| - # Backwards compatibility check - uses_from_macos used to be a part of dependencies on Linux - next if !json_formula.key?("uses_from_macos_bounds") && uses_from_macos_names.include?(dep) && - !Homebrew::SimulateSystem.simulating_or_running_on_macos? + 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!(&:to_sym) - depends_on dep => type - end - end - - 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!(&:to_sym) - - if dep.is_a?(Hash) - uses_from_macos dep.deep_transform_values(&:to_sym).merge(bounds) - else - uses_from_macos dep, bounds - end + if dep.is_a?(Hash) + uses_from_macos dep.deep_transform_values(&:to_sym).merge(bounds) + else + uses_from_macos dep, bounds end end end @@ -299,15 +266,10 @@ module Formulary using: urls_stable["using"]&.to_sym, }.compact url urls_stable["url"], **url_spec - version Homebrew::API.internal_json_v3? ? json_formula["version"] : json_formula["versions"]["stable"] + version json_formula["versions"]["stable"] sha256 urls_stable["checksum"] if urls_stable["checksum"].present? - if Homebrew::API.internal_json_v3? - instance_exec(json_formula["dependencies"], &add_deps) - else - instance_exec(:stable, &add_deps) - end - + instance_exec(:stable, &add_deps) requirements[:stable]&.each do |req| depends_on req end @@ -322,23 +284,14 @@ module Formulary }.compact url urls_head["url"], **url_spec - if Homebrew::API.internal_json_v3? - instance_exec(json_formula["head_dependencies"], &add_deps) - else - instance_exec(:head, &add_deps) - end - + instance_exec(:head, &add_deps) requirements[:head]&.each do |req| depends_on req end end end - bottles_stable = if Homebrew::API.internal_json_v3? - json_formula["bottle"] - else - json_formula["bottle"]["stable"] - end.presence + bottles_stable = json_formula["bottle"]["stable"].presence if bottles_stable bottle do @@ -426,26 +379,20 @@ module Formulary .gsub(HOMEBREW_HOME_PLACEHOLDER, Dir.home) end - @tap_git_head_string = if Homebrew::API.internal_json_v3? - Homebrew::API::Formula.tap_git_head - else - json_formula["tap_git_head"] - end + @tap_git_head_string = json_formula["tap_git_head"] def tap_git_head self.class.instance_variable_get(:@tap_git_head_string) end - unless Homebrew::API.internal_json_v3? - @oldnames_array = json_formula["oldnames"] || [json_formula["oldname"]].compact - def oldnames - self.class.instance_variable_get(:@oldnames_array) - end + @oldnames_array = json_formula["oldnames"] || [json_formula["oldname"]].compact + def oldnames + self.class.instance_variable_get(:@oldnames_array) + end - @aliases_array = json_formula.fetch("aliases", []) - def aliases - self.class.instance_variable_get(:@aliases_array) - end + @aliases_array = json_formula.fetch("aliases", []) + def aliases + self.class.instance_variable_get(:@aliases_array) end @versioned_formulae_array = json_formula.fetch("versioned_formulae", []) diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 40b3ebec8e..a00f95b9e1 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -1307,8 +1307,6 @@ class CoreTap < AbstractCoreTap @tap_migrations ||= if Homebrew::EnvConfig.no_install_from_api? ensure_installed! super - elsif Homebrew::API.internal_json_v3? - Homebrew::API::Formula.tap_migrations else migrations, = Homebrew::API.fetch_json_api_file "formula_tap_migrations.jws.json", stale_seconds: TAP_MIGRATIONS_STALE_SECONDS