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.
- checksums.yaml +4 -4
- data/lib/cocoapods-hmap-prebuilt.rb +1 -13
- data/lib/cocoapods-hmap-prebuilt/hmap_constructor.rb +48 -0
- data/lib/cocoapods-hmap-prebuilt/hmap_version.rb +2 -2
- data/lib/cocoapods-hmap-prebuilt/hmap_writer.rb +68 -0
- data/lib/cocoapods-hmap-prebuilt/pod_context_hook.rb +42 -0
- data/lib/cocoapods-hmap-prebuilt/pod_target.rb +65 -0
- data/lib/cocoapods-hmap-prebuilt/pod_xcconfig.rb +83 -0
- data/lib/cocoapods-hmap-prebuilt/podfile_dsl.rb +22 -0
- data/lib/cocoapods_plugin.rb +10 -11
- metadata +10 -47
- data/README.md +0 -40
- data/bin/hmap-prebuilt-read +0 -10
- data/bin/hmap-prebuilt-write +0 -10
- data/lib/cocoapods-hmap-prebuilt/command/hmap_reader.rb +0 -39
- data/lib/cocoapods-hmap-prebuilt/command/hmap_writer.rb +0 -46
- data/lib/cocoapods-hmap-prebuilt/hmap_exceptions.rb +0 -30
- data/lib/cocoapods-hmap-prebuilt/hmap_file.rb +0 -31
- data/lib/cocoapods-hmap-prebuilt/hmap_file_reader.rb +0 -91
- data/lib/cocoapods-hmap-prebuilt/hmap_file_writer.rb +0 -148
- data/lib/cocoapods-hmap-prebuilt/hmap_helper.rb +0 -85
- data/lib/cocoapods-hmap-prebuilt/hmap_struct.rb +0 -264
- data/lib/cocoapods-hmap-prebuilt/hmap_utils.rb +0 -136
- data/lib/cocoapods-hmap-prebuilt/hmap_view.rb +0 -29
data/README.md
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
# cocoapods-hmap-prebuilt
|
2
|
-
|
3
|
-
A description of cocoapods-hmap-prebuilt.
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
$ gem install cocoapods-hmap-prebuilt
|
8
|
-
|
9
|
-
## Usage
|
10
|
-
|
11
|
-
The command should be executed in directory that contains podfile.
|
12
|
-
|
13
|
-
```shell
|
14
|
-
# write the hmap file to podfile/Pods/Headers/HMap
|
15
|
-
$ pod hmap-writer
|
16
|
-
|
17
|
-
# write the hmap file to /project/dir/Pods/Headers/HMap
|
18
|
-
$ pod hmap-writer --project-directory=/project/dir/
|
19
|
-
|
20
|
-
# write the hmap file to /project/dir/Pods/Headers/HMap and no save origin [HEADER_SEARCH_PATHS]
|
21
|
-
$ pod hmap-writer --project-directory=/project/dir/ --nosave-origin-header-search-paths
|
22
|
-
|
23
|
-
# cleanup the hmap file
|
24
|
-
$ pod hmap-writer --clean-hmap
|
25
|
-
|
26
|
-
# read the hmap file from /hmap/dir/file
|
27
|
-
$ pod hmap-reader --hmap-path=/hmap/dir/file
|
28
|
-
```
|
29
|
-
|
30
|
-
At same time, you can put this line in your podfile:
|
31
|
-
|
32
|
-
```rb
|
33
|
-
plugin 'cocoapods-hmap-prebuilt'
|
34
|
-
```
|
35
|
-
|
36
|
-
## Command Line Tool
|
37
|
-
|
38
|
-
Installing the 'cocoapods-hmap-prebuilt' gem will also install two command-line tool `hmap-prebuilt-read` and `hmap-prebuilt-write` which you can use to generate header map file and read hmap file.
|
39
|
-
|
40
|
-
For more information consult `hmap-prebuilt-read --help` or `hmap-prebuilt-write --help`.
|
data/bin/hmap-prebuilt-read
DELETED
data/bin/hmap-prebuilt-write
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'cocoapods-hmap-prebuilt'
|
2
|
-
require 'cocoapods'
|
3
|
-
|
4
|
-
module Pod
|
5
|
-
class Command
|
6
|
-
class HMapReader < Command
|
7
|
-
self.summary = 'Read mapfile and puts result.'
|
8
|
-
|
9
|
-
self.description = <<-DESC
|
10
|
-
Read mapfile and puts result, header, buckets, string_table.
|
11
|
-
DESC
|
12
|
-
|
13
|
-
def initialize(argv)
|
14
|
-
super
|
15
|
-
hmap_file_path = argv.option('hmap-path')
|
16
|
-
@hmap_file_path = Pathname.new(hmap_file_path).expand_path unless hmap_file_path.nil?
|
17
|
-
end
|
18
|
-
|
19
|
-
def validate!
|
20
|
-
super
|
21
|
-
banner! if help?
|
22
|
-
raise '[ERROR]: --hmap-path no set'.red unless File.exist?(@hmap_file_path)
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.options
|
26
|
-
[
|
27
|
-
['--hmap-path=/hmap/dir/file', 'The path of the hmap file']
|
28
|
-
].concat(super)
|
29
|
-
end
|
30
|
-
|
31
|
-
def run
|
32
|
-
UI.section "\n[hmap-reader] start..............\n".yellow do
|
33
|
-
HMap::MapFileReader.new(@hmap_file_path)
|
34
|
-
end
|
35
|
-
UI.puts("\n[hmap-reader] finish..............\n".yellow)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'cocoapods-hmap-prebuilt'
|
2
|
-
require 'cocoapods'
|
3
|
-
|
4
|
-
module Pod
|
5
|
-
class Command
|
6
|
-
class HMapWriter < Command
|
7
|
-
self.summary = 'Analyzes the dependencies and gen each dependencie mapfile.'
|
8
|
-
|
9
|
-
self.description = <<-DESC
|
10
|
-
Analyzes the dependencies of any cocoapods projects and gen each dependencie mapfile.
|
11
|
-
DESC
|
12
|
-
|
13
|
-
def initialize(argv)
|
14
|
-
super
|
15
|
-
project_directory = argv.option('project-directory')
|
16
|
-
@save_origin_header_search_paths = !argv.flag?('nosave-origin-header-search-paths', false)
|
17
|
-
@clean_hmap = argv.flag?('clean-hmap', false)
|
18
|
-
|
19
|
-
return if project_directory.nil?
|
20
|
-
|
21
|
-
@project_directory = Pathname.new(project_directory).expand_path
|
22
|
-
config.installation_root = @project_directory
|
23
|
-
end
|
24
|
-
|
25
|
-
def validate!
|
26
|
-
super
|
27
|
-
verify_podfile_exists!
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.options
|
31
|
-
[
|
32
|
-
['--project-directory=/project/dir/', 'The path to the root of the project directory'],
|
33
|
-
['--nosave-origin-header-search-paths', 'This option will not save xcconfig origin [HEADER_SEARCH_PATHS] and put hmap file first'],
|
34
|
-
['--clean-hmap', 'This option will clean up all hmap-prebuilt setup for hmap.']
|
35
|
-
].concat(super)
|
36
|
-
end
|
37
|
-
|
38
|
-
def run
|
39
|
-
UI.section "\n[hmap-prebuilt] start.............." do
|
40
|
-
HMap::HMapFileWriter.new(@save_origin_header_search_paths, @clean_hmap)
|
41
|
-
end
|
42
|
-
UI.puts('[hmap-prebuilt] finish..............')
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module HMap
|
2
|
-
# A generic HMap error in execution.
|
3
|
-
class HMapError < RuntimeError
|
4
|
-
end
|
5
|
-
|
6
|
-
# Raised when a file is not a HMap.
|
7
|
-
class NotAHMapOError < HMapError
|
8
|
-
end
|
9
|
-
|
10
|
-
# Raised when a file is too short to be a valid HMap file.
|
11
|
-
class TruncatedFileError < NotAHMapOError
|
12
|
-
def initialize
|
13
|
-
super 'File is too short to be a valid HMap'
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
# Raised when a file's magic bytes are not valid HMap magic.
|
18
|
-
class MagicError < NotAHMapOError
|
19
|
-
def initialize(magic)
|
20
|
-
super format('Unrecognized HMap magic: 0x%02<magic>x', magic: magic)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
# Raised when a class is not the class of obj.
|
25
|
-
class ClassIncludedError < HMapError
|
26
|
-
def initialize(cls1, cls2)
|
27
|
-
super format('%<cls1>s must be the %<cls2>s of obj', cls1: cls1, cls2: cls2)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module HMap
|
2
|
-
class HMapFile
|
3
|
-
# @return mapfile string_table
|
4
|
-
attr_reader :string_table
|
5
|
-
|
6
|
-
# @return [Array<HMap::HMapBucketStr>] an array of the file's bucktes
|
7
|
-
# @note bucktes are provided in order of ascending offset.
|
8
|
-
attr_reader :buckets
|
9
|
-
|
10
|
-
# @api private
|
11
|
-
def initialize(strings, buckets)
|
12
|
-
@string_table = strings
|
13
|
-
@buckets = buckets
|
14
|
-
@map_data = HMapData.new(buckets)
|
15
|
-
end
|
16
|
-
|
17
|
-
# @return [String] the serialized fields of the mafile
|
18
|
-
def serialize
|
19
|
-
@map_data.serialize + @string_table
|
20
|
-
end
|
21
|
-
|
22
|
-
# Write all mafile data to the given filename.
|
23
|
-
# @param filename [String] the file to write to
|
24
|
-
# @return [void]
|
25
|
-
def write(path)
|
26
|
-
contents = serialize
|
27
|
-
Utils.update_changed_file(path, contents)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
@@ -1,91 +0,0 @@
|
|
1
|
-
module HMap
|
2
|
-
|
3
|
-
class HMapFileReader
|
4
|
-
# @return [String, nil] the filename loaded from, or nil if loaded from a binary
|
5
|
-
# string
|
6
|
-
attr_reader :filename
|
7
|
-
# # @return [Hash] any parser options that the instance was created with
|
8
|
-
# attr_reader :options
|
9
|
-
|
10
|
-
# @return true/false the swapped of the mapfile
|
11
|
-
attr_reader :swapped
|
12
|
-
|
13
|
-
# @return [HMap::HMapHeader]
|
14
|
-
attr_reader :header
|
15
|
-
|
16
|
-
# @return [Hash<HMap::HMapBucket => HMap::HMapBucketStr>] an array of the file's bucktes
|
17
|
-
# @note bucktes are provided in order of ascending offset.
|
18
|
-
attr_reader :bucktes
|
19
|
-
|
20
|
-
def initialize(path)
|
21
|
-
raise ArgumentError, "#{path}: no such file" unless File.file?(path)
|
22
|
-
|
23
|
-
@filename = path
|
24
|
-
@raw_data = File.open(@filename, 'rb', &:read)
|
25
|
-
populate_fields
|
26
|
-
puts description
|
27
|
-
end
|
28
|
-
|
29
|
-
# Populate the instance's fields with the raw HMap data.
|
30
|
-
# @return [void]
|
31
|
-
# @note This method is public, but should (almost) never need to be called.
|
32
|
-
def populate_fields
|
33
|
-
@header = populate_hmap_header
|
34
|
-
string_t = @raw_data[header.strings_offset..-1]
|
35
|
-
@bucktes = populate_buckets do |bucket|
|
36
|
-
bucket_s = bucket.to_a.map do |key|
|
37
|
-
string_t[key..-1].match(/[^\0]+/)[0]
|
38
|
-
end
|
39
|
-
HMapBucketStr.new(*bucket_s)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
# The file's HMapheader structure.
|
44
|
-
# @return [HMap::HMapHeader]
|
45
|
-
# @raise [TruncatedFileError] if the file is too small to have a valid header
|
46
|
-
# @api private
|
47
|
-
def populate_hmap_header
|
48
|
-
raise TruncatedFileError if @raw_data.size < HMapHeader.bytesize + 8 * HMapBucket.bytesize
|
49
|
-
|
50
|
-
populate_and_check_magic
|
51
|
-
HMapHeader.new_from_bin(swapped, @raw_data[0, HMapHeader.bytesize])
|
52
|
-
end
|
53
|
-
|
54
|
-
# Read just the file's magic number and check its validity.
|
55
|
-
# @return [Integer] the magic
|
56
|
-
# @raise [MagicError] if the magic is not valid HMap magic
|
57
|
-
# @api private
|
58
|
-
def populate_and_check_magic
|
59
|
-
magic = @raw_data[0..3].unpack1('N')
|
60
|
-
raise MagicError, magic unless Utils.magic?(magic)
|
61
|
-
|
62
|
-
version = @raw_data[4..5].unpack1('n')
|
63
|
-
@swapped = Utils.swapped_magic?(magic, version)
|
64
|
-
end
|
65
|
-
|
66
|
-
# All buckets in the file.
|
67
|
-
# @return [Array<HMap::HMapBucket>] an array of buckets
|
68
|
-
# @api private
|
69
|
-
def populate_buckets
|
70
|
-
bucket_offset = header.class.bytesize
|
71
|
-
bucktes = []
|
72
|
-
header.num_buckets.times do |i|
|
73
|
-
bucket = HMapBucket.new_from_bin(swapped, @raw_data[bucket_offset, HMapBucket.bytesize])
|
74
|
-
bucket_offset += HMapBucket.bytesize
|
75
|
-
next if bucket.key == HEADER_CONST[:HMAP_EMPTY_BUCKT_KEY]
|
76
|
-
|
77
|
-
bucktes[i] = { bucket => yield(bucket) }
|
78
|
-
end
|
79
|
-
bucktes
|
80
|
-
end
|
81
|
-
|
82
|
-
def description
|
83
|
-
sum = " Header map: #{filename}\n" + header.description
|
84
|
-
bucktes.each_with_index do |buckte_h, index|
|
85
|
-
sum += "\t- Bucket: #{index}" + Utils.safe_encode(buckte_h.values[0].description, 'UTF-8') unless buckte_h.nil?
|
86
|
-
sum
|
87
|
-
end
|
88
|
-
sum
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
@@ -1,148 +0,0 @@
|
|
1
|
-
require 'cocoapods'
|
2
|
-
|
3
|
-
module HMap
|
4
|
-
|
5
|
-
HMAP_DIR_NAME = 'HMap'
|
6
|
-
|
7
|
-
# mapfile type
|
8
|
-
# @note public => pods public,
|
9
|
-
# private => pods private,
|
10
|
-
# all => public + private + extra.
|
11
|
-
# @api private
|
12
|
-
HMMAP_TYPE = {
|
13
|
-
public_header_files: 'public',
|
14
|
-
private_header_files: 'private',
|
15
|
-
all_files: 'all'
|
16
|
-
}.freeze
|
17
|
-
|
18
|
-
HEAD_SEARCH_PATHS = 'HEADER_SEARCH_PATHS'
|
19
|
-
|
20
|
-
# Helper module which returns handle method from HMapFileWriter.
|
21
|
-
class HMapFileWriter
|
22
|
-
def initialize(save_origin_header_search_paths, clean_hmap)
|
23
|
-
config = Pod::Config.instance
|
24
|
-
analyze = Helper::PodHelper.pod_analyze(config)
|
25
|
-
hmap_dir = hmap_dir(config)
|
26
|
-
targets = analyze.targets
|
27
|
-
pod_targets = analyze.pod_targets
|
28
|
-
clean_hmap(clean_hmap, hmap_dir, targets, pod_targets)
|
29
|
-
return if clean_hmap
|
30
|
-
|
31
|
-
@save_origin_header_search_paths = save_origin_header_search_paths
|
32
|
-
gen_hmapfile(targets, pod_targets, hmap_dir)
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
def hmap_dir(config)
|
38
|
-
hmap_dir = File.join(config.sandbox.headers_root, HMAP_DIR_NAME)
|
39
|
-
puts "HMap dir: #{hmap_dir}"
|
40
|
-
hmap_dir
|
41
|
-
end
|
42
|
-
|
43
|
-
def clean_hmap(clean_hmap, hmap_dir, *targets)
|
44
|
-
return unless clean_hmap
|
45
|
-
FileUtils.rm_rf(hmap_dir)
|
46
|
-
targets.each do |tg|
|
47
|
-
Utils.clean_target_build_setting(tg, HEAD_SEARCH_PATHS)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def gen_hmapfile(targets, pod_targets, hmap_dir)
|
52
|
-
puts('Inspecting targets to integrate ')
|
53
|
-
merge_all_pods_target_headers_mapfile(pod_targets, hmap_dir)
|
54
|
-
merge_all_target_public_mapfile(targets, hmap_dir)
|
55
|
-
create_each_target_mapfile(pod_targets, hmap_dir)
|
56
|
-
end
|
57
|
-
|
58
|
-
def header_perfix(file, keys)
|
59
|
-
perfix = "#{file.dirname}/"
|
60
|
-
suffix = file.basename.to_s
|
61
|
-
keys.inject([]) do |sum, name|
|
62
|
-
sum << [name.to_s, perfix, suffix]
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def header_to_hash(keys, headers, index, buckets)
|
67
|
-
index = index.length
|
68
|
-
keys.inject('') do |sum, bucket|
|
69
|
-
buckte = HMapBucketStr.new(*bucket)
|
70
|
-
string_t = buckte.bucket_to_string(headers, index + sum.length)
|
71
|
-
buckets.push(buckte)
|
72
|
-
sum + string_t
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def merge_all_target_public_mapfile(targets, hmap_dir)
|
77
|
-
method = method(:from_header_mappings_by_file_accessor)
|
78
|
-
targets.each do |target|
|
79
|
-
hmap_file_name = "#{target.name}-All-Public-Headers.hmap"
|
80
|
-
single_target_mapfile(target.pod_targets, hmap_dir, hmap_file_name, method)
|
81
|
-
change_target_xcconfig_header_search_path([hmap_file_name], true, target)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
def merge_all_pods_target_headers_mapfile(pod_targets, hmap_dir)
|
86
|
-
method = method(:from_header_mappings_by_file_accessor)
|
87
|
-
hmap_file_name = 'All-Pods-Headers.hmap'
|
88
|
-
single_target_mapfile(pod_targets, hmap_dir, hmap_file_name, method, :all_files)
|
89
|
-
change_target_xcconfig_header_search_path([hmap_file_name], false, *pod_targets)
|
90
|
-
end
|
91
|
-
|
92
|
-
def create_each_target_mapfile(pod_targets, hmap_dir)
|
93
|
-
pod_targets.each do |target|
|
94
|
-
HMMAP_TYPE.flat_map do |key, value|
|
95
|
-
hmap_file_name = "#{target.name}-#{value}-hmap.hmap"
|
96
|
-
method = method(:from_header_mappings_by_file_accessor)
|
97
|
-
single_target_mapfile([target], File.join(hmap_dir, target.name), hmap_file_name, method, key)
|
98
|
-
"#{target.name}/#{hmap_file_name}" if key == :all_files
|
99
|
-
end.compact
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
def from_header_mappings_by_file_accessor(header_h, buckets, target, hmap_type)
|
104
|
-
hmap_t = hmap_type == :all_files ? 'headers' : "#{HMMAP_TYPE[hmap_type]}_headers"
|
105
|
-
valid_accessors = target.file_accessors.reject { |fa| fa.spec.non_library_specification? }
|
106
|
-
headers = valid_accessors.each_with_object({}) do |file_accessor, sum|
|
107
|
-
# Private headers will always end up in Pods/Headers/Private/PodA/*.h
|
108
|
-
# This will allow for `""` imports to work.
|
109
|
-
type_header = file_accessor.method(hmap_t.to_sym).call
|
110
|
-
Helper::PodHelper.header_mappings(file_accessor, type_header, target).each do |key, value|
|
111
|
-
sum[key] ||= []
|
112
|
-
sum[key] += value
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
if target.build_as_framework?
|
117
|
-
headers[target.prefix_header_path] = [target.prefix_header_path.basename]
|
118
|
-
headers[target.umbrella_header_path] = [target.umbrella_header_path.basename]
|
119
|
-
end
|
120
|
-
headers.each_with_object(buckets) do |header_f, sum|
|
121
|
-
keys = header_perfix(*header_f)
|
122
|
-
sum[0] += header_to_hash(keys, header_h, *sum)
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
def single_target_mapfile(pod_targets, hmap_dir, hmap_file_name, headers, hmap_type = :public_header_files)
|
127
|
-
hmap_file_path = Pathname(File.join(hmap_dir, hmap_file_name))
|
128
|
-
header_h = {}
|
129
|
-
buckets = pod_targets.inject(["\0", []]) do |bucktes, target|
|
130
|
-
headers.call(header_h, bucktes, target, hmap_type)
|
131
|
-
end
|
132
|
-
wirte_mapfile_to_path(hmap_file_path, buckets)
|
133
|
-
end
|
134
|
-
|
135
|
-
def wirte_mapfile_to_path(hmap_file_path, buckets)
|
136
|
-
print "\t - save hmap file to path:"
|
137
|
-
puts hmap_file_path.to_s.yellow
|
138
|
-
HMapFile.new(*buckets).write(hmap_file_path)
|
139
|
-
end
|
140
|
-
|
141
|
-
def change_target_xcconfig_header_search_path(hmap_h, use_headermap, *targets)
|
142
|
-
Utils.target_xcconfig_path(targets) do |xc|
|
143
|
-
Utils.change_xcconfig_header_search_path(xc, hmap_h, use_headermap: use_headermap,
|
144
|
-
save_origin: @save_origin_header_search_paths)
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|