Commit 6c15ca8b authored by Samuel E. Giddins's avatar Samuel E. Giddins Committed by Kyle Fuller

[PodTargetInstaller] Support the specification of file patterns for `requires_arc`

parent 6ceb4f1d
...@@ -7,7 +7,7 @@ GIT ...@@ -7,7 +7,7 @@ GIT
GIT GIT
remote: https://github.com/CocoaPods/Core.git remote: https://github.com/CocoaPods/Core.git
revision: a00e38bc4ad61cb4cf23a5accba4ef25e48871a5 revision: 60a486e8141323390dc5ff7f6676cf893a251a48
branch: master branch: master
specs: specs:
cocoapods-core (0.35.0.rc2) cocoapods-core (0.35.0.rc2)
......
...@@ -35,12 +35,20 @@ module Pod ...@@ -35,12 +35,20 @@ module Pod
def add_files_to_build_phases def add_files_to_build_phases
target.file_accessors.each do |file_accessor| target.file_accessors.each do |file_accessor|
consumer = file_accessor.spec_consumer consumer = file_accessor.spec_consumer
flags = compiler_flags_for_consumer(consumer)
all_source_files = file_accessor.source_files other_source_files = file_accessor.source_files.select { |sf| sf.extname == '.d' }
regular_source_files = all_source_files.reject { |sf| sf.extname == '.d' }
regular_file_refs = regular_source_files.map { |sf| project.reference_for_path(sf) } {
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) 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) } end
other_file_refs = other_source_files.map { |sf| project.reference_for_path(sf) }
native_target.add_file_references(other_file_refs, nil) native_target.add_file_references(other_file_refs, nil)
end end
end end
...@@ -152,9 +160,9 @@ module Pod ...@@ -152,9 +160,9 @@ module Pod
# #
# @return [String] The compiler flags. # @return [String] The compiler flags.
# #
def compiler_flags_for_consumer(consumer) def compiler_flags_for_consumer(consumer, arc)
flags = consumer.compiler_flags.dup flags = consumer.compiler_flags.dup
if !consumer.requires_arc if !arc
flags << '-fno-objc-arc' flags << '-fno-objc-arc'
else else
platform_name = consumer.platform_name platform_name = consumer.platform_name
......
...@@ -78,6 +78,27 @@ module Pod ...@@ -78,6 +78,27 @@ module Pod
paths_for_attribute(:source_files) paths_for_attribute(:source_files)
end 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. # @return [Array<Pathname>] the headers of the specification.
# #
def headers def headers
......
...@@ -161,8 +161,8 @@ module Pod ...@@ -161,8 +161,8 @@ module Pod
@installer.target.target_definition.stubs(:inhibits_warnings_for_pod?).returns(true) @installer.target.target_definition.stubs(:inhibits_warnings_for_pod?).returns(true)
@installer.install! @installer.install!
dtrace_files = @installer.target.native_target.source_build_phase.files.reject do |sf| dtrace_files = @installer.target.native_target.source_build_phase.files.select do |sf|
!(File.extname(sf.file_ref.path) == '.d') File.extname(sf.file_ref.path) == '.d'
end end
dtrace_files.each do |dt| dtrace_files.each do |dt|
dt.settings.should.be.nil dt.settings.should.be.nil
...@@ -171,64 +171,60 @@ module Pod ...@@ -171,64 +171,60 @@ module Pod
it 'adds -w per pod if target definition inhibits warnings for that pod' do 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) @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') flags.should.include?('-w')
end end
it "doesn't inhibit warnings by default" do 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') flags.should.not.include?('-w')
end end
it 'adds -Xanalyzer -analyzer-disable-checker per pod' do it 'adds -Xanalyzer -analyzer-disable-checker per pod' do
@installer.target.target_definition.stubs(:inhibits_warnings_for_pod?).returns(true) @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') flags.should.include?('-Xanalyzer -analyzer-disable-checker')
end end
it "doesn't inhibit analyzer warnings by default" do 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') flags.should.not.include?('-Xanalyzer -analyzer-disable-checker')
end end
describe 'concerning ARC before and after iOS 6.0 and OS X 10.8' do 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 it 'does not do anything if ARC is *not* required' do
@spec.requires_arc = false
@spec.ios.deployment_target = '5' @spec.ios.deployment_target = '5'
@spec.osx.deployment_target = '10.6' @spec.osx.deployment_target = '10.6'
ios_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios)) ios_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios), false)
osx_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:osx)) osx_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:osx), false)
ios_flags.should.not.include '-DOS_OBJECT_USE_OBJC' ios_flags.should.not.include '-DOS_OBJECT_USE_OBJC'
osx_flags.should.not.include '-DOS_OBJECT_USE_OBJC' osx_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 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.ios.deployment_target = '6'
@spec.osx.deployment_target = '10.8' @spec.osx.deployment_target = '10.8'
ios_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios)) ios_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios), false)
osx_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:osx)) osx_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:osx), false)
ios_flags.should.not.include '-DOS_OBJECT_USE_OBJC' ios_flags.should.not.include '-DOS_OBJECT_USE_OBJC'
osx_flags.should.not.include '-DOS_OBJECT_USE_OBJC' osx_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 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.ios.deployment_target = '5.1'
@spec.osx.deployment_target = '10.7.2' @spec.osx.deployment_target = '10.7.2'
ios_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios)) ios_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios), true)
osx_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:osx)) osx_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:osx), true)
ios_flags.should.include '-DOS_OBJECT_USE_OBJC' ios_flags.should.include '-DOS_OBJECT_USE_OBJC'
osx_flags.should.include '-DOS_OBJECT_USE_OBJC' osx_flags.should.include '-DOS_OBJECT_USE_OBJC'
end end
it '*does* disable the `OS_OBJECT_USE_OBJC` flag if ARC is required and *no* deployment target is specified' do 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), true)
ios_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios)) osx_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:osx), true)
osx_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:osx))
ios_flags.should.include '-DOS_OBJECT_USE_OBJC' ios_flags.should.include '-DOS_OBJECT_USE_OBJC'
osx_flags.should.include '-DOS_OBJECT_USE_OBJC' osx_flags.should.include '-DOS_OBJECT_USE_OBJC'
end end
......
...@@ -53,6 +53,19 @@ module Pod ...@@ -53,6 +53,19 @@ module Pod
] ]
end 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 it 'returns the header files' do
@accessor.headers.sort.should == [ @accessor.headers.sort.should == [
@root + 'Classes/Banana.h', @root + 'Classes/Banana.h',
...@@ -166,6 +179,30 @@ module Pod ...@@ -166,6 +179,30 @@ module Pod
] ]
end 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 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