Commit 9e0c68a0 authored by Kyle Fuller's avatar Kyle Fuller

Merge pull request #2829 from CocoaPods/seg-requires-arc-file-pattern

[PodTargetInstaller] Support the specification of file patterns for `requires_arc`
parents 6ceb4f1d 6eab4c6e
......@@ -6,6 +6,14 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
## Master
##### Enhancements
* Allow the specification of file patterns for the Podspec's `requires_arc`
attribute.
[Kyle Fuller](https://github.com/kylef)
[Samuel Giddins](https://github.com/segiddins)
[#532](https://github.com/CocoaPods/CocoaPods/issues/532)
##### Bug Fixes
* Show a helpful error message if the old resolver incorrectly activated a
......
......@@ -7,7 +7,7 @@ GIT
GIT
remote: https://github.com/CocoaPods/Core.git
revision: a00e38bc4ad61cb4cf23a5accba4ef25e48871a5
revision: 60a486e8141323390dc5ff7f6676cf893a251a48
branch: master
specs:
cocoapods-core (0.35.0.rc2)
......
......@@ -35,12 +35,20 @@ module Pod
def add_files_to_build_phases
target.file_accessors.each do |file_accessor|
consumer = file_accessor.spec_consumer
flags = compiler_flags_for_consumer(consumer)
all_source_files = file_accessor.source_files
regular_source_files = all_source_files.reject { |sf| sf.extname == '.d' }
regular_file_refs = regular_source_files.map { |sf| project.reference_for_path(sf) }
native_target.add_file_references(regular_file_refs, flags)
other_file_refs = (all_source_files - regular_source_files).map { |sf| project.reference_for_path(sf) }
other_source_files = file_accessor.source_files.select { |sf| sf.extname == '.d' }
{
true => file_accessor.arc_source_files,
false => file_accessor.non_arc_source_files,
}.each do |arc, files|
files = files - other_source_files
flags = compiler_flags_for_consumer(consumer, arc)
regular_file_refs = files.map { |sf| project.reference_for_path(sf) }
native_target.add_file_references(regular_file_refs, flags)
end
other_file_refs = other_source_files.map { |sf| project.reference_for_path(sf) }
native_target.add_file_references(other_file_refs, nil)
end
end
......@@ -152,9 +160,9 @@ module Pod
#
# @return [String] The compiler flags.
#
def compiler_flags_for_consumer(consumer)
def compiler_flags_for_consumer(consumer, arc)
flags = consumer.compiler_flags.dup
if !consumer.requires_arc
if !arc
flags << '-fno-objc-arc'
else
platform_name = consumer.platform_name
......
......@@ -78,6 +78,27 @@ module Pod
paths_for_attribute(:source_files)
end
# @return [Array<Pathname>] the source files of the specification that
# use ARC.
#
def arc_source_files
case spec_consumer.requires_arc
when TrueClass
source_files
when FalseClass
[]
else
paths_for_attribute(:requires_arc) & source_files
end
end
# @return [Array<Pathname>] the source files of the specification that
# do not use ARC.
#
def non_arc_source_files
source_files - arc_source_files
end
# @return [Array<Pathname>] the headers of the specification.
#
def headers
......
......@@ -161,8 +161,8 @@ module Pod
@installer.target.target_definition.stubs(:inhibits_warnings_for_pod?).returns(true)
@installer.install!
dtrace_files = @installer.target.native_target.source_build_phase.files.reject do |sf|
!(File.extname(sf.file_ref.path) == '.d')
dtrace_files = @installer.target.native_target.source_build_phase.files.select do |sf|
File.extname(sf.file_ref.path) == '.d'
end
dtrace_files.each do |dt|
dt.settings.should.be.nil
......@@ -171,64 +171,60 @@ module Pod
it 'adds -w per pod if target definition inhibits warnings for that pod' do
@installer.target.target_definition.stubs(:inhibits_warnings_for_pod?).returns(true)
flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios))
flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios), true)
flags.should.include?('-w')
end
it "doesn't inhibit warnings by default" do
flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios))
flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios), true)
flags.should.not.include?('-w')
end
it 'adds -Xanalyzer -analyzer-disable-checker per pod' do
@installer.target.target_definition.stubs(:inhibits_warnings_for_pod?).returns(true)
flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios))
flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios), true)
flags.should.include?('-Xanalyzer -analyzer-disable-checker')
end
it "doesn't inhibit analyzer warnings by default" do
flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios))
flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios), true)
flags.should.not.include?('-Xanalyzer -analyzer-disable-checker')
end
describe 'concerning ARC before and after iOS 6.0 and OS X 10.8' do
it 'does not do anything if ARC is *not* required' do
@spec.requires_arc = false
@spec.ios.deployment_target = '5'
@spec.osx.deployment_target = '10.6'
ios_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios))
osx_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:osx))
ios_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios), false)
osx_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:osx), false)
ios_flags.should.not.include '-DOS_OBJECT_USE_OBJC'
osx_flags.should.not.include '-DOS_OBJECT_USE_OBJC'
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.requires_arc = false
@spec.ios.deployment_target = '6'
@spec.osx.deployment_target = '10.8'
ios_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios))
osx_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:osx))
ios_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios), false)
osx_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:osx), false)
ios_flags.should.not.include '-DOS_OBJECT_USE_OBJC'
osx_flags.should.not.include '-DOS_OBJECT_USE_OBJC'
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_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios))
osx_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:osx))
ios_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios), true)
osx_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:osx), true)
ios_flags.should.include '-DOS_OBJECT_USE_OBJC'
osx_flags.should.include '-DOS_OBJECT_USE_OBJC'
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_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios))
osx_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:osx))
ios_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios), true)
osx_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:osx), true)
ios_flags.should.include '-DOS_OBJECT_USE_OBJC'
osx_flags.should.include '-DOS_OBJECT_USE_OBJC'
end
......
......@@ -53,6 +53,19 @@ module Pod
]
end
it 'returns the source files that use arc' do
@accessor.arc_source_files.sort.should == [
@root + 'Classes/Banana.h',
@root + 'Classes/Banana.m',
@root + 'Classes/BananaPrivate.h',
@root + 'Classes/BananaTrace.d',
]
end
it 'returns the source files that do not use arc' do
@accessor.non_arc_source_files.sort.should == []
end
it 'returns the header files' do
@accessor.headers.sort.should == [
@root + 'Classes/Banana.h',
......@@ -166,6 +179,30 @@ module Pod
]
end
describe 'using requires_arc' do
it 'when false returns all source files as non-arc' do
@spec_consumer.stubs(:requires_arc).returns(false)
@accessor.non_arc_source_files.should == @accessor.source_files
@accessor.arc_source_files.should.be.empty?
end
it 'when true returns all source files as arc' do
@spec_consumer.stubs(:requires_arc).returns(true)
@accessor.arc_source_files.should == @accessor.source_files
@accessor.non_arc_source_files.should.be.empty?
end
it 'when a file pattern returns all source files as arc that match' do
@spec_consumer.stubs(:requires_arc).returns(['Classes/Banana.m'])
@accessor.arc_source_files.should == [@root + 'Classes/Banana.m']
@accessor.non_arc_source_files.sort.should == [
@root + 'Classes/Banana.h',
@root + 'Classes/BananaPrivate.h',
@root + 'Classes/BananaTrace.d',
]
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