cocoapods-kz 0.0.14 → 0.0.15

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 (26) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cocoapods-kz/command/info.rb +5 -2
  3. data/lib/cocoapods-kz/command/repair.rb +19 -12
  4. data/lib/cocoapods-kz/gem_version.rb +1 -1
  5. data/lib/cocoapods-kz/helpers/kz_analyzer.rb +6 -0
  6. data/lib/cocoapods-kz/helpers/{kz_generator.rb → kz_generator_hmap.rb} +2 -222
  7. data/lib/cocoapods-kz/helpers/kz_generator_on_demand_resources.rb +231 -0
  8. data/lib/cocoapods-kz/helpers/kz_global_helper.rb +26 -7
  9. data/lib/cocoapods-kz/helpers/kz_pod_target.rb +72 -5
  10. data/lib/cocoapods-kz/helpers/repair_module_import.rb +1 -1
  11. data/lib/cocoapods-kz/native/build_configuration.rb +12 -0
  12. data/lib/cocoapods-kz/native/dls.rb +13 -7
  13. data/lib/cocoapods-kz/native/installer.rb +10 -2
  14. data/lib/cocoapods-kz/native/path_list.rb +11 -0
  15. data/lib/cocoapods-kz/native/pod_target_installer.rb +0 -20
  16. data/lib/cocoapods-kz/native/specification.rb +6 -0
  17. data/lib/cocoapods-kz/native/target_installer_helper.rb +16 -1
  18. data/lib/cocoapods-kz/native/target_integrator.rb +6 -12
  19. data/lib/cocoapods-kz/native.rb +2 -0
  20. data/lib/cocoapods-kz/resources/on_demand_resources/kz_on_demand_resources_process.rb +194 -0
  21. data/lib/cocoapods-kz/resources/on_demand_resources/kz_on_demand_resources_xocde.sh +4 -81
  22. metadata +7 -7
  23. data/lib/cocoapods-kz/native/dsl_spec.rb +0 -7
  24. data/lib/cocoapods-kz/resources/on_demand_resources/kz_complete_asset_pack_output_spec_plist.rb +0 -26
  25. data/lib/cocoapods-kz/resources/on_demand_resources/kz_create_asset_pack_manifest_plist.rb +0 -44
  26. data/lib/cocoapods-kz/resources/on_demand_resources/kz_create_on_demand_resources_plis.rb +0 -26
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e5dcadeaa76d480bc0a06c97d9f07fc514d4f6c6fa6e1321ea60546f9b425a5f
4
- data.tar.gz: 01ab3e043531cbc9e29d6a73ddc15e63873245c7aa99c8a301ae79dc531f4914
3
+ metadata.gz: 772c4e4e048e8879e3a0e9a922b887c3206338c9ec397f8747b017891f47e51d
4
+ data.tar.gz: 995dfcee40ec45c2c6b23d43bc7d08a8e3c8e2c6570fc9d7881c76850b679014
5
5
  SHA512:
6
- metadata.gz: e163e6c506505a9a1cf39ae263a5a40ccaf1ff8aae61d0ac808f1256106409ff7d5fd29de8c52abe9fb93666e42a6ad0db504a759eadb94b2781478a61aa83c9
7
- data.tar.gz: f678b463d568835f87a1d5d490c8f5096651d94fe7123ce94ac26ea8eee3ea1bd9130e908b7e2c616811e26c804523ef5897b2c69306f8e0ca89160cd3159830
6
+ metadata.gz: 802feb2c0501d20a2cf5b18031ee8f029d8b234a28bb9c8e6b6fbf6a21ac27d429a90af7f26aadb6977fb4b76d9e9e75cb07e94b33b1acbd0d0eb969bf7e065b
7
+ data.tar.gz: 3b9c1b52b50bb27d1b5f2ae8d595cd427409c0fc0653a0781ae5ae394efdfa5d2642d1fe6d29f2e12ef9b92c6e08ce276201ab2843b777bb9b9dcacacc9899a6
@@ -11,8 +11,11 @@ module Pod
11
11
  DESC
12
12
 
13
13
  def initialize(argv)
14
- KZ::KZGlobalHelper.instance.analyze_special_parameters(true, false, argv.arguments!)
15
- KZ::KZGlobalHelper.instance.generate_kz_pod_targets = true
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
+ KZ::KZGlobalHelper.instance.generate_kz_pod_targets = true
18
+ end
16
19
  super
17
20
  end
18
21
 
@@ -25,24 +25,31 @@ module Pod
25
25
  @repair_private_hmap = argv.flag?('private-hmap')
26
26
  banner! unless @repair_module_import || @repair_dynamic_swift || @repair_private_hmap
