cocoapods-hmap-prebuilt 0.0.2 → 0.0.7

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.
@@ -1,85 +0,0 @@
1
-
2
- require 'cocoapods'
3
-
4
- module HMap
5
- # A collection of Helper functions used throughout cocoapods-hmap-prebuilt.
6
- module Helper
7
- # A collection of PodHelper functions used throughout cocoapods-hmap-prebuilt.
8
- module PodHelper
9
- HEADER_EXTENSIONS = Pod::Sandbox::FileAccessor::HEADER_EXTENSIONS
10
-
11
- def self.pod_analyze(config)
12
- podfile = Pod::Podfile.from_file(config.podfile_path)
13
- lockfile = Pod::Lockfile.from_file(config.lockfile_path)
14
- Pod::Installer::Analyzer.new(config.sandbox, podfile, lockfile).analyze
15
- end
16
-
17
- # @!group Private helpers
18
-
19
- # Returns the list of the paths founds in the file system for the
20
- # attribute with given name. It takes into account any dir pattern and
21
- # any file excluded in the specification.
22
- #
23
- # @param [Symbol] attribute
24
- # the name of the attribute.
25
- #
26
- # @return [Array<Pathname>] the paths.
27
- #
28
- def self.paths_for_attribute(key, attribute, include_dirs: false)
29
- file_patterns = key.spec_consumer.send(attribute)
30
- options = {
31
- exclude_patterns: key.spec_consumer.exclude_files,
32
- dir_pattern: Pod::Sandbox::FileAccessor::GLOB_PATTERNS[attribute],
33
- include_dirs: include_dirs
34
- }
35
- extensions = HEADER_EXTENSIONS
36
- key.path_list.relative_glob(file_patterns, options).map do |f|
37
- [f, key.path_list.root.join(f)] if extensions.include?(f.extname)
38
- end.compact
39
- end
40
-
41
- def self.header_mappings(file_accessor, headers, target)
42
- consumer = file_accessor.spec_consumer
43
- header_mappings_dir = consumer.header_mappings_dir
44
- dir = target.headers_sandbox
45
- dir_h = Pathname.new(target.product_module_name)
46
- dir += consumer.header_dir if consumer.header_dir
47
- mappings = {}
48
- headers.each do |header|
49
- next if header.to_s.include?('.framework/')
50
-
51
- sub_dir = [dir, dir_h]
52
- if header_mappings_dir
53
- relative_path = header.relative_path_from(file_accessor.path_list.root + header_mappings_dir)
54
- sub_dir << dir + relative_path.dirname
55
- sub_dir << dir_h + relative_path.dirname
56
- else
57
- relative_path = header.relative_path_from(file_accessor.path_list.root)
58
- sub_dir << relative_path.dirname
59
- end
60
- mappings[header] ||= []
61
- sub_dir.uniq.each do |d|
62
- mappings[header] << d + header.basename
63
- end
64
- mappings[header] << header.basename
65
- end
66
- mappings
67
- end
68
-
69
- def self.pod_target_source_header(target, hmap_t)
70
- target.header_mappings_by_file_accessor.keys.flat_map do |key|
71
- paths_for_attribute(key, hmap_t)
72
- end
73
- end
74
-
75
- def self.pod_target_source_header_map(target, hmap_t)
76
- pod_target_source_header(target, hmap_t).each_with_object({}) do |f, sum|
77
- file = f[1]
78
- key = f[0].to_s
79
- r_key = file.basename.to_s
80
- sum[r_key] = [key, r_key].uniq
81
- end
82
- end
83
- end
84
- end
85
- end
@@ -1,264 +0,0 @@
1
-
2
- module HMap
3
- HEADER_CONST = {
4
- HMAP_HEADER_MAGIC_NUMBER: 0x686d6170,
5
- HMAP_HEADER_VERSION: 0x0001,
6
- HMAP_EMPTY_BUCKT_KEY: 0,
7
- HMAP_SWAPPED_MAGIC: 0x70616d68,
8
- HMAP_SWAPPED_VERSION: 0x0100
9
- }.freeze
10
-
11
- # A general purpose pseudo-structure.
12
- # @abstract
13
- class HMapStructure
14
- # The String#unpack format of the data structure.
15
- # @return [String] the unpacking format
16
- # @api private
17
- FORMAT = ''
18
-
19
- # The size of the data structure, in bytes.
20
- # @return [Integer] the size, in bytes
21
- # @api private
22
- SIZEOF = 0
23
-
24
- SWAPPED = true
25
-
26
- # @return [Integer] the size, in bytes, of the represented structure.
27
- def self.bytesize
28
- self::SIZEOF
29
- end
30
-
31
- def self.format
32
- self::FORMAT
33
- end
34
-
35
- def self.swapped?
36
- self::SWAPPED
37
- end
38
-
39
- # @param swapped [Bool] the swapped of the mapfile
40
- # @param bin [String] the string to be unpacked into the new structure
41
- # @return [HMap::HMapStructure] the resulting structure
42
- # @api private
43
- def self.new_from_bin(swapped, bin)
44
- format = Utils.specialize_format(self::FORMAT, swapped)
45
- new(*bin.unpack(format))
46
- end
47
-
48
- def serialize
49
- [].pack(format)
50
- end
51
-
52
- # @return [Hash] a hash representation of this {HMapStructure}.
53
- def to_h
54
- {
55
- 'structure' => {
56
- 'format' => self.class::FORMAT,
57
- 'bytesize' => self.class.bytesize
58
- }
59
- }
60
- end
61
- end
62
-
63
- # HMapHeader structure.
64
- # @see https://clang.llvm.org/doxygen/structclang_1_1HMapHeader.html
65
- # @abstract
66
- class HMapHeader < HMapStructure
67
- # @return [HMap::HMapView, nil] the raw view associated with the load command,
68
- # or nil if the HMapHeader was created via {create}.
69
- attr_reader :num_entries, :magic, :version, :reserved, :strings_offset, :num_buckets, :max_value_length
70
-
71
- FORMAT = 'L=1S=2L4'
72
- # @see HMapStructure::SIZEOF
73
- # @api private
74
- SIZEOF = 24
75
-
76
- # @api private
77
- def initialize(magic, version, reserved, strings_offset, num_entries, num_buckets, max_value_length)
78
- @magic = magic
79
- @version = version
80
- @reserved = reserved
81
- @strings_offset = strings_offset
82
- @num_entries = num_entries
83
- @num_buckets = num_buckets
84
- @max_value_length = max_value_length
85
- super()
86
- end
87
-
88
- # @return [String] the serialized fields of the mafile
89
- def serialize
90
- format = Utils.specialize_format(FORMAT, SWAPPED)
91
- [magic, version, reserved, strings_offset, num_entries, num_buckets, max_value_length].pack(format)
92
- end
93
-
94
- def description
95
- <<-DESC
96
- Hash bucket count: #{@num_buckets}
97
- String table entry count: #{@num_entries}
98
- Max value length: #{@max_value_length}
99
- DESC
100
- end
101
-
102
- def to_h
103
- {
104
- 'magic' => magic,
105
- 'version' => version,
106
- 'reserved' => reserved,
107
- 'strings_offset' => strings_offset,
108
- 'num_entries' => num_entries,
109
- 'num_buckets' => num_buckets,
110
- 'max_value_length' => max_value_length
111
- }.merge super
112
- end
113
- end
114
-
115
- # HMapBucketStr => HMapBucket.
116
- # @see https://clang.llvm.org/doxygen/structclang_1_1HMapHeader.html
117
- # @abstract
118
- class HMapBucketStr
119
- attr_reader :uuid, :key, :perfix, :suffix
120
-
121
- def initialize(key, perfix, suffix)
122
- @uuid = Utils.string_downcase_hash(key)
123
- @key = key
124
- @perfix = perfix
125
- @suffix = suffix
126
- @str_ins = {}
127
- end
128
-
129
- def bucket_to_string(headers, index)
130
- bucket = [key, perfix, suffix]
131
- bucket.inject('') do |sum, arg|
132
- if headers[arg].nil?
133
- headers[arg] = sum.length + index
134
- sum += "#{Utils.safe_encode(arg, 'ASCII-8BIT')}\0"
135
- end
136
- @str_ins[arg] = headers[arg]
137
- sum
138
- end
139
- end
140
-
141
- def bucket
142
- HMapBucket.new(@str_ins[@key], @str_ins[@perfix], @str_ins[@suffix])
143
- end
144
-
145
- # @return [String] the serialized fields of the mafile
146
- def serialize
147
- bucket.serialize
148
- end
149
-
150
- def description
151
- <<-DESC
152
- Key #{@key} -> Prefix #{@perfix}, Suffix #{@suffix}
153
- DESC
154
- end
155
-
156
- def to_h
157
- {
158
- 'key' => { 'index' => str_ins[@key], 'key' => @key },
159
- 'perfix' => { 'index' => str_ins[@perfix], 'perfix' => @perfix },
160
- 'suffix' => { 'index' => str_ins[@suffix], 'suffix' => @suffix }
161
- }
162
- end
163
- end
164
-
165
- # HMapBucket structure.
166
- # @see https://clang.llvm.org/doxygen/structclang_1_1HMapHeader.html
167
- # @abstract
168
- class HMapBucket < HMapStructure
169
- attr_accessor :key, :perfix, :suffix
170
-
171
- SIZEOF = 12
172
-
173
- FORMAT = 'L=3'
174
-
175
- def initialize(key, perfix, suffix)
176
- @key = key
177
- @perfix = perfix
178
- @suffix = suffix
179
- super()
180
- end
181
-
182
- # @return [String] the serialized fields of the mafile
183
- def serialize
184
- format = Utils.specialize_format(FORMAT, SWAPPED)
185
- [key, perfix, suffix].pack(format)
186
- end
187
-
188
- def to_a
189
- [key, perfix, suffix]
190
- end
191
-
192
- def to_h
193
- {
194
- 'key' => key,
195
- 'perfix' => perfix,
196
- 'suffix' => suffix
197
- }.merge super
198
- end
199
- end
200
-
201
- # HMap blobs.
202
- class HMapData
203
- def initialize(buckets)
204
- super()
205
- count = buckets.count
206
- nums = num_buckets(count, Utils.next_power_of_two(count))
207
- entries = entries(count, nums)
208
- @header = populate_hmap_header(nums, entries)
209
- @buckets = add_bucket(buckets, nums)
210
- end
211
-
212
- def num_buckets(count, pow2)
213
- if count < 8
214
- pow2 <<= 1 if count * 4 >= pow2 * 3
215
- pow2 < 8 ? 8 : pow2
216
- else
217
- index = count > 341 ? 2 : -3
218
- padding = count / 85 % 7 + index
219
- Utils.next_power_of_two(count * 3 + padding)
220
- end
221
- end
222
-
223
- def entries(count, nums)
224
- return count if nums == 8
225
-
226
- last_pow = nums >> 1
227
- index = last_pow < 1024 ? 3 : -2
228
- count - (last_pow + 1 + index) / 3 + 1 + last_pow
229
- end
230
-
231
- # @return [String] the serialized fields of the mafile
232
- def serialize
233
- @header.serialize + @buckets.inject('') do |sum, bucket|
234
- sum += if bucket.nil?
235
- empty_b = [HEADER_CONST[:HMAP_EMPTY_BUCKT_KEY]]*3
236
- empty_b.pack('L<3')
237
- else
238
- bucket
239
- end
240
- sum
241
- end
242
- end
243
-
244
- def add_bucket(buckets, num)
245
- buckets.each_with_object(Array.new(num)) do |bucket, sum|
246
- serialize = bucket.serialize
247
- i = Utils.index_of_range(bucket.uuid, num)
248
- loop do
249
- sum[i] = serialize if sum[i].nil?
250
- break if serialize == sum[i]
251
-
252
- i = Utils.index_of_range(i += 1, num)
253
- end
254
- end
255
- end
256
-
257
- def populate_hmap_header(num_buckets, entries)
258
- strings_offset = HMapHeader.bytesize + HMapBucket.bytesize * num_buckets
259
- HMapHeader.new(HEADER_CONST[:HMAP_HEADER_MAGIC_NUMBER],
260
- HEADER_CONST[:HMAP_HEADER_VERSION], 0, strings_offset, entries, num_buckets, 0)
261
- end
262
- end
263
- end
264
-
@@ -1,136 +0,0 @@
1
- require 'cocoapods'
2
-
3
- module HMap
4
- # A collection of utility functions used throughout cocoapods-hmap-prebuilt.
5
- module Utils
6
- HEADER_EXTENSIONS = Pod::Sandbox::FileAccessor::HEADER_EXTENSIONS
7
-
8
- def self.index_of_range(num, range)
9
- num &= range - 1
10
- num
11
- end
12
-
13
- def self.power_of_two?(num)
14
- num != 0 && (num & (num - 1)).zero?
15
- end
16
-
17
- def self.next_power_of_two(num)
18
- num |= (num >> 1)
19
- num |= (num >> 2)
20
- num |= (num >> 4)
21
- num |= (num >> 8)
22
- num |= (num >> 16)
23
- num |= (num >> 32)
24
- num + 1
25
- end
26
-
27
- def self.hash_set_value(hash, *args)
28
- args.each do |arg|
29
- hash.merge(arg)
30
- end
31
- hash
32
- end
33
-
34
- def self.specialize_format(format, swapped)
35
- modifier = swapped ? '<' : '>'
36
- format.tr('=', modifier)
37
- end
38
-
39
- def self.string_downcase_hash(str)
40
- str.downcase.bytes.inject(0) do |sum, value|
41
- sum += value * 13
42
- sum
43
- end
44
- end
45
-
46
- def self.update_changed_file(path, contents)
47
- if path.exist?
48
- content_stream = StringIO.new(contents)
49
- identical = File.open(path, 'rb') { |f| FileUtils.compare_stream(f, content_stream) }
50
- return if identical
51
- end
52
- path.dirname.mkpath
53
- File.open(path, 'w') { |f| f.write(contents) }
54
- end
55
-
56
- def self.swapped_magic?(magic, version)
57
- magic.eql?(HEADER_CONST[:HMAP_SWAPPED_MAGIC]) && version.eql?(HEADER_CONST[:HMAP_SWAPPED_VERSION])
58
- end
59
-
60
- def self.magic?(magic)
61
- magic.eql?(HEADER_CONST[:HMAP_SWAPPED_MAGIC]) || magic.eql?(HEADER_CONST[:HMAP_HEADER_MAGIC_NUMBER])
62
- end
63
-
64
- def self.safe_encode(string, target_encoding)
65
- string.encode(target_encoding)
66
- rescue Encoding::InvalidByteSequenceError
67
- string.force_encoding(target_encoding)
68
- rescue Encoding::UndefinedConversionError
69
- string.encode(target_encoding, fallback: lambda { |c|
70
- c.force_encoding(target_encoding)
71
- })
72
- end
73
-
74
- def self.clean_target_build_setting(targets, build_setting)
75
- target_xcconfig_path(targets) do |xc|
76
- clean_build_setting_to_xcconfig(xc, build_setting)
77
- end
78
- end
79
-
80
- def self.target_xcconfig_path(targets)
81
- targets.each do |target|
82
- raise ClassIncludedError.new(target.class, Pod::Target) unless target.is_a?(Pod::Target)
83
-
84
- config_h = Pod::Target.instance_method(:build_settings).bind(target).call
85
- config_h.each_key do |configuration_name|
86
- xcconfig = target.xcconfig_path(configuration_name)
87
- yield(xcconfig) if block_given?
88
- end
89
- end
90
- end
91
-
92
- def self.change_xcconfig_header_search_path(xcconfig, hmap_h, use_headermap: true, save_origin: true)
93
- hmap_header_serach_paths = hmap_h.inject('') do |sum, hmap_n|
94
- hmap_pod_root_path = "${PODS_ROOT}/Headers/#{HMAP_DIR_NAME}/#{hmap_n}"
95
- sum + "\"#{hmap_pod_root_path}\" "
96
- end
97
- save_build_setting_to_xcconfig(xcconfig, hmap_header_serach_paths, HEAD_SEARCH_PATHS, save_origin: save_origin) do |xc|
98
- xc.attributes['USE_HEADERMAP'] = 'NO' unless use_headermap
99
- end
100
- end
101
-
102
- def self.save_build_setting_to_xcconfig(path, value, build_setting, save_origin: true)
103
- xc = Xcodeproj::Config.new(path)
104
- save_origin_build_setting = "SAVE_#{build_setting}"
105
- hmap_build_setting = "HMAP_PREBUILT_#{build_setting}"
106
- origin_build_setting = xc.attributes[build_setting]
107
-
108
- if !origin_build_setting.nil? && !origin_build_setting.include?(hmap_build_setting)
109
- xc.attributes[save_origin_build_setting] =
110
- origin_build_setting
111
- end
112
-
113
- save_origin_build_setting_value = xc.attributes[save_origin_build_setting]
114
- value = "#{value} ${#{save_origin_build_setting}}" if save_origin && !save_origin_build_setting_value.nil?
115
- xc.attributes[hmap_build_setting] = value
116
- xc.attributes[build_setting] = "${#{hmap_build_setting}}"
117
- yield(xc) if block_given?
118
- xc.save_as(path)
119
- end
120
-
121
- def self.clean_build_setting_to_xcconfig(path, build_setting)
122
- xc = Xcodeproj::Config.new(path)
123
- save_origin_build_setting = "SAVE_#{build_setting}"
124
- hmap_build_setting = "HMAP_PREBUILT_#{build_setting}"
125
- return if xc.attributes[hmap_build_setting].nil?
126
-
127
- xc.attributes[build_setting] = xc.attributes[save_origin_build_setting]
128
- xc.attributes.delete(save_origin_build_setting)
129
- xc.attributes.delete(hmap_build_setting)
130
- xc.attributes['USE_HEADERMAP'] = 'YES'
131
- xc.attributes.delete(build_setting) if xc.attributes[build_setting].nil?
132
- xc.save_as(path)
133
- puts "\t -xcconfig path: #{path} clean finish."
134
- end
135
- end
136
- end