Class: Dongjia::PodsIterator
- Inherits:
-
Object
- Object
- Dongjia::PodsIterator
- Defined in:
- lib/dongjia_pods_iterator.rb
Class Method Summary collapse
-
.convert_umbrella_header_import(pod_name) ⇒ Object
将 umbrella 导出的头文件改为尖括号形式.
-
.disable_warnings(config, target_name) ⇒ Object
关闭警告.
-
.enable_lto(config) ⇒ Object
打开 LTO.
-
.iterate(params, sandbox_root) ⇒ Object
遍历所有 Pod 工程配置.
- .update_build_setting(config, key, value) ⇒ Object
Class Method Details
.convert_umbrella_header_import(pod_name) ⇒ Object
将 umbrella 导出的头文件改为尖括号形式
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# 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 |
.disable_warnings(config, target_name) ⇒ Object
关闭警告
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# 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) ⇒ Object
打开 LTO
44 45 46 47 48 |
# 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) ⇒ Object
遍历所有 Pod 工程配置
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# 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) ⇒ Object
7 8 9 10 11 12 13 14 |
# 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 |