cocoapods-kz 0.0.16 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cocoapods-kz/command/info.rb +23 -2
  3. data/lib/cocoapods-kz/command/install.rb +0 -4
  4. data/lib/cocoapods-kz/command/repair.rb +10 -19
  5. data/lib/cocoapods-kz/command/update.rb +0 -4
  6. data/lib/cocoapods-kz/gem_version.rb +1 -1
  7. data/lib/cocoapods-kz/helpers/kz_analyzer.rb +10 -3
  8. data/lib/cocoapods-kz/helpers/kz_framework_manager.rb +37 -12
  9. data/lib/cocoapods-kz/helpers/kz_generator_hmap.rb +20 -9
  10. data/lib/cocoapods-kz/helpers/kz_generator_on_demand_resources.rb +36 -7
  11. data/lib/cocoapods-kz/helpers/kz_global_helper.rb +14 -7
  12. data/lib/cocoapods-kz/helpers/kz_log.rb +23 -3
  13. data/lib/cocoapods-kz/helpers/kz_pod_target.rb +10 -15
  14. data/lib/cocoapods-kz/helpers/repair_module_import.rb +14 -4
  15. data/lib/cocoapods-kz/native/dls.rb +1 -1
  16. data/lib/cocoapods-kz/native/installer.rb +20 -7
  17. data/lib/cocoapods-kz/native/pod_target_installer.rb +9 -3
  18. data/lib/cocoapods-kz/native/target_installer_helper.rb +20 -7
  19. data/lib/cocoapods-kz/native/target_integrator.rb +6 -2
  20. data/lib/cocoapods-kz/resources/FlexCompiler +0 -0
  21. data/lib/cocoapods-kz/resources/hmap +0 -0
  22. data/lib/cocoapods-kz/resources/{kz_generator_framework.sh → kz_generate_framework.sh} +2 -0
  23. data/lib/cocoapods-kz/resources/kz_generate_xcode_env.sh +21 -0
  24. data/lib/cocoapods-kz/resources/kz_improve_custom_yaml.sh +2 -1
  25. data/lib/cocoapods-kz/resources/on_demand_resources/kz_on_demand_resources_process.rb +23 -5
  26. data/lib/cocoapods-kz/resources/on_demand_resources/kz_on_demand_resources_xocde.sh +8 -23
  27. metadata +4 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8897bc08210ec4f9d4ceb2c3a4004e9535264667432a09c8eabb3c37c81e090d
4
- data.tar.gz: 58cda02e1cba05f25c87c1c75701de1fa23077075d6976daf1b396a1f3483fb4
3
+ metadata.gz: 1d054c8e5514bb6136c627613b061ced1961f9f069d0c6160718f060d8394b4d
4
+ data.tar.gz: cced90a605f5652c04c46f39d4f44ef3ab21da9131842b3cbbe22fe0bb8eb58c
5
5
  SHA512:
6
- metadata.gz: eee9d236f5b1f1b4a32b31ce6b385548fe2a847f79cd8f1729f7643f4485086d26db831cb67361ee282be1f613081ea567b921ae35a3b6f3aaead3fdde6114ff
7
- data.tar.gz: 89a2b27fd83674b77c50bec39e8a115da01c462d42f4a023e78f84d15f1ccd975ae53c3d3c5f79dd6388e91575fc0de9c5f3570af07ac06eb2156f18bf478e06
6
+ metadata.gz: 5b83c0a3b25538cf2d6dfff81c419de10062a93ec78480fc3022df7c751e7bb920d130f6d2f93740bfed80fd4c80b335979606d5d649cc75c6e3bbca4297020a
7
+ data.tar.gz: 6deb0853f199c345a66bfef9e0f10da7d1493bc20a6bc1b05c14ef4bae455f3187658b14c42d90bca096085557ab1aee3153d2feee22621c360cbc5a2dd4cbac
@@ -12,9 +12,8 @@ module Pod
12
12
 
13
13
  def initialize(argv)
14
14
  if Pod.match_version?('~> 1.11')
15
- KZ::KZGlobalHelper.instance.kz_pod_enable = true
16
- KZ::KZGlobalHelper.instance.analyze_special_parameters(true, false, argv.arguments!)
17
15
  KZ::KZGlobalHelper.instance.generate_kz_pod_targets = true
16
+ KZ::KZGlobalHelper.instance.analyze_special_parameters(true, false, argv.arguments!)
18
17
  end
19
18
  super
20
19
  end
@@ -26,14 +25,36 @@ module Pod
26
25
  installer.download_dependencies
27
26
 
28
27
  result_info = {}
28
+ main_project = installer.aggregate_targets.first.user_project
29
+ result_info[main_project.root_object.display_name] = {
30
+ "path": main_project.project_dir.to_s
31
+ }
29
32
  KZ::KZGlobalHelper.instance.kz_analyzer.all_kz_pod_targets.values.each do |kz_pod_target|
30
33
  pod_info = {}
31
34
  pod_info["path"] = kz_pod_target.native_pod_target.sandbox.pod_dir(kz_pod_target.name)
32
35
  pod_info["is_dev"] = kz_pod_target.is_dev_pod
36
+ dependent_target_names = []
37
+ kz_pod_target.native_pod_target.dependent_targets.each do |native_dependent_target|
38
+ traverse_dependent_targets(native_dependent_target) do |target|
39
+ dependent_target_names.append(target.name)
40
+ end
41
+ end
42
+ pod_info["dependent_target_names"] = dependent_target_names
33
43
  result_info[kz_pod_target.name] = pod_info
34
44
  end
35
45
  puts result_info.to_json
36
46
  end
47
+
48
+ def traverse_dependent_targets(native_dependent_target)
49
+ if native_dependent_target.dependent_targets.count > 0
50
+ yield(native_dependent_target)
51
+ native_dependent_target.dependent_targets.each do |sub_native_dependent_target|
52
+ traverse_dependent_targets(sub_native_dependent_target) do |target|
53
+ yield(target)
54
+ end
55
+ end
56
+ end
57
+ end
37
58
  end
38
59
  end
39
60
  end
@@ -34,10 +34,6 @@ module Pod
34
34
  banner! if (use_code_tag && use_framework_tag)
35
35
 
36
36
  KZ::KZGlobalHelper.instance.analyze_special_parameters(use_code_tag, use_framework_tag, argv.arguments!)
37
- if Pod.match_version?('~> 1.11')
38
- KZ::KZGlobalHelper.instance.kz_pod_enable = true
39
- KZ::KZGlobalHelper.instance.generate_kz_pod_targets = true
40
- end
41
37
  KZ::KZGlobalHelper.instance.debug = true if argv.flag?('debug')
42
38
  KZ::KZGlobalHelper.instance.arm64_simulator = true if argv.flag?('arm64-simulator')
43
39
  framework_update = argv.flag?('framework-update')
@@ -15,18 +15,15 @@ module Pod
15
15
  [
16
16
  ['--module-import', "指定组件名(只针对开发组件),修复该组件所有文件头文件导入方式,壳工程使用“Main”,如果不指定,默认对所有开发组件进行修复"],
17
17
  ['--dynamic-swift', "指定组件名(只针对开发组件),将该组件中所有swift文件添加OC特性,壳工程使用“Main”,如果不指定,默认对所有开发组件进行修复"],
18
- ['--private-hmap', "重新生成组件私有hamp"],
19
18
  ]
20
19
  end
21
20
 
22
21
  def initialize(argv)
23
22
  @repair_module_import = argv.flag?('module-import')
24
23
  @repair_dynamic_swift = argv.flag?('dynamic-swift')
25
- @repair_private_hmap = argv.flag?('private-hmap')
26
- banner! unless @repair_module_import || @repair_dynamic_swift || @repair_private_hmap
24
+ banner! unless @repair_module_import || @repair_dynamic_swift
27
25
 
28
26
  if Pod.match_version?('~> 1.11')
29
- KZ::KZGlobalHelper.instance.kz_pod_enable = true
30
27
  KZ::KZGlobalHelper.instance.analyze_special_parameters(true, false, argv.arguments!)
31
28
  KZ::KZGlobalHelper.instance.generate_kz_pod_targets = true
32
29
  end
@@ -35,21 +32,15 @@ module Pod
35
32
  end
36
33
 
37
34
  def run
38
- KZ::KZGlobalHelper.instance.prepare
39
-
40
- if KZ::KZGlobalHelper.instance.kz_pod_enable
41
- installer = installer_for_config
42
- installer.prepare
43
- installer.resolve_dependencies
44
- installer.download_dependencies
45
-
46
- if @repair_dynamic_swift
47
- KZ::KZSwiftAttachOCFeature.new.repair
48
- elsif @repair_module_import
49
- KZ::KZRepairModuleImport.new(installer.aggregate_targets.first.user_project).repair
50
- else @repair_private_hmap
51
- KZ::KZGlobalHelper.instance.kz_generator.create_hamp
52
- end
35
+ installer = installer_for_config
36
+ installer.prepare
37
+ installer.resolve_dependencies
38
+ installer.download_dependencies
39
+
40
+ if @repair_dynamic_swift
41
+ KZ::KZSwiftAttachOCFeature.new.repair
42
+ elsif @repair_module_import
43
+ KZ::KZRepairModuleImport.new(installer.aggregate_targets.first.user_project).repair
53
44
  end
