From af9400f98d459c369100ec2d7cb747aff11e6210 Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Thu, 10 Dec 2015 00:16:49 -0600 Subject: [PATCH] [JSON] Fix platform serialization to handle inheritance --- lib/cocoapods-core/specification/json.rb | 7 +++--- spec/specification/json_spec.rb | 31 +++++++++++++++++++++--- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/lib/cocoapods-core/specification/json.rb b/lib/cocoapods-core/specification/json.rb index 7cfc67e91..2ccbf24f7 100644 --- a/lib/cocoapods-core/specification/json.rb +++ b/lib/cocoapods-core/specification/json.rb @@ -22,9 +22,10 @@ def to_pretty_json(*a) # def to_hash hash = attributes_hash.dup - platforms = platform_hash - platforms = Hash[DSL::PLATFORMS.map { |p| [p.to_s, nil] }] if platforms.empty? - hash['platforms'] = platforms + if root? || available_platforms != parent.available_platforms + platforms = Hash[available_platforms.map { |p| [p.name.to_s, p.deployment_target && p.deployment_target.to_s] }] + hash['platforms'] = platforms + end unless subspecs.empty? hash['subspecs'] = subspecs.map(&:to_hash) end diff --git a/spec/specification/json_spec.rb b/spec/specification/json_spec.rb index a7d5332a3..6bc550c5b 100644 --- a/spec/specification/json_spec.rb +++ b/spec/specification/json_spec.rb @@ -80,19 +80,42 @@ module Pod end it 'handles subspecs when converted to a hash' do + hash = @spec.to_hash + hash['subspecs'].should == [{ + 'name' => 'GreenBanana', + 'source_files' => 'GreenBanana', + }] + end + + it 'handles subspecs with different platforms' do + subspec = @spec.subspec_by_name('BananaLib/GreenBanana') + subspec.platforms = { + 'ios' => '9.0', + 'tvos' => '9.0', + } hash = @spec.to_hash hash['subspecs'].should == [{ 'name' => 'GreenBanana', 'source_files' => 'GreenBanana', 'platforms' => { - 'osx' => nil, - 'ios' => nil, - 'tvos' => nil, - 'watchos' => nil, + 'ios' => '9.0', + 'tvos' => '9.0', }, }] end + it 'handles subspecs when the parent spec specifies platforms and the ' \ + 'subspec inherits' do + @spec.platforms = { + 'tvos' => '9.0', + } + hash = @spec.to_hash + hash['subspecs'].should == [{ + 'name' => 'GreenBanana', + 'source_files' => 'GreenBanana', + }] + end + it 'can be loaded from an hash' do hash = { 'name' => 'BananaLib',