【问题标题】:Xcode Analyzer - Ignore CocoaPods targetsXcode Analyzer - 忽略 CocoaPods 目标
【发布时间】:2014-11-27 16:54:50
【问题描述】:

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

我已取消选中 pod 构建目标中的“分析”,但这似乎没有任何效果。

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

【问题讨论】:

标签: ios xcode cocoapods clang-static-analyzer


【解决方案1】:

您可以在 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 -- 这告诉静态分析器忽略关联项目中的文件。

【讨论】:

    【解决方案2】:

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

    使用 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
    

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

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

    【讨论】:

      猜你喜欢
      • 2012-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-08
      相关资源
      最近更新 更多