54
45
  end
55
46
  end
@@ -34,10 +34,6 @@ module Pod
34
34
  banner! if (use_code_tag && use_framework_tag)
35
35
 
36
36
  KZ::KZGlobalHelper.instance.analyze_special_parameters(use_code_tag, use_framework_tag, argv.arguments!)
37
- if Pod.match_version?('~> 1.11')
38
- KZ::KZGlobalHelper.instance.kz_pod_enable = true
39
- KZ::KZGlobalHelper.instance.generate_kz_pod_targets = true
40
- end
41
37
  KZ::KZGlobalHelper.instance.debug = true if argv.flag?('debug')
42
38
  KZ::KZGlobalHelper.instance.arm64_simulator = true if argv.flag?('arm64-simulator')
43
39
  framework_update = argv.flag?('framework-update')
@@ -1,5 +1,5 @@
1
1
  module CocoapodsKz
2
- VERSION = "0.0.16"
2
+ VERSION = "0.0.17"
3
3
  end
4
4
 
5
5
  module Pod
@@ -39,12 +39,15 @@ module KZ
39
39
  @pod_of_flexlib_info.have_kzswiftui_pod = true
40
40
  end
41
41
  }
42
+ KZ::KZLog.log("已经完成所有pod解析", :success)
43
+ return unless KZGlobalHelper.instance.kz_pod_enable
42
44
 
43
45
  # 检测是否有product名称相同的target
44
46
  temp_repeat_product_name = []
45
47
  @all_kz_pod_targets.each do |name, kz_pod_target|
46
48
  result = KZGlobalHelper.instance.pod_config_result_with_target(kz_pod_target)
47
- if temp_repeat_product_name.include?("#{kz_pod_target.product_name}_#{kz_pod_target.platform_name}")
49
+ temp_name = "#{kz_pod_target.product_name}_#{kz_pod_target.platform_name}"
50
+ if temp_repeat_product_name.include?(temp_name)
48
51
  kz_pod_target.product_name = "#{kz_pod_target.name}.framework"
49
52
  kz_pod_target.product_basename = kz_pod_target.name
50
53
  if result
@@ -59,8 +62,9 @@ module KZ
59
62
  end
60
63
  end
61
64
  kz_pod_target.need_repair_module_import = true
65
+ KZLog.log("检测到多个target编译产物名均为:#{temp_name},已配置#{kz_pod_target.name}使用新产物名:#{kz_pod_target.name}.framework,并使用modulemap进行修复引用方式保持不变", :info)
62
66
  elsif kz_pod_target.origin_should_build?
63
- temp_repeat_product_name << "#{kz_pod_target.product_name}_#{kz_pod_target.platform_name}"
67
+ temp_repeat_product_name << "#{temp_name}"
64
68
  end
65
69
 
66
70
  if kz_pod_target.force_load
@@ -69,6 +73,7 @@ module KZ
69
73
  else
70
74
  kz_pod_target.force_load_info = "#{kz_pod_target.configuration_build_dir(true)}/#{kz_pod_target.product_name}/#{kz_pod_target.product_basename}"
71
75
  end
76
+ KZLog.log("'#{kz_pod_target.name}'开启force load,已配置其framework在链接时会使用-force-load", :info)
72
77
  end
73
78
  end
74
79
  end
@@ -77,7 +82,9 @@ module KZ
77
82
  native_pod_target_name = native_pod_target.name
78
83
  if @all_kz_pod_targets.has_key?(native_pod_target_name)
79
84
  kz_pod_target = @all_kz_pod_targets[native_pod_target_name]
80
- kz_pod_target.config_pod_mode = config_pod_mode unless kz_pod_target.is_dev_pod
85
+ if !kz_pod_target.is_dev_pod && config_pod_mode != :kz_pod_origin_mode
86
+ kz_pod_target.config_pod_mode = config_pod_mode
87
+ end
81
88
  else
82
89
  kz_pod_target = KZPodTarget.new(native_pod_target)
83
90
  is_dev_pod = @development_pods.include?(native_pod_target_name)
@@ -115,7 +115,9 @@ module KZ
115
115
  available_libraries = info_plist["AvailableLibraries"]
116
116
  available_libraries.each do |available_librarie|
117
117
  if available_librarie["SupportedPlatformVariant"] == "simulator" && available_librarie["SupportedArchitectures"].include?("arm64")
118
- return origin_framework_path
118
+ FileUtils.mkdir_p(destination_path) unless File.exist?(destination_path)
119
+ FileUtils.cp_r(origin_framework_path, destination_path)
120
+ return xcframework_path
119
121
  end
120
122
  end
121
123
 
@@ -153,7 +155,7 @@ module KZ
153
155
  FileUtils.cp_r(origin_framework_path, arm64_framework_path)
154
156
  arm64_framework_exe_path = arm64_framework_path + framework_basename
155
157
  if self.contain_multiple_arch?(arm64_framework_exe_path)
156
- system("lipo #{arm64_framework_exe_path} -thin arm64 -output #{arm64_framework_exe_path} #{KZGlobalHelper.instance.debug_shell_log_tag}")
158
+ KZLog.run_shell("lipo #{arm64_framework_exe_path} -thin arm64 -output #{arm64_framework_exe_path}")
157
159
  end
158
160
 
159
161
  simulator_path = tempdir + "simulator"
@@ -163,13 +165,15 @@ module KZ
163
165
  simulator_framework_exe_path = simulator_framework_path + framework_basename
164
166
  contain_x8664 = self.contain_x8664?(simulator_framework_exe_path)
165
167
  if contain_x8664
166
- system("lipo #{simulator_framework_exe_path} -thin x86_64 -output #{simulator_framework_exe_path} #{KZGlobalHelper.instance.debug_shell_log_tag}")
168
+ KZLog.run_shell("lipo #{simulator_framework_exe_path} -thin x86_64 -output #{simulator_framework_exe_path}")
167
169
  else
168
170
  FileUtils.rm(simulator_framework_exe_path)
169
171
  end
170
172
 
171
173
  temp_framwork_exe_path = tempdir + "#{framework_basename}_arm64_simulator"
172
174
  if self.is_dynamic_library?(origin_framework_path + framework_basename)
175
+ KZLog.log("'#{origin_framework_path.basename}' 是一个动态库,开始做Load command转换")
176
+
173
177
  xcrun_vtool_show_result = `xcrun vtool -arch arm64 -show #{origin_framework_path + framework_basename}`.lines.map(&:chomp)
174
178
  framework_sdk_version = "16.0"
175
179
  framework_deployment_version = "12.0"
@@ -192,35 +196,51 @@ module KZ
192
196
  end
193
197
  end
194
198
  end
195
- xcrun_vtool_set_result = system("xcrun vtool -arch arm64 -set-build-version 7 #{framework_deployment_version} #{framework_sdk_version} -replace -output #{temp_framwork_exe_path} #{arm64_framework_exe_path}")
199
+ xcrun_vtool_set_result = KZLog.run_shell("xcrun vtool -arch arm64 -set-build-version 7 #{framework_deployment_version} #{framework_sdk_version} -replace -output #{temp_framwork_exe_path} #{arm64_framework_exe_path}")
196
200
  unless xcrun_vtool_set_result
201
+ KZLog.log("'#{origin_framework_path.basename}' Load command转换转换失败", :warning)
197
202
  FileUtils.rm_r(tempdir)
198
203
  return false
199
204
  end
200
205
  else
201
206
  ar_x_path = tempdir + "ar_x"
202
207
  FileUtils.mkdir_p(ar_x_path)
203
- ar_x_success = system("cd #{ar_x_path}; ar x #{arm64_framework_exe_path}")
204
- if ar_x_success
205
- Dir["#{ar_x_path}/*.o"].each do |file|
206
- system(ARM64_TO_SIMULATOR_EXECUTE_PATH, file)
208
+ if self.is_current_ar_archive?(origin_framework_path + framework_basename)
209
+ KZLog.log("'#{origin_framework_path.basename}' 是一个ar archive类型静态库,开始拆分.o并重新构建")
210
+
211
+ ar_x_success = KZLog.run_shell("cd #{ar_x_path}; ar x #{arm64_framework_exe_path}")
212
+ if ar_x_success
213
+ Dir["#{ar_x_path}/*.o"].each do |file|
214
+ status = KZLog.run_shell("#{ARM64_TO_SIMULATOR_EXECUTE_PATH} '#{file}'")
215
+ unless status
216
+ KZLog.log("'#{file}' 存在.o转换失败", :warning)
217
+ FileUtils.rm_r(tempdir)
218
+ return false
219
+ end
220
+ end
221
+ KZLog.run_shell("ar crv #{temp_framwork_exe_path} #{ar_x_path}/*.o")
222
+ else
223
+ KZLog.log("'#{origin_framework_path.basename}' ar拆分失败", :warning)
224
+ FileUtils.rm_r(tempdir)
225
+ return false
207
226
  end
