class Dongjia::PodsIterator
Public Class Methods
convert_umbrella_header_import(pod_name)
click to toggle source
将 umbrella 导出的头文件改为尖括号形式
# File lib/dongjia_pods_iterator.rb, line 51 def self.convert_umbrella_header_import(pod_name) umbrella_path = "./Pods/Target Support Files/#{pod_name}/#{pod_name}-umbrella.h" return unless File.exist?(umbrella_path) contents = File.read(umbrella_path) return unless contents.include?("#import \"") File.open(umbrella_path, 'r+') do |f| x = f.read begin x.gsub!("#import \"#{pod_name}/", "#import <#{pod_name}/").gsub!('.h"', '.h>') rescue nil end begin x.gsub!('#import "', "#import <#{pod_name}/").gsub!('.h"', '.h>') rescue nil end f.rewind f.write(x) end end # 遍历所有 Pod 工程配置 def self.iterate(params, sandbox_root) turn_off_warnings = params[:turn_off_warnings] lto_enabled = params[:lto_enabled] return if (turn_off_warnings != true) && (lto_enabled != true) Dir.foreach(sandbox_root).select{|f| f.end_with?('xcodeproj')}.each do |name| proj = Xcodeproj::Project.open(File.join(sandbox_root, name)) if name != 'Pods.xcodeproj' proj.build_configurations.each do | config | # 强制设置 deployment 版本为 9.0 if config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'].to_f < 9.0 config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = "9.0" end end end # project 的每个 target 配置 changed = false proj.targets.select {|t| !t.name.start_with?('Pods')}.each do | target | next if target.name.start_with?('Pods') target.build_configurations.each do | config | changed ||= disable_warnings(config, target.name) if turn_off_warnings changed ||= enable_lto(config) if lto_enabled convert_umbrella_header_import(target.name) end end if changed proj.save end end end end end
disable_warnings(config, target_name)
click to toggle source
关闭警告
# File lib/dongjia_pods_iterator.rb, line 17 def self.disable_warnings(config, target_name) changed = false # 禁用非 DJ 开头 Pod 的警告 changed ||= update_build_setting(config, 'GCC_WARN_INHIBIT_ALL_WARNINGS', 'YES') unless target_name.start_with?('DJ') # 不检测 block 中的隐式 self 调用 changed ||= update_build_setting(config, 'CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF', "NO") # 不检测已废弃的方法 changed ||= update_build_setting(config, 'GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS', "NO") # 不检测注释 changed ||= update_build_setting(config, 'CLANG_WARN_DOCUMENTATION_COMMENTS', "NO") # 强制设置 deployment 版本为 9.0 if config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'].to_f < 9.0 changed ||= update_build_setting(config, 'IPHONEOS_DEPLOYMENT_TARGET', "9.0") end # 关闭 bitcode changed ||= update_build_setting(config, 'ENABLE_BITCODE', "NO") changed end
enable_lto(config)
click to toggle source
打开 LTO
# File lib/dongjia_pods_iterator.rb, line 44 def self.enable_lto(config) changed = false # changed ||= update_build_setting(config, 'LLVM_LTO', 'YES_THIN') if config.name == 'Release' changed end
iterate(params, sandbox_root)
click to toggle source
遍历所有 Pod
工程配置
# File lib/dongjia_pods_iterator.rb, line 66 def self.iterate(params, sandbox_root) turn_off_warnings = params[:turn_off_warnings] lto_enabled = params[:lto_enabled] return if (turn_off_warnings != true) && (lto_enabled != true) Dir.foreach(sandbox_root).select{|f| f.end_with?('xcodeproj')}.each do |name| proj = Xcodeproj::Project.open(File.join(sandbox_root, name)) if name != 'Pods.xcodeproj' proj.build_configurations.each do | config | # 强制设置 deployment 版本为 9.0 if config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'].to_f < 9.0 config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = "9.0" end end end # project 的每个 target 配置 changed = false proj.targets.select {|t| !t.name.start_with?('Pods')}.each do | target | next if target.name.start_with?('Pods') target.build_configurations.each do | config | changed ||= disable_warnings(config, target.name) if turn_off_warnings changed ||= enable_lto(config) if lto_enabled convert_umbrella_header_import(target.name) end end if changed proj.save end end end
update_build_setting(config, key, value)
click to toggle source
# File lib/dongjia_pods_iterator.rb, line 7 def self.update_build_setting(config, key, value) if config.build_settings[key] != value config.build_settings[key] = value return true else return false end end