27
27
 
28
- KZ::KZGlobalHelper.instance.analyze_special_parameters(true, false, argv.arguments!)
29
- KZ::KZGlobalHelper.instance.generate_kz_pod_targets = true
28
+ if Pod.match_version?('~> 1.11')
29
+ KZ::KZGlobalHelper.instance.kz_pod_enable = true
30
+ KZ::KZGlobalHelper.instance.analyze_special_parameters(true, false, argv.arguments!)
31
+ KZ::KZGlobalHelper.instance.generate_kz_pod_targets = true
32
+ end
30
33
 
31
34
  super
32
35
  end
33
36
 
34
37
  def run
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
44
- else @repair_private_hmap
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
45
51
  KZ::KZGlobalHelper.instance.kz_generator.create_hamp
52
+ end
46
53
  end
47
54
  end
48
55
  end
@@ -1,5 +1,5 @@
1
1
  module CocoapodsKz
2
- VERSION = "0.0.14"
2
+ VERSION = "0.0.15"
3
3
  end
4
4
 
5
5
  module Pod
@@ -82,6 +82,12 @@ module KZ
82
82
  kz_pod_target = KZPodTarget.new(native_pod_target)
83
83
  is_dev_pod = @development_pods.include?(native_pod_target_name)
84
84
  kz_pod_target.is_dev_pod = is_dev_pod
85
+ if KZGlobalHelper.instance.on_demand_resources_info.enable
86
+ on_demand_resources_config_patterns = KZGlobalHelper.instance.on_demand_resources_info.config_plist_path_patterns[kz_pod_target.root_name]
87
+ unless on_demand_resources_config_patterns.nil?
88
+ kz_pod_target.on_demand_resources_config_patterns = on_demand_resources_config_patterns
89
+ end
90
+ end
85
91
  kz_pod_target.force_config_pod_mode = get_force_config_pod_mode(kz_pod_target)
86
92
  if config_pod_mode != :kz_pod_origin_mode && !is_dev_pod
87
93
  kz_pod_target.config_pod_mode = config_pod_mode
@@ -1,5 +1,6 @@
1
1
  require 'xcodeproj'
2
2
  require 'fileutils'
3
+ require_relative 'kz_generator_on_demand_resources'
3
4
 
4
5
  module KZ
5
6
 
@@ -8,8 +9,6 @@ module KZ
8
9
  def initialize(main_project)
9
10
  @all_kz_pod_targets = KZGlobalHelper.instance.kz_analyzer.all_kz_pod_targets
10
11
  @main_project = main_project
11
- @installation_root = Pod::Config.instance.installation_root
12
- @on_demand_resources_folder = KZ_POD_CONFIG_ROOT + "OnDemandResources"
13
12
  end
14
13
 
15
14
  def add_framework_generator_build_phase(native_target)
@@ -346,224 +345,5 @@ module KZ
346
345
  json_file.close
347
346
  end
348
347
 
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
-
568
348
  end