208
- system("ar crv #{temp_framwork_exe_path} #{ar_x_path}/*.o &> /dev/null")
209
227
  else
228
+ KZLog.log("'#{origin_framework_path.basename}' 是一个不支持转换的格式,arm64 simulator转换失败", :warning)
229
+
210
230
  FileUtils.rm_r(tempdir)
211
231
  return false
212
232
  end
213
233
  end
214
234
 
215
235
  if contain_x8664
216
- system("lipo -create #{temp_framwork_exe_path} #{simulator_framework_exe_path} -output #{simulator_framework_exe_path} #{KZGlobalHelper.instance.debug_shell_log_tag}")
236
+ KZLog.run_shell("lipo -create #{temp_framwork_exe_path} #{simulator_framework_exe_path} -output #{simulator_framework_exe_path}")
217
237
  else
218
238
  FileUtils.mv("#{temp_framwork_exe_path}", simulator_framework_exe_path)
219
239
  end
220
240
  FileUtils.mkdir_p(destination_xcframework_path) unless File.exist?(destination_xcframework_path)
221
- system("xcodebuild -create-xcframework -framework $(readlink -f '#{arm64_framework_path}') -framework $(readlink -f '#{simulator_framework_path}') -output #{destination_xcframework_path} #{KZGlobalHelper.instance.debug_shell_log_tag}")
241
+ KZLog.run_shell("xcodebuild -create-xcframework -framework $(readlink -f '#{arm64_framework_path}') -framework $(readlink -f '#{simulator_framework_path}') -output #{destination_xcframework_path}")
222
242
  FileUtils.rm_r(tempdir)
223
-
243
+ KZLog.log("'#{origin_framework_path.basename}'xcframework创建成功", :success)
224
244
  return true
225
245
  end
226
246
 
@@ -229,6 +249,11 @@ module KZ
229
249
  return file_result.include?("dynamically linked shared library")
230
250
  end
231
251
 
252
+ def self.is_current_ar_archive?(file_path)
253
+ file_result = `file -b #{file_path}`
254
+ return file_result.include?("current ar archive")
255
+ end
256
+
232
257
  def self.contain_x8664?(file_path)
233
258
  file_result = `file -b #{file_path}`
234
259
  return file_result.include?("for architecture x86_64")
@@ -11,13 +11,15 @@ module KZ
11
11
  @main_project = main_project
12
12
  end
13
13
 
14
- def add_framework_generator_build_phase(native_target)
14
+ def add_framework_generator_build_phase(native_target, input_paths)
15
15
  return if KZ::KZGlobalHelper.instance.disable_generate_framework
16
16
 
17
17
  build_phase = native_target.new_shell_script_build_phase('[KZ] Generate Framework')
18
18
  build_phase.show_env_vars_in_log = '0'
19
- build_phase.output_paths = ['${KZ_FRAMEWORK_CACHE_PATH}/${PRODUCT_NAME}.xcframework']
20
- build_phase.shell_script = KZ.deal_path_for_xcconfig(KZ_GENERATOR_FRAMEWORK_PATH, true)
19
+ build_phase.shell_path = '/bin/zsh'
20
+ build_phase.input_paths = Array[input_paths]
21
+ build_phase.output_paths = Array['${KZ_FRAMEWORK_CACHE_PATH}/${PRODUCT_NAME}.xcframework']
22
+ build_phase.shell_script = KZ.deal_path_for_xcconfig(KZ_GENERATE_FRAMEWORK_PATH, true)
21
23
  end
22
24
 
23
25
  def add_flexlib_xml_build_rules(project, native_target)
@@ -32,22 +34,26 @@ module KZ
32
34
  xml_rule = new_build_rule(project, native_target, '[KZ] Custom Xml Build')
33
35
  xml_rule.run_once_per_architecture = '0'
34
36
  xml_rule.file_type = 'text.xml'
37
+ xml_rule.input_files = Array['${INPUT_FILE_PATH}']
35
38
  xml_rule.output_files = Array['${KZ_XML_FLEX_DIR}/${INPUT_FILE_BASE}.flex']
36
39
  xml_rule.script = KZ.deal_path_for_xcconfig(KZ_XML_BUILD_PATH, true)
37
40
  end
38
41
 
39
- def add_force_load_exe_path_build_phase(native_target, output_path)
42
+ def add_force_load_exe_path_build_phase(native_target, input_path, output_path)
40
43
  build_phase = native_target.new_shell_script_build_phase('[KZ] Froce Load File Output Path')
41
44
  build_phase.show_env_vars_in_log = '0'
42
- build_phase.output_paths = [output_path]
45
+ build_phase.shell_path = '/bin/zsh'
46
+ build_phase.input_paths = Array[input_path]
47
+ build_phase.output_paths = Array[output_path]
43
48
  build_phase.shell_script = KZ.deal_path_for_xcconfig(KZ_FIX_FORCE_LOAD_EXE, true)
44
49
  end
45
50
 
46
- def add_improve_yaml_build_phase(project, native_target, output_path)
51
+ def add_improve_yaml_build_phase(project, native_target, input_path, output_path)
47
52
  build_phase = new_shell_script_build_phase(project, native_target, '[KZ] Improve Custom Yaml', true)
48
53
  build_phase.show_env_vars_in_log = '0'
49
- # build_phase.always_out_of_date = '1'
50
- build_phase.output_paths = [output_path]
54
+ build_phase.shell_path = '/bin/zsh'
55
+ build_phase.input_paths = Array[input_path]
56
+ build_phase.output_paths = Array[output_path]
51
57
  build_phase.shell_script = KZ.deal_path_for_xcconfig(KZ_IMPROVE_CUSTOM_YAML_PATH, true)
52
58
  end
53
59
 
@@ -141,6 +147,8 @@ module KZ
141
147
 
142
148
  save_hmap_file(all_repair_hmap_info, hmap_cache_path, target_name + '_repair')
143
149
  kz_pod_target.repair_header_search_path = hmap_cache_path + "#{target_name}_repair.hmap"
150
+
151
+ KZLog.log("修复'#{kz_pod_target.name}'头文件导入", :success)
144
152
  end
145
153
 
146
154
  # 添加私有头文件引用
@@ -166,6 +174,8 @@ module KZ
166
174
  end
167
175
  end
168
176
  end
177
+
178
+ KZLog.log("完成所有hmap&yaml配置", :success)
169
179
  end
170
180
 
171
181
  def traverse_folder(folder_path)
@@ -331,7 +341,8 @@ module KZ
331
341
  json_file.syswrite(hmap_json)
332
342
  json_file.close
333
343
 
334
- system "#{HMAP_EXECUTE_PATH} convert #{hmap_json_path} #{hmap_path}"
344
+ KZLog.run_shell("#{HMAP_EXECUTE_PATH} convert #{hmap_json_path} #{hmap_path}")
345
+ KZLog.log("'#{file_name}.hamp'生成失败", :error) unless File.exist?(hmap_path)
335
346
 
336
347
  FileUtils.rm(hmap_json_path) unless KZ::KZGlobalHelper.instance.debug
337
348
  end
@@ -10,11 +10,13 @@ module KZ
10
10
 
11
11
  # 汇总所有配置文件,用于代码中加载资源
12
12
  on_demand_resources_all_config = {}
13
+ # 用于记录tag防止重复
14
+ current_all_tags = {}
13
15
  @all_kz_pod_targets.each do |target_name, kz_pod_target|
14
16
  on_demand_resources_info = kz_pod_target.on_demand_resources_info
15
17
  next if on_demand_resources_info.empty?
16
18
 
17
- analyze_on_demand_resources_config_plist(on_demand_resources_info, kz_pod_target)
19
+ analyze_on_demand_resources_config_plist(on_demand_resources_info, kz_pod_target, current_all_tags)
18
20
  new_on_demand_resources_info = on_demand_resources_info.transform_values do |inner_hash|
19
21
  inner_hash.transform_values do |paths|
20
22
  paths.map { |path| File.basename(path) }
@@ -26,7 +28,11 @@ module KZ
26
28
  # 将汇总的配置写入app中,供代码读取
27
29
  if on_demand_resources_all_config.size > 0
28
30
  write_to_path(on_demand_resources_all_config, kz_on_demand_resources_all_config_path)
31
+ else
32
+ KZLog.log("KZOnDemandResourcesAllConfig.plist内容为空,创建失败", :warning)
29
33
  end
34
+
35
+ KZLog.log("完成所有ODR配置", :success)
30
36
  end
31
37
 
32
38
  def get_all_xcassets(kz_pod_target)
@@ -43,7 +49,7 @@ module KZ
43
49
  all_xcassets_paths
44
50
  end
45
51
 
46
- def analyze_on_demand_resources_config_plist(plist_hash, kz_pod_target)
52
+ def analyze_on_demand_resources_config_plist(plist_hash, kz_pod_target, current_all_tags)
47
53
  resources_path = kz_pod_target.pod_config_cache_path(false, false, true)
