且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使除本地Pod以外的所有Pod的警告静音?

更新时间:2021-07-28 20:58:04

我今天遇到了类似的问题,并根据依赖关系的复杂程度,找到了两种解决方法

I encountered a similar problem today and figured out two ways to achieve this depending on the complexity of your dependencies.

第一种方法很简单,如果本地开发容器位于主容器文件中而不嵌套在其他依赖项中,则应该可以使用。基本上照常禁止所有警告,但是在每个本地Pod上指定false:

The first way is simple and should work if your local development pods are in your main pod file and not nested in another dependency. Basically inhibit all the warnings as per usual, but specify false on each local pod:

inhibit_all_warnings!

pod 'LocalPod', :path => '../LocalPod', :inhibit_warnings => false
pod 'ThirdPartyPod',

第二种方法更全面,应该适用于复杂的嵌套依赖项是通过创建本地Pod的白名单,然后在安装后进行操作,禁止任何不属于白名单的Pod的警告:

The second way which is more comprehensive and should work for complex nested dependencies is by creating a whitelist of your local pods and then during post install, inhibit the warnings of any pod that is not part of the whitelist:

$local_pods = Hash[
  'LocalPod0' => true,
  'LocalPod1' => true,
  'LocalPod2' => true,
]

def inhibit_warnings_for_third_party_pods(target, build_settings)
  return if $local_pods[target.name]
  if build_settings["OTHER_SWIFT_FLAGS"].nil?
    build_settings["OTHER_SWIFT_FLAGS"] = "-suppress-warnings"
  else
    build_settings["OTHER_SWIFT_FLAGS"] += " -suppress-warnings"
  end
  build_settings["GCC_WARN_INHIBIT_ALL_WARNINGS"] = "YES"
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      inhibit_warnings_for_third_party_pods(target, config.build_settings)
    end
  end
end

这现在将仅禁止第三方依赖,但将警告保留在任何本地容器上。

This will now only inhibit 3rd party dependencies but keep the warnings on any local pods.