cocoapods-kz 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cocoapods-kz/command/install.rb +12 -9
  3. data/lib/cocoapods-kz/command/kz.rb +1 -0
  4. data/lib/cocoapods-kz/command/repair.rb +47 -0
  5. data/lib/cocoapods-kz/command/update.rb +12 -8
  6. data/lib/cocoapods-kz/gem_version.rb +1 -1
  7. data/lib/cocoapods-kz/helpers/kz_analyzer.rb +46 -3
  8. data/lib/cocoapods-kz/helpers/kz_framework_manager.rb +1 -1
  9. data/lib/cocoapods-kz/helpers/kz_generator.rb +256 -0
  10. data/lib/cocoapods-kz/helpers/kz_global_helper.rb +127 -0
  11. data/lib/cocoapods-kz/helpers/kz_pod_target.rb +95 -24
  12. data/lib/cocoapods-kz/helpers/repair_dynamic_swift.rb +373 -0
  13. data/lib/cocoapods-kz/helpers/repair_module_import.rb +113 -0
  14. data/lib/cocoapods-kz/native/acknowledgements.rb +8 -15
  15. data/lib/cocoapods-kz/native/analyzer.rb +5 -4
  16. data/lib/cocoapods-kz/native/dls.rb +2 -1
  17. data/lib/cocoapods-kz/native/file_accessor.rb +25 -8
  18. data/lib/cocoapods-kz/native/installer.rb +9 -22
  19. data/lib/cocoapods-kz/native/pod_target.rb +17 -0
  20. data/lib/cocoapods-kz/native/pod_target_installer.rb +30 -0
  21. data/lib/cocoapods-kz/native/target.rb +34 -0
  22. data/lib/cocoapods-kz/native/target_installer_helper.rb +105 -0
  23. data/lib/cocoapods-kz/native.rb +4 -1
  24. metadata +13 -10
  25. data/lib/cocoapods-kz/helpers/build_framework_config.rb +0 -48
  26. data/lib/cocoapods-kz/helpers/create_hamp.rb +0 -214
  27. data/lib/cocoapods-kz/helpers/global_helper.rb +0 -71
  28. data/lib/cocoapods-kz/helpers/strip_framework_config.rb +0 -40
  29. data/lib/cocoapods-kz/helpers/xml_build_config.rb +0 -53
  30. data/lib/cocoapods-kz/native/user_project_integrator.rb +0 -16
