Skip to content

Commit

Permalink
Do not pass inhibit warnings compiler flags for Swift source files.
Browse files Browse the repository at this point in the history
  • Loading branch information
dnkoutso committed Jul 18, 2019
1 parent a6f845c commit ca8cfd3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 23 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Expand Up @@ -12,7 +12,9 @@ To install release candidates run `[sudo] gem install cocoapods --pre`

##### Bug Fixes

* None.
* Do not pass inhibit warnings compiler flags for Swift source files.
[Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#9013](https://github.com/CocoaPods/CocoaPods/issues/9013)


## 1.7.4 (2019-07-09)
Expand Down
Expand Up @@ -287,12 +287,18 @@ def add_files_to_build_phases(native_target, test_native_targets, app_native_tar
{
true => file_accessor.arc_source_files,
false => file_accessor.non_arc_source_files,
}.each do |arc, files|
next if files.empty?
files = files - headers - other_source_files
flags = compiler_flags_for_consumer(consumer, arc)
regular_file_refs = project_file_references_array(files, 'source')
native_target.add_file_references(regular_file_refs, flags)
}.each do |arc, source_files|
next if source_files.empty?
source_files = source_files - headers - other_source_files
swift_source_files, non_swift_source_files = source_files.partition { |file| file.extname == '.swift' }

non_swift_compiler_flags = compiler_flags_for_consumer(consumer, arc, :objc)
non_swift_file_refs = project_file_references_array(non_swift_source_files, 'source')
native_target.add_file_references(non_swift_file_refs, non_swift_compiler_flags)

swift_compiler_flags = compiler_flags_for_consumer(consumer, arc, :swift)
swift_file_refs = project_file_references_array(swift_source_files, 'source')
native_target.add_file_references(swift_file_refs, swift_compiler_flags)
end

header_file_refs = project_file_references_array(headers, 'header')
Expand Down Expand Up @@ -780,9 +786,15 @@ def create_build_phase_to_symlink_header_folders(native_target)
# The consumer for the specification for which the compiler flags
# are needed.
#
# @param [Boolean] arc
# Whether the arc is enabled or not.
#
# @param [Symbol] language
# The language these compiler warnings are for. Can be either :objc or :swift.
#
# @return [String] The compiler flags.
#
def compiler_flags_for_consumer(consumer, arc)
def compiler_flags_for_consumer(consumer, arc, language)
flags = consumer.compiler_flags.dup
if !arc
flags << '-fno-objc-arc'
Expand All @@ -793,7 +805,7 @@ def compiler_flags_for_consumer(consumer, arc)
flags << '-DOS_OBJECT_USE_OBJC=0'
end
end
if target.inhibit_warnings?
if target.inhibit_warnings? && language == :objc
flags << '-w -Xanalyzer -analyzer-disable-all-checks'
end
flags * ' '
Expand Down
Expand Up @@ -1196,59 +1196,64 @@ class PodsProjectGenerator

it 'adds -w per pod if target definition inhibits warnings for that pod' do
@installer.target.target_definitions.first.stubs(:inhibits_warnings_for_pod?).returns(true)
flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios), true)
flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios), true, :objc)

flags.should.include?('-w')
end

it "doesn't inhibit warnings by default" do
flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios), true)
flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios), true, :objc)
flags.should.not.include?('-w')
end

it 'adds -Xanalyzer -analyzer-disable-checker per pod' do
it 'adds -Xanalyzer -analyzer-disable-checker per pod for objc language' do
@installer.target.target_definitions.first.stubs(:inhibits_warnings_for_pod?).returns(true)
flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios), true)
flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios), true, :objc)

flags.should.include?('-Xanalyzer -analyzer-disable-all-checks')
end

it "doesn't inhibit analyzer warnings by default" do
flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios), true)
it "doesn't inhibit analyzer warnings by default for objc language" do
flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios), true, :objc)
flags.should.not.include?('-Xanalyzer -analyzer-disable-all-checks')
end

it "doesn't inhibit analyzer warnings for Swift language" do
flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios), true, :swift)
flags.should.not.include?('-Xanalyzer -analyzer-disable-all-checks')
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.ios.deployment_target = '5'
@spec.osx.deployment_target = '10.6'
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 = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios), false, :objc)
osx_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:osx), false, :objc)
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.ios.deployment_target = '6'
@spec.osx.deployment_target = '10.8'
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 = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios), false, :objc)
osx_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:osx), false, :objc)
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.ios.deployment_target = '5.1'
@spec.osx.deployment_target = '10.7.2'
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 = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios), true, :objc)
osx_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:osx), true, :objc)
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
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 = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:ios), true, :objc)
osx_flags = @installer.send(:compiler_flags_for_consumer, @spec.consumer(:osx), true, :objc)
ios_flags.should.include '-DOS_OBJECT_USE_OBJC'
osx_flags.should.include '-DOS_OBJECT_USE_OBJC'
end
Expand Down

0 comments on commit ca8cfd3

Please sign in to comment.