Xcode Analyzer - 忽略CocoaPods目标

Bri*_*yle 14 xcode clang-static-analyzer ios cocoapods

我有一个使用CocoaPods设置的Xcode工作区.当我在我的项目上运行Xcode的Analyzer时,它会分析我自己的源代码以及Pods目标中的所有源代码.这引发了许多我不感兴趣的警告,因为我只想看到我自己的源代码的分析器警告.

我从pod的构建目标中取消选中"Analyze"但这似乎没有任何效果.

有没有办法在运行分析器时忽略Pods目标?

在此输入图像描述

phi*_*our 7

这是对现有答案的更新/修改:

使用Cocoapods 0.38+安装程序属性需要使项目发生变化,以便您需要使用"pods_project"而不是"project",如下所示:

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
Run Code Online (Sandbox Code Playgroud)

有关更改的更多详细信息,请参阅以下Cocoapods博客公告:http://blog.cocoapods.org/CocoaPods-0.38/#breaking-change-to-the-hooks-api

此外,这是一个(已关闭)问题,显示如果您尝试使用新代码的旧方法将收到的错误:https://github.com/CocoaPods/CocoaPods/issues/3918


小智 4

您可以在 podfile 末尾添加安装后步骤,以添加控制静态分析器的编译器标志。

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
Run Code Online (Sandbox Code Playgroud)

然后只需运行“pod update”命令即可重新生成项目文件。

不同部分:

  • $(inherited) -- 避免意外删除标志的好习惯
  • -Qunused-arguments -- llvm 不理解 clang 选项,这会消除主编译产生的警告
  • -Xanalyzer -analyzer-disable-all-checks -- 这告诉静态分析器忽略关联项目中的文件。