cocoapods-hmap-simple 1.0.1 → 1.0.2

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 (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hmap_optimize.rb +76 -89
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 250c86d07ab698229d2c1683751d8de2505af1e5438c55e8b3b186aa20f4dc36
4
- data.tar.gz: cb0a9e02ed361ca71e6e8c04f1d58f0a05f9635bb6d7a44dc270c1f0b116c9c1
3
+ metadata.gz: 533c0f5130721d03cd3f2faf06d940caa8b82e60015eb76c35a4ce2f108d1389
4
+ data.tar.gz: 1d39859b22204520e9a18c78154c4a560fa831b0d7bc0bfe2303ab36d4c20cd2
5
5
  SHA512:
6
- metadata.gz: 76b7e5bf4fdd3591f3e865a2094771bddc58cb320bad99047fab61c112eb19ea8b9dcda5a8da5b136c793296eec29fe83660e48cb552c2195ff63c673029671a
7
- data.tar.gz: abc8efb050e94118684bb9241504d5d0cc69826007b4f3c3251be574fa72f8ad01e13ba254f0da8e250f6ead2d23539b3064eaae87f49406931ebc706ede5872
6
+ metadata.gz: cfbcb9cf8fad7c176e82fbbf03f9213ce25f146e0429989979baf9e61d71f71f81006a2ee0985dc0b7228ba26accb76988224fe65012404851220b2f2f998daf
7
+ data.tar.gz: 4f4281be9706877de371d7aca837f5a6521863b090a6ea2d741ac9deebe4a1a48c6040b5369f947cf03657218a6fdc03b107d2ec2ad03e58742d24b5e910a257
data/lib/hmap_optimize.rb CHANGED
@@ -4,132 +4,119 @@ combining "${PODS_ROOT}/Headers/Public/*" to a single hmap. (not including ${POD
4
4
  =end
5
5
 
6
6
  module Pod
7
- class Target
8
- class BuildSettings
9
- attr_accessor :hmap_md5
10
- end
11
- end
12
-
13
- class Installer
14
- # helper functions
15
- def to_remove?(header_search_path)
16
- header_search_path.include?("${PODS_ROOT}/Headers/Public/")
17
- end
18
-
19
- def headers_for_path(path)
20
- @cached_headers ||= {}
21
- cached = @cached_headers.fetch(path, {})
22
- return cached unless cached.blank?
23
-
24
- full_path = path.sub(/^\$\{PODS_ROOT\}/, sandbox.root.to_s)
25
- headers = Dir.glob("#{full_path}/**/{*.h,*.hpp}")
26
- return {} if headers.blank?
27
-
28
- target_headers_hash = headers.to_h do |header|
29
- prefix = File.dirname(header)
30
- relative_dir = prefix.sub(/^#{full_path}/, '').sub(/^\//, '')
31
- file_name = File.basename(header)
32
- file_name = File.join(relative_dir, file_name) unless relative_dir.blank?
33
-
34
- sub_header_hash = {}
35
- sub_header_hash['suffix'] = File.basename(header)
36
- sub_header_hash['prefix'] = prefix + "/"
37
-
38
- [file_name, sub_header_hash]
7
+ class HmapHelper
8
+ def self.post_install(installer)
9
+ to_remove = -> path { path.include?("${PODS_ROOT}/Headers/Public/") }
10
+
11
+ headers_for_path = -> path do
12
+ @cached_headers ||= {}
13
+ cached = @cached_headers.fetch(path, {})
14
+ return cached unless cached.blank?
15
+
16
+ full_path = path.sub(/^\$\{PODS_ROOT\}/, installer.sandbox.root.to_s)
17
+ headers = Dir.glob("#{full_path}/**/{*.h,*.hpp}")
18
+ return {} if headers.blank?
19
+
20
+ target_headers_hash = headers.to_h do |header|
21
+ prefix = File.dirname(header)
22
+ relative_dir = prefix.sub(/^#{full_path}/, '').sub(/^\//, '')
23
+ file_name = File.basename(header)
24
+ file_name = File.join(relative_dir, file_name) unless relative_dir.blank?
25
+
26
+ sub_header_hash = {}
27
+ sub_header_hash['suffix'] = File.basename(header)
28
+ sub_header_hash['prefix'] = prefix + "/"
29
+
30
+ [file_name, sub_header_hash]
31
+ end
32
+ @cached_headers[path] = target_headers_hash
33
+ target_headers_hash
39
34
  end
40
- @cached_headers[path] = target_headers_hash
41
- target_headers_hash
42
- end
43
35
 
44
- def create_hmap(build_settings)
45
- header_search_paths = build_settings.header_search_paths
46
- return if header_search_paths.blank?
36
+ create_hmap = -> build_settings do
37
+ header_search_paths = build_settings.header_search_paths
38
+ return if header_search_paths.blank?
47
39
 
48
- convert_paths = header_search_paths.select { |p| to_remove?(p) }
49
- return if convert_paths.blank?
40
+ convert_paths = header_search_paths.select { |p| to_remove.call(p) }
41
+ return if convert_paths.blank?
50
42
 
51
- convert_paths_string = convert_paths.join(" ")&.strip
52
- md5_string = Digest::MD5.hexdigest(convert_paths_string)
43
+ convert_paths_string = convert_paths.join(" ")&.strip
44
+ md5_string = Digest::MD5.hexdigest(convert_paths_string)
53
45
 
54
- UI.message "md5(#{convert_paths_string})=#{md5_string}"
46
+ UI.message "md5(#{convert_paths_string})=#{md5_string}"
55
47
 
56
- hmap_dir = File.expand_path("Headers/hmap", sandbox.root.to_s)
57
- hmap_path = File.expand_path("#{md5_string}.hmap", hmap_dir)
58
- if File.exist?(hmap_path)
59
- build_settings.hmap_md5 = md5_string
60
- return
61
- end
48
+ hmap_dir = File.expand_path("Headers/hmap", installer.sandbox.root.to_s)
49
+ hmap_path = File.expand_path("#{md5_string}.hmap", hmap_dir)
50
+ if File.exist?(hmap_path)
51
+ return md5_string
52
+ end
62
53
 
63
- header_path_hash = convert_paths.map { |x| headers_for_path(x) }.inject(:merge)
64
- return if header_path_hash.blank?
54
+ header_path_hash = convert_paths.map { |x| headers_for_path.call(x) }.inject(:merge)
55
+ return if header_path_hash.blank?
65
56
 
66
- begin
67
57
  FileUtils.mkdir_p(hmap_dir) unless File.directory?(hmap_dir)
68
58
  json_path = File.expand_path("#{md5_string}.json", hmap_dir)
69
59
  File.open(json_path, 'w') do |file|
70
60
  file << header_path_hash.to_json
71
61
  end
72
62
 
73
- convert_json_to_hmap(json_path, hmap_path)
63
+ hmap = File.expand_path("hmap", File.dirname(__FILE__ ))
64
+ `#{hmap} convert '#{json_path}' '#{hmap_path}' `
74
65
  File.delete(json_path)
75
66
 
76
- build_settings.hmap_md5 = md5_string
77
67
  UI.message "created hmap #{hmap_path}"
78
- rescue => e
79
- UI.warn "create hmap error: #{e.inspect}"
68
+ return md5_string
80
69
  end
81
- end
82
70
 
83
- def convert_json_to_hmap(public_json, public_hmap)
84
- hmap = File.expand_path("hmap", File.dirname(__FILE__ ))
85
- `#{hmap} convert '#{public_json}' '#{public_hmap}' `
86
- end
71
+ handle_target_with_settings = -> hmap_md5, target, config do
72
+ return if hmap_md5.blank?
87
73
 
88
- def handle_target_with_settings(build_settings, xcconfig, xcconfig_path)
89
- return if build_settings.blank? || build_settings.hmap_md5.blank?
74
+ xcconfig_path = target.xcconfig_path(config)
75
+ xcconfig = Xcodeproj::Config.new(xcconfig_path)
90
76
 
91
- hmap_path = File.expand_path("Headers/hmap/#{build_settings.hmap_md5}.hmap", sandbox.root.to_s)
92
- return unless File.exist?(hmap_path)
77
+ hmap_path = File.expand_path("Headers/hmap/#{hmap_md5}.hmap", installer.sandbox.root.to_s)
78
+ return unless File.exist?(hmap_path)
93
79
 
94
- hmap_item = "\"${PODS_ROOT}/Headers/hmap/#{build_settings.hmap_md5}.hmap\""
80
+ hmap_item = "\"${PODS_ROOT}/Headers/hmap/#{hmap_md5}.hmap\""
95
81
 
96
- header_search_paths = xcconfig.to_hash['HEADER_SEARCH_PATHS']
97
- path_items = header_search_paths.split(/\s+/)
82
+ header_search_paths = xcconfig.to_hash['HEADER_SEARCH_PATHS']
83
+ path_items = header_search_paths.split(/\s+/)
98
84
 
99
- keep_paths = path_items.reject { |p| to_remove?(p) }
100
- keep_paths << hmap_item
85
+ keep_paths = path_items.reject { |p| to_remove.call(p) }
86
+ keep_paths << hmap_item
101
87
 
102
- new_header_search_paths = keep_paths.join(" ")
103
- xcconfig.attributes['HEADER_SEARCH_PATHS'] = new_header_search_paths
104
- xcconfig.save_as(xcconfig_path)
105
- end
88
+ new_header_search_paths = keep_paths.join(" ")
89
+ xcconfig.attributes['HEADER_SEARCH_PATHS'] = new_header_search_paths
90
+ xcconfig.save_as(xcconfig_path)
91
+ end
106
92
 
107
- # hook point
108
- alias_method :_old_run_podfile_post_install_hook, :run_podfile_post_install_hook
109
- def run_podfile_post_install_hook
110
93
  # 生成 hmap file,然后修改 xcconfig 文件
111
- aggregate_targets.each do |aggregate_target|
94
+ installer.aggregate_targets.each do |aggregate_target|
112
95
  UI.message "convert hmap for aggregate_target #{aggregate_target}"
113
96
  aggregate_target.user_build_configurations.each_key do |config| # "Debug" => :debug
114
97
  build_settings = aggregate_target.build_settings(config) # AggregateTargetSettings
115
- create_hmap(build_settings)
116
-
117
- xcconfig_path = aggregate_target.xcconfig_path(config)
118
- xcconfig = aggregate_target.xcconfigs[config]
119
- handle_target_with_settings(build_settings, xcconfig, xcconfig_path)
98
+ hmap_md5 = create_hmap.call(build_settings)
99
+ handle_target_with_settings.call(hmap_md5, aggregate_target, config)
120
100
  end
121
101
  end
122
102
 
123
- pod_targets.each do |pod_target|
103
+ installer.pod_targets.each do |pod_target|
124
104
  UI.message "convert hmap for pod_target #{pod_target}"
125
105
  pod_target.build_settings.each do |config, build_settings| # "Debug" => PodTargetSettings
126
- create_hmap(build_settings)
127
-
128
- xcconfig_path = pod_target.xcconfig_path(config)
129
- xcconfig = Xcodeproj::Config.new(xcconfig_path)
130
- handle_target_with_settings(build_settings, xcconfig, xcconfig_path)
106
+ hmap_md5 = create_hmap.call(build_settings)
107
+ handle_target_with_settings.call(hmap_md5, pod_target, config)
131
108
  end
132
109
  end
110
+ end
111
+ end
112
+ end
113
+
114
+ # hook point
115
+ module Pod
116
+ class Installer
117
+ alias_method :_old_run_podfile_post_install_hook, :run_podfile_post_install_hook
118
+ def run_podfile_post_install_hook
119
+ HmapHelper.post_install(self)
133
120
 
134
121
  _old_run_podfile_post_install_hook
135
122
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-hmap-simple
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - shyang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-06 00:00:00.000000000 Z
11
+ date: 2022-03-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |-
14
14
  This plugin modifies HEADER_SEARCH_PATHS in Pods/Target Support Files/*/*.xcconfig
@@ -41,7 +41,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
41
41
  - !ruby/object:Gem::Version
42
42
  version: '0'
43
43
  requirements: []
44
- rubygems_version: 3.2.22
44
+ rubygems_version: 3.0.3
45
45
  signing_key:
46
46
  specification_version: 4
47
47
  summary: A simple hmap generating plugin for cocoapods.