@@ -1,214 +0,0 @@
1
- require 'fileutils'
2
- require_relative 'global_helper'
3
-
4
- module KZ
5
- class HmapContentStyle
6
- QUOTES_PRIVATE = 1
7
- QUOTES_REPAIR = 2
8
- end
9
-
10
- class CreateHmap
11
-
12
- def initialize(main_project, pod_project)
13
- @main_project = main_project
14
- @pod_project = pod_project
15
- end
16
-
17
- def traverse_folder(folder_path)
18
- Dir.foreach(folder_path) do |file_name|
19
- next if file_name == '.' || file_name == '..'
20
-
21
- file_path = File.join(folder_path, file_name)
22
- if File.file?(file_path)
23
- yield(file_path) if file_name.end_with?('.h')
24
- elsif File.directory?(file_path)
25
- traverse_folder(file_path) do |file_path|
26
- yield(file_path)
27
- end
28
- end
29
- end
30
- end
31
-
32
- def get_pod_pchfile_path(target_name)
33
- @pod_project.project_dir + 'Target Support Files' + target_name + "#{target_name}-prefix.pch"
34
- end
35
-
36
- def save_hmap_file(hmap_hash, save_path, file_name)
37
- hmap_json = JSON.pretty_generate(hmap_hash)
38
- hmap_json_path = save_path + "#{file_name}.json"
39
- hmap_path = save_path + "#{file_name}.hmap"
40
- json_file = File.new(hmap_json_path, 'w')
41
- return unless json_file
42
-
43
- json_file.syswrite(hmap_json)
44
- system "#{HMAP_EXECUTE_PATH} convert #{hmap_json_path} #{hmap_path}"
45
-
46
- FileUtils.rm(hmap_json_path) unless KZ::KZGlobalHelper.instance.debug
47
- end
48
-
49
- def create_main_hamp
50
- main_sources_path = @main_project.project_dir + @main_project.root_object.display_name
51
- private_hmap_hash = {}
52
- traverse_folder(main_sources_path) do |header_path|
53
- header_pathname = Pathname.new(header_path)
54
- header_pathname_basename = header_pathname.basename.to_s
55
-
56
- header_hmap_value = {}
57
- header_hmap_value['suffix'] = header_pathname_basename
58
- header_hmap_value['prefix'] = header_pathname.dirname.to_s + '/'
59
-
60
- private_hmap_hash[header_pathname_basename] = header_hmap_value
61
- end
62
-
63
- if !private_hmap_hash.empty?
64
- save_hmap_file(private_hmap_hash, KZ_POD_CONFIG_ROOT, @main_project.root_object.display_name)
65
- end
66
-
67
- @main_project.targets.each do |target|
68
- if target.isa == "PBXNativeTarget" and target.product_type == "com.apple.product-type.application"
69
- target.build_configurations.each do |config|
70
- config.build_settings['HEADER_SEARCH_PATHS'] = "${PODS_ROOT}/#{@main_project.root_object.display_name }.hmap"
71
- config.build_settings['USE_HEADERMAP'] = 'NO'
72
- end
73
- end
74
- end
75
- end
76
-
77
- def get_all_native_target_from(project)
78
- all_native_target = {}
79
-
80
- project.targets.each do |target|
81
- if target.isa == "PBXNativeTarget" and target.product_type == "com.apple.product-type.framework" and !target.name.start_with?('Pods-')
82
- all_native_target[target.name] = target
83
- end
84
- end
85
- all_native_target
86
- end
87
-
88
- def get_all_handle_target_from(project)
89
- all_handle_target = {}
90
-
91
- project.targets.each do |target|
92
- if !(target.isa == "PBXNativeTarget" and target.product_type == "com.apple.product-type.bundle") and !target.name.start_with?('Pods-')
93
- all_handle_target[target.name] = target
94
- end
95
- end
96
- all_handle_target
97
- end
98
-
99
- def get_hmap_info_from(kz_pod_target, hmap_content_style)
100
- header_paths = kz_pod_target.public_headers
101
- header_paths = kz_pod_target.all_headers if hmap_content_style == HmapContentStyle::QUOTES_PRIVATE
102
- hmap_info = {}
103
- header_paths.each do |header_pathname|
104
- header_pathname_basename = header_pathname.basename.to_s
105
-
106
- header_hmap_value_quotes = {}
107
- header_hmap_value_quotes['suffix'] = header_pathname_basename
108
- header_hmap_value_quotes['prefix'] = header_pathname.dirname.to_s + '/'
109
- hmap_info[header_pathname_basename] = header_hmap_value_quotes
110
-
111
- if hmap_content_style == HmapContentStyle::QUOTES_PRIVATE
112
- # pch
113
- pchfile_path = get_pod_pchfile_path(kz_pod_target.name)
114
- if pchfile_path.exist?
115
- suffix = pchfile_path.basename.to_s
116
- prefix = pchfile_path.dirname.to_s + '/'
117
- header_hmap_value = {}
118
- header_hmap_value['suffix'] = suffix
119
- header_hmap_value['prefix'] = prefix
120
- hmap_info[suffix] = header_hmap_value
121
- end
122
-
123
- unless kz_pod_target.is_dev_pod
124
- # 各别第三方在使用自己组件文件时,会使用#import <xx/xx.h>的方式
125
- hmap_info[kz_pod_target.name + '/' + header_pathname_basename] = header_hmap_value_quotes
126
- end
127
-
128
- # 例如SPBoss.h会被在SPBoss-Swift.h中以#import <SPBoss/SPBoss.h>的方式使用,需要重定义寻找路径
129
- if kz_pod_target.uses_swift && kz_pod_target.is_dev_pod && header_pathname_basename == "#{kz_pod_target.name}.h"
130
- hmap_info[kz_pod_target.name + '/' + header_pathname_basename] = header_hmap_value_quotes
131
- end
132
- elsif hmap_content_style == HmapContentStyle::QUOTES_REPAIR
133
- header_hmap_value_slash = {}
134
- header_hmap_value_slash['suffix'] = header_pathname_basename
135
- header_hmap_value_slash['prefix'] = kz_pod_target.name + '/'
136
- hmap_info[header_pathname_basename] = header_hmap_value_slash
137
- end
138
- end
139
- hmap_info
140
- end
141
-
142
- def create_pod_hamp(all_kz_pod_targets)
143
- all_handle_targets = get_all_handle_target_from(@pod_project)
144
- all_handle_targets.each do |target_name, target|
145
- kz_pod_target = all_kz_pod_targets[target_name]
146
- next unless kz_pod_target
147
-
148
- # 修复头文件导入方式
149
- kz_recursive_dependent_targets = kz_pod_target.repair_import
150
- if kz_recursive_dependent_targets.count > 0
151
- all_repair_hmap_info = {}
152
- kz_recursive_dependent_targets.each { |recursive_dependent_target|
153
- repair_hmap_info = get_hmap_info_from(recursive_dependent_target, HmapContentStyle::QUOTES_REPAIR)
154
- all_repair_hmap_info.merge!(repair_hmap_info)
155
- }
156
- if all_repair_hmap_info.count > 0
157
- hmap_cache_path = kz_pod_target.pod_config_cache_path(false)
158
- save_hmap_file(all_repair_hmap_info, hmap_cache_path, target_name + '_repair')
159
- kz_pod_target.repair_header_search_path = hmap_cache_path + "#{target_name}_repair.hmap"
160
- end
161
- end
162
- end
163
-
164
- all_native_targets = get_all_native_target_from(@pod_project)
165
- all_native_targets.each do |target_name, target|
166
- kz_pod_target = all_kz_pod_targets[target_name]
167
- next unless kz_pod_target
168
-
169
- # 添加私有头文件引用
170
- private_hamp_info = get_hmap_info_from(kz_pod_target, HmapContentStyle::QUOTES_PRIVATE)
171
- if private_hamp_info.count > 0
172
- hmap_cache_path = kz_pod_target.pod_config_cache_path(false)
173
- save_hmap_file(private_hamp_info, kz_pod_target.pod_config_cache_path(false), target_name)
174
- kz_pod_target.private_header_search_path = hmap_cache_path + "#{target_name}.hmap"
175
- end
176
-
177
- # 修复缺失的依赖
178
- framework_search_paths = '$(inherited)'
179
- kz_pod_target.all_repair_dependent_target_info.values.each do |repair_target|
180
- result = KZGlobalHelper.instance.pod_config_result_with_target(repair_target)
181
- if result
182
- framework_search_paths += (' ' + "#{result.resource_path.to_s}")
183
- else
184
- # 修复target依赖
185
- dependency_target = all_native_targets[repair_target.name]
186
- target.add_dependency(dependency_target) if dependency_target
187
- # 修复framework_search_paths
188
- framework_search_paths += (' ' + '"${PODS_CONFIGURATION_BUILD_DIR}/' + repair_target.name + '"')
189
- end
190
- end
191
- kz_pod_target.framwork_search_paths = framework_search_paths
192
- end
193
-
194
- all_native_targets.each do |target_name, target|
195
- kz_pod_target = all_kz_pod_targets[target_name]
196
- next unless kz_pod_target
197
-
198
- # 添加配置
199
- target.build_configurations.each do |config|
200
- config.build_settings['HEADER_SEARCH_PATHS'] = kz_pod_target.header_search_paths
201
- config.build_settings['USE_HEADERMAP'] = 'NO'
202
- config.build_settings['FRAMEWORK_SEARCH_PATHS'] = kz_pod_target.framwork_search_paths
203
- config.build_settings['KZ_FRAMEWORK_CACHE_PATH'] = kz_pod_target.pod_config_cache_path(true).to_s
204
- end
205
- end
206
- end
207
-
208
- def config_project
209
- create_main_hamp
210
- create_pod_hamp(KZGlobalHelper.instance.kz_analyzer.all_kz_pod_targets)
211
- end
212
-
213
- end
214
- end
@@ -1,71 +0,0 @@
1
- require 'cocoapods'
2
- require 'fileutils'
3
- require_relative 'kz_analyzer'
4
- require_relative 'kz_framework_manager'
5
- require_relative 'kz_config_result'
6
- require_relative 'kz_pod_target'
7
-
8
- module KZ
9
- KZ_POD_CONFIG_ROOT = Pod::Config.instance.sandbox_root + 'KZPodConfigure'
10
-
11
- HMAP_EXECUTE_PATH = File.dirname(__FILE__) + '/../resources/hmap'
12
- FLEX_COMPLIER_PATH = KZ_POD_CONFIG_ROOT + 'FlexCompiler'
13
-
14
- class KZGlobalHelper
15
- attr_accessor :kz_pod_enable
16
- attr_accessor :kz_pod_config
17
- attr_accessor :kz_analyzer
18
- attr_accessor :specify_pod_names
19
- attr_accessor :specify_pod_mode
20
- attr_accessor :debug
21
-
22
- private_class_method :new
23
-
24
- def initialize
25
- @kz_pod_enable = false
26
- @specify_pod_mode = :kz_pod_origin_mode
27
- @pods_config_cache = {}
28
- @debug = false
29
-
30
- FileUtils.mkdir_p(KZ_POD_CONFIG_ROOT)
31
- FileUtils.cp_r(File.dirname(__FILE__) + '/../resources/FlexCompiler', KZ_POD_CONFIG_ROOT)
32
- end
33
-
34
- @@instance = nil
35
- def self.instance
36
- @@instance ||= new
37
- end
38
-
39
- def analyze_special_parameters(use_code_tag, use_framework_tag, pod_names)
40
- specify_pod_names = []
41
- if pod_names.count > 0
42
- pod_names.each do |param|
43
- if param.include?(',')
44
- specify_pod_names.concat(param.split(","))
45
- else
46
- specify_pod_names << param
47
- end
48
- end
49
- end
50
- @specify_pod_names = specify_pod_names
51
- if use_code_tag
52
- @specify_pod_mode = :kz_pod_code_mode
53
- elsif use_framework_tag
54
- @specify_pod_mode = :kz_pod_framework_mode
55
- end
56
- end
57
-
58
- def pod_config_result_with_target(kz_pod_target)
59
- return nil unless @kz_pod_enable && @kz_analyzer != nil
60
- return nil unless kz_pod_target && kz_pod_target.config_pod_mode == :kz_pod_framework_mode
61
-
62
- return @pods_config_cache[kz_pod_target.name] if @pods_config_cache.has_key?(kz_pod_target.name)
63
-
64
- result = KZFrameworkManager.validate_framework_and_get_result(kz_pod_target)
65
-
66
- @pods_config_cache[kz_pod_target.name] = result if result
67
- result
68
- end
69
-
70
- end
71
- end
@@ -1,40 +0,0 @@
1
- require 'fileutils'
2
- require 'tempfile'
3
-
4
- module KZ
5
- class StripFrameworkConfig
6
- def initialize(main_project, pod_project)
7
- @main_project = main_project
8
- @pod_project = pod_project
9
- end
10
-
11
- def pod_target_support_files_path
12
- @pod_project.project_dir + 'Target Support Files'
13
- end
14
-
15
- def config_project
16
- @main_project.targets.each do |target|
17
- if target.isa == "PBXNativeTarget" and target.product_type == "com.apple.product-type.application"
18
- target_support_file_path = pod_target_support_files_path + "Pods-#{target.name}" + "Pods-#{target.name}-frameworks.sh"
19
- if target_support_file_path.exist?
20
- temp_sh_file_path = @main_project.project_dir + "Pods-#{target.name}" + 'temp.sh'
21
- temp_sh_file = Tempfile.new(temp_sh_file_path.to_s)
22
- chmod_cmd = "chmod +x #{temp_sh_file.path}"
23
- system chmod_cmd
24
-
25
- sh_file = File.open(target_support_file_path, "r+")
26
- sh_file.each_line { |line|
27
- temp_sh_file.puts(line)
28
- if line.start_with?(" # Resign the code if required by the build settings to avoid unstable apps")
29
- temp_sh_file.puts(' xcrun strip -x "${destination}/${basename}.framework/${basename}" 2> /dev/null')
30
- end
31
- }
32
- temp_sh_file.close
33
- FileUtils.mv(temp_sh_file.path, target_support_file_path)
34
- end
35
- end
36
- end
37
- end
38
-
39
- end
40
- end
@@ -1,53 +0,0 @@
1
- require_relative 'global_helper'
2
-
3
- module KZ
4
- class XmlBuildConfig
5
- def initialize(main_project, pod_project)
6
- @pod_project = pod_project
7
- end
8
-
9
- def new_build_rule(project, target, name)
10
- new_rule = nil
11
- target.build_rules.each do |build_rule|
12
- new_rule = build_rule if build_rule.name == name
13
- end
14
-
15
- if new_rule == nil
16
- new_rule = project.new(Xcodeproj::Project::PBXBuildRule)
17
- target.build_rules << new_rule
18
- end
19
-
20
- new_rule.name = name
21
- new_rule.compiler_spec = 'com.apple.compilers.proxy.script'
22
- new_rule
23
- end
24
-
25
- def create_xml_rule(project, target)
26
- xml_rule = new_build_rule(project, target, '[KZ] Custom Xml Build')
27
- xml_rule.file_type = 'text.xml'
28
- xml_rule.output_files = Array['${KZ_XML_FLEX_DIR}/${INPUT_FILE_BASE}.flex']
29
- xml_rule.script = %Q{FLEX_PATH=${KZ_XML_FLEX_DIR}/${INPUT_FILE_BASE}.flex
30
- rm -rf ${FLEX_PATH}
31
- $KZ_XML_FLEX_COMPILER $INPUT_FILE_PATH $FLEX_PATH
32
- if [ -f $FLEX_PATH ] ; then
33
- cp $FLEX_PATH $KZ_XML_FLEX_BUILD_DIR
34
- exit 0
35
- else
36
- exit 1
37
- fi}
38
- end
39
-
40
- def config_project
41
- @pod_project.targets.each do |target|
42
- if target.isa == "PBXNativeTarget" && target.product_type == "com.apple.product-type.framework" && target.name.start_with?("SP")
43
- target.build_configurations.each do |config|
44
- config.build_settings["KZ_XML_FLEX_COMPILER"] = FLEX_COMPLIER_PATH.to_s
45
- config.build_settings["KZ_XML_FLEX_DIR"] = "${TARGET_TEMP_DIR}/XmlFlexs"
46
- config.build_settings["KZ_XML_FLEX_BUILD_DIR"] = "${TARGET_BUILD_DIR}/${PRODUCT_NAME}.bundle"
47
- end
48
- self.create_xml_rule(@pod_project, target)
49
- end
50
- end
51
- end
52
- end
53
- end
@@ -1,16 +0,0 @@
1
- require 'cocoapods/installer/user_project_integrator'
2
- require 'cocoapods-kz/helpers/global_helper'
3
-
4
- module Pod
5
- class Installer
6
- class UserProjectIntegrator
7
-
8
- alias_method :origin_print_override_warning, :print_override_warning
9
- def print_override_warning(aggregate_target, user_target, config, key)
10
- unless KZ::KZGlobalHelper.instance.kz_pod_enable
11
- origin_print_override_warning(aggregate_target, user_target, config, key)
12
- end
13
- end
14
- end
15
- end
16
- end