48
54
  FileUtils.rm_r(resources_path) if File.exist?(resources_path)
49
55
  FileUtils.mkdir_p(resources_path)
@@ -64,7 +70,7 @@ module KZ
64
70
 
65
71
  # 从配置plist中读取'Initial Install Tags'资源
66
72
  initial_plist_hash = plist_hash["Initial Install Tags"]
67
- on_demand_resources_from_plist(initial_plist_hash, kz_pod_target, 1, resources_path, odr_build_info) do |tag, bundle_id, bundle_path, normal_file_names, have_xcassets_paths|
73
+ on_demand_resources_from_plist(initial_plist_hash, kz_pod_target, 1, resources_path, odr_build_info, current_all_tags) do |tag, bundle_id, bundle_path, normal_file_names, have_xcassets_paths|
68
74
  # 如有配置中有.xcassets资源,需要先标记,等待编译时单独再单独编译
69
75
  if have_xcassets_paths
70
76
  resource_item = {}
@@ -76,11 +82,13 @@ module KZ
76
82
 
77
83
  bundle_resource_request_tags[tag] = { "NSAssetPacks" => [bundle_id] }
78
84
  bundle_resource_request_asset_packs[bundle_id] = normal_file_names if normal_file_names.size > 0
85
+
86
+ KZLog.log("已经完成'#{kz_pod_target.name}'中'#{tag}'ODR配置,资源id为:'#{bundle_id}'")
79
87
  end
80
88
 
81
89
  # Prefetched Tag Order
82
90
  prefetched_plist_hash = plist_hash["Prefetched Tag Order"]
83
- on_demand_resources_from_plist(prefetched_plist_hash, kz_pod_target, 0.5, resources_path, odr_build_info) do |tag, bundle_id, bunlde_path, normal_file_names, have_xcassets_paths|
91
+ on_demand_resources_from_plist(prefetched_plist_hash, kz_pod_target, 0.5, resources_path, odr_build_info, current_all_tags) do |tag, bundle_id, bunlde_path, normal_file_names, have_xcassets_paths|
84
92
  if have_xcassets_paths
85
93
  resource_item = {}
86
94
  resource_item["bundle-id"] = bundle_id
@@ -91,11 +99,13 @@ module KZ
91
99
 
92
100
  bundle_resource_request_tags[tag] = { "NSAssetPacks" => [bundle_id] }
93
101
  bundle_resource_request_asset_packs[bundle_id] = normal_file_names if normal_file_names.size > 0
102
+
103
+ KZLog.log("已经完成'#{kz_pod_target.name}'中'#{tag}'ODR配置,资源id为:'#{bundle_id}'")
94
104
  end
95
105
 
96
106
  # Download Only On Demand
97
107
  download_plist_hash = plist_hash["Download Only On Demand"]
98
- on_demand_resources_from_plist(download_plist_hash, kz_pod_target, 0, resources_path, odr_build_info) do |tag, bundle_id, bunlde_path, normal_file_names, have_xcassets_paths|
108
+ on_demand_resources_from_plist(download_plist_hash, kz_pod_target, 0, resources_path, odr_build_info, current_all_tags) do |tag, bundle_id, bunlde_path, normal_file_names, have_xcassets_paths|
99
109
  if have_xcassets_paths
100
110
  resource_item = {}
101
111
  resource_item["bundle-id"] = bundle_id
@@ -106,6 +116,8 @@ module KZ
106
116
 
107
117
  bundle_resource_request_tags[tag] = { "NSAssetPacks" => [bundle_id] }
108
118
  bundle_resource_request_asset_packs[bundle_id] = normal_file_names if normal_file_names.size > 0
119
+
120
+ KZLog.log("已经完成'#{kz_pod_target.name}'中'#{tag}'ODR配置,资源id为:'#{bundle_id}'")
109
121
  end
110
122
 
111
123
  if asset_pack_output_specifications_resources.size > 0
@@ -122,11 +134,18 @@ module KZ
122
134
  end
123
135
  end
124
136
 
125
- def on_demand_resources_from_plist(plist_hash, kz_pod_target, priority, resources_path, odr_build_info)
137
+ def on_demand_resources_from_plist(plist_hash, kz_pod_target, priority, resources_path, odr_build_info, current_all_tags)
126
138
  return unless (!plist_hash.nil? && plist_hash.size > 0)
127
139
 
128
140
  all_normal_file_names = []
129
141
  plist_hash.each do |tag, file_paths|
142
+ if current_all_tags.key?(tag)
143
+ KZLog.log("#{kz_pod_target.name}与#{current_all_tags[tag]}中存在相同tag:#{tag},#{kz_pod_target.name}中的tag将被废弃", :warning)
144
+ next
145
+ else
146
+ current_all_tags[tag] = kz_pod_target.name
147
+ end
148
+
130
149
  normal_file_names = []
131
150
  normal_file_paths = []
132
151
 
@@ -141,9 +160,15 @@ module KZ
141
160
  on_demand_resources_xcassets(kz_pod_target, odr_build_info, xcassets_path) do |tag_info|
142
161
  tag_info[file_path.relative_path_from(xcassets_path)] = tag
143
162
  end
163
+ else
164
+ KZLog.log("资源'#{file_path}'不在xcassets文件夹中,将作为普通文件做ODR配置", :warning)
144
165
  end
145
166
  else
146
167
  # 普通文件配置
168
+ if File.directory?(file_path) && file_path.extname != "bundle"
169
+ KZLog.log("资源'#{file_path}'是一个非bundle的文件夹,将被废弃", :warning)
170
+ next
171
+ end
147
172
  normal_file_paths << file_path
148
173
  normal_file_names << file_path.basename
149
174
  all_normal_file_names << file_path.basename
@@ -201,7 +226,11 @@ module KZ
201
226
  FileUtils.mkdir_p(demand_bundle_folder) unless FileTest::exist?(demand_bundle_folder)
202
227
  # copy file
203
228
  normal_file_paths.each do |file|
204
- FileUtils.cp(file, demand_bundle_folder)
229
+ if File.directory?(file)
230
+ FileUtils.cp_r(file, demand_bundle_folder)
231
+ else
232
+ FileUtils.cp(file, demand_bundle_folder)
233
+ end
205
234
  end
206
235
 
207
236
  bundle_info_plist = {}
@@ -11,13 +11,13 @@ module KZ
11
11
  attr_accessor :enable
12
12
  attr_accessor :config_plist_path_patterns
13
13
  attr_accessor :bundle_id
14
- attr_accessor :odr_target_name
14
+ attr_accessor :odr_target_names
15
15
 
16
16
  def initialize
17
17
  @enable = false
18
18
  @config_plist_path_patterns = {}
19
19
  @bundle_id = ""
20
- @odr_target_name = ""
20
+ @odr_target_names = []
21
21
  end
22
22
 
23
23
  end
@@ -34,7 +34,8 @@ module KZ
34
34
  HMAP_EXECUTE_PATH = File.dirname(__FILE__) + '/../resources/hmap'
35
35
  FLEX_COMPLIER_PATH = KZ_POD_CONFIG_SUPPORT_FILES + 'FlexCompiler'
36
36
  ARM64_TO_SIMULATOR_EXECUTE_PATH = File.dirname(__FILE__) + '/../resources/arm64ToSimulator'
37
- KZ_GENERATOR_FRAMEWORK_PATH = KZ_POD_CONFIG_SUPPORT_FILES + 'kz_generator_framework.sh'
37
+ KZ_GENERATE_FRAMEWORK_PATH = KZ_POD_CONFIG_SUPPORT_FILES + 'kz_generate_framework.sh'
38
+ KZ_GENERATE_XCODE_ENV_PATH = File.dirname(__FILE__) + '/../resources/kz_generate_xcode_env.sh'
38
39
  KZ_XML_BUILD_PATH = KZ_POD_CONFIG_SUPPORT_FILES + 'kz_xml_build.sh'
39
40
  KZ_LOCK_FILE_PATH = KZ_POD_CONFIG_ROOT + 'KZConfigLock'
40
41
  KZ_FIX_FORCE_LOAD_EXE = KZ_POD_CONFIG_SUPPORT_FILES + 'kz_fix_force_load_exe.sh'
@@ -68,7 +69,6 @@ module KZ
68
69
  attr_accessor :kz_config_lock
69
70
  attr_accessor :disable_generate_framework
70
71
  attr_accessor :generate_kz_pod_targets
71
- attr_accessor :debug_shell_log_tag
72
72
  attr_accessor :arm64_simulator
73
73
  attr_accessor :on_demand_resources_info
74
74
 
@@ -83,7 +83,6 @@ module KZ
83
83
  @disable_generate_framework = false
84
84
  @generate_kz_pod_targets = false
85
85
  @olde_lock_file_content = nil
86
- @debug_shell_log_tag = "&> /dev/null"
87
86
  @arm64_simulator = false
88
87
  @on_demand_resources_info = KZOnDemandResourcesInfo.new
