cocoapods-kz 0.0.11 → 0.0.13

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c043498bc76c19c7f49d1b6f64f00f10535f3512b9eb85853e213e4faa9b4d1c
4
- data.tar.gz: e86ca96c094fb8f90d6434d1ce99421c0d4c2d2bca37b0e91f23639f841ea3df
3
+ metadata.gz: 60b78485f551ed394bb167d18aad9e08008ea9c432ef555ade88cfc241f918bb
4
+ data.tar.gz: '082f62c4d943cde90357a9a5a55c10636a39ad232e9aded7230170301c01453e'
5
5
  SHA512:
6
- metadata.gz: 15a3769ef86e707c147f1d8d0f3b03832c316a895869703e501fdf3efb9f365938548bc73b2db8331624d90c9ba714bb41763755696d42e7e64cf800c80729d0
7
- data.tar.gz: 70b54fcc641af9ae839c916568e6af18444dc42d00054fcae859e64c9639b780a52eab7320582c15a1c392245fb0cad1cc43cc91557c4ae8716de04c419a6086
6
+ metadata.gz: ea906c0ac96d2c98a2eab4631a356cb1753de215ca0c0694cd13af454b3418f96f1fe4400d081c63f69115c6870efabdd146ef839168cdaa8d9de2ba3e2bdc6d
7
+ data.tar.gz: 295dec357984a4e81fea271b0b261af9e0dc6a0e383d048df8e46224521d3e77ee58124116b0e0d42731121af35d8d4234b92b63c51ca0fc26028e714cba830a
@@ -1,5 +1,5 @@
1
1
  module CocoapodsKz
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.13"
3
3
  end
4
4
 
5
5
  module Pod
@@ -29,7 +29,7 @@ module KZ
29
29
  config_folder = KZ_POD_CONFIG_POD_TARGETS + folder_name
30
30
  if File.directory?(config_folder)
31
31
  Dir.foreach(config_folder) do |version|
32
- next if version == '.' || version == '..' || version == '.DS_Store'
32
+ next if version == '.' || version == '..' || version == '.DS_Store' || version == 'Headers'
33
33
 
34
34
  version_folder = config_folder + version
35
35
  if File.directory?(version_folder)
@@ -52,7 +52,10 @@ module KZ
52
52
 
53
53
  def self.handle_origin_framework(origin_frameworks, kz_pod_target)
54
54
  new_frameworks = []
55
- destination_path = kz_pod_target.pod_config_cache_path(false, true)
55
+ old_destination_path = kz_pod_target.pod_config_cache_path(false , true)
56
+ FileUtils.rm_rf(old_destination_path) if File.exist?(old_destination_path)
57
+
58
+ destination_path = kz_pod_target.pod_config_cache_path(true, true)
56
59
  origin_frameworks.each do |origin_framework_path|
57
60
  if kz_pod_target.disable_to_simulator_frameworks.include?(origin_framework_path)
58
61
  new_frameworks.append(origin_framework_path)
@@ -145,7 +148,6 @@ module KZ
145
148
  end
146
149
 
147
150
  temp_framwork_exe_path = tempdir + "#{framework_basename}_arm64_simulator"
148
-
149
151
  if self.is_dynamic_library?(origin_framework_path + framework_basename)
150
152
  xcrun_vtool_show_result = `xcrun vtool -arch arm64 -show #{origin_framework_path + framework_basename}`.lines.map(&:chomp)
151
153
  framework_sdk_version = "16.0"
@@ -8,6 +8,8 @@ module KZ
8
8
  def initialize(main_project)
9
9
  @all_kz_pod_targets = KZGlobalHelper.instance.kz_analyzer.all_kz_pod_targets
10
10
  @main_project = main_project
11
+ @installation_root = Pod::Config.instance.installation_root
12
+ @on_demand_resources_folder = KZ_POD_CONFIG_ROOT + "OnDemandResources"
11
13
  end
12
14
 
13
15
  def add_framework_generator_build_phase(native_target)
@@ -29,20 +31,27 @@ module KZ
29
31
  end
30
32
 
31
33
  xml_rule = new_build_rule(project, native_target, '[KZ] Custom Xml Build')
34
+ xml_rule.run_once_per_architecture = '0'
32
35
  xml_rule.file_type = 'text.xml'
33
36
  xml_rule.output_files = Array['${KZ_XML_FLEX_DIR}/${INPUT_FILE_BASE}.flex']
34
37
  xml_rule.script = KZ.deal_path_for_xcconfig(KZ_XML_BUILD_PATH, true)
35
38
  end
36
39
 
37
40
  def add_force_load_exe_path_build_phase(native_target, output_path)
38
- return if KZ::KZGlobalHelper.instance.disable_generate_framework
39
-
40
41
  build_phase = native_target.new_shell_script_build_phase('[KZ] Froce Load File Output Path')
41
42
  build_phase.show_env_vars_in_log = '0'
42
43
  build_phase.output_paths = [output_path]
43
44
  build_phase.shell_script = KZ.deal_path_for_xcconfig(KZ_FIX_FORCE_LOAD_EXE, true)
44
45
  end
45
46
 
47
+ def add_improve_yaml_build_phase(project, native_target, output_path)
48
+ build_phase = new_shell_script_build_phase(project, native_target, '[KZ] Improve Custom Yaml', true)
49
+ build_phase.show_env_vars_in_log = '0'
50
+ # build_phase.always_out_of_date = '1'
51
+ build_phase.output_paths = [output_path]
52
+ build_phase.shell_script = KZ.deal_path_for_xcconfig(KZ_IMPROVE_CUSTOM_YAML_PATH, true)
53
+ end
54
+
46
55
  def new_build_rule(project, native_target, name)
47
56
  new_rule = nil
48
57
  native_target.build_rules.each do |build_rule|
@@ -59,6 +68,27 @@ module KZ
59
68
  new_rule
60
69
  end
61
70
 
71
+ def new_shell_script_build_phase(project, native_target, name, before_compile = false)
72
+ new_build_phase = project.new(Xcodeproj::Project::PBXShellScriptBuildPhase)
73
+ new_build_phase.name = name
74
+ if before_compile
75
+ find_compile = false
76
+ native_target.build_phases.each_with_index do |build_phase, index|
77
+ if build_phase.is_a?(Xcodeproj::Project::PBXSourcesBuildPhase)
78
+ find_compile = true
79
+ native_target.build_phases.insert(index, new_build_phase)
80
+ break
81
+ end
82
+ end
83
+ unless find_compile
84
+ native_target.build_phases << new_build_phase
85
+ end
86
+ else
87
+ native_target.build_phases << new_build_phase
88
+ end
89
+ new_build_phase
90
+ end
91
+
62
92
  def create_hamp
63
93
  # 创建壳工程hmap
64
94
  main_sources_path = @main_project.project_dir + @main_project.root_object.display_name
@@ -116,14 +146,25 @@ module KZ
116
146
 
117
147
  # 添加私有头文件引用
118
148
  if kz_pod_target.current_should_build?
119
- private_hamp_info = private_hmap_info(kz_pod_target)
120
- if private_hamp_info.count > 0
149
+ pod_hamp_info = pod_hmap_info(kz_pod_target)
150
+ if pod_hamp_info.count > 0
121
151
  hmap_cache_path = kz_pod_target.pod_config_cache_path(false)
122
152
  FileUtils.mkdir_p(hmap_cache_path) unless File.exist?(hmap_cache_path)
123
153
 
124
- save_hmap_file(private_hamp_info, hmap_cache_path, target_name)
154
+ save_hmap_file(pod_hamp_info, hmap_cache_path, target_name)
125
155
  kz_pod_target.private_header_search_path = hmap_cache_path + "#{target_name}.hmap"
126
156
  end
