Podfile static-lib memo

Updated
Dec 25, 2020 8:04 AM
Created
Dec 25, 2020 8:03 AM
Tags
Cocoapods
Keywords
Date
post_install do |installer|

  puts installer
  puts "========="

  merged_framework_target = "Pods-Umbrella"
  wrap_target = installer.analysis_result.targets.find { |item| item.name == merged_framework_target }
  if wrap_target.nil?
    raise "Could not find target for Merged Framework from #{installer.analysis_result.targets}"
  end

  target_names_should_be_static = wrap_target.pod_targets.map { |i| i.name }

  # wrap_target.pod_targets.each { |i| puts "📦 Static Framework ->#{i.name}" }

  # puts "==="
  # wrap_target.pod_targets.each { |target|
  #   puts "@_exported import #{target.product_module_name}"
  # }
  # puts "==="

  # installer.analysis_result.targets
  #   .select { |item| item.name != merged_framework_target }
  #   .each { |target|
  #     puts "Validate : #{target}"
  #     result = target.pod_targets.find { |item| target_names_should_be_static.include? item.name  }
  #     unless result.nil?
  #       # raise "#{target.name} includes this pod (#{result.name})"
  #     end
  # }

  if false
    installer.aggregate_targets.each do |aggregate_target|

      if aggregate_target.name != merged_framework_target
        aggregate_target.xcconfigs.each do |config_name, config_file|

          # puts "💥 Integrate with Umbrella =>" + aggregate_target.name

          wrap_target.pod_targets.each { |target|
            # puts "  🎫 Remove linking => " + target.product_module_name
            config_file.frameworks.delete(target.product_module_name)
          }

          xcconfig_path = aggregate_target.xcconfig_path(config_name)
          config_file.save_as(xcconfig_path)
        end
      end

    end

    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        if target_names_should_be_static.include? target.name
          config.build_settings['MACH_O_TYPE'] = "staticlib"
        end
      end
    end
  end

  installer.pods_project.targets.each do |target|

    target.build_configurations.each do |config|

      config.build_settings['DEBUG_INFORMATION_FORMAT'] = 'dwarf-with-dsym'

      if swift4_names.include? target.name
        config.build_settings['SWIFT_VERSION'] = "4.1"
      end

      if swift42_names.include? target.name
        config.build_settings['SWIFT_VERSION'] = "4.2"
      end

      if target.name == 'Keyboard+LayoutGuide'
        config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO'
      end

      if target.name == 'MosaiqueAssetsPicker'
        config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO'
      end

      if target.name == 'RxSwift' || target.name == 'RxCocoa'
        config.build_settings['OTHER_SWIFT_FLAGS'] ||= ['$(inherited)', '-D EXPANDABLE_SHARED_SEQUENCE']
      end

    end
  end
end