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.
- checksums.yaml +4 -4
- data/lib/cocoapods-kz/command/info.rb +5 -2
- data/lib/cocoapods-kz/command/repair.rb +19 -12
- data/lib/cocoapods-kz/gem_version.rb +1 -1
- data/lib/cocoapods-kz/helpers/kz_analyzer.rb +6 -0
- data/lib/cocoapods-kz/helpers/{kz_generator.rb → kz_generator_hmap.rb} +2 -222
- data/lib/cocoapods-kz/helpers/kz_generator_on_demand_resources.rb +231 -0
- data/lib/cocoapods-kz/helpers/kz_global_helper.rb +26 -7
- data/lib/cocoapods-kz/helpers/kz_pod_target.rb +72 -5
- data/lib/cocoapods-kz/helpers/repair_module_import.rb +1 -1
- data/lib/cocoapods-kz/native/build_configuration.rb +12 -0
- data/lib/cocoapods-kz/native/dls.rb +13 -7
- data/lib/cocoapods-kz/native/installer.rb +10 -2
- data/lib/cocoapods-kz/native/path_list.rb +11 -0
- data/lib/cocoapods-kz/native/pod_target_installer.rb +0 -20
- data/lib/cocoapods-kz/native/specification.rb +6 -0
- data/lib/cocoapods-kz/native/target_installer_helper.rb +16 -1
- data/lib/cocoapods-kz/native/target_integrator.rb +6 -12
- data/lib/cocoapods-kz/native.rb +2 -0
- data/lib/cocoapods-kz/resources/on_demand_resources/kz_on_demand_resources_process.rb +194 -0
- data/lib/cocoapods-kz/resources/on_demand_resources/kz_on_demand_resources_xocde.sh +4 -81
- metadata +7 -7
- data/lib/cocoapods-kz/native/dsl_spec.rb +0 -7
- data/lib/cocoapods-kz/resources/on_demand_resources/kz_complete_asset_pack_output_spec_plist.rb +0 -26
- data/lib/cocoapods-kz/resources/on_demand_resources/kz_create_asset_pack_manifest_plist.rb +0 -44
- data/lib/cocoapods-kz/resources/on_demand_resources/kz_create_on_demand_resources_plis.rb +0 -26
@@ -5,6 +5,10 @@ require_relative 'kz_global_helper'
|
|
5
5
|
|
6
6
|
module KZ
|
7
7
|
|
8
|
+
Initial_Install_Tags = "Initial Install Tags"
|
9
|
+
Prefetched_Tag_Order = "Prefetched Tag Order"
|
10
|
+
Download_Only_On_Demand = "Download Only On Demand"
|
11
|
+
|
8
12
|
class KZPodTarget
|
9
13
|
|
10
14
|
attr_reader :native_pod_target
|
@@ -50,6 +54,9 @@ module KZ
|
|
50
54
|
|
51
55
|
attr_accessor :disable_to_simulator_frameworks
|
52
56
|
|
57
|
+
attr_accessor :on_demand_resources_config_patterns
|
58
|
+
attr_accessor :on_demand_resources_config_path
|
59
|
+
|
53
60
|
def initialize(native_pod_target)
|
54
61
|
@native_pod_target = native_pod_target
|
55
62
|
@name = native_pod_target.name
|
@@ -235,10 +242,11 @@ module KZ
|
|
235
242
|
end
|
236
243
|
|
237
244
|
# 获取target对应的配置根目录,部分文件需要依赖版本进行存储
|
238
|
-
def pod_config_cache_path(concat_version, vendored_framework = false)
|
245
|
+
def pod_config_cache_path(concat_version, vendored_framework = false, on_demand_resources = false)
|
239
246
|
kz_target_config_folder = KZ_POD_CONFIG_POD_TARGETS + @name
|
240
247
|
kz_target_config_folder += @version if concat_version
|
241
248
|
kz_target_config_folder += "vendored_framework" if vendored_framework
|
249
|
+
kz_target_config_folder += "on_demand_resources" if on_demand_resources
|
242
250
|
kz_target_config_folder
|
243
251
|
end
|
244
252
|
|
@@ -341,11 +349,70 @@ module KZ
|
|
341
349
|
@native_pod_target.configuration_build_dir
|
342
350
|
end
|
343
351
|
|
344
|
-
def
|
345
|
-
@
|
352
|
+
def on_demand_resources_info
|
353
|
+
return {} if @on_demand_resources_config_patterns.nil?
|
354
|
+
|
355
|
+
pod_root = self.native_pod_target.sandbox.pod_dir(self.root_name)
|
356
|
+
path_list = Pod::Sandbox::PathList.new(pod_root)
|
357
|
+
list = path_list.glob(@on_demand_resources_config_patterns)
|
358
|
+
result = list.select {|path| path.extname == ".plist" }
|
359
|
+
|
360
|
+
on_demand_resources_info = {}
|
361
|
+
result.each do |config_plist_path|
|
362
|
+
plist_hash = Xcodeproj::Plist.read_from_path(config_plist_path)
|
363
|
+
initial_plist_hash = plist_hash[Initial_Install_Tags]
|
364
|
+
traversal_resource_for_tag(initial_plist_hash, path_list) do |tag_resources|
|
365
|
+
on_demand_resources_info[Initial_Install_Tags] = tag_resources
|
366
|
+
end
|
367
|
+
|
368
|
+
prefetched_plist_hash = plist_hash[Prefetched_Tag_Order]
|
369
|
+
traversal_resource_for_tag(prefetched_plist_hash, path_list) do |tag_resources|
|
370
|
+
on_demand_resources_info[Prefetched_Tag_Order] = tag_resources
|
371
|
+
end
|
372
|
+
|
373
|
+
download_plist_hash = plist_hash[Download_Only_On_Demand]
|
374
|
+
traversal_resource_for_tag(download_plist_hash, path_list) do |tag_resources|
|
375
|
+
on_demand_resources_info[Download_Only_On_Demand] = tag_resources
|
376
|
+
end
|
377
|
+
end
|
378
|
+
on_demand_resources_info
|
379
|
+
end
|
380
|
+
|
381
|
+
def traversal_resource_for_tag(plist_hash, path_list)
|
382
|
+
if !plist_hash.nil? && plist_hash.size > 0
|
383
|
+
tag_resources = {}
|
384
|
+
|
385
|
+
plist_hash.each do |tag, resource_paths|
|
386
|
+
valid_paths = []
|
387
|
+
resource_paths.each do |resource_path|
|
388
|
+
valid_path = path_list.relative_path_in_snadbox?(resource_path)
|
389
|
+
unless valid_path.nil?
|
390
|
+
valid_paths.append(valid_path)
|
391
|
+
end
|
392
|
+
end
|
393
|
+
if valid_paths.size > 0
|
394
|
+
tag_resources[tag] = valid_paths
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
yield(tag_resources)
|
399
|
+
end
|
346
400
|
end
|
347
|
-
|
348
|
-
|
401
|
+
|
402
|
+
def all_xcassets_paths
|
403
|
+
@all_xcassets_paths ||= begin
|
404
|
+
all_xcassets_paths = []
|
405
|
+
native_pod_target.file_accessors.each do |file_accessor|
|
406
|
+
file_accessor.resource_bundles.map do |_, paths|
|
407
|
+
paths.each do |path|
|
408
|
+
if path.extname == ".xcassets"
|
409
|
+
all_xcassets_paths << path
|
410
|
+
end
|
411
|
+
end
|
412
|
+
end
|
413
|
+
end
|
414
|
+
all_xcassets_paths
|
415
|
+
end
|
349
416
|
end
|
350
417
|
|
351
418
|
def get_swift_lldb_ast_path
|
@@ -31,7 +31,7 @@ module KZ
|
|
31
31
|
|
32
32
|
@all_kz_pod_targets.values.each do |kz_pod_target|
|
33
33
|
next unless kz_pod_target.is_dev_pod
|
34
|
-
next unless @specify_pod_names.count > 0 && @specify_pod_names.include?(kz_pod_target.name)
|
34
|
+
next unless @specify_pod_names.count == 0 || (@specify_pod_names.count > 0 && @specify_pod_names.include?(kz_pod_target.name))
|
35
35
|
|
36
36
|
need_repair_files = []
|
37
37
|
kz_pod_target.native_pod_target.file_accessors.each do |file_accessor|
|
@@ -40,14 +40,20 @@ module Pod
|
|
40
40
|
KZ::KZGlobalHelper.instance.kz_pod_config.merge!(kz_pod_config)
|
41
41
|
end
|
42
42
|
|
43
|
-
def
|
44
|
-
|
45
|
-
|
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
|
43
|
+
def odr_target(name, options = nil)
|
44
|
+
if options
|
45
|
+
raise Informative, "Unsupported options `#{options}` for " \
|
46
|
+
"target `#{name}`."
|
50
47
|
end
|
48
|
+
KZ::KZGlobalHelper.instance.on_demand_resources_info.enable = true
|
49
|
+
KZ::KZGlobalHelper.instance.on_demand_resources_info.odr_target_name = name
|
50
|
+
|
51
|
+
parent = current_target_definition
|
52
|
+
definition = TargetDefinition.new(name, parent)
|
53
|
+
self.current_target_definition = definition
|
54
|
+
yield if block_given?
|
55
|
+
ensure
|
56
|
+
self.current_target_definition = parent
|
51
57
|
end
|
52
58
|
|
53
59
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'cocoapods/installer'
|
2
2
|
require 'cocoapods-kz/helpers/kz_global_helper'
|
3
|
-
require 'cocoapods-kz/helpers/
|
3
|
+
require 'cocoapods-kz/helpers/kz_generator_hmap'
|
4
4
|
|
5
5
|
module Pod
|
6
6
|
class Installer
|
@@ -12,6 +12,13 @@ module Pod
|
|
12
12
|
# 因为kz_pod_target提供不少方法,需要判断pod文件情况,所以依赖分析需要挪到download之后
|
13
13
|
if KZ::KZGlobalHelper.instance.generate_kz_pod_targets
|
14
14
|
main_project = aggregate_targets.first.user_project
|
15
|
+
main_project.targets.each do |main_target|
|
16
|
+
if main_target.display_name == KZ::KZGlobalHelper.instance.on_demand_resources_info.odr_target_name
|
17
|
+
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?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
15
22
|
kz_analyer = KZ::KZAnalyzer.new(pod_targets, self.sandbox.development_pods)
|
16
23
|
kz_analyer.analyer
|
17
24
|
KZ::KZGlobalHelper.instance.kz_analyzer = kz_analyer
|
@@ -25,7 +32,8 @@ module Pod
|
|
25
32
|
if KZ::KZGlobalHelper.instance.kz_pod_enable
|
26
33
|
# hmap的创建需要在download之后,integrate之前
|
27
34
|
KZ::KZGlobalHelper.instance.kz_generator.create_hamp
|
28
|
-
|
35
|
+
|
36
|
+
if KZ::KZGlobalHelper.instance.on_demand_resources_info.enable
|
29
37
|
KZ::KZGlobalHelper.instance.kz_generator.create_on_demand_resources
|
30
38
|
end
|
31
39
|
end
|
@@ -42,26 +42,6 @@ module Pod
|
|
42
42
|
|
43
43
|
target_installation_result
|
44
44
|
end
|
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
|
-
|
65
45
|
end
|
66
46
|
end
|
67
47
|
end
|
@@ -27,5 +27,11 @@ module Pod
|
|
27
27
|
{}
|
28
28
|
end
|
29
29
|
end
|
30
|
+
|
31
|
+
def on_demand_resources_config_plists=(paths)
|
32
|
+
if KZ::KZGlobalHelper.instance.on_demand_resources_info.enable
|
33
|
+
KZ::KZGlobalHelper.instance.on_demand_resources_info.config_plist_path_patterns[self.name] = Array(paths)
|
34
|
+
end
|
35
|
+
end
|
30
36
|
end
|
31
37
|
end
|
@@ -23,6 +23,7 @@ module Pod
|
|
23
23
|
pod_targets = self.target.pod_targets_for_build_configuration(generator.configuration_name)
|
24
24
|
|
25
25
|
swift_lldb_ast_paths = []
|
26
|
+
on_demand_resources_config_paths = []
|
26
27
|
pod_targets.each do |native_pod_target|
|
27
28
|
kz_pod_target = native_pod_target.weakRef_kz_pod_target
|
28
29
|
if kz_pod_target
|
@@ -41,6 +42,10 @@ module Pod
|
|
41
42
|
if !ast_path.nil? and generator.configuration_name == "Debug"
|
42
43
|
swift_lldb_ast_paths << ast_path
|
43
44
|
end
|
45
|
+
|
46
|
+
unless kz_pod_target.on_demand_resources_config_path.nil?
|
47
|
+
on_demand_resources_config_paths << (kz_pod_target.name + ":" + kz_pod_target.on_demand_resources_config_path)
|
48
|
+
end
|
44
49
|
end
|
45
50
|
end
|
46
51
|
|
@@ -51,7 +56,17 @@ module Pod
|
|
51
56
|
xcconfig.attributes.delete("EXCLUDED_ARCHS[sdk=iphonesimulator*]")
|
52
57
|
xcconfig.attributes['VALID_ARCHS'] = 'arm64 arm64_32 x86_64'
|
53
58
|
end
|
54
|
-
|
59
|
+
if KZ::KZGlobalHelper.instance.on_demand_resources_info.odr_target_name == self.target.name.sub('Pods-', '')
|
60
|
+
xcconfig.attributes["ENABLE_ON_DEMAND_RESOURCES"] = "NO"
|
61
|
+
|
62
|
+
on_demadn_resources_paths = ""
|
63
|
+
on_demand_resources_config_paths.each do |path|
|
64
|
+
on_demadn_resources_paths += ((on_demadn_resources_paths.empty? ? '' : ' ') + '"' + path + '"')
|
65
|
+
end
|
66
|
+
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
|
+
end
|
69
|
+
|
55
70
|
kz_update_xcconfig_file(xcconfig, path)
|
56
71
|
return
|
57
72
|
end
|
@@ -7,24 +7,18 @@ module Pod
|
|
7
7
|
alias_method :origin_integrate!, :integrate!
|
8
8
|
def integrate!
|
9
9
|
origin_integrate!
|
10
|
-
|
11
|
-
unless KZ::KZGlobalHelper.instance.on_demand_resources_bundle_id.nil?
|
12
|
-
add_on_demand_resources_script_phase
|
13
|
-
end
|
10
|
+
handle_on_demand_resources_script_phase
|
14
11
|
end
|
15
12
|
|
16
|
-
def
|
13
|
+
def handle_on_demand_resources_script_phase
|
17
14
|
phase_name = "[KZ] On Demand Resources Build"
|
18
15
|
native_targets.each do |native_target|
|
19
|
-
|
20
|
-
|
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
|
21
18
|
native_target.build_phases.push(phase).uniq! unless native_target.build_phases.include?(phase)
|
22
19
|
phase.shell_script = KZ.deal_path_for_xcconfig(KZ::KZ_ON_DEMAND_RESOURCES_SHELL, true)
|
23
|
-
|
24
|
-
native_target.
|
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
|
20
|
+
else
|
21
|
+
native_target.build_phases.delete(phase) if native_target.build_phases.include?(phase)
|
28
22
|
end
|
29
23
|
end
|
30
24
|
end
|
data/lib/cocoapods-kz/native.rb
CHANGED
@@ -14,4 +14,6 @@ if Pod.match_version?('~> 1.11')
|
|
14
14
|
require 'cocoapods-kz/native/pods_project_writer'
|
15
15
|
require 'cocoapods-kz/native/pod_target_integrator'
|
16
16
|
require 'cocoapods-kz/native/target_integrator'
|
17
|
+
require 'cocoapods-kz/native/path_list'
|
18
|
+
require 'cocoapods-kz/native/build_configuration'
|
17
19
|
end
|
@@ -0,0 +1,194 @@
|
|
1
|
+
require 'xcodeproj'
|
2
|
+
require "date"
|
3
|
+
require 'fileutils'
|
4
|
+
require 'tmpdir'
|
5
|
+
require 'json'
|
6
|
+
autoload :Nanaimo, 'nanaimo'
|
7
|
+
|
8
|
+
def write_to_path(hash, path)
|
9
|
+
unless path.is_a?(String) || path.is_a?(Pathname)
|
10
|
+
raise TypeError, "The given `#{path}` must be a string or 'pathname'."
|
11
|
+
end
|
12
|
+
path = path.to_s
|
13
|
+
raise IOError, 'Empty path.' if path.empty?
|
14
|
+
|
15
|
+
File.open(path, 'w') do |f|
|
16
|
+
plist = Nanaimo::Plist.new(hash, :xml)
|
17
|
+
Nanaimo::Writer::XMLWriter.new(plist, :pretty => true, :output => f, :strict => false).write
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# shell输入参数
|
22
|
+
kz_on_demand_resources_paths = ENV["KZ_ON_DEMAND_RESOURCES_PATHS"]
|
23
|
+
target_build_dir = Pathname(ENV["TARGET_BUILD_DIR"])
|
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
|
+
app_path = target_build_dir + ENV["UNLOCALIZED_RESOURCES_FOLDER_PATH"]
|
29
|
+
|
30
|
+
# pod过程解析的odr内容路径,放在环境参数KZ_ON_DEMAND_RESOURCES_PATHS中,
|
31
|
+
# 格式为:'"KZChat:/Users/admin/Desktop/RubyProject/washington-ios/Pods/KZPodConfigure/PodTargets/KZChat/on_demand_resources" "KZGeek:/Users/admin/Desktop/RubyProject/washington-ios/Pods/KZPodConfigure/PodTargets/KZGeek/on_demand_resources"'
|
32
|
+
kz_on_demand_resources_info = kz_on_demand_resources_paths.gsub('"', '').split.map { |s| s.split(':', 2) }.to_h
|
33
|
+
# Xcode编译的产物路径,build目录下Product目录,开启odr时,会在这个目录下生成OnDemandResources,因为这里odr改成手动构建,所以此文件夹需要手动创建
|
34
|
+
target_build_on_demand_resources_path = target_build_dir + "OnDemandResources"
|
35
|
+
if ENV["ACTION"] == "install" && ENV["SKIP_INSTALL"] == "NO"
|
36
|
+
target_build_on_demand_resources_path = Pathname(ENV["INSTALL_ROOT"]) + "OnDemandResources"
|
37
|
+
end
|
38
|
+
FileUtils.mkdir_p(target_build_on_demand_resources_path) unless File.exist?(target_build_on_demand_resources_path)
|
39
|
+
|
40
|
+
# 将KZOnDemandResourcesAllConfig.plist拷贝到.app中,用于业务使用代码加载odr资源
|
41
|
+
kz_on_demand_resources_all_config_plist_path = Pathname(ENV["KZ_POD_CONFIG_ROOT"]) + "KZOnDemandResourcesAllConfig.plist"
|
42
|
+
return unless File.exist?(kz_on_demand_resources_all_config_plist_path)
|
43
|
+
FileUtils.cp(kz_on_demand_resources_all_config_plist_path, app_path)
|
44
|
+
|
45
|
+
# 用于在最终.app中生成所有odr信息的plist文件,固定名称为OnDemandResources.plist,系统会自动识别
|
46
|
+
app_on_demand_resources_plist = {}
|
47
|
+
bundle_resource_request_tags = {}
|
48
|
+
app_on_demand_resources_plist["NSBundleResourceRequestTags"] = bundle_resource_request_tags
|
49
|
+
bundle_resource_request_asset_packs = {}
|
50
|
+
app_on_demand_resources_plist["NSBundleResourceRequestAssetPacks"] = bundle_resource_request_asset_packs
|
51
|
+
|
52
|
+
# 遍历所有组件的odr信息,然后将需要的资源进行拷贝
|
53
|
+
kz_on_demand_resources_info.each do |pod_name, kz_on_demand_resources_path|
|
54
|
+
kz_on_demand_resources_path = Pathname(kz_on_demand_resources_path)
|
55
|
+
odr_build_info_plist_paht = kz_on_demand_resources_path + "odr_build_info.plist"
|
56
|
+
next unless File.exist?(odr_build_info_plist_paht)
|
57
|
+
|
58
|
+
odr_build_info = Xcodeproj::Plist.read_from_path(odr_build_info_plist_paht)
|
59
|
+
|
60
|
+
# 获取对应组件的bundle,如果没有需要创建,这里的bundle名称会与target名称相同
|
61
|
+
pod_bundle_path = Pathname(app_path) + "#{pod_name}.bundle"
|
62
|
+
FileUtils.mkdir_p(pod_bundle_path) unless File.exist?(pod_bundle_path)
|
63
|
+
|
64
|
+
# 将预处理的OnDemandResources拷贝到Product的OnDemandResources中
|
65
|
+
on_demand_resources_build_path = kz_on_demand_resources_path + "OnDemandResources"
|
66
|
+
FileUtils.cp_r("#{on_demand_resources_build_path}/.", target_build_on_demand_resources_path)
|
67
|
+
|
68
|
+
# 将组件自己的OnDemandResources.plist拷贝到组件bundle中,这里bundle其实也是一种app,也需要OnDemandResources.plist,用于系统识别odr资源
|
69
|
+
bundle_on_demand_resources_plist_path = kz_on_demand_resources_path + "OnDemandResources.plist"
|
70
|
+
FileUtils.cp(bundle_on_demand_resources_plist_path, pod_bundle_path + "OnDemandResources.plist")
|
71
|
+
# 读取组件的OnDemandResources.plist中的tag信息,用于最终.app中生成的OnDemandResources.plist
|
72
|
+
bundle_on_demand_resources_plist = Xcodeproj::Plist.read_from_path(bundle_on_demand_resources_plist_path)
|
73
|
+
bundle_resource_request_tags.update(bundle_on_demand_resources_plist["NSBundleResourceRequestTags"])
|
74
|
+
bundle_resource_request_asset_packs.update(bundle_on_demand_resources_plist["NSBundleResourceRequestAssetPacks"])
|
75
|
+
|
76
|
+
# 清除已经编译的普通非odr资源
|
77
|
+
if odr_build_info["normal_files"]
|
78
|
+
odr_build_info["normal_files"].each do |file_name|
|
79
|
+
normal_file_path = pod_bundle_path + file_name
|
80
|
+
FileUtils.rm_rf(normal_file_path) if File.exist?(normal_file_path)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# 将pod install过程生成的AssetPackOutputSpecifications拷贝到编译临时目录,并修改AssetPackOutputSpecifications.plist中的路径
|
85
|
+
kz_asset_pack_output_specifications_plist_path = kz_on_demand_resources_path + "AssetPackOutputSpecifications.plist"
|
86
|
+
next unless File.exist?(kz_asset_pack_output_specifications_plist_path)
|
87
|
+
# 在Xcode编译过程中,会在build目录下生成一个临时目录,用于存放AssetPackOutputSpecifications.plist(该文件在pod install过程中生成了模版,拷贝到这里会进行修改后才能使用)
|
88
|
+
build_on_demand_resources_temp_path = target_build_temp_dir + pod_name + "KZOnDemandResources"
|
89
|
+
FileUtils.mkdir_p(build_on_demand_resources_temp_path) unless File.exist?(build_on_demand_resources_temp_path)
|
90
|
+
FileUtils.cp(kz_asset_pack_output_specifications_plist_path, build_on_demand_resources_temp_path)
|
91
|
+
|
92
|
+
# 修改编译临时目录中AssetPackOutputSpecifications.plist文件标记资源的真实路径
|
93
|
+
asset_pack_output_specifications_plist_path = build_on_demand_resources_temp_path + "AssetPackOutputSpecifications.plist"
|
94
|
+
asset_pack_output_specifications_plist = Xcodeproj::Plist.read_from_path(asset_pack_output_specifications_plist_path)
|
95
|
+
asset_pack_output_specifications_plist.each do |item|
|
96
|
+
bundle_paht = item["bundle-path"]
|
97
|
+
unless bundle_paht.start_with?(target_build_on_demand_resources_path.to_s)
|
98
|
+
item["bundle-path"] = target_build_on_demand_resources_path + bundle_paht
|
99
|
+
end
|
100
|
+
end
|
101
|
+
write_to_path(asset_pack_output_specifications_plist, asset_pack_output_specifications_plist_path)
|
102
|
+
|
103
|
+
# 处理xcasset资源编译,从odr_info中读取原始xcasset资源,为了不破坏原有资源,这里将原始资源拷贝到临时目录,并修改对应的odr信息,然后使用actool进行编译
|
104
|
+
all_xcassets = odr_build_info["all_xcassets"]
|
105
|
+
unless all_xcassets.nil?
|
106
|
+
temp_dir = Pathname(Dir.mktmpdir)
|
107
|
+
xcasset_files = []
|
108
|
+
all_xcassets.each do |xcassets_name, xcassets_info|
|
109
|
+
path = xcassets_info["path"]
|
110
|
+
next if path.nil? || path.empty? || !File.exist?(path)
|
111
|
+
path = Pathname(path)
|
112
|
+
tags = xcassets_info["tags"]
|
113
|
+
next if tags.nil? || tags.empty?
|
114
|
+
|
115
|
+
FileUtils.cp_r(path, temp_dir)
|
116
|
+
new_path = temp_dir + path.basename
|
117
|
+
xcasset_files << new_path
|
118
|
+
|
119
|
+
tags.each do |imageset_name, tag|
|
120
|
+
content_json_path = new_path + imageset_name + "Contents.json"
|
121
|
+
content_json = JSON.parse(File.read(content_json_path))
|
122
|
+
content_json["properties"] = { "on-demand-resource-tags" => [tag] }
|
123
|
+
content_json_file = File.new(content_json_path, 'w')
|
124
|
+
content_json_file.syswrite(JSON.pretty_generate(content_json))
|
125
|
+
end
|
126
|
+
end
|
127
|
+
next if xcasset_files.empty?
|
128
|
+
|
129
|
+
# 将所有配置好的xcasset资源进行编译,生成odr资源,odr资源到Product的OnDemandResources中,非odr资源放到组件bundle中
|
130
|
+
if ENV["WRAPPER_EXTENSION"] && `xcrun --find actool`.strip != "" && !xcasset_files.empty?
|
131
|
+
actool_cmd = [
|
132
|
+
"xcrun", "actool",
|
133
|
+
"--output-format", "human-readable-text",
|
134
|
+
"--notices", "--warnings",
|
135
|
+
"--platform", ENV["PLATFORM_NAME"],
|
136
|
+
"--minimum-deployment-target", ENV["#{ENV['DEPLOYMENT_TARGET_SETTING_NAME']}"],
|
137
|
+
*ENV["TARGET_DEVICE_ARGS"].to_s.split,
|
138
|
+
"--compress-pngs",
|
139
|
+
"--enable-on-demand-resources", "YES",
|
140
|
+
"--asset-pack-output-specifications", asset_pack_output_specifications_plist_path.to_s,
|
141
|
+
"--compile", pod_bundle_path.to_s,
|
142
|
+
*xcasset_files.map(&:to_s)
|
143
|
+
].compact
|
144
|
+
system(*actool_cmd)
|
145
|
+
end
|
146
|
+
FileUtils.rm_rf(temp_dir)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
# OnDemandResources.plist放到.app中,用于系统读取odr资源
|
151
|
+
app_on_demand_resources_plist_path = app_path + "OnDemandResources.plist"
|
152
|
+
write_to_path(app_on_demand_resources_plist, app_on_demand_resources_plist_path)
|
153
|
+
|
154
|
+
# 生成AssetPackManifestTemplate.plist放到.app中,用于系统读取odr记载路径与信息(archive时,系统会使用此文件生成新的AssetPackManifest.plist)
|
155
|
+
asset_pack_manifest_template_plist_path = app_path + "AssetPackManifestTemplate.plist"
|
156
|
+
manifest_url = "http://127.0.0.1"
|
157
|
+
|
158
|
+
manifest_template_plist_hash = {}
|
159
|
+
manifest_template_resources = []
|
160
|
+
manifest_template_plist_hash["resources"] = manifest_template_resources
|
161
|
+
|
162
|
+
Dir.foreach(target_build_on_demand_resources_path) do |sub_file|
|
163
|
+
if sub_file != "." && sub_file != ".." && sub_file != ".DS_Store"
|
164
|
+
resources_item = {}
|
165
|
+
primary_content_hash = {}
|
166
|
+
time = Time.now
|
167
|
+
primary_content_hash["hash"] = time.utc.strftime('%Y-%m-%dT%H:%M:%S.000Z')
|
168
|
+
primary_content_hash["strategy"] = "modtime"
|
169
|
+
resources_item["primaryContentHash"] = primary_content_hash
|
170
|
+
resources_item["isStreamable"] = true
|
171
|
+
total_size = 0
|
172
|
+
Dir.foreach(target_build_on_demand_resources_path + sub_file) do |resource|
|
173
|
+
if resource != "." && resource != ".." && resource != ".DS_Store"
|
174
|
+
if resource == "Info.plist"
|
175
|
+
info_plist = Xcodeproj::Plist.read_from_path(target_build_on_demand_resources_path + sub_file + resource)
|
176
|
+
priority = info_plist["Priority"]
|
177
|
+
if priority && priority > 0
|
178
|
+
resources_item["downloadPriority"] = priority
|
179
|
+
end
|
180
|
+
resources_item["bundleKey"] = info_plist["CFBundleIdentifier"]
|
181
|
+
else
|
182
|
+
resources_item["URL"] = "#{manifest_url}#{target_build_on_demand_resources_path}/#{sub_file}"
|
183
|
+
total_size = total_size + File.size(target_build_on_demand_resources_path + sub_file + resource)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
resources_item["uncompressedSize"] = total_size
|
188
|
+
manifest_template_resources << resources_item
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
if manifest_template_resources.size > 0
|
193
|
+
write_to_path(manifest_template_plist_hash, asset_pack_manifest_template_plist_path)
|
194
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
#!/bin/sh
|
2
2
|
|
3
3
|
set -e
|
4
4
|
set -u
|
@@ -13,14 +13,8 @@ if [ -z ${UNLOCALIZED_RESOURCES_FOLDER_PATH+x} ]; then
|
|
13
13
|
exit 0
|
14
14
|
fi
|
15
15
|
|
16
|
-
|
17
|
-
|
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
|
16
|
+
if [ -z "${KZ_ON_DEMAND_RESOURCES_PATHS+x}" ]; then
|
17
|
+
exit 0
|
24
18
|
fi
|
25
19
|
|
26
20
|
case "${TARGETED_DEVICE_FAMILY:-}" in
|
@@ -88,75 +82,4 @@ if [ -z $RUBY_PATH ];then
|
|
88
82
|
exit 1
|
89
83
|
fi
|
90
84
|
|
91
|
-
|
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}"
|
85
|
+
$RUBY_PATH "${KZ_POD_CONFIG_ROOT}/SupportFiles/on_demand_resources/kz_on_demand_resources_process.rb"
|