157
+
158
+ pod_yaml_info = pod_yaml_info(kz_pod_target)
159
+ if pod_yaml_info.count > 0
160
+ yaml_cache_path = kz_pod_target.pod_config_cache_path(false)
161
+ FileUtils.mkdir_p(yaml_cache_path) unless File.exist?(yaml_cache_path)
162
+
163
+ yaml_name = "#{target_name}_origin.yaml"
164
+ save_yaml_file(pod_yaml_info, yaml_cache_path + yaml_name)
165
+ kz_pod_target.custom_origin_yaml_path = yaml_cache_path + yaml_name
166
+ kz_pod_target.custom_yaml_path = yaml_cache_path + "#{target_name}.yaml"
167
+ end
127
168
  end
128
169
  end
129
170
  end
@@ -149,7 +190,7 @@ module KZ
149
190
  Dir.foreach(hmap_cache_path) do |file_name|
150
191
  next if file_name == '.' || file_name == '..' || file_name == '.DS_Store'
151
192
 
152
- if file_name.end_with?(".hmap", ".json")
193
+ if file_name.end_with?(".hmap", ".json", "yaml")
153
194
  FileUtils.rm(hmap_cache_path + file_name) if File.exist?(hmap_cache_path + file_name)
154
195
  end
155
196
  end if File.exist?(hmap_cache_path)
@@ -180,50 +221,105 @@ module KZ
180
221
  end
181
222
  end
182
223
 
183
- def private_hmap_info(kz_pod_target)
184
- header_paths = kz_pod_target.all_headers
185
- # 更新Headers
186
- if kz_pod_target.is_dev_pod
187
- header_paths.each do |header_pathname|
188
- symlink_path = kz_pod_target.local_private_headers_path + header_pathname.basename
189
- File.symlink(header_pathname, symlink_path) unless File.symlink?(symlink_path) || File.exist?(symlink_path)
190
- end
191
- kz_pod_target.use_local_private_headers_path = true
224
+ def pod_hmap_info(kz_pod_target)
225
+ pod_hmap_info = {}
226
+ module_name = kz_pod_target.kz_module_name
227
+
228
+ # public headers
229
+ public_headers = kz_pod_target.public_headers
230
+ public_headers.each do |header_pathname|
231
+ header_pathname_basename = header_pathname.basename.to_s
232
+
233
+ header_hmap_value_quotes = {}
234
+ header_hmap_value_quotes['suffix'] = header_pathname_basename
235
+ header_hmap_value_quotes['prefix'] = module_name + '/'
236
+ pod_hmap_info[header_pathname_basename] = header_hmap_value_quotes
237
+ pod_hmap_info[module_name + '/' + header_pathname_basename] = header_hmap_value_quotes
192
238
  end
193
- header_paths.each_with_object({}) do |header_pathname, hmap_info|
239
+
240
+ # private headers
241
+ all_headers = kz_pod_target.all_headers
242
+ (all_headers - public_headers).each do |header_pathname|
194
243
  header_pathname_basename = header_pathname.basename.to_s
195
244
 
196
245
  header_hmap_value_quotes = {}
197
246
  header_hmap_value_quotes['suffix'] = header_pathname_basename
198
247
  header_hmap_value_quotes['prefix'] = header_pathname.dirname.to_s + '/'
199
- hmap_info[header_pathname_basename] = header_hmap_value_quotes
248
+ pod_hmap_info[header_pathname_basename] = header_hmap_value_quotes
249
+ end
200
250
 
201
- # pch
202
- pchfile_path = kz_pod_target.prefix_header_path
203
- if pchfile_path.exist?
204
- suffix = pchfile_path.basename.to_s
205
- hmap_info[suffix] = { 'suffix' => suffix, 'prefix' => "#{pchfile_path.dirname.to_s}/" }
206
- end
251
+ # pch
252
+ pchfile_path = kz_pod_target.prefix_header_path
253
+ if pchfile_path.exist?
254
+ suffix = pchfile_path.basename.to_s
255
+ pod_hmap_info[suffix] = { 'suffix' => suffix, 'prefix' => "#{pchfile_path.dirname.to_s}/" }
256
+ end
207
257
 
208
- unless kz_pod_target.is_dev_pod
209
- # 个别第三方在使用自己组件文件时,会使用#import <xx/xx.h>的方式
210
- hmap_info[kz_pod_target.product_basename + '/' + header_pathname_basename] = header_hmap_value_quotes
211
- end
258
+ # umbrella
259
+ umbrella_path = kz_pod_target.umbrella_header_path
260
+ if umbrella_path.exist?
261
+ suffix = umbrella_path.basename.to_s
262
+ pod_hmap_info[suffix] = { 'suffix' => suffix, 'prefix' => "#{module_name}/" }
263
+ end
212
264
 
213
- if kz_pod_target.current_uses_swift? && kz_pod_target.is_dev_pod
214
- # 修改SPBoss-Swift.h文件的导入方式
215
- swift_bridge_file_name = "#{kz_pod_target.name}-Swift.h"
216
- hmap_info[swift_bridge_file_name] = { 'suffix' => swift_bridge_file_name, 'prefix' => "#{kz_pod_target.name}/" }
265
+ if kz_pod_target.current_uses_swift? && kz_pod_target.is_dev_pod
266
+ # 修改SPBoss-Swift.h文件的导入方式
267
+ swift_bridge_file_name = "#{module_name}-Swift.h"
268
+ pod_hmap_info[swift_bridge_file_name] = { 'suffix' => swift_bridge_file_name, 'prefix' => "#{module_name}/" }
269
+ end
217
270
 
218
- # 以SPBoss为例,在混编模式中,SPBoss-Swift.h会使用#import <SPBoss/SPBoss.h>方式导入swift需要使用的OC头文件
219
- # SPBoss中头文件会存在当前组件与framework的Headers中,有两份。SPBoss-Swift.h只在framework中
220
- # 编译默认从SPBoss-Swift.h找SPBoss.h,然后找SPBoss.h中的头文件也都会在framework中寻在,会造成与当前组件头文件重复
221
- # 需要重新将#import <SPBoss/SPBoss.h>方式修复为寻找当前组件中的SPBoss.h文件,而不是framework中的SPBoss.h
222
- if header_pathname_basename == "#{kz_pod_target.name}.h"
223
- hmap_info[kz_pod_target.name + '/' + header_pathname_basename] = header_hmap_value_quotes
224
- end
271
+ # 另存一份Headers,用于创建文件与import时的提示信息
272
+ if kz_pod_target.is_dev_pod
273
+ all_headers.each do |header_pathname|
274
+ symlink_path = kz_pod_target.local_private_headers_path + header_pathname.basename
275
+ File.symlink(header_pathname, symlink_path) unless File.symlink?(symlink_path) || File.exist?(symlink_path)
225
276
  end
277
+ kz_pod_target.use_local_private_headers_path = true
226
278
  end
279
+ pod_hmap_info
280
+ end
281
+
282
+ def pod_yaml_info(kz_pod_target)
283
+ built_products_dir = "__built_products_dir__/"
284
+
285
+ pod_yaml_info = {}
286
+ pod_yaml_info["case-sensitive"] = "false"
287
+ pod_yaml_info["version"] = "0"
288
+
289
+ yaml_roots = []
290
+ pod_yaml_info["roots"] = yaml_roots
291
+
292
+ yaml_header_info = {}
293
+ yaml_header_info["type"] = "directory"
294
+ yaml_header_info["name"] = built_products_dir + "#{kz_pod_target.product_name}/Headers"
295
+ yaml_roots.append(yaml_header_info)
296
+
297
+ public_headers = kz_pod_target.public_headers
298
+ yaml_header_contents = []
299
+ yaml_header_info["contents"] = yaml_header_contents
300
+ public_headers.each do |header_pathname|
301
+ yaml_header_content = {}
302
+ yaml_header_content["type"] = "file"
303
+ yaml_header_content["name"] = header_pathname.basename.to_s
304
+ yaml_header_content["external-contents"] = header_pathname.to_s
305
+ yaml_header_contents.append(yaml_header_content)
306
+ end
307
+
308
+ yaml_modulemap_info = {}
309
+ yaml_modulemap_info["type"] = "directory"
310
+ yaml_modulemap_info["name"] = built_products_dir + "#{kz_pod_target.product_name}/Modules"
311
+ yaml_roots.append(yaml_modulemap_info)
312
+
313
+ yaml_modulemap_contents = []
314
+ yaml_modulemap_info["contents"] = yaml_modulemap_contents
315
+
316
+ yaml_modulemap_content = {}
317
+ yaml_modulemap_content["type"] = "file"
318
+ yaml_modulemap_content["name"] = "module.modulemap"
319
+ yaml_modulemap_content["external-contents"] = built_products_dir + "#{kz_pod_target.product_name}/Modules/module.modulemap"
320
+ yaml_modulemap_contents.append(yaml_modulemap_content)
321
+
322
+ pod_yaml_info
227
323
  end
