16

I have an Xcode workspace set up with CocoaPods. When I run Xcode's Analyzer on my project it analyzes my own source code as well as all the source code in the Pods targets. This throws up lots of warnings that I am not interested in as I only want to see the analyzer warnings of my own source code.

I have unchecked "Analyze" from the build target for pods but this doesn't seem to have any effect.

Is there a way to ignore Pods targets when running the analyzer?

enter image description here

Keith Smiley
  • 61,481
  • 12
  • 97
  • 110
Brian Boyle
  • 2,849
  • 5
  • 27
  • 35

2 Answers2

8

Here's an update/modification for the existing answer:

With Cocoapods 0.38+ installer attribute needed to get the project has changed such that you need to use "pods_project" instead of "project" like so:

post_install do |installer|
    puts 'Removing static analyzer support'
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings['OTHER_CFLAGS'] = "$(inherited) -Qunused-arguments -Xanalyzer -analyzer-disable-all-checks"
        end
    end
end

See the following Cocoapods blog announcement for more details on the change: http://blog.cocoapods.org/CocoaPods-0.38/#breaking-change-to-the-hooks-api

Also, here's a (closed) issue showing the error you would receive if you tried the old way with the new code: https://github.com/CocoaPods/CocoaPods/issues/3918

philarmour
  • 394
  • 5
  • 10
4

You can add a post install step at the end of your podfile to add compiler flags that control the static analyzer.

post_install do |installer|
    puts 'Removing static analyzer support'
    installer.project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings['OTHER_CFLAGS'] = "$(inherited) -Qunused-arguments -Xanalyzer -analyzer-disable-all-checks"
        end
    end
end

Then just run a "pod update" command to regenerate your project files.

The different parts:

  • $(inherited) -- A good habit to not avoid accidentally removing flags
  • -Qunused-arguments -- llvm doesn't understand the clang options, this silences the resulting warning from the main compilation
  • -Xanalyzer -analyzer-disable-all-checks -- This tells the static analyzer to ignore files in the associated project.
Kyle Bolen
  • 41
  • 2