How can I silence warnings from all pods except local pods?
我假设是
1 2 3 4 5 6 7 8 9 10 11 12 | post_install do |installer| # Debug symbols installer.pod_project.targets.each do |target| target.build_configurations.each do |config| if ? == ? config.build_settings['?'] = '?' end end end end |
我今天遇到了类似的问题,并根据依赖项的复杂程度,找到了两种解决方法。
第一种方法很简单,如果本地开发容器位于主容器文件中而不嵌套在其他依赖项中,则应该可以使用。基本上像往常一样禁止所有警告,但在每个本地Pod上指定false:
1 2 3 4 | inhibit_all_warnings! pod 'LocalPod', :path => '../LocalPod', :inhibit_warnings => false pod 'ThirdPartyPod', |
更全面且应适用于复杂嵌套依赖项的第二种方法是通过创建本地容器的白名单,然后在安装后,禁止任何不属于白名单的容器的警告:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | $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 |
这现在将仅禁止第三方依赖,但将警告保留在任何本地容器上。
有CocoaPods插件,https://github.com/leavez/cocoapods-developing-folder,其中包含
e?"? Inhibit warnings for specific pods
Add the following to your podfile
1
2
3
4
5
6
7 plugin 'cocoapods-developing-folder'
inhibit_warnings_with_condition do |pod_name, pod_target|
# your condition written in ruby, like:
# `not pod_name.start_with?"LE"` or
# `['Asuka', 'Ayanami', 'Shinji'].include? pod_name`
endpod_target is a instance of Pod::PodTarget class, containing many more
info than the name. You can use it to set up complex rules.This function will override the warning inhibition settings by the
original methods, like: inhibit_all_warnings!, pod 'Ayanami',
:inhibit_warnings => true
因此,如果您知道本地Pod的名称,则可以像上面的示例中所示对它们进行过滤。或者,您可以尝试执行以下操作(尝试利用本地Pod不在Pods目录下的事实):
1 2 3 | inhibit_warnings_with_condition do |pod_name, pod_target| pod_target.file_accessors.first.root.to_path.start_with? pod_target.sandbox.root.to_path end |
请注意,如果我正确地获得了最后一条语句,它将排除
Podfile解决方案
尽管
1 2 3 4 5 | # Disable warnings for each remote Pod pod 'TGPControls', :inhibit_warnings => true # Do not disable warnings for your own development Pod pod 'Name', :path => '~/code/Pods/' |