228
324
 
229
325
  def save_hmap_file(hmap_hash, save_path, file_name)
@@ -234,10 +330,240 @@ module KZ
234
330
  return unless json_file
235
331
 
236
332
  json_file.syswrite(hmap_json)
333
+ json_file.close
334
+
237
335
  system "#{HMAP_EXECUTE_PATH} convert #{hmap_json_path} #{hmap_path}"
238
336
 
239
337
  FileUtils.rm(hmap_json_path) unless KZ::KZGlobalHelper.instance.debug
240
338
  end
241
339
 
340
+ def save_yaml_file(yaml_hash, save_path)
341
+ yaml_json = JSON.pretty_generate(yaml_hash)
342
+ json_file = File.new(save_path, 'w')
343
+ return unless json_file
344
+
345
+ json_file.syswrite(yaml_json)
346
+ json_file.close
347
+ end
348
+
349
+ def create_on_demand_resources
350
+ # 清除历史配置
351
+ FileUtils.rm_r(@on_demand_resources_folder) if File.exist?(@on_demand_resources_folder)
352
+ FileUtils.mkdir_p(@on_demand_resources_folder)
353
+
354
+ # 汇总所有配置文件,用于代码中加载资源
355
+ on_demand_resources_all_config = {}
356
+ @all_kz_pod_targets.each do |target_name, kz_pod_target|
357
+ if kz_pod_target.is_dev_pod
358
+ # 寻找配置文件KZOnDemandResourcesConfig.plist
359
+ kz_pod_target.native_pod_target.file_accessors.each do |file_accessor|
360
+ file_accessor.resource_bundles.map do |bundle_name, paths|
361
+ paths.each do |path|
362
+ if path.basename.to_s == "KZOnDemandResourcesConfig.plist"
363
+ plist_hash = Xcodeproj::Plist.read_from_path(path)
364
+ if plist_hash.size > 0
365
+ on_demand_resources_all_config[kz_pod_target.name] = plist_hash
366
+ analyze_on_demand_resources_config_plist(plist_hash, kz_pod_target, paths)
367
+ kz_pod_target.add_on_demand_resources(path)
368
+ end
369
+ end
370
+ end
371
+ end
372
+ end
373
+ end
374
+ end
375
+
376
+ if on_demand_resources_all_config.size > 0
377
+ use_for_code_plist_path = @on_demand_resources_folder + "KZOnDemandResourcesAllConfig.plist"
378
+ Xcodeproj::Plist.write_to_path(on_demand_resources_all_config, use_for_code_plist_path)
379
+ end
380
+ end
381
+
382
+ def analyze_on_demand_resources_config_plist(plist_hash, kz_pod_target, all_resources_paths)
383
+ resources_path = @on_demand_resources_folder + "Bundles/#{kz_pod_target.name}"
384
+ FileUtils.mkdir_p(resources_path)
385
+
386
+ # 生成AssetPackOutputSpecifications.plist,用于Images.xcassets编译
387
+ asset_pack_output_specifications_resources = []
388
+
389
+ # 用于生成OnDemandResources.plist文件,放到main bundle中标记按需加载资源
390
+ on_demand_resources_plist = {}
391
+ bundle_resource_request_tags = {}
392
+ on_demand_resources_plist["NSBundleResourceRequestTags"] = bundle_resource_request_tags
393
+ bundle_resource_request_asset_packs = {}
394
+ on_demand_resources_plist["NSBundleResourceRequestAssetPacks"] = bundle_resource_request_asset_packs
395
+
396
+ # 统计所有的xcassets资源
397
+ have_config_xcassets = false
398
+
399
+ # 从配置plist中读取'Initial Install Tags'资源
400
+ initial_plist_hash = plist_hash["Initial Install Tags"]
401
+ on_deman_resources_from_plist(initial_plist_hash, kz_pod_target, 1, all_resources_paths, resources_path) do |tag, bundle_id, bundle_path, normal_file_names, have_xcassets_paths|
402
+ # 如有配置中有.xcassets资源,需要先标记,等待编译时单独再单独编译
403
+ if have_xcassets_paths
404
+ have_config_xcassets = true
405
+
406
+ resource_item = {}
407
+ resource_item["bundle-id"] = bundle_id
408
+ resource_item["bundle-path"] = bundle_path
409
+ resource_item["tags"] = [tag]
410
+ asset_pack_output_specifications_resources << resource_item
411
+ end
412
+
413
+ bundle_resource_request_tags[tag] = { "NSAssetPacks" => [bundle_id] }
414
+ bundle_resource_request_asset_packs[bundle_id] = normal_file_names if normal_file_names.size > 0
415
+ end
416
+
417
+ # Prefetched Tag Order
418
+ prefetched_plist_hash = plist_hash["Prefetched Tag Order"]
419
+ on_deman_resources_from_plist(prefetched_plist_hash, kz_pod_target, 0.5, all_resources_paths, resources_path) do |tag, bundle_id, bunlde_path, normal_file_names, have_xcassets_paths|
420
+ if have_xcassets_paths
421
+ have_config_xcassets = true
422
+
423
+ resource_item = {}
424
+ resource_item["bundle-id"] = bundle_id
425
+ resource_item["bundle-path"] = bunlde_path
426
+ resource_item["tags"] = [tag]
427
+ asset_pack_output_specifications_resources << resource_item
428
+ end
429
+
430
+ bundle_resource_request_tags[tag] = { "NSAssetPacks" => [bundle_id] }
431
+ bundle_resource_request_asset_packs[bundle_id] = normal_file_names if normal_file_names.size > 0
432
+ end
433
+
434
+ # Download Only On Demand
435
+ download_plist_hash = plist_hash["Download Only On Demand"]
436
+ on_deman_resources_from_plist(download_plist_hash, kz_pod_target, 0, all_resources_paths, resources_path) do |tag, bundle_id, bunlde_path, normal_file_names, have_xcassets_paths|
437
+ if have_xcassets_paths
438
+ have_config_xcassets = true
439
+
440
+ resource_item = {}
441
+ resource_item["bundle-id"] = bundle_id
442
+ resource_item["bundle-path"] = bunlde_path
443
+ resource_item["tags"] = [tag]
444
+ asset_pack_output_specifications_resources << resource_item
445
+ end
446
+
447
+ bundle_resource_request_tags[tag] = { "NSAssetPacks" => [bundle_id] }
448
+ bundle_resource_request_asset_packs[bundle_id] = normal_file_names if normal_file_names.size > 0
449
+ end
450
+
451
+ if asset_pack_output_specifications_resources.size > 0
452
+ write_to_path(asset_pack_output_specifications_resources, resources_path + "AssetPackOutputSpecifications.plist")
453
+ end
454
+
455
+ if bundle_resource_request_tags.size > 0 || bundle_resource_request_asset_packs.size > 0
456
+ Xcodeproj::Plist.write_to_path(on_demand_resources_plist, resources_path + "OnDemandResources.plist")
457
+ end
458
+
459
+ # 一个组件可能有多个xcassets,只要其中一个有配置on demand resources,所有xcassets都需要单独编译
460
+ all_xcassets_paths = []
461
+ if have_config_xcassets
462
+ all_resources_paths.each do |path|
463
+ if path.extname == ".xcassets"
464
+ all_xcassets_paths << path
465
+ end
466
+ end
467
+ end
468
+
469
+ target_bundle_info = {}
470
+ target_bundle_info["name"] = kz_pod_target.name
471
+ target_bundle_info["xcassets_paths"] = all_xcassets_paths
472
+ Xcodeproj::Plist.write_to_path(target_bundle_info, resources_path + "TargetBundleInfo.plist")
473
+
474
+ end
475
+
476
+ def on_deman_resources_from_plist(plist_hash, kz_pod_target, priority, all_resources_paths, resources_path)
477
+ return unless (!plist_hash.nil? && plist_hash.size > 0)
478
+
479
+ plist_hash.each do |tag, file_paths|
480
+ normal_file_names = []
481
+ normal_file_paths = []
482
+ have_xcassets_paths = false
483
+ file_paths.each do |rel_file_path|
484
+ file_path = @installation_root + rel_file_path.strip
485
+ next unless file_path.exist?
486
+
487
+ if file_path.extname == ".imageset"
488
+ # imageset文件配置
489
+ xcassets_path = find_xcassets_path(file_path)
490
+ if all_resources_paths.include?(xcassets_path)
491
+ kz_pod_target.add_on_demand_resources(xcassets_path)
492
+ have_xcassets_paths = true
493
+ end
494
+
495
+ content_json_path = file_path + "Contents.json"
496
+ content_json = JSON.parse(File.read(file_path + "Contents.json"))
497
+ content_json["properties"] = { "on-demand-resource-tags" => [tag] }
498
+ content_json_file = File.new(content_json_path, 'w')
499
+ content_json_file.syswrite(JSON.pretty_generate(content_json))
500
+ else
501
+ # 普通文件配置
502
+ if all_resources_paths.include?(file_path)
503
+ kz_pod_target.add_on_demand_resources(file_path)
504
+ normal_file_paths << file_path
505
+ normal_file_names << file_path.basename
506
+ end
507
+ end
508
+ end
509
+
510
+ create_bundle_info_plist(tag, priority, normal_file_paths, resources_path) do |bundle_id, bundle_path|
511
+ yield(tag, bundle_id, bundle_path, normal_file_names, have_xcassets_paths)
512
+ end
513
+ end
514
+ end
515
+
516
+ def find_xcassets_path(path)
517
+ return "" if path.root?
518
+
519
+ if path.extname == ".xcassets"
520
+ path
521
+ else
522
+ find_xcassets_path(path + "..")
523
+ end
524
+ end
525
+
526
+ def create_bundle_info_plist(tag, priority, normal_file_paths, resource_path)
527
+ # project bundle identifier
528
+ project_bundle_identifier = KZGlobalHelper.instance.on_demand_resources_bundle_id
529
+ tag_md5 = md5_sign(tag)
530
+ # bundle folder
531
+ demand_bundle_folder_name = "#{project_bundle_identifier}.#{tag}-#{tag_md5}.assetpack"
532
+ demand_bundle_folder = resource_path + "OnDemandResources/#{demand_bundle_folder_name}"
533
+ # create bundle folder
534
+ FileUtils.mkdir_p(demand_bundle_folder) unless FileTest::exist?(demand_bundle_folder)
535
+ # copy file
536
+ normal_file_paths.each do |file|
537
+ FileUtils.cp(file, demand_bundle_folder)
538
+ end
539
+
540
+ bundle_info_plist = {}
541
+ bundle_info_plist["Priority"] = priority if priority > 0
542
+ bundle_info_plist["Tags"] = [tag]
543
+ demand_bundle_id = "#{project_bundle_identifier}.asset-pack-#{tag_md5}"
544
+ bundle_info_plist["CFBundleIdentifier"] = demand_bundle_id
545
+ Xcodeproj::Plist.write_to_path(bundle_info_plist, demand_bundle_folder + "Info.plist")
546
+
547
+ yield(demand_bundle_id, demand_bundle_folder_name)
548
+ end
549
+
550
+ def md5_sign(key)
551
+ OpenSSL::Digest::MD5.hexdigest(key)
552
+ end
553
+
554
+ # Xcodeproj::Plist.write_to_path只支持hash,如果是数组需要重写write方法
555
+ def write_to_path(hash, path)
556
+ unless path.is_a?(String) || path.is_a?(Pathname)
557
+ raise TypeError, "The given `#{path}` must be a string or 'pathname'."
558
+ end
559
+ path = path.to_s
560
+ raise IOError, 'Empty path.' if path.empty?
561
+
562
+ File.open(path, 'w') do |f|
563
+ plist = Nanaimo::Plist.new(hash, :xml)
564
+ Nanaimo::Writer::XMLWriter.new(plist, :pretty => true, :output => f, :strict => false).write
565
+ end
566
+ end
567
+
242
568
  end
