8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/hmap_optimize.rb', line 8
def self.post_install(installer)
to_remove = -> path { path.include?("${PODS_ROOT}/Headers/Public/") || path.include?("${PODS_ROOT}/Headers/hmap/") }
= -> path do
@cached_headers ||= {}
cached = @cached_headers.fetch(path, {})
return cached unless cached.blank?
full_path = path.sub(/^\$\{PODS_ROOT\}/, installer.sandbox.root.to_s)
= Dir.glob("#{full_path}/**/{*.h,*.hpp}")
return {} if .blank?
= .to_h do ||
prefix = File.dirname()
relative_dir = prefix.sub(/^#{full_path}/, '').sub(/^\//, '')
file_name = File.basename()
file_name = File.join(relative_dir, file_name) unless relative_dir.blank?
= {}
['suffix'] = File.basename()
['prefix'] = prefix + "/"
[file_name, ]
end
@cached_headers[path] =
end
create_hmap = -> build_settings do
= build_settings.
return if .blank?
convert_paths = .select { |p| to_remove.call(p) }
return if convert_paths.blank?
convert_paths_string = convert_paths.join(" ")&.strip
md5_string = Digest::MD5.hexdigest(convert_paths_string)
UI.message "md5(#{convert_paths_string})=#{md5_string}"
hmap_dir = File.expand_path("Headers/hmap", installer.sandbox.root.to_s)
hmap_path = File.expand_path("#{md5_string}.hmap", hmap_dir)
if File.exist?(hmap_path)
return md5_string
end
= convert_paths.map { |x| .call(x) }.inject(:merge)
return if .blank?
FileUtils.mkdir_p(hmap_dir) unless File.directory?(hmap_dir)
json_path = File.expand_path("#{md5_string}.json", hmap_dir)
File.open(json_path, 'w') do |file|
file << .to_json
end
hmap = File.expand_path("hmap", File.dirname(__FILE__ ))
`#{hmap} convert '#{json_path}' '#{hmap_path}' `
File.delete(json_path)
UI.message "created hmap #{hmap_path}"
return md5_string
end
handle_target_with_settings = -> hmap_md5, target, config do
return if hmap_md5.blank?
xcconfig_path = target.xcconfig_path(config)
return unless File.exist?(xcconfig_path)
xcconfig = Xcodeproj::Config.new(xcconfig_path)
hmap_path = File.expand_path("Headers/hmap/#{hmap_md5}.hmap", installer.sandbox.root.to_s)
return unless File.exist?(hmap_path)
hmap_item = "\"${PODS_ROOT}/Headers/hmap/#{hmap_md5}.hmap\""
= xcconfig.to_hash['HEADER_SEARCH_PATHS']
path_items = .split(/\s+/)
keep_paths = path_items.reject { |p| to_remove.call(p) }
keep_paths << hmap_item
= keep_paths.join(" ")
xcconfig.attributes['HEADER_SEARCH_PATHS'] =
xcconfig.save_as(xcconfig_path)
end
installer.aggregate_targets.each do |aggregate_target|
UI.message "convert hmap for aggregate_target #{aggregate_target}"
aggregate_target.user_build_configurations.each_key do |config| build_settings = aggregate_target.build_settings(config) hmap_md5 = create_hmap.call(build_settings)
handle_target_with_settings.call(hmap_md5, aggregate_target, config)
end
end
installer.pod_targets.each do |pod_target|
UI.message "convert hmap for pod_target #{pod_target}"
pod_target.build_settings.each do |config, build_settings| hmap_md5 = create_hmap.call(build_settings)
handle_target_with_settings.call(hmap_md5, pod_target, config)
end
end
end
|