569
- end
349
+ end
@@ -0,0 +1,231 @@
1
+ require 'xcodeproj'
2
+ require 'fileutils'
3
+
4
+ module KZ
5
+ class KZGenerator
6
+
7
+ def create_on_demand_resources
8
+ kz_on_demand_resources_all_config_path = KZ_POD_CONFIG_ROOT + "KZOnDemandResourcesAllConfig.plist"
9
+ FileUtils.rm(kz_on_demand_resources_all_config_path) if File.exist?(kz_on_demand_resources_all_config_path)
10
+
11
+ # 汇总所有配置文件,用于代码中加载资源
12
+ on_demand_resources_all_config = {}
13
+ @all_kz_pod_targets.each do |target_name, kz_pod_target|
14
+ on_demand_resources_info = kz_pod_target.on_demand_resources_info
15
+ next if on_demand_resources_info.empty?
16
+
17
+ analyze_on_demand_resources_config_plist(on_demand_resources_info, kz_pod_target)
18
+ on_demand_resources_all_config[target_name] = on_demand_resources_info
19
+ end
20
+
21
+ # 将汇总的配置写入app中,供代码读取
22
+ if on_demand_resources_all_config.size > 0
23
+ write_to_path(on_demand_resources_all_config, kz_on_demand_resources_all_config_path)
24
+ end
25
+ end
26
+
27
+ def get_all_xcassets(kz_pod_target)
28
+ all_xcassets_paths = []
29
+ kz_pod_target.native_pod_target.file_accessors.each do |file_accessor|
30
+ file_accessor.resource_bundles.map do |bundle_name, paths|
31
+ paths.each do |path|
32
+ if path.extname == ".xcassets"
33
+ all_xcassets_paths << path
34
+ end
35
+ end
36
+ end
37
+ end
38
+ all_xcassets_paths
39
+ end
40
+
41
+ def analyze_on_demand_resources_config_plist(plist_hash, kz_pod_target)
42
+ resources_path = kz_pod_target.pod_config_cache_path(false, false, true)
43
+ FileUtils.rm_r(resources_path) if File.exist?(resources_path)
44
+ FileUtils.mkdir_p(resources_path)
45
+ kz_pod_target.on_demand_resources_config_path = resources_path.to_s
46
+
47
+ # 生成AssetPackOutputSpecifications.plist,用于Images.xcassets编译
48
+ asset_pack_output_specifications_resources = []
49
+
50
+ # 用于生成OnDemandResources.plist文件,放到main bundle中标记按需加载资源
51
+ on_demand_resources_plist = {}
52
+ bundle_resource_request_tags = {}
53
+ on_demand_resources_plist["NSBundleResourceRequestTags"] = bundle_resource_request_tags
54
+ bundle_resource_request_asset_packs = {}
55
+ on_demand_resources_plist["NSBundleResourceRequestAssetPacks"] = bundle_resource_request_asset_packs
56
+
57
+ # 用于odr资源编译时读取所需的参数
58
+ odr_build_info = {}
59
+
60
+ # 从配置plist中读取'Initial Install Tags'资源
61
+ initial_plist_hash = plist_hash["Initial Install Tags"]
62
+ 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|
63
+ # 如有配置中有.xcassets资源,需要先标记,等待编译时单独再单独编译
64
+ if have_xcassets_paths
65
+ resource_item = {}
66
+ resource_item["bundle-id"] = bundle_id
67
+ resource_item["bundle-path"] = bundle_path
68
+ resource_item["tags"] = [tag]
69
+ asset_pack_output_specifications_resources << resource_item
70
+ end
71
+
72
+ bundle_resource_request_tags[tag] = { "NSAssetPacks" => [bundle_id] }
73
+ bundle_resource_request_asset_packs[bundle_id] = normal_file_names if normal_file_names.size > 0
74
+ end
75
+
76
+ # Prefetched Tag Order
77
+ prefetched_plist_hash = plist_hash["Prefetched Tag Order"]
78
+ 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|
79
+ if have_xcassets_paths
80
+ resource_item = {}
81
+ resource_item["bundle-id"] = bundle_id
82
+ resource_item["bundle-path"] = bunlde_path
83
+ resource_item["tags"] = [tag]
84
+ asset_pack_output_specifications_resources << resource_item
85
+ end
86
+
87
+ bundle_resource_request_tags[tag] = { "NSAssetPacks" => [bundle_id] }
88
+ bundle_resource_request_asset_packs[bundle_id] = normal_file_names if normal_file_names.size > 0
89
+ end
90
+
91
+ # Download Only On Demand
92
+ download_plist_hash = plist_hash["Download Only On Demand"]
93
+ 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|
94
+ if have_xcassets_paths
95
+ resource_item = {}
96
+ resource_item["bundle-id"] = bundle_id
97
+ resource_item["bundle-path"] = bunlde_path
98
+ resource_item["tags"] = [tag]
99
+ asset_pack_output_specifications_resources << resource_item
100
+ end
101
+
102
+ bundle_resource_request_tags[tag] = { "NSAssetPacks" => [bundle_id] }
103
+ bundle_resource_request_asset_packs[bundle_id] = normal_file_names if normal_file_names.size > 0
104
+ end
105
+
106
+ if asset_pack_output_specifications_resources.size > 0
107
+ write_to_path(asset_pack_output_specifications_resources, resources_path + "AssetPackOutputSpecifications.plist")
108
+ end
109
+
110
+ if bundle_resource_request_tags.size > 0 || bundle_resource_request_asset_packs.size > 0
111
+ write_to_path(on_demand_resources_plist, resources_path + "OnDemandResources.plist")
112
+ end
113
+
114
+ unless odr_build_info.empty?
115
+ all_xcassets_dest_plist_path = kz_pod_target.pod_config_cache_path(false, false, true) + "odr_build_info.plist"
116
+ write_to_path(odr_build_info, all_xcassets_dest_plist_path)
117
+ end
118
+ end
119
+
120
+ def on_demand_resources_from_plist(plist_hash, kz_pod_target, priority, resources_path, odr_build_info)
121
+ return unless (!plist_hash.nil? && plist_hash.size > 0)
122
+
123
+ all_normal_file_names = []
124
+ plist_hash.each do |tag, file_paths|
125
+ normal_file_names = []
126
+ normal_file_paths = []
127
+
128
+ have_xcassets_paths = false
129
+ file_paths.each do |file_path|
130
+ next unless file_path.exist?
131
+
132
+ if file_path.extname == ".imageset"
133
+ have_xcassets_paths = true
134
+ xcassets_path = find_xcassets_path(file_path)
135
+ unless xcassets_path.nil?
136
+ on_demand_resources_xcassets(kz_pod_target, odr_build_info, xcassets_path) do |tag_info|
137
+ tag_info[file_path.relative_path_from(xcassets_path)] = tag
138
+ end
139
+ end
140
+ else
141
+ # 普通文件配置
142
+ normal_file_paths << file_path
143
+ normal_file_names << file_path.basename
144
+ all_normal_file_names << file_path.basename
145
+ end
146
+ end
147
+
148
+ create_bundle_info_plist(tag, priority, normal_file_paths, resources_path) do |bundle_id, bundle_path|
149
+ yield(tag, bundle_id, bundle_path, normal_file_names, have_xcassets_paths)
150
+ end
151
+ end
152
+
153
+ unless all_normal_file_names.empty?
154
+ odr_build_info["normal_files"] ||= []
155
+ odr_normal_files = odr_build_info["normal_files"]
156
+ odr_normal_files.concat(all_normal_file_names)
157
+ end
158
+ end
159
+
160
+ def find_xcassets_path(path)
161
+ return nil if path.root?
162
+
163
+ if path.extname == ".xcassets"
164
+ path
165
+ else
166
+ find_xcassets_path(path.parent)
167
+ end
168
+ end
169
+
170
+ def on_demand_resources_xcassets(kz_pod_target, odr_build_info, xcassets_path)
171
+ if odr_build_info["all_xcassets"].nil?
172
+ all_xcassets_info = {}
173
+ all_xcassets_paths = kz_pod_target.all_xcassets_paths
174
+ all_xcassets_paths.each do |path|
175
+ all_xcassets_info[path.basename.to_s] = { "path" => path.to_s, "tags" => {} }
176
+ end
177
+ odr_build_info["all_xcassets"] = all_xcassets_info
178
+ end
179
+ all_xcassets_info = odr_build_info["all_xcassets"]
180
+ xcassets_name = xcassets_path.basename.to_s
181
+ xcassets_info = all_xcassets_info[xcassets_name]
182
+ if xcassets_info.nil?
183
+ all_xcassets_info[xcassets_name] = { "path" => xcassets_path.to_s, "tags" => {} }
184
+ end
185
+ yield(all_xcassets_info[xcassets_name]["tags"])
186
+ end
187
+
188
+ def create_bundle_info_plist(tag, priority, normal_file_paths, resource_path)
189
+ # project bundle identifier
190
+ project_bundle_identifier = KZGlobalHelper.instance.on_demand_resources_info.bundle_id
191
+ tag_md5 = md5_sign(tag)
192
+ # bundle folder
193
+ demand_bundle_folder_name = "#{project_bundle_identifier}.#{tag}-#{tag_md5}.assetpack"
194
+ demand_bundle_folder = resource_path + "OnDemandResources/#{demand_bundle_folder_name}"
195
+ # create bundle folder
196
+ FileUtils.mkdir_p(demand_bundle_folder) unless FileTest::exist?(demand_bundle_folder)
197
+ # copy file
198
+ normal_file_paths.each do |file|
199
+ FileUtils.cp(file, demand_bundle_folder)
200
+ end
201
+
202
+ bundle_info_plist = {}
203
+ bundle_info_plist["Priority"] = priority if priority > 0
204
+ bundle_info_plist["Tags"] = [tag]
205
+ demand_bundle_id = "#{project_bundle_identifier}.asset-pack-#{tag_md5}"
206
+ bundle_info_plist["CFBundleIdentifier"] = demand_bundle_id
207
+ Xcodeproj::Plist.write_to_path(bundle_info_plist, demand_bundle_folder + "Info.plist")
208
+
209
+ yield(demand_bundle_id, demand_bundle_folder_name)
210
+ end
211
+
212
+ def md5_sign(key)
213
+ OpenSSL::Digest::MD5.hexdigest(key)
214
+ end
215
+
216
+ # Xcodeproj::Plist.write_to_path只支持hash,如果是数组需要重写write方法
217
+ def write_to_path(hash, path)
218
+ unless path.is_a?(String) || path.is_a?(Pathname)
219
+ raise TypeError, "The given `#{path}` must be a string or 'pathname'."
220
+ end
221
+ path = path.to_s
222
+ raise IOError, 'Empty path.' if path.empty?
223
+
224
+ File.open(path, 'w') do |f|
225
+ plist = Nanaimo::Plist.new(hash, :xml)
226
+ Nanaimo::Writer::XMLWriter.new(plist, :pretty => true, :output => f, :strict => false).write
227
+ end
228
+ end
229
+
230
+ end
231
+ end
@@ -7,6 +7,21 @@ require_relative 'kz_config_result'
7
7
  require_relative 'kz_pod_target'
