Merge pull request #16420 from Homebrew/allow-cask-formula-loading-from-api-hash-missing-more-keys
API: Load casks/formula from JSON with missing keys
This commit is contained in:
commit
3e027de4ed
@ -124,11 +124,12 @@ module Homebrew
|
||||
|
||||
sig { params(json: Hash).returns(Hash) }
|
||||
def self.merge_variations(json)
|
||||
return json unless json.key?("variations")
|
||||
|
||||
bottle_tag = ::Utils::Bottles::Tag.new(system: Homebrew::SimulateSystem.current_os,
|
||||
arch: Homebrew::SimulateSystem.current_arch)
|
||||
|
||||
if (variations = json["variations"].presence) &&
|
||||
(variation = variations[bottle_tag.to_s].presence)
|
||||
if (variation = json.dig("variations", bottle_tag.to_s).presence)
|
||||
json = json.merge(variation)
|
||||
end
|
||||
|
||||
|
||||
@ -279,7 +279,7 @@ module Cask
|
||||
def populate_from_api!(json_cask)
|
||||
raise ArgumentError, "Expected cask to be loaded from the API" unless loaded_from_api?
|
||||
|
||||
@languages = json_cask[:languages]
|
||||
@languages = json_cask.fetch(:languages, [])
|
||||
@tap_git_head = json_cask.fetch(:tap_git_head, "HEAD")
|
||||
|
||||
@ruby_source_path = json_cask[:ruby_source_path]
|
||||
|
||||
@ -280,7 +280,7 @@ module Cask
|
||||
|
||||
url json_cask[:url], **json_cask.fetch(:url_specs, {}) if json_cask[:url].present?
|
||||
appcast json_cask[:appcast] if json_cask[:appcast].present?
|
||||
json_cask[:name].each do |cask_name|
|
||||
json_cask[:name]&.each do |cask_name|
|
||||
name cask_name
|
||||
end
|
||||
desc json_cask[:desc]
|
||||
|
||||
@ -154,14 +154,14 @@ module Formulary
|
||||
|
||||
json_formula = Homebrew::API.merge_variations(json_formula)
|
||||
|
||||
uses_from_macos_names = json_formula["uses_from_macos"].map do |dep|
|
||||
uses_from_macos_names = json_formula["uses_from_macos"]&.map do |dep|
|
||||
next dep unless dep.is_a? Hash
|
||||
|
||||
dep.keys.first
|
||||
end
|
||||
|
||||
requirements = {}
|
||||
json_formula["requirements"].map do |req|
|
||||
json_formula["requirements"]&.map do |req|
|
||||
req_name = req["name"].to_sym
|
||||
next if API_SUPPORTED_REQUIREMENTS.exclude?(req_name)
|
||||
|
||||
@ -176,7 +176,7 @@ module Formulary
|
||||
|
||||
req_tags = []
|
||||
req_tags << req_version if req_version.present?
|
||||
req_tags += req["contexts"].map do |tag|
|
||||
req_tags += req["contexts"]&.map do |tag|
|
||||
case tag
|
||||
when String
|
||||
tag.to_sym
|
||||
@ -202,7 +202,7 @@ module Formulary
|
||||
|
||||
dep_json = json_formula.fetch("#{spec}_dependencies", json_formula)
|
||||
|
||||
dep_json["dependencies"].each do |dep|
|
||||
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?
|
||||
@ -211,7 +211,7 @@ module Formulary
|
||||
end
|
||||
|
||||
[:build, :test, :recommended, :optional].each do |type|
|
||||
dep_json["#{type}_dependencies"].each do |dep|
|
||||
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?
|
||||
@ -220,7 +220,7 @@ module Formulary
|
||||
end
|
||||
end
|
||||
|
||||
dep_json["uses_from_macos"].each_with_index do |dep, index|
|
||||
dep_json["uses_from_macos"]&.each_with_index do |dep, index|
|
||||
bounds = dep_json.fetch("uses_from_macos_bounds", [])[index] || {}
|
||||
bounds.deep_transform_keys!(&:to_sym)
|
||||
bounds.deep_transform_values! { |val| val.is_a?(String) ? val.to_sym : val }
|
||||
@ -311,7 +311,7 @@ module Formulary
|
||||
disable! date: disable_date, because: reason
|
||||
end
|
||||
|
||||
json_formula["conflicts_with"].each_with_index do |conflict, index|
|
||||
json_formula["conflicts_with"]&.each_with_index do |conflict, index|
|
||||
conflicts_with conflict, because: json_formula.dig("conflicts_with_reasons", index)
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user