89
88
  end
@@ -103,6 +102,9 @@ module KZ
103
102
 
104
103
  def prepare
105
104
  if Pod::Config.instance.podfile && Pod::Config.instance.podfile.plugins.has_key?("cocoapods-kz")
105
+ @kz_pod_enable = true
106
+ @generate_kz_pod_targets = true
107
+
106
108
  if olde_lock_file_content == nil || olde_lock_file_content['version'] != KZ_POD_CONFIG_VERSION
107
109
  FileUtils.rm_rf(KZ_POD_CONFIG_ROOT)
108
110
  FileUtils.mkdir_p(KZ_POD_CONFIG_ROOT)
@@ -112,8 +114,8 @@ module KZ
112
114
  FileUtils.rm_rf(KZ_POD_CONFIG_POD_TEMPDIR) if File.exist?(KZ_POD_CONFIG_POD_TEMPDIR)
113
115
  FileUtils.mkdir_p(KZ_POD_CONFIG_POD_TEMPDIR)
114
116
 
115
- FileUtils.cp_r(File.dirname(__FILE__) + '/../resources/kz_generator_framework.sh', KZ_GENERATOR_FRAMEWORK_PATH)
116
- system("chmod +x #{KZ_GENERATOR_FRAMEWORK_PATH}")
117
+ FileUtils.cp_r(File.dirname(__FILE__) + '/../resources/kz_generate_framework.sh', KZ_GENERATE_FRAMEWORK_PATH)
118
+ system("chmod +x #{KZ_GENERATE_FRAMEWORK_PATH}")
117
119
 
118
120
  FileUtils.cp_r(File.dirname(__FILE__) + '/../resources/kz_xml_build.sh', KZ_XML_BUILD_PATH)
119
121
  system("chmod +x #{KZ_XML_BUILD_PATH}")
@@ -133,6 +135,7 @@ module KZ
133
135
  FileUtils.cp_r(File.dirname(__FILE__) + '/../resources/on_demand_resources/', KZ_ON_DEMAND_RESOURCES)
134
136
  system("chmod +x #{KZ_ON_DEMAND_RESOURCES_SHELL}")
135
137
  end
138
+ KZLog.log("cocoapods-kz已启用,已完成环境配置", :success)
136
139
  else
137
140
  @kz_pod_enable = false
138
141
  @generate_kz_pod_targets = false
@@ -144,11 +147,14 @@ module KZ
144
147
  FileUtils.rm(FLEX_COMPLIER_PATH) if File.exist?(FLEX_COMPLIER_PATH)
145
148
  if flexlib_info.have_flexLib_pod
146
149
  if flexlib_info.flexLib_version.major >= 4
150
+ KZLog.log("当前使用Flexlib使用4.0及以上版本,xml解析器使用新版", :info)
147
151
  FileUtils.cp_r(File.dirname(__FILE__) + '/../resources/FlexCompiler_V1', FLEX_COMPLIER_PATH)
148
152
  else
153
+ KZLog.log("当前使用Flexlib使用4.0以下版本,xml解析器使用旧版", :info)
149
154
  FileUtils.cp_r(File.dirname(__FILE__) + '/../resources/FlexCompiler', FLEX_COMPLIER_PATH)
150
155
  end
151
156
  elsif flexlib_info.have_kzswiftui_pod
157
+ KZLog.log("当前使用KZSwiftUI,xml解析器使用新版", :info)
152
158
  FileUtils.cp_r(File.dirname(__FILE__) + '/../resources/FlexCompiler_V1', FLEX_COMPLIER_PATH)
153
159
  end
154
160
  system("chmod +x #{FLEX_COMPLIER_PATH}") if File.exist?(FLEX_COMPLIER_PATH)
@@ -213,6 +219,7 @@ module KZ
213
219
  File.open(KZ_LOCK_FILE_PATH, 'w') do |file|
214
220
  file.write(lock_file_content)
215
221
  end
222
+ KZLog.log("Lock File文件保存成功", :success)
216
223
  end
217
224
  end
218
225
 
@@ -1,11 +1,31 @@
1
+ require 'open3'
2
+
1
3
  module KZ
2
4
 
3
5
  class KZLog
4
- def self.log(logStr)
5
- if KZGlobalHelper.instance.debug
6
- puts logStr
6
+ @log_types = {
7
+ error: "\e[31m",
8
+ success: "\e[32m",
9
+ warning: "\e[33m",
10
+ info: "\e[34m",
11
+ reset: "\e[0m",
12
+ normal: ""
13
+ }
14
+
15
+ def self.log(log_string, type = :normal)
16
+ if KZGlobalHelper.instance.debug || type == :error || type == :warning
17
+ puts "\e[36m【Cocoapods-kz】\e[0m#{@log_types[type]}【#{type}】#{@log_types[:reset]}#{log_string}"
7
18
  end
8
19
  end
20
+
21
+ def self.run_shell(cmd)
22
+ stdout, stderr, status = Open3.capture3(cmd)
23
+
24
+ self.log(stdout) unless stdout.empty?
25
+ self.log(stderr, :error) unless stderr.empty?
26
+
27
+ return status.success?
28
+ end
9
29
  end
10
30
  end
11
31
 
@@ -114,19 +114,6 @@ module KZ
114
114
  end
115
115
  end
116
116
 
117
- # 重些config_pod_mode的set方法,kz_pod_framework_mode优先级最高
118
- def config_pod_mode=(value)
119
- return if value == :kz_pod_origin_mode
120
-
121
- if @config_pod_mode != :kz_pod_framework_mode
122
- @config_pod_mode = value
123
- end
124
-
125
- @dependent_target_info.values.each do |dependent_target|
126
- dependent_target.config_pod_mode=(value) unless dependent_target.is_dev_pod
127
- end
128
- end
129
-
130
117
  # 重些config_pod_mode的get方法,force_config_pod_mode优先级最高
131
118
  def config_pod_mode
132
119
  return @force_config_pod_mode if @force_config_pod_mode != :kz_pod_origin_mode
@@ -213,7 +200,7 @@ module KZ
213
200
  if @use_local_private_headers_path
214
201
  header_search_paths += (' ' + KZ.deal_path_for_xcconfig(local_private_headers_path, true))
215
202
  end
216
- header_search_paths += (' ' + KZ.deal_path_for_xcconfig(self.native_pod_target.sandbox.public_headers.root, true))
203
+ header_search_paths += (' ' + KZ.deal_path_for_xcconfig("${PODS_ROOT}/Headers/Public", true))
217
204
  custom_paths.each do |custom_path|
218
205
  header_search_paths += (' ' + custom_path)
219
206
  end if custom_paths
@@ -359,7 +346,13 @@ module KZ
359
346
 
360
347
  on_demand_resources_info = {}
361
348
  result.each do |config_plist_path|
362
- plist_hash = Xcodeproj::Plist.read_from_path(config_plist_path)
349
+ begin
350
+ plist_hash = Xcodeproj::Plist.read_from_path(config_plist_path)
351
+ rescue => e
352
+ KZLog.log("'#{@name}'中ODR配置文件:'#{config_plist_path}'格式不正确,请参考文档使用正确的plist文件", :error)
353
+ next
354
+ end
355
+
363
356
  initial_plist_hash = plist_hash[Initial_Install_Tags]
364
357
  traversal_resource_for_tag(initial_plist_hash, path_list) do |tag_resources|
365
358
  on_demand_resources_info[Initial_Install_Tags] = tag_resources
@@ -388,6 +381,8 @@ module KZ
388
381
  valid_path = path_list.relative_path_in_snadbox?(resource_path)
389
382
  unless valid_path.nil?
390
383
  valid_paths.append(valid_path)
384
+ else
385
+ KZLog.log("'#{@name}'中ODR资源路径:'#{resource_path}'不存在,请示使用相对podspec文件的相对路径", :warning)
391
386
  end
392
387
  end
393
388
  if valid_paths.size > 0
@@ -6,9 +6,15 @@ module KZ
6
6
  @main_project = main_project
7
7
  @all_kz_pod_targets = KZ::KZGlobalHelper.instance.kz_analyzer.all_kz_pod_targets
8
8
  @specify_pod_names = KZ::KZGlobalHelper.instance.specify_pod_names
9
+ @header_white_list = %w[ifaddrs.h netdb.h resolv.h math.h Availability.h fcntl.h netdb.h unistd.h TargetConditionals.h]
9
10
  end
10
11
 
11
12
  def repair
13
+ if @all_kz_pod_targets.empty?
14
+ KZLog.log("项目pod分析失败,请检测配置后重试", :error)
15
+ return
16
+ end
17
+
12
18
  if @specify_pod_names.count == 0 || @specify_pod_names.include?("Main")
13
19
  main_project_file_folder = @main_project.project_dir + @main_project.root_object.display_name
14
20
  main_project_files = []
@@ -23,7 +29,7 @@ module KZ
23
29
  end
24
30
  end
25
31
  end
26
- puts "Start reair main project..."
32
+ KZLog.log("Start reair main project...", :info)
27
33
  main_project_files.each do |file_path|