8
8
 
9
9
  module KZ
10
+ class KZOnDemandResourcesInfo
11
+ attr_accessor :enable
12
+ attr_accessor :config_plist_path_patterns
13
+ attr_accessor :bundle_id
14
+ attr_accessor :odr_target_name
15
+
16
+ def initialize
17
+ @enable = false
18
+ @config_plist_path_patterns = {}
19
+ @bundle_id = ""
20
+ @odr_target_name = ""
21
+ end
22
+
23
+ end
24
+
10
25
  KZ_POD_CONFIG_VERSION = '1.0.2'
11
26
  KZ_POD_CONFIG_ROOT = Pod::Config.instance.installation_root + 'Pods/KZPodConfigure'
12
27
  KZ_POD_CONFIG_SUPPORT_FILES = KZ_POD_CONFIG_ROOT + 'SupportFiles'
@@ -55,7 +70,7 @@ module KZ
55
70
  attr_accessor :generate_kz_pod_targets
56
71
  attr_accessor :debug_shell_log_tag
57
72
  attr_accessor :arm64_simulator
58
- attr_accessor :on_demand_resources_bundle_id
73
+ attr_accessor :on_demand_resources_info
59
74
 
60
75
  private_class_method :new
61
76
 
@@ -70,6 +85,7 @@ module KZ
70
85
  @olde_lock_file_content = nil
