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

[Platform] Default deployment targets.

parent c4cb7a49
......@@ -22,33 +22,56 @@ module Pod
# Constructs a platform from either another platform or by
# specifying the symbolic name and optionally the deployment target.
#
# @overload initialize(platform)
# @param [Platform] platform Another platform or a symbolic name for the platform.
# @overload initialize(name, deployment_target)
# @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
#
# p = Platform.new :ios
# Platform.new p
# Platform.new(:ios)
# Platform.new(:ios, '4.3')
#
# @overload initialize(name, deployment_target)
# @param [Symbol] input Another platform or a symbolic name for the platform.
# @param [Version] deployment_target The optional deployment target if initialized by symbolic name.
# @overload initialize(name, opts)
# @deprecated Remove after adding a warning to {Podfile} class.
# @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
#
# Platform.new(:ios)
# Platform.new(:ios, '4.3')
# platform = Platform.new(:ios)
# Platform.new(platform)
#
def initialize(input = nil, deployment_target = nil)
def initialize(input = nil, target = nil)
if input.is_a? Platform
@symbolic_name = input.name
@deployment_target = input.deployment_target
@declared_deployment_target = input.declared_deployment_target
else
@symbolic_name = input
if deployment_target
version = deployment_target.is_a?(Hash) ? deployment_target[:deployment_target] : deployment_target # backwards compatibility from 0.6
@deployment_target = Pod::Version.create(version)
target = target[:deployment_target] if target.is_a?(Hash)
@declared_deployment_target = target
unless target
case @symbolic_name
when :ios
target = '4.3'
when :osx
target = '10.6'
else
target = ''
end
end
@deployment_target = Version.create(target)
end
end
......@@ -58,18 +81,22 @@ module Pod
@symbolic_name
end
# A deployment target can be initialized by any value that initializes a {Version}.
#
# @return [Version] The optional deployment target of the platform.
# @return [Version] The deployment target of the platform.
#
attr_reader :deployment_target
# @return [Version] The deployment target declared on initialization.
#
attr_reader :declared_deployment_target
def deployment_target= (version)
@deployment_target = Pod::Version.create(version)
end
# @param [Platform, Symbol] other The other platform to check. If a symbol is
# passed the comparison does not take into account the deployment target.
# @param [Platform, Symbol] other The other platform to check.
#
# @note If a symbol is passed the comparison does not take into account
# the deployment target.
#
# @return [Boolean] Whether two platforms are the equivalent.
#
......@@ -77,36 +104,41 @@ module Pod
if other.is_a?(Symbol)
@symbolic_name == other
else
self.name == (other.name) && self.deployment_target == other.deployment_target
(name == other.name) && (deployment_target == other.deployment_target)
end
end
# A platform supports (from the point of view of a pod) another platform 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.
# A platform supports (from the point of view of a pod) another platform
# 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 described by another platform.
# @return Whether the platform supports being used in the environment
# described by another platform.
#
# @todo rename to supported_on?
#
def supports?(other)
return true if @symbolic_name.nil? || other.nil?
os_check = @symbolic_name == other.name
version_check = (deployment_target.nil? || other.deployment_target.nil? || deployment_target >= other.deployment_target)
os_check && version_check
other = Platform.new(other)
(name == other.name) && (deployment_target >= other.deployment_target)
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
case @symbolic_name
when :ios
'iOS' + (deployment_target ? " #{deployment_target}" : '')
s = 'iOS'
when :osx
'OS X' + (deployment_target ? " #{deployment_target}" : '')
s = 'OS X'
else
'iOS - OS X'
s = 'iOS - OS X'
end
s << " #{declared_deployment_target}" if declared_deployment_target
s
end
# @return [Symbol] A Symbol representation of the SDK.
......@@ -126,8 +158,7 @@ module Pod
# @return Whether the platform requires legacy architectures for iOS.
#
def requires_legacy_ios_archs?
return unless deployment_target
(name == :ios) && (deployment_target < Pod::Version.new("4.3"))
(name == :ios) && (deployment_target < Version.new("4.3"))
end
end
end
......@@ -63,6 +63,11 @@ describe Pod::Platform do
p.deployment_target = Pod::Version.new('4.0.0')
p.deployment_target.should == Pod::Version.new('4.0.0')
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
describe "with a nil value" do
......@@ -99,13 +104,6 @@ describe Pod::Platform do
p2.should.not.supports?(p1)
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
p1 = Pod::Platform.new(:ios)
p2 = Pod::Platform.new(:osx)
......
......@@ -382,7 +382,7 @@ describe "A Pod::Specification subspec" do
@subspec.supports_platform?(:osx).should.be.false
@subspec.supports_platform?(:ios, '4.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?(:ios, '4.0').should.be.false
@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