28
34
  repair_file(file_path, main_project_headers)
29
35
  end
@@ -44,7 +50,7 @@ module KZ
44
50
  end
45
51
  end
46
52
 
47
- puts "Start reair '#{kz_pod_target.name}' files..."
53
+ KZLog.log("Start reair '#{kz_pod_target.name}' files...", :info)
48
54
  need_repair_files.each do |file_path|
49
55
  repair_file(file_path, kz_pod_target.all_headers, kz_pod_target.recursive_dependent_targets)
50
56
  end
@@ -58,8 +64,9 @@ module KZ
58
64
  contents = file.readlines
59
65
  file.close
60
66
 
67
+ previous_line = ""
61
68
  contents.each do |line|
62
- if line =~ /#import\s*["<]([a-zA-Z\+]+\.h)[">]/
69
+ if !line.start_with?("//") && line =~ /#import\s*["<]([a-zA-Z\+]+\.h)[">]/
63
70
  heaer_name = $1
64
71
  other_module_name = find_other_module_name(heaer_name, current_module_headers, sub_pods)
65
72
  if other_module_name
@@ -69,12 +76,15 @@ module KZ
69
76
  new_header_content << "#import <#{other_module_name}/#{heaer_name}>\n"
70
77
  end
71
78
  else
72
- new_header_content << "#warning '#{heaer_name}' is not included in the current pod or its subpods\n"
79
+ unless previous_line.end_with?("is not included in the current pod or its subpods\n") || @header_white_list.include?(heaer_name)
80
+ new_header_content << "#warning '#{heaer_name}' is not included in the current pod or its subpods\n"
81
+ end
73
82
  new_header_content << line
74
83
  end
75
84
  else
76
85
  new_header_content << line
77
86
  end
87
+ previous_line = line
78
88
  end
79
89
  write_swift_file(file_path, new_header_content)
80
90
  end
@@ -46,7 +46,7 @@ module Pod
46
46
  "target `#{name}`."
47
47
  end
48
48
  KZ::KZGlobalHelper.instance.on_demand_resources_info.enable = true
49
- KZ::KZGlobalHelper.instance.on_demand_resources_info.odr_target_name = name
49
+ KZ::KZGlobalHelper.instance.on_demand_resources_info.odr_target_names.append(name)
50
50
 
51
51
  parent = current_target_definition
52
52
  definition = TargetDefinition.new(name, parent)
@@ -11,17 +11,28 @@ module Pod
11
11
 
12
12
  # 因为kz_pod_target提供不少方法,需要判断pod文件情况,所以依赖分析需要挪到download之后
13
13
  if KZ::KZGlobalHelper.instance.generate_kz_pod_targets
14
+ kz_analyer = KZ::KZAnalyzer.new(pod_targets, self.sandbox.development_pods)
15
+ kz_analyer.analyer
16
+ KZ::KZGlobalHelper.instance.kz_analyzer = kz_analyer
17
+ end
18
+
19
+ if KZ::KZGlobalHelper.instance.kz_pod_enable
14
20
  main_project = aggregate_targets.first.user_project
15
21
  main_project.targets.each do |main_target|
16
- if main_target.display_name == KZ::KZGlobalHelper.instance.on_demand_resources_info.odr_target_name
22
+ if KZ::KZGlobalHelper.instance.on_demand_resources_info.odr_target_names.include?(main_target.display_name)
17
23
  bundle_id = main_target.build_configurations.first.kz_simple_attributes_buildSettings_hash["PRODUCT_BUNDLE_IDENTIFIER"]
18
- KZ::KZGlobalHelper.instance.on_demand_resources_info.bundle_id = bundle_id unless bundle_id.nil?
24
+ unless bundle_id.nil?
25
+ if !KZ::KZGlobalHelper.instance.on_demand_resources_info.bundle_id.empty? && KZ::KZGlobalHelper.instance.on_demand_resources_info.bundle_id != bundle_id
26
+ KZ::KZLog.log("'#{main_target.display_name}'的bundleId:'#{bundle_id}'与其他odr target不同,ODR配置失败", :error)
27
+ exit
28
+ end
29
+ KZ::KZGlobalHelper.instance.on_demand_resources_info.bundle_id = bundle_id
30
+ KZ::KZLog.log("'#{main_target.display_name}'开启ODR,bundleId为: '#{bundle_id}'", :success)
31
+ else
32
+ KZ::KZLog.log("'#{main_target.display_name}'开启ODR失败,bundleId为空", :warning)
33
+ end
19
34
  end
20
35
  end
21
-
22
- kz_analyer = KZ::KZAnalyzer.new(pod_targets, self.sandbox.development_pods)
23
- kz_analyer.analyer
24
- KZ::KZGlobalHelper.instance.kz_analyzer = kz_analyer
25
36
  KZ::KZGlobalHelper.instance.kz_generator = KZ::KZGenerator.new(main_project)
26
37
  KZ::KZGlobalHelper.instance.handle_flexCompiler
27
38
  end
@@ -48,9 +59,11 @@ module Pod
48
59
  if KZ::KZGlobalHelper.instance.kz_pod_enable
49
60
  KZ::KZGlobalHelper.instance.write_lock_file
50
61
 
62
+ KZ::KZLog.run_shell("sh '#{KZ::KZ_GENERATE_XCODE_ENV_PATH}' #{KZ::KZ_POD_CONFIG_ROOT + ".xcode_env.sh"}")
63
+
51
64
  current_pods_pbxproj_path = self.pods_project.path + 'project.pbxproj'
52
65
  temp_pods_pbxproj_path = KZ::KZ_POD_CONFIG_POD_TEMPDIR + 'project.pbxproj'
53
- system("(sleep 1 && ruby '#{KZ::KZ_FEFRESH_PODS_PBXPROJ}' '#{current_pods_pbxproj_path}' '#{temp_pods_pbxproj_path}') &")
66
+ KZ::KZLog.run_shell("(sleep 1 && ruby '#{KZ::KZ_FEFRESH_PODS_PBXPROJ}' '#{current_pods_pbxproj_path}' '#{temp_pods_pbxproj_path}') &")
54
67
  end
55
68
  end
56
69
  end
@@ -15,7 +15,8 @@ module Pod
15
15
 
16
16
  if self.target.should_build?
17
17
  unless self.target.name.start_with?('Pods-')
18
- KZ::KZGlobalHelper.instance.kz_generator.add_framework_generator_build_phase(target_installation_result.native_target)
18
+ input_path = "${PODS_CONFIGURATION_BUILD_DIR}/${TARGET_NAME}/${FULL_PRODUCT_NAME}/#{kz_pod_target.product_basename}"
19
+ KZ::KZGlobalHelper.instance.kz_generator.add_framework_generator_build_phase(target_installation_result.native_target, input_path)
19
20
  end
20
21
 
21
22
  if kz_pod_target&.is_dev_pod
@@ -25,17 +26,22 @@ module Pod
25
26
 
26
27
  if kz_pod_target&.origin_should_build?
27
28
  if kz_pod_target.force_load
28
- KZ::KZGlobalHelper.instance.kz_generator.add_force_load_exe_path_build_phase(target_installation_result.native_target, kz_pod_target.force_load_info)
29
+ input_path = "${PODS_CONFIGURATION_BUILD_DIR}/${TARGET_NAME}/${FULL_PRODUCT_NAME}/#{kz_pod_target.product_basename}"
30
+ output_path = kz_pod_target.force_load_info
31
+ KZ::KZGlobalHelper.instance.kz_generator.add_force_load_exe_path_build_phase(target_installation_result.native_target, input_path, output_path)
29
32
  end
30
33
 
31
34
  unless kz_pod_target.custom_origin_yaml_path.nil?
32
- KZ::KZGlobalHelper.instance.kz_generator.add_improve_yaml_build_phase(self.project, target_installation_result.native_target, kz_pod_target.custom_yaml_path)
35
+ input_path = KZ.deal_path_for_xcconfig(kz_pod_target.custom_origin_yaml_path)
36
+ output_path = KZ.deal_path_for_xcconfig(kz_pod_target.custom_yaml_path)
37
+ KZ::KZGlobalHelper.instance.kz_generator.add_improve_yaml_build_phase(self.project, target_installation_result.native_target, input_path, output_path)
33
38
  end
34
39
  end
35
40
 
36
41
  if kz_pod_target && !kz_pod_target.use_modulemap
37
42
  target_installation_result.native_target.build_configurations.each do |c|
38
43
  c.build_settings['DEFINES_MODULE'] = 'NO'
44
+ KZ::KZLog.log("'#{kz_pod_target.name}' [#{c.name}] 已经配置为不使用modulemap", :info)
39
45
  end
40
46
  end
41
47
  end
@@ -52,11 +52,12 @@ module Pod
52
52
  kz_add_swift_lldb_ast_paths(xcconfig, swift_lldb_ast_paths)
53
53
  xcconfig.attributes['HEADER_SEARCH_PATHS'] = main_hamp_search_path
