Xcode分析器 - 忽略CocoaPods目标

16

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

我已经取消了“Analyze”选项对Pods构建目标的勾选,但似乎没有任何效果。

是否有一种方法可以在运行分析器时忽略Pods目标?

enter image description here


1
答案在这里:https://dev59.com/rmYs5IYBdhLWcg3wBvRp - Yuri Solodkin
1
@YuriSolodkin 这是针对警告而言,而不是静态分析器的警告。 - CarmeloS
2个回答

8

以下是对已有答案的更新/修改:

从Cocoapods 0.38+版本开始,获取项目所需的installer属性已更改,您需要像这样使用"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

请参考以下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

然后运行“pod update”命令来重新生成项目文件。

不同的部分:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接