71
86
  @debug_shell_log_tag = "&> /dev/null"
72
87
  @arm64_simulator = false
88
+ @on_demand_resources_info = KZOnDemandResourcesInfo.new
73
89
  end
74
90
 
75
91
  def debug=(value)
@@ -112,8 +128,8 @@ module KZ
112
128
 
113
129
  Pod::Config.instance.podfile.use_frameworks!(:linkage => :static)
114
130
 
115
- if !@on_demand_resources_bundle_id.nil?
116
- FileUtils.rm_r(KZ_ON_DEMAND_RESOURCES) if File.exist?(KZ_ON_DEMAND_RESOURCES)
131
+ FileUtils.rm_r(KZ_ON_DEMAND_RESOURCES) if File.exist?(KZ_ON_DEMAND_RESOURCES)
132
+ if on_demand_resources_info.enable
117
133
  FileUtils.cp_r(File.dirname(__FILE__) + '/../resources/on_demand_resources/', KZ_ON_DEMAND_RESOURCES)
118
134
  system("chmod +x #{KZ_ON_DEMAND_RESOURCES_SHELL}")
119
135
  end
@@ -124,15 +140,18 @@ module KZ
124
140
  end
125
141
 
126
142
  def handle_flexCompiler
127
- if have_flexLib_pod_target
128
- FileUtils.rm(FLEX_COMPLIER_PATH) if File.exist?(FLEX_COMPLIER_PATH)
129
- if @kz_analyzer.pod_of_flexlib_info.flexLib_version.major >= 4
143
+ flexlib_info = @kz_analyzer.pod_of_flexlib_info
144
+ FileUtils.rm(FLEX_COMPLIER_PATH) if File.exist?(FLEX_COMPLIER_PATH)
145
+ if flexlib_info.have_flexLib_pod
146
+ if flexlib_info.flexLib_version.major >= 4
130
147
  FileUtils.cp_r(File.dirname(__FILE__) + '/../resources/FlexCompiler_V1', FLEX_COMPLIER_PATH)
131
148
  else
132
149
  FileUtils.cp_r(File.dirname(__FILE__) + '/../resources/FlexCompiler', FLEX_COMPLIER_PATH)
133
150
  end
134
- system("chmod +x #{FLEX_COMPLIER_PATH}")
151
+ elsif flexlib_info.have_kzswiftui_pod
152
+ FileUtils.cp_r(File.dirname(__FILE__) + '/../resources/FlexCompiler_V1', FLEX_COMPLIER_PATH)
135
153
  end
154
+ system("chmod +x #{FLEX_COMPLIER_PATH}") if File.exist?(FLEX_COMPLIER_PATH)
136
155
  end
137
156
 
138
157
  def analyze_special_parameters(use_code_tag, use_framework_tag, pod_names)