243
569
  end
@@ -24,6 +24,10 @@ module KZ
24
24
  KZ_LOCK_FILE_PATH = KZ_POD_CONFIG_ROOT + 'KZConfigLock'
25
25
  KZ_FIX_FORCE_LOAD_EXE = KZ_POD_CONFIG_SUPPORT_FILES + 'kz_fix_force_load_exe.sh'
26
26
  KZ_FEFRESH_PODS_PBXPROJ = KZ_POD_CONFIG_SUPPORT_FILES + 'kz_refresh_pods_pbxproj.rb'
27
+ KZ_IMPROVE_CUSTOM_YAML_PATH = KZ_POD_CONFIG_SUPPORT_FILES + 'kz_improve_custom_yaml.sh'
28
+
29
+ KZ_ON_DEMAND_RESOURCES = KZ_POD_CONFIG_SUPPORT_FILES + 'on_demand_resources'
30
+ KZ_ON_DEMAND_RESOURCES_SHELL = KZ_ON_DEMAND_RESOURCES + 'kz_on_demand_resources_xocde.sh'
27
31
 
28
32
  def self.deal_path_for_xcconfig(path, add_quotes = false)
29
33
  if path.is_a?(String)
@@ -51,6 +55,7 @@ module KZ
51
55
  attr_accessor :generate_kz_pod_targets
52
56
  attr_accessor :debug_shell_log_tag
53
57
  attr_accessor :arm64_simulator
58
+ attr_accessor :on_demand_resources_bundle_id
54
59
 
55
60
  private_class_method :new
56
61
 
@@ -88,7 +93,8 @@ module KZ
88
93
  end
89
94
  FileUtils.mkdir_p(KZ_POD_CONFIG_SUPPORT_FILES) unless File.exist?(KZ_POD_CONFIG_SUPPORT_FILES)
90
95
  FileUtils.mkdir_p(KZ_POD_CONFIG_POD_TARGETS) unless File.exist?(KZ_POD_CONFIG_POD_TARGETS)
91
- FileUtils.mkdir_p(KZ_POD_CONFIG_POD_TEMPDIR) unless File.exist?(KZ_POD_CONFIG_POD_TEMPDIR)
96
+ FileUtils.rm_rf(KZ_POD_CONFIG_POD_TEMPDIR) if File.exist?(KZ_POD_CONFIG_POD_TEMPDIR)
97
+ FileUtils.mkdir_p(KZ_POD_CONFIG_POD_TEMPDIR)
92
98
 
93
99
  FileUtils.rm(FLEX_COMPLIER_PATH) if File.exist?(FLEX_COMPLIER_PATH)
94
100
  FileUtils.cp_r(File.dirname(__FILE__) + '/../resources/FlexCompiler', FLEX_COMPLIER_PATH)
@@ -105,7 +111,16 @@ module KZ
105
111
 
106
112
  FileUtils.cp_r(File.dirname(__FILE__) + '/../resources/kz_refresh_pods_pbxproj.rb', KZ_FEFRESH_PODS_PBXPROJ)
107
113
 
114
+ FileUtils.cp_r(File.dirname(__FILE__) + '/../resources/kz_improve_custom_yaml.sh', KZ_IMPROVE_CUSTOM_YAML_PATH)
115
+ system("chmod +x #{KZ_IMPROVE_CUSTOM_YAML_PATH}")
116
+
108
117
  Pod::Config.instance.podfile.use_frameworks!(:linkage => :static)