54
54
  xcconfig.attributes['USE_HEADERMAP'] = 'NO'
55
+ xcconfig.attributes["KZ_POD_CONFIG_ROOT"] = KZ::KZ_POD_CONFIG_ROOT_STR
55
56
  if KZ::KZGlobalHelper.instance.arm64_simulator
56
57
  xcconfig.attributes.delete("EXCLUDED_ARCHS[sdk=iphonesimulator*]")
57
58
  xcconfig.attributes['VALID_ARCHS'] = 'arm64 arm64_32 x86_64'
58
59
  end
59
- if KZ::KZGlobalHelper.instance.on_demand_resources_info.odr_target_name == self.target.name.sub('Pods-', '')
60
+ if KZ::KZGlobalHelper.instance.on_demand_resources_info.odr_target_names.include?(self.target.name.sub('Pods-', ''))
60
61
  xcconfig.attributes["ENABLE_ON_DEMAND_RESOURCES"] = "NO"
61
62
 
62
63
  on_demadn_resources_paths = ""
@@ -64,7 +65,6 @@ module Pod
64
65
  on_demadn_resources_paths += ((on_demadn_resources_paths.empty? ? '' : ' ') + '"' + path + '"')
65
66
  end
66
67
  xcconfig.attributes["KZ_ON_DEMAND_RESOURCES_PATHS"] = on_demadn_resources_paths unless on_demadn_resources_paths.empty?
67
- xcconfig.attributes["KZ_POD_CONFIG_ROOT"] = KZ::KZ_POD_CONFIG_ROOT_STR
68
68
  end
69
69
 
70
70
  kz_update_xcconfig_file(xcconfig, path)
@@ -73,11 +73,24 @@ module Pod
73
73
  elsif generator.is_a?(Pod::Target::BuildSettings::PodTargetSettings)
74
74
  kz_pod_target = self.target.weakRef_kz_pod_target
75
75
  if kz_pod_target
76
+ xcconfig = generator.xcconfig
77
+
78
+ custom_paths = []
79
+ origin_header_search_paths = xcconfig.attributes['HEADER_SEARCH_PATHS'].split(" ")
80
+ unless origin_header_search_paths.nil? || origin_header_search_paths.empty?
81
+ origin_header_search_paths.each do |origin_search_paht|
82
+ if origin_search_paht.include?("PODS_XCFRAMEWORKS_BUILD_DIR")
83
+ custom_paths.append(origin_search_paht)
84
+ end
85
+ end
86
+ end
87
+
76
88
  pod_custom_header_search_paths = generator.pod_target_xcconfig_values_by_consumer_by_key["HEADER_SEARCH_PATHS"]
77
- pod_custom_header_search_paths = pod_custom_header_search_paths.values if pod_custom_header_search_paths
89
+ unless pod_custom_header_search_paths.nil? || pod_custom_header_search_paths.values.empty?
90
+ custom_paths.concat(pod_custom_header_search_paths.values)
91
+ end
78
92
 
79
- xcconfig = generator.xcconfig
80
- xcconfig.attributes['HEADER_SEARCH_PATHS'] = kz_pod_target.header_search_paths(pod_custom_header_search_paths)
93
+ xcconfig.attributes['HEADER_SEARCH_PATHS'] = kz_pod_target.header_search_paths(custom_paths)
81
94
  xcconfig.attributes['USE_HEADERMAP'] = 'NO'
82
95
  framework_cache_path = KZ.deal_path_for_xcconfig(kz_pod_target.pod_config_cache_path(true))
83
96
  xcconfig.attributes['KZ_FRAMEWORK_CACHE_PATH'] = framework_cache_path
@@ -90,8 +103,8 @@ module Pod
90
103
  end
91
104
 
92
105
  unless kz_pod_target.custom_origin_yaml_path.nil?
93
- xcconfig.attributes['KZ_CUSTOM_ORIGIN_YAML_PATH'] = kz_pod_target.custom_origin_yaml_path
94
- xcconfig.attributes['KZ_CUSTOM_YAML_PATH'] = kz_pod_target.custom_yaml_path
106
+ xcconfig.attributes['KZ_CUSTOM_ORIGIN_YAML_PATH'] = KZ.deal_path_for_xcconfig(kz_pod_target.custom_origin_yaml_path)
107
+ xcconfig.attributes['KZ_CUSTOM_YAML_PATH'] = KZ.deal_path_for_xcconfig(kz_pod_target.custom_yaml_path)
95
108
 
96
109
  other_cflags = xcconfig.attributes['OTHER_CFLAGS']
97
110
  if other_cflags == nil
@@ -14,9 +14,13 @@ module Pod
14
14
  phase_name = "[KZ] On Demand Resources Build"
15
15
  native_targets.each do |native_target|
16
16
  phase = TargetIntegrator.create_or_update_shell_script_build_phase(native_target, phase_name)
17
- if native_target.name == KZ::KZGlobalHelper.instance.on_demand_resources_info.odr_target_name
17
+ if KZ::KZGlobalHelper.instance.on_demand_resources_info.odr_target_names.include?(native_target.name)
18
18
  native_target.build_phases.push(phase).uniq! unless native_target.build_phases.include?(phase)
19
- phase.shell_script = KZ.deal_path_for_xcconfig(KZ::KZ_ON_DEMAND_RESOURCES_SHELL, true)
19
+ # Xcode会默认给脚本内容增加换行,为了避免频繁的git变动,这里主动加上\n
20
+ phase.shell_script = "#{KZ.deal_path_for_xcconfig(KZ::KZ_ON_DEMAND_RESOURCES_SHELL, true)}\n"
21
+ phase.shell_path = '/bin/zsh'
22
+ phase.input_paths = Array["#{KZ::KZ_POD_CONFIG_ROOT_STR}/KZOnDemandResourcesAllConfig.plist"]
23
+ phase.output_paths = Array['${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/KZOnDemandResourcesAllConfig.plist']
20
24
  else
21
25
  native_target.build_phases.delete(phase) if native_target.build_phases.include?(phase)
22
26
  end
Binary file
@@ -1,3 +1,5 @@
1
+ #!/bin/zsh
2
+
1
3
  if [ "${MACH_O_TYPE}" != "staticlib" ]; then
2
4
  exit 0
3
5
  fi
@@ -0,0 +1,21 @@
1
+ #!/bin/zsh
2
+
3
+ OUTPUT_FILE=$1
4
+ VARS=(
5
+ PATH
6
+ GEM_HOME
7
+ GEM_PATH
8
+ RUBYLIB
9
+ RUBYOPT
10
+ LANG
11
+ LC_ALL
12
+ )
13
+ for var in "${VARS[@]}"; do
14
+ val="${!var}"
15
+ if [ -n "$val" ]; then
16
+ # 使用 printf 安全转义引号
17
+ printf "export %s=\"%s\"\n" "$var" "$val" >> "$OUTPUT_FILE"
18
+ fi
19
+ done
20
+
21
+ echo "" >> "$OUTPUT_FILE"
@@ -1,4 +1,5 @@
1
- #!/bin/sh
1
+ #!/bin/zsh
2
+
2
3
  set -e
3
4
  set -u
4
5
  set -o pipefail
@@ -22,9 +22,6 @@ end
22
22
  kz_on_demand_resources_paths = ENV["KZ_ON_DEMAND_RESOURCES_PATHS"]
23
23
  target_build_dir = Pathname(ENV["TARGET_BUILD_DIR"])
24
24
  target_build_temp_dir = Pathname(ENV["TARGET_TEMP_DIR"])
25
- if ENV["ACTION"] == "install" && ENV["SKIP_INSTALL"] == "NO"
26
- target_build_dir = Pathname(ENV["INSTALL_DIR"])
27
- end
28
25
  app_path = target_build_dir + ENV["UNLOCALIZED_RESOURCES_FOLDER_PATH"]
29
26
 
30
27
  # pod过程解析的odr内容路径,放在环境参数KZ_ON_DEMAND_RESOURCES_PATHS中,
