Commit 1f1c9496 authored by Eloy Durán's avatar Eloy Durán

Disable libSystem objects for ARC libs that target older platforms.

This applies when the deployment target is set to < iOS 6.0 or
OS X 10.8, or not specified at all.
parent c37de717
...@@ -319,9 +319,49 @@ module Pod ...@@ -319,9 +319,49 @@ module Pod
@parent ? @parent.recursive_compiler_flags | @compiler_flags[active_platform] : @compiler_flags[active_platform] @parent ? @parent.recursive_compiler_flags | @compiler_flags[active_platform] : @compiler_flags[active_platform]
end end
ENABLE_OBJECT_USE_OBJC_FROM = {
:ios => Version.new('6'),
:osx => Version.new('10.8')
}
# The following behavior is regarding the `OS_OBJECT_USE_OBJC` flag. When
# set to `0`, it will allow code to use `dispatch_release()` on >= iOS 6.0
# and OS X 10.8.
#
# * New libraries that do *not* require ARC don’t need to care about this
# issue at all.
#
# * New libraries that *do* require ARC _and_ have a deployment target of
# >= iOS 6.0 or OS X 10.8:
#
# These no longer use `dispatch_release()` and should *not* have the
# `OS_OBJECT_USE_OBJC` flag set to `0`.
#
# **Note:** this means that these libraries *have* to specify the
# deployment target in order to function well.
#
# * New libraries that *do* require ARC, but have a deployment target of
# < iOS 6.0 or OS X 10.8:
#
# These contain `dispatch_release()` calls and as such need the
# `OS_OBJECT_USE_OBJC` flag set to `1`.
#
# **Note:** libraries that do *not* specify a platform version are
# assumed to have a deployment target of < iOS 6.0 or OS X 10.8.
#
# For more information, see: http://opensource.apple.com/source/libdispatch/libdispatch-228.18/os/object.h
#
def compiler_flags def compiler_flags
flags = recursive_compiler_flags.dup flags = recursive_compiler_flags.dup
flags << '-fobjc-arc' if requires_arc if requires_arc
flags << '-fobjc-arc'
ios_target, osx_target = deployment_target(:ios), deployment_target(:osx)
if (ios_target.nil? && osx_target.nil?) ||
(ios_target && Version.new(ios_target) < ENABLE_OBJECT_USE_OBJC_FROM[:ios]) ||
(osx_target && Version.new(osx_target) < ENABLE_OBJECT_USE_OBJC_FROM[:osx])
flags << '-DOS_OBJECT_USE_OBJC=0'
end
end
flags.join(' ') flags.join(' ')
end end
......
...@@ -107,11 +107,11 @@ describe "A Pod::Specification loaded from a podspec" do ...@@ -107,11 +107,11 @@ describe "A Pod::Specification loaded from a podspec" do
it "adds compiler flags if ARC is required" do it "adds compiler flags if ARC is required" do
@spec.parent.should == nil @spec.parent.should == nil
@spec.requires_arc = true @spec.requires_arc = true
@spec.activate_platform(:ios).compiler_flags.should == "-fobjc-arc" @spec.activate_platform(:ios).compiler_flags.should == "-fobjc-arc -DOS_OBJECT_USE_OBJC=0"
@spec.activate_platform(:osx).compiler_flags.should == "-fobjc-arc" @spec.activate_platform(:osx).compiler_flags.should == "-fobjc-arc -DOS_OBJECT_USE_OBJC=0"
@spec.compiler_flags = "-Wunused-value" @spec.compiler_flags = "-Wunused-value"
@spec.activate_platform(:ios).compiler_flags.should == "-Wunused-value -fobjc-arc" @spec.activate_platform(:ios).compiler_flags.should == "-Wunused-value -fobjc-arc -DOS_OBJECT_USE_OBJC=0"
@spec.activate_platform(:osx).compiler_flags.should == "-Wunused-value -fobjc-arc" @spec.activate_platform(:osx).compiler_flags.should == "-Wunused-value -fobjc-arc -DOS_OBJECT_USE_OBJC=0"
end end
end end
...@@ -523,7 +523,7 @@ describe "A Pod::Specification, concerning its attributes that support different ...@@ -523,7 +523,7 @@ describe "A Pod::Specification, concerning its attributes that support different
end end
it "returns the same list of compiler flags for each platform" do it "returns the same list of compiler flags for each platform" do
compiler_flags = '-Wdeprecated-implementations -fobjc-arc' compiler_flags = '-Wdeprecated-implementations -fobjc-arc -DOS_OBJECT_USE_OBJC=0'
@spec.activate_platform(:ios).compiler_flags.should == compiler_flags @spec.activate_platform(:ios).compiler_flags.should == compiler_flags
@spec.activate_platform(:osx).compiler_flags.should == compiler_flags @spec.activate_platform(:osx).compiler_flags.should == compiler_flags
end end
...@@ -587,8 +587,8 @@ describe "A Pod::Specification, concerning its attributes that support different ...@@ -587,8 +587,8 @@ describe "A Pod::Specification, concerning its attributes that support different
end end
it "returns the same list of compiler flags for each platform" do it "returns the same list of compiler flags for each platform" do
@spec.activate_platform(:ios).compiler_flags.should == '-Wdeprecated-implementations -fobjc-arc' @spec.activate_platform(:ios).compiler_flags.should == '-Wdeprecated-implementations -fobjc-arc -DOS_OBJECT_USE_OBJC=0'
@spec.activate_platform(:osx).compiler_flags.should == '-Wfloat-equal -fobjc-arc' @spec.activate_platform(:osx).compiler_flags.should == '-Wfloat-equal -fobjc-arc -DOS_OBJECT_USE_OBJC=0'
end end
it "returns the same list of dependencies for each platform" do it "returns the same list of dependencies for each platform" do
...@@ -596,4 +596,42 @@ describe "A Pod::Specification, concerning its attributes that support different ...@@ -596,4 +596,42 @@ describe "A Pod::Specification, concerning its attributes that support different
@spec.activate_platform(:osx).dependencies.should == [Pod::Dependency.new('SSZipArchive')] @spec.activate_platform(:osx).dependencies.should == [Pod::Dependency.new('SSZipArchive')]
end end
end end
describe "concerning ARC before and after iOS 6.0 and OS X 10.8" do
before do
@spec = Pod::Spec.new
end
it "does not do anything if ARC is *not* required" do
@spec.ios.deployment_target = '5'
@spec.osx.deployment_target = '10.6'
[:ios, :osx, [:ios, '6'], [:ios, '6.1'], [:osx, '10.8'], [:osx, '10.8.2']].each do |target|
@spec.activate_platform(*target).compiler_flags.should.not.include '-DOS_OBJECT_USE_OBJC'
end
end
it "does *not* disable the `OS_OBJECT_USE_OBJC` flag if ARC is required and has a deployment target of >= iOS 6.0 or OS X 10.8" do
@spec.ios.deployment_target = '6'
@spec.osx.deployment_target = '10.8'
[[:ios, '6'], [:ios, '6.1'], [:osx, '10.8'], [:osx, '10.8.2']].each do |target|
@spec.activate_platform(*target).compiler_flags.should.not.include '-DOS_OBJECT_USE_OBJC'
end
end
it "*does* disable the `OS_OBJECT_USE_OBJC` flag if ARC is required but has a deployment target < iOS 6.0 or OS X 10.8" do
@spec.requires_arc = true
@spec.ios.deployment_target = '5.1'
@spec.osx.deployment_target = '10.7.2'
[[:ios, '6'], [:ios, '6.1'], [:osx, '10.8'], [:osx, '10.8.2']].each do |target|
@spec.activate_platform(*target).compiler_flags.should.include '-DOS_OBJECT_USE_OBJC=0'
end
end
it "*does* disable the `OS_OBJECT_USE_OBJC` flag if ARC is required and *no* deployment target is specified" do
@spec.requires_arc = true
[:ios, :osx, [:ios, '6'], [:ios, '6.1'], [:osx, '10.8'], [:osx, '10.8.2']].each do |target|
@spec.activate_platform(*target).compiler_flags.should.include '-DOS_OBJECT_USE_OBJC=0'
end
end
end
end end
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