118
+
119
+ if !@on_demand_resources_bundle_id.nil?
120
+ FileUtils.rm_r(KZ_ON_DEMAND_RESOURCES) if File.exist?(KZ_ON_DEMAND_RESOURCES)
121
+ FileUtils.cp_r(File.dirname(__FILE__) + '/../resources/on_demand_resources/', KZ_ON_DEMAND_RESOURCES)
122
+ system("chmod +x #{KZ_ON_DEMAND_RESOURCES_SHELL}")
123
+ end
109
124
  else
110
125
  @kz_pod_enable = false
111
126
  @generate_kz_pod_targets = false
@@ -26,6 +26,8 @@ module KZ
26
26
  # 用于临时保存hamp过程的配置
27
27
  attr_accessor :private_header_search_path
28
28
  attr_accessor :repair_header_search_path
29
+ attr_accessor :custom_yaml_path
30
+ attr_accessor :custom_origin_yaml_path
29
31
 
30
32
  attr_accessor :platform_name
31
33
  # target编译最终的产物名称
@@ -67,6 +69,8 @@ module KZ
67
69
  @force_load = false
68
70
  @use_modulemap = true
69
71
  @disable_to_simulator_frameworks = []
72
+ # 配置按需加载的资源,需要从bundle target中移除,然后手动进行配置
73
+ @on_demand_resources = []
70
74
 
71
75
  native_pod_target.file_accessors.each do |file_accessor|
72
76
  file_accessor.kz_pod_target = self
@@ -233,8 +237,8 @@ module KZ
233
237
  # 获取target对应的配置根目录,部分文件需要依赖版本进行存储
234
238
  def pod_config_cache_path(concat_version, vendored_framework = false)
235
239
  kz_target_config_folder = KZ_POD_CONFIG_POD_TARGETS + @name
236
- kz_target_config_folder += "vendored_framework" if vendored_framework
237
240
  kz_target_config_folder += @version if concat_version
241
+ kz_target_config_folder += "vendored_framework" if vendored_framework
238
242
  kz_target_config_folder
239
243
  end
240
244
 
@@ -252,7 +256,7 @@ module KZ
252
256
  end
253
257
  end
254
258
  end
255
- return @native_pod_target.product_module_name
259
+ @native_pod_target.product_module_name
256
260
  end
257
261
 
258
262
  # 获取所有用于修复的modulemap路径,原因参考@repair_modulemap_path
@@ -280,6 +284,10 @@ module KZ
280
284
  @native_pod_target.prefix_header_path
281
285
  end
282
286
 
287
+ def umbrella_header_path
288
+ @native_pod_target.umbrella_header_path
289
+ end
290
+
283
291
  # 当前pod是否存在可编译的文件,配置framework后当前pod就不存在可编译文件
284
292
  def current_should_build?
285
293
  @native_pod_target.should_build?
@@ -333,5 +341,12 @@ module KZ
333
341
  @native_pod_target.configuration_build_dir
334
342
  end
335
343
 
344
+ def add_on_demand_resources(path)
345
+ @on_demand_resources.push(path).uniq!
346
+ end
347
+ def get_on_demand_resources
348
+ @on_demand_resources
349
+ end
350
+
336
351
  end
337
352
  end
@@ -40,6 +40,16 @@ module Pod
40
40
  KZ::KZGlobalHelper.instance.kz_pod_config.merge!(kz_pod_config)
41
41
  end
42
42
 
43
+ def kz_cocoapods_configure(*requirements)
44
+ configure = requirements.last
45
+ return false unless configure.is_a?(Hash)
46
+
47
+ on_demand_resources_bundle_id = configure.delete(:on_demand_resources_bundle_id)
48
+ if !on_demand_resources_bundle_id.nil? && on_demand_resources_bundle_id.is_a?(String)
49
+ KZ::KZGlobalHelper.instance.on_demand_resources_bundle_id = on_demand_resources_bundle_id
50
+ end
51
+ end
52
+
43
53
  end
44
54
  end
45
55
  end
@@ -0,0 +1,7 @@
1
+ # require File.expand_path('../../spec_helper', __FILE__)
2
+ #
3
+ # module Pod
4
+ # describe Specification::DSL do
5
+ #
6
+ # end
7
+ # end
@@ -24,6 +24,9 @@ module Pod
24
24
  if KZ::KZGlobalHelper.instance.kz_pod_enable
25
25
  # hmap的创建需要在download之后,integrate之前
26
26
  KZ::KZGlobalHelper.instance.kz_generator.create_hamp
27
+ unless KZ::KZGlobalHelper.instance.on_demand_resources_bundle_id.nil?
28
+ KZ::KZGlobalHelper.instance.kz_generator.create_on_demand_resources
29
+ end
27
30
  end
28
31
  original_integrate
29
32
  end
@@ -27,6 +27,10 @@ module Pod
27
27
  if kz_pod_target.force_load
28
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
29
  end
30
+
31
+ 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)
33
+ end
30
34
  end
31
35
 
32
36
  if kz_pod_target && !kz_pod_target.use_modulemap
@@ -39,6 +43,25 @@ module Pod
39
43
  target_installation_result
40
44
  end
41
45
 
46
+ alias_method :origin_filter_resource_file_references, :filter_resource_file_references
47
+ def filter_resource_file_references(resource_file_references)
48
+ kz_pod_target = self.target.weakRef_kz_pod_target
49
+ if kz_pod_target
50
+ new_resource_file_references = []
51
+ odr_resources = kz_pod_target.get_on_demand_resources
52
+ resource_file_references.each do |path|
53
+ new_resource_file_references.push(path) unless odr_resources.include?(path)
54
+ end
55
+ origin_filter_resource_file_references(new_resource_file_references) do |compile_phase_refs, resources_phase_refs|
56
+ yield compile_phase_refs, resources_phase_refs
57
+ end
58
+ else
59
+ origin_filter_resource_file_references(resource_file_references) do |compile_phase_refs, resources_phase_refs|
60
+ yield compile_phase_refs, resources_phase_refs
61
+ end
62
+ end
63
+ end
64
+
42
65
  end
43
66
  end
44
67
  end
@@ -64,6 +64,38 @@ module Pod
64
64
  xcconfig.attributes['VALID_ARCHS'] = 'arm64 arm64_32 x86_64'
65
65
  end
66
66
 
67
+ unless kz_pod_target.custom_origin_yaml_path.nil?
68
+ xcconfig.attributes['KZ_CUSTOM_ORIGIN_YAML_PATH'] = kz_pod_target.custom_origin_yaml_path
69
+ xcconfig.attributes['KZ_CUSTOM_YAML_PATH'] = kz_pod_target.custom_yaml_path
70
+
71
+ other_cflags = xcconfig.attributes['OTHER_CFLAGS']
72
+ if other_cflags == nil
73
+ other_cflags = ""
74
+ elsif !other_cflags.end_with?(" ")
75
+ other_cflags += " "
76
+ end
77
+ other_cflags += ("-ivfsoverlay #{KZ.deal_path_for_xcconfig(kz_pod_target.custom_yaml_path, true)}")
78
+ xcconfig.attributes['OTHER_CFLAGS'] = other_cflags
79
+
80
+ other_cplusplusflags = xcconfig.attributes['OTHER_CPLUSPLUSFLAGS']
81
+ if other_cplusplusflags == nil
82
+ other_cplusplusflags = ""
83
+ elsif !other_cplusplusflags.end_with?(" ")
84
+ other_cplusplusflags += " "
85
+ end
86
+ other_cplusplusflags += ("-ivfsoverlay #{KZ.deal_path_for_xcconfig(kz_pod_target.custom_yaml_path, true)}")
87
+ xcconfig.attributes['OTHER_CPLUSPLUSFLAGS'] = other_cplusplusflags
88
+
89
+ other_swift_flags = xcconfig.attributes['OTHER_SWIFT_FLAGS']
90
+ if other_swift_flags == nil
91
+ other_swift_flags = ""
92
+ elsif !other_swift_flags.end_with?(" ")
93
+ other_swift_flags += " "
94
+ end
95
+ other_swift_flags += ("-Xcc -ivfsoverlay -Xcc #{KZ.deal_path_for_xcconfig(kz_pod_target.custom_yaml_path, true)}")
96
+ xcconfig.attributes['OTHER_SWIFT_FLAGS'] = other_swift_flags
97
+ end
98
+
67
99
  add_repair_modulemap(xcconfig, kz_pod_target.all_repair_modulemap_paths, kz_pod_target.current_uses_swift?)
