Commit 05fba7b6 authored by Fabio Pelosin's avatar Fabio Pelosin

[Platform] Default deployment targets.

parent c4cb7a49
...@@ -22,33 +22,56 @@ module Pod ...@@ -22,33 +22,56 @@ module Pod
# Constructs a platform from either another platform or by # Constructs a platform from either another platform or by
# specifying the symbolic name and optionally the deployment target. # specifying the symbolic name and optionally the deployment target.
# #
# @overload initialize(platform) # @overload initialize(name, deployment_target)
# @param [Platform] platform Another platform or a symbolic name for the platform. # @param [Symbol] name The name of platform.
# @param [String, Version] deployment_target The optional deployment.
# If not provided a default value according to the platform name will
# be assigned.
#
# @note that if the name is not specified a default deployment
# target will not be assigned.
# #
# @example # @example
# #
# p = Platform.new :ios # Platform.new(:ios)
# Platform.new p # Platform.new(:ios, '4.3')
# #
# @overload initialize(name, deployment_target) # @overload initialize(name, opts)
# @param [Symbol] input Another platform or a symbolic name for the platform. # @deprecated Remove after adding a warning to {Podfile} class.
# @param [Version] deployment_target The optional deployment target if initialized by symbolic name. # @param [Symbol] name The name of platform.
# @param [Hash] opts The options to create a platform with.
# @option opts [String, Version] :deployment_target The deployment target.
#
# @overload initialize(platform)
# @param [Platform] platform Another {Platform}.
# #
# @example # @example
# #
# Platform.new(:ios) # platform = Platform.new(:ios)
# Platform.new(:ios, '4.3') # Platform.new(platform)
# #
def initialize(input = nil, deployment_target = nil) def initialize(input = nil, target = nil)
if input.is_a? Platform if input.is_a? Platform
@symbolic_name = input.name @symbolic_name = input.name
@deployment_target = input.deployment_target @deployment_target = input.deployment_target
@declared_deployment_target = input.declared_deployment_target
else else
@symbolic_name = input @symbolic_name = input
if deployment_target
version = deployment_target.is_a?(Hash) ? deployment_target[:deployment_target] : deployment_target # backwards compatibility from 0.6 target = target[:deployment_target] if target.is_a?(Hash)
@deployment_target = Pod::Version.create(version) @declared_deployment_target = target
unless target
case @symbolic_name
when :ios
target = '4.3'
when :osx
target = '10.6'
else
target = ''
end
end end
@deployment_target = Version.create(target)
end end
end end
...@@ -58,18 +81,22 @@ module Pod ...@@ -58,18 +81,22 @@ module Pod
@symbolic_name @symbolic_name
end end
# A deployment target can be initialized by any value that initializes a {Version}. # @return [Version] The deployment target of the platform.
#
# @return [Version] The optional deployment target of the platform.
# #
attr_reader :deployment_target attr_reader :deployment_target
# @return [Version] The deployment target declared on initialization.
#
attr_reader :declared_deployment_target
def deployment_target= (version) def deployment_target= (version)
@deployment_target = Pod::Version.create(version) @deployment_target = Pod::Version.create(version)
end end
# @param [Platform, Symbol] other The other platform to check. If a symbol is # @param [Platform, Symbol] other The other platform to check.
# passed the comparison does not take into account the deployment target. #
# @note If a symbol is passed the comparison does not take into account
# the deployment target.
# #
# @return [Boolean] Whether two platforms are the equivalent. # @return [Boolean] Whether two platforms are the equivalent.
# #
...@@ -77,36 +104,41 @@ module Pod ...@@ -77,36 +104,41 @@ module Pod
if other.is_a?(Symbol) if other.is_a?(Symbol)
@symbolic_name == other @symbolic_name == other
else else
self.name == (other.name) && self.deployment_target == other.deployment_target (name == other.name) && (deployment_target == other.deployment_target)
end end
end end
# A platform supports (from the point of view of a pod) another platform if they represent the same SDK and if the # A platform supports (from the point of view of a pod) another platform
# deployment target of the other is lower. If one of the platforms does not specify the deployment target, it is not taken into account. # if they represent the same SDK and if the deployment target of the other
# is lower. If one of the platforms does not specify the deployment target,
# it is not taken into account.
#
# @note This method returns true if one of the platforms is nil.
# #
# This method always returns true if one of platforms is nil. # @return Whether the platform supports being used in the environment
# @return Whether the platform supports being used in the environment described by another platform. # described by another platform.
# #
# @todo rename to supported_on? # @todo rename to supported_on?
# #
def supports?(other) def supports?(other)
return true if @symbolic_name.nil? || other.nil? return true if @symbolic_name.nil? || other.nil?
os_check = @symbolic_name == other.name other = Platform.new(other)
version_check = (deployment_target.nil? || other.deployment_target.nil? || deployment_target >= other.deployment_target) (name == other.name) && (deployment_target >= other.deployment_target)
os_check && version_check
end end
# @return [String] A string representation of the Platform including the deployment target if specified. # @return [String] A string representation including the deployment target.
# #
def to_s def to_s
case @symbolic_name case @symbolic_name
when :ios when :ios
'iOS' + (deployment_target ? " #{deployment_target}" : '') s = 'iOS'
when :osx when :osx
'OS X' + (deployment_target ? " #{deployment_target}" : '') s = 'OS X'
else else
'iOS - OS X' s = 'iOS - OS X'
end end
s << " #{declared_deployment_target}" if declared_deployment_target
s
end end
# @return [Symbol] A Symbol representation of the SDK. # @return [Symbol] A Symbol representation of the SDK.
...@@ -126,8 +158,7 @@ module Pod ...@@ -126,8 +158,7 @@ module Pod
# @return Whether the platform requires legacy architectures for iOS. # @return Whether the platform requires legacy architectures for iOS.
# #
def requires_legacy_ios_archs? def requires_legacy_ios_archs?
return unless deployment_target (name == :ios) && (deployment_target < Version.new("4.3"))
(name == :ios) && (deployment_target < Pod::Version.new("4.3"))
end end
end end
end end
...@@ -63,6 +63,11 @@ describe Pod::Platform do ...@@ -63,6 +63,11 @@ describe Pod::Platform do
p.deployment_target = Pod::Version.new('4.0.0') p.deployment_target = Pod::Version.new('4.0.0')
p.deployment_target.should == Pod::Version.new('4.0.0') p.deployment_target.should == Pod::Version.new('4.0.0')
end end
it "provides a default deployment target on initialization" do
p = Pod::Platform.new(:ios)
p.deployment_target.should == Pod::Version.new('4.3')
end
end end
describe "with a nil value" do describe "with a nil value" do
...@@ -99,13 +104,6 @@ describe Pod::Platform do ...@@ -99,13 +104,6 @@ describe Pod::Platform do
p2.should.not.supports?(p1) p2.should.not.supports?(p1)
end end
it "supports a platform regardless of the deployment_target if one of the two does not specify it" do
p1 = Pod::Platform.new(:ios)
p2 = Pod::Platform.new(:ios, '4.0')
p1.should.supports?(p2)
p2.should.supports?(p1)
end
it "doesn't supports a platform with a different operating system" do it "doesn't supports a platform with a different operating system" do
p1 = Pod::Platform.new(:ios) p1 = Pod::Platform.new(:ios)
p2 = Pod::Platform.new(:osx) p2 = Pod::Platform.new(:osx)
......
...@@ -382,7 +382,7 @@ describe "A Pod::Specification subspec" do ...@@ -382,7 +382,7 @@ describe "A Pod::Specification subspec" do
@subspec.supports_platform?(:osx).should.be.false @subspec.supports_platform?(:osx).should.be.false
@subspec.supports_platform?(:ios, '4.0').should.be.true @subspec.supports_platform?(:ios, '4.0').should.be.true
@subspec.supports_platform?(:ios, '5.0').should.be.true @subspec.supports_platform?(:ios, '5.0').should.be.true
@subsubspec.supports_platform?(:ios).should.be.true @subsubspec.supports_platform?(:ios).should.be.false
@subsubspec.supports_platform?(:osx).should.be.false @subsubspec.supports_platform?(:osx).should.be.false
@subsubspec.supports_platform?(:ios, '4.0').should.be.false @subsubspec.supports_platform?(:ios, '4.0').should.be.false
@subsubspec.supports_platform?(:ios, '5.0').should.be.true @subsubspec.supports_platform?(:ios, '5.0').should.be.true
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment