How can I silence warnings from all pods except local pods?

試著忘記壹切 提交于 2019-12-05 12:43:19

问题


I'm assuming something along the lines of

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

回答1:


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

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',

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.




回答2:


Podfile Solution

While ignore_all_warnings is an all or none proposition, you can :inhibit_warnings => true on any individual pod in the Podfile.

# 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/' 



回答3:


There's CocoaPods plugin, https://github.com/leavez/cocoapods-developing-folder that has inhibit_warnings_with_condition. Citing the README:

🔸 Inhibit warnings for specific pods

Add the following to your podfile

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`
end

pod_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

So if you know the names of the local pods you can filter them like shown in the above example. Or you can try something like this (that tries to exploit the fact that local pods are not under Pods directory):

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

Beware that, if I get the last statement there correctly, it will rule out inhibit_all_warnings! and :inhibit_warnings from effect (I checked the implementation and it looks like it's indeed the case). So you can not use both inhibit_warnings_with_condition and inhibit_all_warnings! or :inhibit_warnings, but at the end, that kind of makes sense.



来源:https://stackoverflow.com/questions/31644959/how-can-i-silence-warnings-from-all-pods-except-local-pods

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!