68
100
  add_repair_swift_include_path(xcconfig, kz_pod_target.all_repair_swift_include_paths, kz_pod_target.current_uses_swift?)
69
101
  kz_update_xcconfig_file(xcconfig, path)
@@ -0,0 +1,34 @@
1
+
2
+ module Pod
3
+ class Installer
4
+ class UserProjectIntegrator
5
+ class TargetIntegrator
6
+
7
+ alias_method :origin_integrate!, :integrate!
8
+ def integrate!
9
+ origin_integrate!
10
+
11
+ unless KZ::KZGlobalHelper.instance.on_demand_resources_bundle_id.nil?
12
+ add_on_demand_resources_script_phase
13
+ end
14
+ end
15
+
16
+ def add_on_demand_resources_script_phase
17
+ phase_name = "[KZ] On Demand Resources Build"
18
+ native_targets.each do |native_target|
19
+ if native_target.isa == "PBXNativeTarget" && native_target.product_type == "com.apple.product-type.application"
20
+ phase = TargetIntegrator.create_or_update_shell_script_build_phase(native_target, phase_name)
21
+ native_target.build_phases.push(phase).uniq! unless native_target.build_phases.include?(phase)
22
+ phase.shell_script = KZ.deal_path_for_xcconfig(KZ::KZ_ON_DEMAND_RESOURCES_SHELL, true)
23
+
24
+ native_target.build_configurations.each do |config|
25
+ config.build_settings["ENABLE_ON_DEMAND_RESOURCES"] = "NO"
26
+ config.build_settings["KZ_POD_CONFIG_ROOT"] = KZ::KZ_POD_CONFIG_ROOT_STR
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -13,4 +13,5 @@ if Pod.match_version?('~> 1.11')
13
13
  require 'cocoapods-kz/native/specification'
14
14
  require 'cocoapods-kz/native/pods_project_writer'
15
15
  require 'cocoapods-kz/native/pod_target_integrator'
16
+ require 'cocoapods-kz/native/target_integrator'
16
17
  end
@@ -3,9 +3,13 @@ if [ "${MACH_O_TYPE}" != "staticlib" ]; then
3
3
  fi
4
4
 
5
5
  if [ -d "${KZ_FRAMEWORK_CACHE_PATH}" ]; then
6
- rm -r "${KZ_FRAMEWORK_CACHE_PATH}"
6
+ if [ -d "${KZ_FRAMEWORK_CACHE_PATH}/${PRODUCT_NAME}.xcframework" ]; then
7
+ rm -r "${KZ_FRAMEWORK_CACHE_PATH}/${PRODUCT_NAME}.xcframework"
8
+ fi
9
+ else
10
+ mkdir -p "${KZ_FRAMEWORK_CACHE_PATH}"
7
11
  fi
8
- mkdir -p "${KZ_FRAMEWORK_CACHE_PATH}"
12
+
9
13
 
10
14
  CURRENT_PRODUCT_DIR=${PODS_CONFIGURATION_BUILD_DIR}/${TARGET_NAME}
11
15
  find "${CURRENT_PRODUCT_DIR}" -iname "*.bundle" | while read -r BUNDLE_FILE; do
@@ -0,0 +1,25 @@
1
+ #!/bin/sh
2
+ set -e
3
+ set -u
4
+ set -o pipefail
5
+
6
+ function on_error {
7
+ echo "$(realpath -mq "${0}"):$1: error: Unexpected failure"
8
+ }
9
+ trap 'on_error $LINENO' ERR
10
+
11
+ if [ -z "${KZ_CUSTOM_ORIGIN_YAML_PATH+x}" ]; then
12
+ exit 0
13
+ fi
14
+
15
+ if [ -z "${KZ_CUSTOM_YAML_PATH+x}" ]; then
16
+ exit 0
17
+ fi
18
+
19
+ if [ ! -f "$KZ_CUSTOM_ORIGIN_YAML_PATH" ]; then
20
+ exit 0
21
+ fi
22
+
23
+ cp -f "$KZ_CUSTOM_ORIGIN_YAML_PATH" "$KZ_CUSTOM_YAML_PATH"
24
+
25
+ sed -i.bak "s|__built_products_dir__|${BUILT_PRODUCTS_DIR}|g" "$KZ_CUSTOM_YAML_PATH" && rm "$KZ_CUSTOM_YAML_PATH.bak"
@@ -4,14 +4,16 @@ require 'pathname'
4
4
  current_pods_pbxproj_path = Pathname.new(ARGV[0])
5
5
  temp_pods_pbxproj_path = Pathname.new(ARGV[1])
6
6
 
7
- if !File.exist?(current_pods_pbxproj_path) || !FileUtils.compare_file(current_pods_pbxproj_path, temp_pods_pbxproj_path)
8
- FileUtils.cp_r(temp_pods_pbxproj_path, current_pods_pbxproj_path)
9
- end
7
+ if File.exist?(temp_pods_pbxproj_path)
8
+ if !File.exist?(current_pods_pbxproj_path) || !FileUtils.compare_file(current_pods_pbxproj_path, temp_pods_pbxproj_path)
9
+ FileUtils.cp_r(temp_pods_pbxproj_path, current_pods_pbxproj_path)
10
+ end
10
11
 
11
- FileUtils.rm_r(Pathname(temp_pods_pbxproj_path).dirname)
12
+ FileUtils.rm_r(Pathname(temp_pods_pbxproj_path).dirname)
12
13
 
13
- xcode_running = system("ps aux | grep '[X]code' > /dev/null 2>&1")
14
- if xcode_running
15
- system("touch #{current_pods_pbxproj_path}")
14
+ xcode_running = system("ps aux | grep '[X]code' > /dev/null 2>&1")
15
+ if xcode_running
16
+ system("touch #{current_pods_pbxproj_path}")
17
+ end
16
18
  end
17
19
 
