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

前端 未结 3 1505
太阳男子
太阳男子 2021-02-18 17:12

I\'m assuming something along the lines of

post_install do |installer|

  # Debug symbols
  installer.pod_project.targets.each do |target|
    target.build_conf         


        
3条回答
  •  执念已碎
    2021-02-18 17:51

    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.

提交回复
热议问题