@@ -41,6 +38,7 @@ FileUtils.mkdir_p(target_build_on_demand_resources_path) unless File.exist?(targ
41
38
  kz_on_demand_resources_all_config_plist_path = Pathname(ENV["KZ_POD_CONFIG_ROOT"]) + "KZOnDemandResourcesAllConfig.plist"
42
39
  return unless File.exist?(kz_on_demand_resources_all_config_plist_path)
43
40
  FileUtils.cp(kz_on_demand_resources_all_config_plist_path, app_path)
41
+ puts "【KZ-ODR】KZOnDemandResourcesAllConfig.plist生成成功"
44
42
 
45
43
  # 用于在最终.app中生成所有odr信息的plist文件,固定名称为OnDemandResources.plist,系统会自动识别
46
44
  app_on_demand_resources_plist = {}
@@ -51,11 +49,16 @@ app_on_demand_resources_plist["NSBundleResourceRequestAssetPacks"] = bundle_reso
51
49
 
52
50
  # 遍历所有组件的odr信息,然后将需要的资源进行拷贝
53
51
  kz_on_demand_resources_info.each do |pod_name, kz_on_demand_resources_path|
52
+ puts "\n"
54
53
  kz_on_demand_resources_path = Pathname(kz_on_demand_resources_path)
55
54
  odr_build_info_plist_paht = kz_on_demand_resources_path + "odr_build_info.plist"
56
- next unless File.exist?(odr_build_info_plist_paht)
55
+ unless File.exist?(odr_build_info_plist_paht)
56
+ puts "【KZ-ODR】'#{pod_name}' odr_build_info.plist文件不存在\n"
57
+ next
58
+ end
57
59
 
58
60
  odr_build_info = Xcodeproj::Plist.read_from_path(odr_build_info_plist_paht)
61
+ puts "【KZ-ODR】开始配置'#{pod_name}'资源"
59
62
 
60
63
  # 获取对应组件的bundle,如果没有需要创建,这里的bundle名称会与target名称相同
61
64
  pod_bundle_path = Pathname(app_path) + "#{pod_name}.bundle"
@@ -64,10 +67,13 @@ kz_on_demand_resources_info.each do |pod_name, kz_on_demand_resources_path|
64
67
  # 将预处理的OnDemandResources拷贝到Product的OnDemandResources中
65
68
  on_demand_resources_build_path = kz_on_demand_resources_path + "OnDemandResources"
66
69
  FileUtils.cp_r("#{on_demand_resources_build_path}/.", target_build_on_demand_resources_path)
70
+ puts "【KZ-ODR】完成所有'#{pod_name}'预备资源拷贝"
67
71
 
68
72
  # 将组件自己的OnDemandResources.plist拷贝到组件bundle中,这里bundle其实也是一种app,也需要OnDemandResources.plist,用于系统识别odr资源
69
73
  bundle_on_demand_resources_plist_path = kz_on_demand_resources_path + "OnDemandResources.plist"
70
74
  FileUtils.cp(bundle_on_demand_resources_plist_path, pod_bundle_path + "OnDemandResources.plist")
75
+ puts "【KZ-ODR】完成'#{pod_name}' OnDemandResources.plist拷贝"
76
+
71
77
  # 读取组件的OnDemandResources.plist中的tag信息,用于最终.app中生成的OnDemandResources.plist
72
78
  bundle_on_demand_resources_plist = Xcodeproj::Plist.read_from_path(bundle_on_demand_resources_plist_path)
73
79
  bundle_resource_request_tags.update(bundle_on_demand_resources_plist["NSBundleResourceRequestTags"])
@@ -84,6 +90,7 @@ kz_on_demand_resources_info.each do |pod_name, kz_on_demand_resources_path|
84
90
  # 将pod install过程生成的AssetPackOutputSpecifications拷贝到编译临时目录,并修改AssetPackOutputSpecifications.plist中的路径
85
91
  kz_asset_pack_output_specifications_plist_path = kz_on_demand_resources_path + "AssetPackOutputSpecifications.plist"
86
92
  next unless File.exist?(kz_asset_pack_output_specifications_plist_path)
93
+
87
94
  # 在Xcode编译过程中,会在build目录下生成一个临时目录,用于存放AssetPackOutputSpecifications.plist(该文件在pod install过程中生成了模版,拷贝到这里会进行修改后才能使用)
88
95
  build_on_demand_resources_temp_path = target_build_temp_dir + pod_name + "KZOnDemandResources"
89
96
  FileUtils.mkdir_p(build_on_demand_resources_temp_path) unless File.exist?(build_on_demand_resources_temp_path)
@@ -99,6 +106,7 @@ kz_on_demand_resources_info.each do |pod_name, kz_on_demand_resources_path|
99
106
  end
100
107
  end
101
108
  write_to_path(asset_pack_output_specifications_plist, asset_pack_output_specifications_plist_path)
109
+ puts "【KZ-ODR】'#{pod_name}' AssetPackOutputSpecifications.plist中资源路径更新成功"
102
110
 
103
111
  # 处理xcasset资源编译,从odr_info中读取原始xcasset资源,为了不破坏原有资源,这里将原始资源拷贝到临时目录,并修改对应的odr信息,然后使用actool进行编译
104
112
  all_xcassets = odr_build_info["all_xcassets"]
@@ -141,15 +149,22 @@ kz_on_demand_resources_info.each do |pod_name, kz_on_demand_resources_path|
141
149
  "--compile", pod_bundle_path.to_s,
142
150
  *xcasset_files.map(&:to_s)
143
151
  ].compact
144
- system(*actool_cmd)
152
+ status = system(*actool_cmd)
153
+ if status
154
+ puts "【KZ-ODR】'#{pod_name}' xcasset资源编译成功"
155
+ else
156
+ puts "【KZ-ODR】'#{pod_name}' xcasset资源编译失败"
157
+ end
145
158
  end
146
159
  FileUtils.rm_rf(temp_dir)
147
160
  end
161
+ puts "\n"
148
162
  end
149
163
 
150
164
  # OnDemandResources.plist放到.app中,用于系统读取odr资源
151
165
  app_on_demand_resources_plist_path = app_path + "OnDemandResources.plist"
152
166
  write_to_path(app_on_demand_resources_plist, app_on_demand_resources_plist_path)
167
+ puts "【KZ-ODR】完成主工程 OnDemandResources.plist拷贝"
153
168
 
154
169
  # 生成AssetPackManifestTemplate.plist放到.app中,用于系统读取odr记载路径与信息(archive时,系统会使用此文件生成新的AssetPackManifest.plist)
155
170
  asset_pack_manifest_template_plist_path = app_path + "AssetPackManifestTemplate.plist"
@@ -191,4 +206,7 @@ end
191
206
 
192
207
  if manifest_template_resources.size > 0
193
208
  write_to_path(manifest_template_plist_hash, asset_pack_manifest_template_plist_path)
209
+ puts "【KZ-ODR】完成主工程 AssetPackManifestTemplate.plist配置,ODR配置成功"
210
+ else
211
+ puts "【KZ-ODR】主工程 AssetPackManifestTemplate.plist创建失败,ODR配置成功"
194
212
  end
@@ -1,4 +1,4 @@
1
- #!/bin/sh
1
+ #!/bin/zsh
2
2
 
3
3
  set -e
4
4
  set -u
@@ -17,26 +17,11 @@ if [ -z "${KZ_ON_DEMAND_RESOURCES_PATHS+x}" ]; then
17
17
  exit 0
18
18
  fi
19
19
 
20
- case "${TARGETED_DEVICE_FAMILY:-}" in
21
- 1,2)
22
- TARGET_DEVICE_ARGS="--target-device ipad --target-device iphone"
23
- ;;
24
- 1)
25
- TARGET_DEVICE_ARGS="--target-device iphone"
26
- ;;
27
- 2)
28
- TARGET_DEVICE_ARGS="--target-device ipad"
29
- ;;
30
- 3)
31
- TARGET_DEVICE_ARGS="--target-device tv"
32
- ;;
33
- 4)
34
- TARGET_DEVICE_ARGS="--target-device watch"
35
- ;;
36
- *)
37
- TARGET_DEVICE_ARGS="--target-device mac"
38
- ;;
39
- esac
20
+ if [ -z "${KZ_POD_CONFIG_ROOT+x}" ]; then
21
+ exit 0
22
+ fi
23
+
24
+ source "${KZ_POD_CONFIG_ROOT}/.xcode_env.sh"
40
25
 
41
26
  RUBY_PATH=""
42
27
  function find_ruby_path {
@@ -60,13 +45,13 @@ function find_ruby_path {
60
45
  done < $RESOURCE_PATH
61
46
 
62
47
  source $ON_DEMAND_RESOURCES_SHELL_ENV >/dev/null 2>&1
63
- if (gem list | grep cocoapods >/dev/null) ; then
48
+ if gem list | grep -q cocoapods; then
64
49
  RUBY_PATH=$(which ruby)
65
50
  fi
66
51
  fi
67
52
  }
68
53
 
69
- if (gem list | grep cocoapods >/dev/null) ; then
54
+ if gem list | grep -q cocoapods; then
70
55
  RUBY_PATH=$(which ruby)
71
56
  fi
72
57
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-kz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - yixiong
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-06-24 00:00:00.000000000 Z
11
+ date: 2025-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -84,7 +84,8 @@ files:
84
84
  - lib/cocoapods-kz/resources/arm64ToSimulator
85
85
  - lib/cocoapods-kz/resources/hmap
86
86
  - lib/cocoapods-kz/resources/kz_fix_force_load_exe.sh
87
- - lib/cocoapods-kz/resources/kz_generator_framework.sh
87
+ - lib/cocoapods-kz/resources/kz_generate_framework.sh
88
+ - lib/cocoapods-kz/resources/kz_generate_xcode_env.sh
88
89
  - lib/cocoapods-kz/resources/kz_improve_custom_yaml.sh
89
90
  - lib/cocoapods-kz/resources/kz_refresh_pods_pbxproj.rb
90
91
  - lib/cocoapods-kz/resources/kz_xml_build.sh