@@ -0,0 +1,26 @@
1
+ require 'xcodeproj'
2
+ autoload :Nanaimo, 'nanaimo'
3
+
4
+ def write_to_path(hash, path)
5
+ unless path.is_a?(String) || path.is_a?(Pathname)
6
+ raise TypeError, "The given `#{path}` must be a string or 'pathname'."
7
+ end
8
+ path = path.to_s
9
+ raise IOError, 'Empty path.' if path.empty?
10
+
11
+ File.open(path, 'w') do |f|
12
+ plist = Nanaimo::Plist.new(hash, :xml)
13
+ Nanaimo::Writer::XMLWriter.new(plist, :pretty => true, :output => f, :strict => false).write
14
+ end
15
+ end
16
+
17
+ on_demand_resources_folder = ARGV[0]
18
+ asset_pack_output_specifications_plist_path = ARGV[1]
19
+ asset_pack_output_specifications_plist = Xcodeproj::Plist.read_from_path(asset_pack_output_specifications_plist_path)
20
+ asset_pack_output_specifications_plist.each do |item|
21
+ bundle_paht = item["bundle-path"]
22
+ unless bundle_paht.start_with?(on_demand_resources_folder)
23
+ item["bundle-path"] = "#{on_demand_resources_folder}/#{bundle_paht}"
24
+ end
25
+ end
26
+ write_to_path(asset_pack_output_specifications_plist, asset_pack_output_specifications_plist_path)
@@ -0,0 +1,44 @@
1
+ require 'xcodeproj'
2
+ require "date"
3
+
4
+ on_demand_resources_path = ARGV[0]
5
+ manifest_template_plist_path = ARGV[1]
6
+ manifest_url = "http://127.0.0.1"
7
+
8
+ manifest_template_plist_hash = {}
9
+ manifest_template_resources = []
10
+ manifest_template_plist_hash["resources"] = manifest_template_resources
11
+
12
+ Dir.foreach(on_demand_resources_path) do |sub_file|
13
+ if sub_file != "." && sub_file != ".." && sub_file != ".DS_Store"
14
+ resources_item = {}
15
+ primary_content_hash = {}
16
+ time = Time.now
17
+ primary_content_hash["hash"] = time.utc.strftime('%Y-%m-%dT%H:%M:%S.000Z')
18
+ primary_content_hash["strategy"] = "modtime"
19
+ resources_item["primaryContentHash"] = primary_content_hash
20
+ resources_item["isStreamable"] = true
21
+ total_size = 0
22
+ Dir.foreach("#{on_demand_resources_path}/#{sub_file}") do |resource|
23
+ if resource != "." && resource != ".." && resource != ".DS_Store"
24
+ if resource == "Info.plist"
25
+ info_plist = Xcodeproj::Plist.read_from_path("#{on_demand_resources_path}/#{sub_file}/#{resource}")
26
+ priority = info_plist["Priority"]
27
+ if priority && priority > 0
28
+ resources_item["downloadPriority"] = priority
29
+ end
30
+ resources_item["bundleKey"] = info_plist["CFBundleIdentifier"]
31
+ else
32
+ resources_item["URL"] = "#{manifest_url}#{on_demand_resources_path}/#{sub_file}"
33
+ total_size = total_size + File.size("#{on_demand_resources_path}/#{sub_file}/#{resource}")
34
+ end
35
+ end
36
+ end
37
+ resources_item["uncompressedSize"] = total_size
38
+ manifest_template_resources << resources_item
39
+ end
40
+ end
41
+
42
+ if manifest_template_resources.size > 0
43
+ Xcodeproj::Plist.write_to_path(manifest_template_plist_hash, manifest_template_plist_path)
44
+ end
@@ -0,0 +1,26 @@
1
+ require 'xcodeproj'
2
+
3
+ kz_on_demand_resources_path = ARGV[0]
4
+ on_demand_resources_plist_path = ARGV[1]
5
+
6
+ on_demand_resources_plist = {}
7
+ bundle_resource_request_tags = {}
8
+ on_demand_resources_plist["NSBundleResourceRequestTags"] = bundle_resource_request_tags
9
+ bundle_resource_request_asset_packs = {}
10
+ on_demand_resources_plist["NSBundleResourceRequestAssetPacks"] = bundle_resource_request_asset_packs
11
+
12
+ Dir.foreach(kz_on_demand_resources_path) do |sub_file|
13
+ if sub_file != "." && sub_file != ".." && sub_file != ".DS_Store"
14
+ Dir.foreach("#{kz_on_demand_resources_path}/#{sub_file}") do |plist|
15
+ if plist == "OnDemandResources.plist"
16
+ info_plist = Xcodeproj::Plist.read_from_path("#{kz_on_demand_resources_path}/#{sub_file}/#{plist}")
17
+ bundle_resource_request_tags.update(info_plist["NSBundleResourceRequestTags"])
18
+ bundle_resource_request_asset_packs.update(info_plist["NSBundleResourceRequestAssetPacks"])
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ if bundle_resource_request_tags.size > 0 || bundle_resource_request_asset_packs.size > 0
25
+ Xcodeproj::Plist.write_to_path(on_demand_resources_plist, on_demand_resources_plist_path)
26
+ end
@@ -0,0 +1,162 @@
1
+ #!/bin/sh
2
+
3
+ set -e
4
+ set -u
5
+ set -o pipefail
6
+
7
+ function on_error {
8
+ echo "$(realpath -mq "${0}"):$1: error: Unexpected failure"
9
+ }
10
+ trap 'on_error $LINENO' ERR
11
+
12
+ if [ -z ${UNLOCALIZED_RESOURCES_FOLDER_PATH+x} ]; then
13
+ exit 0
14
+ fi
15
+
16
+ TARGET_DIR=${TARGET_BUILD_DIR}
17
+ if [[ "${ACTION}" == "install" ]] && [[ "${SKIP_INSTALL}" == "NO" ]] ; then
18
+ TARGET_DIR=${INSTALL_DIR}
19
+ fi
20
+
21
+ KZ_ON_DEMAND_RESOURCES_PATH="${KZ_POD_CONFIG_ROOT}/OnDemandResources/Bundles"
22
+ if [ ! -d $KZ_ON_DEMAND_RESOURCES_PATH ]; then
23
+ exit 0
24
+ fi
25
+
26
+ case "${TARGETED_DEVICE_FAMILY:-}" in
27
+ 1,2)
28
+ TARGET_DEVICE_ARGS="--target-device ipad --target-device iphone"
29
+ ;;
30
+ 1)
31
+ TARGET_DEVICE_ARGS="--target-device iphone"
32
+ ;;
33
+ 2)
34
+ TARGET_DEVICE_ARGS="--target-device ipad"
35
+ ;;
36
+ 3)
37
+ TARGET_DEVICE_ARGS="--target-device tv"
38
+ ;;
39
+ 4)
40
+ TARGET_DEVICE_ARGS="--target-device watch"
41
+ ;;
42
+ *)
43
+ TARGET_DEVICE_ARGS="--target-device mac"
44
+ ;;
45
+ esac
46
+
47
+ RUBY_PATH=""
48
+ function find_ruby_path {
49
+ if [[ "$1" = /* ]] ; then
50
+ RESOURCE_PATH="$1"
51
+ else
52
+ RESOURCE_PATH="${HOME}/$1"
53
+ fi
54
+
55
+ ON_DEMAND_RESOURCES_SHELL_ENV="${TARGET_TEMP_DIR}/kz_on_demand_resources_env_$1"
56
+ if [ -f $ON_DEMAND_RESOURCES_SHELL_ENV ] ; then
57
+ rm $ON_DEMAND_RESOURCES_SHELL_ENV
58
+ fi
59
+ touch $ON_DEMAND_RESOURCES_SHELL_ENV
60
+
61
+ if [ -f $RESOURCE_PATH ] ; then
62
+ while read line; do
63
+ if [[ "$line" = export* ]] ; then
64
+ echo $line >> $ON_DEMAND_RESOURCES_SHELL_ENV
65
+ fi
66
+ done < $RESOURCE_PATH
67
+
68
+ source $ON_DEMAND_RESOURCES_SHELL_ENV >/dev/null 2>&1
69
+ if (gem list | grep cocoapods >/dev/null) ; then
70
+ RUBY_PATH=$(which ruby)
71
+ fi
72
+ fi
73
+ }
74
+
75
+ if (gem list | grep cocoapods >/dev/null) ; then
76
+ RUBY_PATH=$(which ruby)
77
+ fi
78
+
79
+ if [ -z $RUBY_PATH ];then
80
+ find_ruby_path ".bash_profile"
81
+ fi
82
+
83
+ if [ -z $RUBY_PATH ];then
84
+ find_ruby_path ".zshrc"
85
+ fi
86
+
87
+ if [ -z $RUBY_PATH ];then
88
+ exit 1
89
+ fi
90
+
91
+ BUILDE_ON_DEMAND_RESOURCES_PATH="${TARGET_BUILD_DIR}/OnDemandResources"
92
+ if [[ "${ACTION}" == "install" ]] && [[ "${SKIP_INSTALL}" == "NO" ]] ; then
93
+ BUILDE_ON_DEMAND_RESOURCES_PATH="${INSTALL_ROOT}/OnDemandResources"
94
+ fi
95
+ mkdir -p $BUILDE_ON_DEMAND_RESOURCES_PATH
96
+
97
+ # 拷贝所有配置,供代码中读取
98
+ KZ_ON_DEMAND_RESOURCES_ALL_CONFIG_PATH="${KZ_POD_CONFIG_ROOT}/OnDemandResources/KZOnDemandResourcesAllConfig.plist"
99
+ if [ -e $KZ_ON_DEMAND_RESOURCES_ALL_CONFIG_PATH ]; then
100
+ cp "${KZ_ON_DEMAND_RESOURCES_ALL_CONFIG_PATH}" "${TARGET_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/"
101
+ fi
102
+
103
+ ls $KZ_ON_DEMAND_RESOURCES_PATH | while read line
104
+ do
105
+ KZ_ON_DEMAND_RESOURCES_BUNDLE_INFO_PATH="${KZ_ON_DEMAND_RESOURCES_PATH}/${line}/TargetBundleInfo.plist"
106
+ if [ ! -f $KZ_ON_DEMAND_RESOURCES_BUNDLE_INFO_PATH ] ; then
107
+ continue
108
+ fi
109
+
110
+ TARGET_BUILD_DIR_BUNDLE="${TARGET_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/${line}.bundle"
111
+
112
+ if [ ! -d $TARGET_BUILD_DIR_BUNDLE ] ; then
113
+ mkdir -p $TARGET_BUILD_DIR_BUNDLE
114
+ fi
115
+
116
+ KZ_BUILDE_ON_DEMAND_RESOURCES_PATH="${TARGET_TEMP_DIR}/${line}/KZOnDemandResources"
117
+ mkdir -p $KZ_BUILDE_ON_DEMAND_RESOURCES_PATH
118
+
119
+ # copy on demand resources
120
+ BUNDLE_ON_DEMAND_RESOURCES="${KZ_ON_DEMAND_RESOURCES_PATH}/${line}/OnDemandResources"
121
+ if [ -d $BUNDLE_ON_DEMAND_RESOURCES ] ; then
122
+ cp -r $BUNDLE_ON_DEMAND_RESOURCES/ $BUILDE_ON_DEMAND_RESOURCES_PATH/
123
+ fi
124
+ # copy on demand resources plist
125
+ BUNDLE_ON_DEMAND_RESOURCES_PLIST="${KZ_ON_DEMAND_RESOURCES_PATH}/${line}/OnDemandResources.plist"
126
+ if [ -f $BUNDLE_ON_DEMAND_RESOURCES_PLIST ] ; then
127
+ cp $BUNDLE_ON_DEMAND_RESOURCES_PLIST $TARGET_BUILD_DIR_BUNDLE
128
+ fi
129
+ # complete asset pack output specifications plist
130
+ ASSET_PACK_OUTPUT_SPECIFICATIONS="${KZ_ON_DEMAND_RESOURCES_PATH}/${line}/AssetPackOutputSpecifications.plist"
131
+ if [ ! -f $ASSET_PACK_OUTPUT_SPECIFICATIONS ] ; then
132
+ continue
133
+ fi
134
+ cp -f $ASSET_PACK_OUTPUT_SPECIFICATIONS $KZ_BUILDE_ON_DEMAND_RESOURCES_PATH
135
+ ASSET_PACK_OUTPUT_SPECIFICATIONS="${KZ_BUILDE_ON_DEMAND_RESOURCES_PATH}/AssetPackOutputSpecifications.plist"
136
+ $RUBY_PATH "${KZ_POD_CONFIG_ROOT}/SupportFiles/on_demand_resources/kz_complete_asset_pack_output_spec_plist.rb" "${BUILDE_ON_DEMAND_RESOURCES_PATH}" "${ASSET_PACK_OUTPUT_SPECIFICATIONS}"
137
+ ORIGIN_ASSETS_CAR=$TARGET_BUILD_DIR_BUNDLE/"Assets.car"
138
+ if [ -f $ORIGIN_ASSETS_CAR ] ; then
139
+ rm $ORIGIN_ASSETS_CAR
140
+ fi
141
+ XCASSET_FILES=()
142
+ XCASSETS_PATHS=$(/usr/libexec/PlistBuddy -c "Print xcassets_paths" $KZ_ON_DEMAND_RESOURCES_BUNDLE_INFO_PATH)
143
+ while read xcassets; do
144
+ if [[ $xcassets != "Array {" ]] && [[ $xcassets != "}" ]] ; then
145
+ if [ ! -d $xcassets ] ; then
146
+ continue
147
+ else
148
+ XCASSET_FILES+=("$xcassets")
149
+ fi
150
+ fi
151
+ done <<<"$XCASSETS_PATHS"
152
+ if [[ -n "${WRAPPER_EXTENSION}" ]] && [ "`xcrun --find actool`" ] && [ -n "${XCASSET_FILES:-}" ] ; then
153
+ printf "%s\0" "${XCASSET_FILES[@]}" | xargs -0 xcrun actool --output-format human-readable-text --notices --warnings --platform "${PLATFORM_NAME}" --minimum-deployment-target "${!DEPLOYMENT_TARGET_SETTING_NAME}" ${TARGET_DEVICE_ARGS} --platform "${PLATFORM_NAME}" --compress-pngs --enable-on-demand-resources YES --asset-pack-output-specifications "${ASSET_PACK_OUTPUT_SPECIFICATIONS}" --compile "${TARGET_BUILD_DIR_BUNDLE}"
154
+ fi
155
+ done
156
+
157
+ ASSET_PACK_MANIFEST_TEMPLATE_PATH="${TARGET_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/AssetPackManifestTemplate.plist"
158
+ ON_DEMAND_RESOUCES_PATH="${TARGET_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/OnDemandResources.plist"
159
+ # create asset pack manifest template
160
+ $RUBY_PATH "${KZ_POD_CONFIG_ROOT}/SupportFiles/on_demand_resources/kz_create_asset_pack_manifest_plist.rb" "${BUILDE_ON_DEMAND_RESOURCES_PATH}" "${ASSET_PACK_MANIFEST_TEMPLATE_PATH}"
161
+ # create on demand resources to .app
162
+ $RUBY_PATH "${KZ_POD_CONFIG_ROOT}/SupportFiles/on_demand_resources/kz_create_on_demand_resources_plis.rb" "${KZ_ON_DEMAND_RESOURCES_PATH}" "${ON_DEMAND_RESOUCES_PATH}"
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.11
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - yixiong
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-28 00:00:00.000000000 Z
11
+ date: 2025-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,7 @@ files:
66
66
  - lib/cocoapods-kz/native.rb
67
67
  - lib/cocoapods-kz/native/acknowledgements.rb
68
68
  - lib/cocoapods-kz/native/dls.rb
69
+ - lib/cocoapods-kz/native/dsl_spec.rb
69
70
  - lib/cocoapods-kz/native/file_accessor.rb
70
71
  - lib/cocoapods-kz/native/installer.rb
71
72
  - lib/cocoapods-kz/native/pod_target.rb
@@ -75,13 +76,19 @@ files:
75
76
  - lib/cocoapods-kz/native/specification.rb
76
77
  - lib/cocoapods-kz/native/target.rb
77
78
  - lib/cocoapods-kz/native/target_installer_helper.rb
79
+ - lib/cocoapods-kz/native/target_integrator.rb
78
80
  - lib/cocoapods-kz/resources/FlexCompiler
79
81
  - lib/cocoapods-kz/resources/arm64ToSimulator
80
82
  - lib/cocoapods-kz/resources/hmap
81
83
  - lib/cocoapods-kz/resources/kz_fix_force_load_exe.sh
82
84
  - lib/cocoapods-kz/resources/kz_generator_framework.sh
85
+ - lib/cocoapods-kz/resources/kz_improve_custom_yaml.sh
83
86
  - lib/cocoapods-kz/resources/kz_refresh_pods_pbxproj.rb
84
87
  - lib/cocoapods-kz/resources/kz_xml_build.sh
88
+ - lib/cocoapods-kz/resources/on_demand_resources/kz_complete_asset_pack_output_spec_plist.rb
89
+ - lib/cocoapods-kz/resources/on_demand_resources/kz_create_asset_pack_manifest_plist.rb
90
+ - lib/cocoapods-kz/resources/on_demand_resources/kz_create_on_demand_resources_plis.rb
91
+ - lib/cocoapods-kz/resources/on_demand_resources/kz_on_demand_resources_xocde.sh
85
92
  - lib/cocoapods_plugin.rb
86
93
  homepage: https://github.com/EXAMPLE/cocoapods-kz
87
94
  licenses:
@@ -102,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
109
  - !ruby/object:Gem::Version
103
110
  version: '0'
104
111
  requirements: []
105
- rubygems_version: 3.4.13
112
+ rubygems_version: 3.5.11
106
113
  signing_key:
107
114
  specification_version: 4
108
115
  summary: Kanzhun's cocoapods manage tools.