cocoapods-project-hmap 0.0.2 → 0.0.3
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/LICENSE.txt +1 -1
- data/README.md +80 -26
- data/README_en.md +98 -0
- data/cocoapods-project-hmap.gemspec +2 -2
- data/lib/cocoapods-project-hmap/gem_version.rb +1 -1
- data/lib/cocoapods-project-hmap/hmap_generator.rb +51 -0
- data/lib/cocoapods-project-hmap/pod_target.rb +40 -0
- data/lib/cocoapods-project-hmap/podfile_dsl.rb +39 -0
- data/lib/cocoapods-project-hmap/post_install_hook_context.rb +41 -0
- data/lib/cocoapods-project-hmap/xcconfig.rb +68 -0
- data/lib/cocoapods_plugin.rb +40 -82
- metadata +12 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12c66fa7e9625b8867a07945ecdc93d7ee8fa28e75106472ebb828ceb8ffb2df
|
4
|
+
data.tar.gz: ceee25af45048930c988f96cc181d05278f725b1a48cc43c6ca4dbcd2573b78d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5272b46626dc85c057c618da68509baeae4d42e03532b8fd24def01858f1bc4be8d9d1ec4b5b1ebd7d1904bd1f051b358399fa4a9e0a5fe12f5491a22e12d260
|
7
|
+
data.tar.gz: 9784dd04314a997cb8438febe0d3d545e1e0516deb9acec03361b431889349143552ecdf13a4863f96a8a1d1f6c2d506ab492f71294c68655b68be5c2f1bde30
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,43 +1,97 @@
|
|
1
1
|
# cocoapods-project-hmap
|
2
2
|
|
3
|
-
|
3
|
+
此插件思路来源于[《一款可以让大型iOS工程编译速度提升50%的工具》](https://tech.meituan.com/2021/02/25/cocoapods-hmap-prebuilt.html)。通过使用hmap代替文件路径搜索优化预处理阶段中头文件搜索的性能实现编译速度提升。
|
4
4
|
|
5
|
-
|
5
|
+
[English](./README_en.md)
|
6
6
|
|
7
|
-
|
7
|
+
## 效果测试
|
8
8
|
|
9
|
-
|
10
|
-
| ------ | ---- |
|
11
|
-
| 471s | 330s |
|
9
|
+
我在另一个项目 [hmap-benchmark](https://github.com/chenxGen/hmap-benchmark/) 写了几个测试用例,统计并输出增加M个源文件,N个第三方库在使用和不使用插件的情况下的编译时间.
|
12
10
|
|
13
|
-
|
14
|
-
> - Mac:Mac mini (2018) / 3.2 GHz 六核Intel Core i7 / 16 GB 2667 MHz DDR4
|
15
|
-
> - Xcode: 12.4
|
16
|
-
> - ruby: 2.6.0
|
17
|
-
> - cocoapods: 1.10.1
|
11
|
+
最新一次跑 `run_benchmark.rb` 脚本的时间统计为:
|
18
12
|
|
19
|
-
|
13
|
+
- Mac mini (Intel i7/16g) :
|
14
|
+
|
15
|
+
```
|
16
|
+
+--------------------------------------+--------------------+------------------------------------------------------------------------------------------------------------------------+
|
17
|
+
| Case | Average(s) | Detail(s) |
|
18
|
+
+--------------------------------------+--------------------+------------------------------------------------------------------------------------------------------------------------+
|
19
|
+
| 100 source files & 125 pods (origin) | 192.43606980641684 | [218.57447242736816, 178.7542200088501, 179.97951698303223] |
|
20
|
+
| 100 source files & 125 pods (plugin) | 165.76690363883972 | [166.8555600643158, 165.40182876586914, 165.04332208633423] |
|
21
|
+
| > optimization (speed) | 16.09% | |
|
22
|
+
| > optimization (time cost) | 13.86% | |
|
23
|
+
| 1 source files & 125 pods (origin) | 170.00553512573242 | [175.31463813781738, 173.79285717010498, 160.9091100692749] |
|
24
|
+
| 1 source files & 125 pods (plugin) | 124.49473492304485 | [123.54309391975403, 124.4949209690094, 125.4461898803711] |
|
25
|
+
| > optimization (speed) | 36.56% | |
|
26
|
+
| > optimization (time cost) | 26.77% | |
|
27
|
+
| Total (origin) | 181.22080246607462 | [218.57447242736816, 178.7542200088501, 179.97951698303223, 175.31463813781738, 173.79285717010498, 160.9091100692749] |
|
28
|
+
| Total (plugin) | 145.1308192809423 | [166.8555600643158, 165.40182876586914, 165.04332208633423, 123.54309391975403, 124.4949209690094, 125.4461898803711] |
|
29
|
+
| > optimization (speed) | 24.87% | |
|
30
|
+
| > optimization (time cost) | 19.91% | |
|
31
|
+
+--------------------------------------+--------------------+------------------------------------------------------------------------------------------------------------------------+
|
32
|
+
```
|
33
|
+
- Mac air (Apple M1/16g) :
|
34
|
+
|
35
|
+
```
|
36
|
+
+--------------------------------------+-------------------+--------------------------------------------------------------------------------------------------------------------+
|
37
|
+
| Case | Average(s) | Detail(s) |
|
38
|
+
+--------------------------------------+-------------------+--------------------------------------------------------------------------------------------------------------------+
|
39
|
+
| 100 source files & 125 pods (origin) | 95.07198365529378 | [91.36949586868286, 96.10968923568726, 97.73676586151123] |
|
40
|
+
| 100 source files & 125 pods (plugin) | 91.2074584166289 | [90.87663986448735, 90.77357686752014, 91.97326111793518] |
|
41
|
+
| > optimization (speed) | 4.24% | |
|
42
|
+
| > optimization (time cost) | 4.06% | |
|
43
|
+
| 1 source files & 125 pods (origin) | 81.564133644104 | [80.95829105377197, 82.07278513988386, 81.66132473945618] |
|
44
|
+
| 1 source files & 125 pods (plugin) | 79.28314812668217 | [78.21958923339844, 80.21097787748413, 79.17887886892395] |
|
45
|
+
| > optimization (speed) | 2.98% | |
|
46
|
+
| > optimization (time cost) | 2.89% | |
|
47
|
+
| Total (origin) | 88.3180586496989 | [91.36949586868286, 96.10968923568726, 97.73676586151123, 80.95829105377197, 82.07278513988386, 81.66132473945618] |
|
48
|
+
| Total (plugin) | 85.2053037/161153 | [90.87663986448735, 90.77357686752014, 91.97326111793518, 78.21958923339844, 80.21097787748413, 79.17887886892395] |
|
49
|
+
| > optimization (speed) | 3.65% | |
|
50
|
+
| > optimization (time cost) | 3.52% | |
|
51
|
+
+--------------------------------------+-------------------+--------------------------------------------------------------------------------------------------------------------+
|
52
|
+
```
|
53
|
+
|
54
|
+
从上面的输出日志可以看出,插件可以带来3%-36%的编译速度提升,在使用Intel芯片的机器上优化效果还是挺好的,但是在使用Apple M1芯片的机器上效果就约等于没有了,只能说是M1的性能实在牛批。**如果你用的是M1,这里建议直接 `return`**
|
55
|
+
|
56
|
+
## 环境要求
|
57
|
+
|
58
|
+
- CocoaPods Version: `>=1.7.0`
|
59
|
+
- 安装命令行工具 [hmap](https://github.com/milend/hmap) : `brew install milend/taps/hmap`
|
20
60
|
|
21
61
|
## 安装
|
22
62
|
|
23
|
-
|
63
|
+
- 使用Gemfile : 在你的 `Gemfile` 中添加: `gem 'cocoapods-project-hmap'`
|
64
|
+
- 通过命令行安装 : `sudo gem install cocoapods-project-hmap`
|
24
65
|
|
25
|
-
|
66
|
+
## 使用
|
26
67
|
|
27
|
-
|
28
|
-
```ruby
|
29
|
-
gem 'cocoapods-project-hmap', :git=>'https://github.com/chenxGen/cocoapods-project-hmap.git', :branch=>'main'
|
30
|
-
```
|
68
|
+
只需要在你的`Podfile`中调用:`plugin 'cocoapods-project-hmap'` 声明使用该插件。
|
31
69
|
|
32
|
-
|
70
|
+
同时插件还为`Podfile`提供了一下几个可选的方法调用:
|
33
71
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
72
|
+
- **set_hmap_black_pod_list:** 开发插件的时候发现有些Pod target使用预生成的hmap编译会出错,比如使用了`#import "a/very/very/long/path/to/header.h"`,暂时没想到好的解决方案,所以针对这种情况需要手动添加到黑名单,不对该target的进行处理,如:`set_hmap_black_pod_list(['PodA','PodB'])`,插件内置了一些这种情况的三方库,具体见:[built-in black list](/lib/cocoapods-project-hmap/podfile_dsl.rb)。如果你还有其他的三方库由于其他原因编译失败,也可以把它添加到黑名单。。。
|
73
|
+
|
74
|
+
- **turn_prebuilt_hmap_off_for_pod_targets:** 如果你发现有太多的三方库需要添加到黑名单,你可以直接通过调用这个方法开启“纯净模式”,关闭插件对Pod Project内部所有target的header处理,仅仅对提供给主项目使用的target处理hmap
|
75
|
+
|
76
|
+
- **set_hmap_use_strict_mode:** 在一个target中引用另一个target的header,严格意义上来说应该使用`#import <PodA/Header.h>`的方式,但是有些是通过`#import "Header.h"`,这种情况如果设置了对应的header search path编译是可以成功的,比如使用原生的cocoapods情况下,在项目中使用`#import "Masonry.h"`、`#import <Mansory.h>`和`#import <Masonry/Mansory.h>`三种方式引入都是可以成功的,如果你使用这个插件并且开启这个选项后只有`#import <Masonry/Mansory.h>`可以编译成功。默认为关闭。
|
77
|
+
|
78
|
+
|
79
|
+
最终你的Podfile看起来会是这样的 :
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
platform :ios, '10.0'
|
83
|
+
plugin 'cocoapods-project-hmap'
|
84
|
+
set_hmap_black_pod_list(['PodA','PodB'])
|
85
|
+
turn_prebuilt_hmap_off_for_pod_targets
|
86
|
+
#set_hmap_use_strict_mode(true)
|
87
|
+
|
88
|
+
target 'app' do
|
89
|
+
pod 'PodA'
|
90
|
+
...
|
91
|
+
pod 'PodB'
|
92
|
+
end
|
39
93
|
```
|
40
94
|
|
41
|
-
##
|
95
|
+
## License
|
42
96
|
|
43
|
-
|
97
|
+
cocoapods-project-hmap is released under the MIT license. See LICENSE for details.
|
data/README_en.md
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
# cocoapods-project-hmap
|
2
|
+
|
3
|
+
An cocoapods plugin improving clang build time at preprocess phase by using hmap instead of file paths for header searching. The idea comes from [《一款可以让大型iOS工程编译速度提升50%的工具》](https://tech.meituan.com/2021/02/25/cocoapods-hmap-prebuilt.html)
|
4
|
+
|
5
|
+
## Benchmark
|
6
|
+
|
7
|
+
There are some test cases in the benchmark project : [hmap-benchmark](https://github.com/chenxGen/hmap-benchmark/).
|
8
|
+
|
9
|
+
The latest outputs by running `run_benchmark.rb` are:
|
10
|
+
|
11
|
+
- Mac mini (Intel i7/16g) :
|
12
|
+
|
13
|
+
```
|
14
|
+
+--------------------------------------+--------------------+------------------------------------------------------------------------------------------------------------------------+
|
15
|
+
| Case | Average(s) | Detail(s) |
|
16
|
+
+--------------------------------------+--------------------+------------------------------------------------------------------------------------------------------------------------+
|
17
|
+
| 100 source files & 125 pods (origin) | 192.43606980641684 | [218.57447242736816, 178.7542200088501, 179.97951698303223] |
|
18
|
+
| 100 source files & 125 pods (plugin) | 165.76690363883972 | [166.8555600643158, 165.40182876586914, 165.04332208633423] |
|
19
|
+
| > optimization (speed) | 16.09% | |
|
20
|
+
| > optimization (time cost) | 13.86% | |
|
21
|
+
| 1 source files & 125 pods (origin) | 170.00553512573242 | [175.31463813781738, 173.79285717010498, 160.9091100692749] |
|
22
|
+
| 1 source files & 125 pods (plugin) | 124.49473492304485 | [123.54309391975403, 124.4949209690094, 125.4461898803711] |
|
23
|
+
| > optimization (speed) | 36.56% | |
|
24
|
+
| > optimization (time cost) | 26.77% | |
|
25
|
+
| Total (origin) | 181.22080246607462 | [218.57447242736816, 178.7542200088501, 179.97951698303223, 175.31463813781738, 173.79285717010498, 160.9091100692749] |
|
26
|
+
| Total (plugin) | 145.1308192809423 | [166.8555600643158, 165.40182876586914, 165.04332208633423, 123.54309391975403, 124.4949209690094, 125.4461898803711] |
|
27
|
+
| > optimization (speed) | 24.87% | |
|
28
|
+
| > optimization (time cost) | 19.91% | |
|
29
|
+
+--------------------------------------+--------------------+------------------------------------------------------------------------------------------------------------------------+
|
30
|
+
```
|
31
|
+
- Mac air (Apple M1/16g) :
|
32
|
+
|
33
|
+
```
|
34
|
+
+--------------------------------------+-------------------+--------------------------------------------------------------------------------------------------------------------+
|
35
|
+
| Case | Average(s) | Detail(s) |
|
36
|
+
+--------------------------------------+-------------------+--------------------------------------------------------------------------------------------------------------------+
|
37
|
+
| 100 source files & 125 pods (origin) | 95.07198365529378 | [91.36949586868286, 96.10968923568726, 97.73676586151123] |
|
38
|
+
| 100 source files & 125 pods (plugin) | 91.2074584166289 | [90.87663986448735, 90.77357686752014, 91.97326111793518] |
|
39
|
+
| > optimization (speed) | 4.24% | |
|
40
|
+
| > optimization (time cost) | 4.06% | |
|
41
|
+
| 1 source files & 125 pods (origin) | 81.564133644104 | [80.95829105377197, 82.07278513988386, 81.66132473945618] |
|
42
|
+
| 1 source files & 125 pods (plugin) | 79.28314812668217 | [78.21958923339844, 80.21097787748413, 79.17887886892395] |
|
43
|
+
| > optimization (speed) | 2.98% | |
|
44
|
+
| > optimization (time cost) | 2.89% | |
|
45
|
+
| Total (origin) | 88.3180586496989 | [91.36949586868286, 96.10968923568726, 97.73676586151123, 80.95829105377197, 82.07278513988386, 81.66132473945618] |
|
46
|
+
| Total (plugin) | 85.2053037/161153 | [90.87663986448735, 90.77357686752014, 91.97326111793518, 78.21958923339844, 80.21097787748413, 79.17887886892395] |
|
47
|
+
| > optimization (speed) | 3.65% | |
|
48
|
+
| > optimization (time cost) | 3.52% | |
|
49
|
+
+--------------------------------------+-------------------+--------------------------------------------------------------------------------------------------------------------+
|
50
|
+
```
|
51
|
+
|
52
|
+
The outputs indicate that this plugin has about 3%-36% build speed improvement, the improvement is not significant on mac using M1 processor because of Apple M1 processor's high IO performance (I GUESS...).
|
53
|
+
|
54
|
+
**So if you are using Mac with Apple M1 processor, There may be no need to use this plugin.**
|
55
|
+
|
56
|
+
## Requirement
|
57
|
+
|
58
|
+
- CocoaPods Version: `>=1.7.0`
|
59
|
+
- Install command line tool [hmap](https://github.com/milend/hmap) : `brew install milend/taps/hmap`
|
60
|
+
|
61
|
+
## Installation
|
62
|
+
|
63
|
+
- With Gemfile : Add this line to your `Gemfile` : `gem 'cocoapods-project-hmap'`
|
64
|
+
- With CommandLine : `sudo gem install cocoapods-project-hmap`
|
65
|
+
|
66
|
+
## Usage
|
67
|
+
|
68
|
+
In your `Podfile`, add this line : `plugin 'cocoapods-project-hmap'`
|
69
|
+
|
70
|
+
And this plugin also provides Podfile DSL bellow:
|
71
|
+
|
72
|
+
- `set_hmap_black_pod_list`: There are some unsolved situation in develping this plugin, such as a 'pod' using a long path import in their code, like `#import "a/very/very/long/path/to/header.h"`, I did not think of a suitable strategy to handle this, so I provide a method to adding then to black list, you can add then with code `set_hmap_black_pod_list(['PodA','PodB'])`, and there are some built-in 'pod' in black list, see : [built-in black list](/lib/cocoapods-project-hmap/podfile_dsl.rb). And if you have some other build error because of this plugin, adding then to black list...
|
73
|
+
- `turn_prebuilt_hmap_off_for_pod_targets`: If you have to many build error after using this plugin, or have to add to many 'pod' to black list, I provides a most non-intrusive way to use, call this method `turn_prebuilt_hmap_off_for_pod_targets` to ignore hmap prebuilt for most of the pod target (excepting the 'main' pods, named `Pods-${YOUR SCHEME}`).
|
74
|
+
- `set_hmap_use_strict_mode`: Import a header in other library(PodA), strictly speaking, we should use `#import <PodA/Header.h>`, but not all library developer do like that, if you turn it on, you can find then.
|
75
|
+
|
76
|
+
The code in your Podfile may look like that in the end :
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
platform :ios, '10.0'
|
80
|
+
plugin 'cocoapods-project-hmap'
|
81
|
+
set_hmap_black_pod_list(['PodA','PodB'])
|
82
|
+
turn_prebuilt_hmap_off_for_pod_targets
|
83
|
+
#set_hmap_use_strict_mode(true)
|
84
|
+
|
85
|
+
target 'app' do
|
86
|
+
pod 'PodA'
|
87
|
+
...
|
88
|
+
pod 'PodB'
|
89
|
+
end
|
90
|
+
```
|
91
|
+
|
92
|
+
## Contact
|
93
|
+
|
94
|
+
Your can contact me on [Twitter](http://twitter.com/chenxGen).
|
95
|
+
|
96
|
+
## License
|
97
|
+
|
98
|
+
cocoapods-project-hmap is released under the MIT license. See LICENSE for details.
|
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = CocoapodsProjectHmap::VERSION
|
9
9
|
spec.authors = ['chenxGen']
|
10
10
|
spec.email = ['chenxGen@outlook.com']
|
11
|
-
spec.description = %q{A
|
12
|
-
spec.summary = %q{A
|
11
|
+
spec.description = %q{A cocoapods plugin which using hmap instead of header search paths to improve preprocess time.}
|
12
|
+
spec.summary = %q{A cocoapods plugin which using hmap instead of header search paths to improve preprocess time.}
|
13
13
|
spec.homepage = 'https://github.com/chenxGen/cocoapods-project-hmap'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# !/usr/bin/env ruby
|
2
|
+
|
3
|
+
module ProjectHeaderMap
|
4
|
+
class HmapGenerator
|
5
|
+
QUOTE = 1 # 001
|
6
|
+
ANGLE_BRACKET = 2 # 010
|
7
|
+
BOTH = 3 # 011
|
8
|
+
def initialize
|
9
|
+
@hmap = Hash.new
|
10
|
+
end
|
11
|
+
# header_mapping : [Hash{FileAccessor => Hash}] Hash of file accessors by header mappings.
|
12
|
+
def add_hmap_with_header_mapping(header_mapping, type, target_name=nil)
|
13
|
+
header_mapping.each do |facc, headers|
|
14
|
+
headers.each do |key, value|
|
15
|
+
value.each do |path|
|
16
|
+
pn = Pathname.new(path)
|
17
|
+
name = pn.basename.to_s
|
18
|
+
dirname = pn.dirname.to_s + '/'
|
19
|
+
# construct hmap hash info
|
20
|
+
path_info = Hash['suffix' => name, 'prefix' => dirname]
|
21
|
+
if type & QUOTE > 0
|
22
|
+
# import with quote
|
23
|
+
@hmap[name] = path_info
|
24
|
+
end
|
25
|
+
if type & ANGLE_BRACKET > 0 && target_name != nil
|
26
|
+
# import with angle bracket
|
27
|
+
@hmap["#{target_name}/#{name}"] = path_info
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
# @path : path/to/xxx.hmap
|
34
|
+
# @return : succeed
|
35
|
+
def save_to(path)
|
36
|
+
if path != nil && @hmap.empty? == false
|
37
|
+
pn=Pathname(path)
|
38
|
+
json_path=pn.dirname.to_s + '/' + 'temp.json'
|
39
|
+
# write hmap json to file
|
40
|
+
File.open(json_path, 'w') { |file| file << @hmap.to_json }
|
41
|
+
# json to hmap
|
42
|
+
suc=system("hmap convert #{json_path} #{path}")
|
43
|
+
# delete json file
|
44
|
+
File.delete(json_path)
|
45
|
+
suc
|
46
|
+
else
|
47
|
+
false
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# !/usr/bin/env ruby
|
2
|
+
require 'cocoapods-project-hmap/xcconfig'
|
3
|
+
|
4
|
+
module Pod
|
5
|
+
class PodTarget
|
6
|
+
def reset_header_search_with_relative_hmap_path(hmap_path)
|
7
|
+
if build_settings.instance_of?(Hash)
|
8
|
+
build_settings.each do |config_name, setting|
|
9
|
+
config_file = setting.xcconfig
|
10
|
+
config_file.reset_header_search_with_relative_hmap_path(hmap_path)
|
11
|
+
# https://github.com/CocoaPods/CocoaPods/issues/1216
|
12
|
+
# just turn off private xcconfig's USE_HEADERMAP flag
|
13
|
+
config_file.set_use_hmap(false)
|
14
|
+
config_path = xcconfig_path(config_name)
|
15
|
+
config_file.save_as(config_path)
|
16
|
+
end
|
17
|
+
elsif build_settings.instance_of?(BuildSettings::PodTargetSettings)
|
18
|
+
config_file = build_settings.xcconfig
|
19
|
+
config_file.reset_header_search_with_relative_hmap_path(hmap_path)
|
20
|
+
# https://github.com/CocoaPods/CocoaPods/issues/1216
|
21
|
+
# just turn off private xcconfig's USE_HEADERMAP flag
|
22
|
+
config_file.set_use_hmap(false)
|
23
|
+
config_path = xcconfig_path
|
24
|
+
config_file.save_as(config_path)
|
25
|
+
else
|
26
|
+
puts 'Unknown build settings'.red
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
class AggregateTarget
|
31
|
+
def reset_header_search_with_relative_hmap_path(hmap_path)
|
32
|
+
# override xcconfig
|
33
|
+
xcconfigs.each do |config_name, config_file|
|
34
|
+
config_file.reset_header_search_with_relative_hmap_path(hmap_path)
|
35
|
+
config_path = xcconfig_path(config_name)
|
36
|
+
config_file.save_as(config_path)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# !/usr/bin/env ruby
|
2
|
+
# built-in black list pods (long import path not supported
|
3
|
+
# you can use hmap_black_pod_list to add other pods
|
4
|
+
$hmap_black_pod_list = [
|
5
|
+
'GoogleUtilities',
|
6
|
+
'MeshPipe',
|
7
|
+
'GoogleDataTransport',
|
8
|
+
'FirebaseCoreDiagnostics',
|
9
|
+
'FirebaseCore',
|
10
|
+
'FirebaseCrashlytics',
|
11
|
+
'FirebaseInstallations',
|
12
|
+
'CoreDragon',
|
13
|
+
'Objective-LevelDB'
|
14
|
+
]
|
15
|
+
|
16
|
+
$strict_mode = false
|
17
|
+
$prebuilt_hmap_for_pod_targets = true
|
18
|
+
|
19
|
+
module Pod
|
20
|
+
class Podfile
|
21
|
+
module DSL
|
22
|
+
def set_hmap_black_pod_list(pods)
|
23
|
+
if pods != nil && pods.size() > 0
|
24
|
+
$hmap_black_pod_list.concat(pods)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
# if use strict mode, main project can only use `#import <PodTargetName/SomeHeader.h>`
|
28
|
+
# `#import <SomeHeader.h>` will get 'file not found' error
|
29
|
+
# as well as PodTarget dependent on other PodTarget
|
30
|
+
def set_hmap_use_strict_mode
|
31
|
+
$strict_mode = true
|
32
|
+
end
|
33
|
+
# turn off prebuilt hmap for targets in pod project except the `main` target
|
34
|
+
def turn_prebuilt_hmap_off_for_pod_targets
|
35
|
+
$prebuilt_hmap_for_pod_targets = false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# !/usr/bin/env ruby
|
2
|
+
|
3
|
+
module Pod
|
4
|
+
class Installer
|
5
|
+
class PostInstallHooksContext
|
6
|
+
attr_accessor :aggregate_targets
|
7
|
+
version = Gem::Version.new(Pod::VERSION)
|
8
|
+
if version < Gem::Version.new('1.7.0')
|
9
|
+
# Method `generate` has two args
|
10
|
+
class << self
|
11
|
+
alias old_generate generate
|
12
|
+
def generate(sandbox, aggregate_targets)
|
13
|
+
context = old_generate(sandbox, aggregate_targets)
|
14
|
+
UI.info "- generate method of post install hook context hooked"
|
15
|
+
context.aggregate_targets = aggregate_targets
|
16
|
+
context
|
17
|
+
end
|
18
|
+
end
|
19
|
+
elsif version < Gem::Version.new('1.10.0')
|
20
|
+
# Method `generate` has three args
|
21
|
+
class << self
|
22
|
+
alias old_generate generate
|
23
|
+
def generate(sandbox, pods_project, aggregate_targets)
|
24
|
+
context = old_generate(sandbox, pods_project, aggregate_targets)
|
25
|
+
UI.info "- generate method of post install hook context hooked"
|
26
|
+
context.aggregate_targets = aggregate_targets
|
27
|
+
context
|
28
|
+
end
|
29
|
+
end
|
30
|
+
else
|
31
|
+
# PostInstallHooksContext inherit BaseContext, just override `generate`
|
32
|
+
def self.generate(sandbox, pods_project, aggregate_targets)
|
33
|
+
context = super
|
34
|
+
UI.info "- generate method of post install hook context override"
|
35
|
+
context.aggregate_targets = aggregate_targets
|
36
|
+
context
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# !/usr/bin/env ruby
|
2
|
+
|
3
|
+
module Xcodeproj
|
4
|
+
class Config
|
5
|
+
def remove_attr_with_key(key)
|
6
|
+
unless key == nil
|
7
|
+
@attributes.delete(key)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
def remove_header_search_path
|
11
|
+
header_search_paths = @attributes['HEADER_SEARCH_PATHS']
|
12
|
+
if header_search_paths
|
13
|
+
new_paths = Array.new
|
14
|
+
header_search_paths.split(' ').each do |p|
|
15
|
+
unless p.include?('${PODS_ROOT}/Headers')
|
16
|
+
new_paths << p
|
17
|
+
end
|
18
|
+
end
|
19
|
+
if new_paths.size > 0
|
20
|
+
@attributes['HEADER_SEARCH_PATHS'] = new_paths.join(' ')
|
21
|
+
else
|
22
|
+
remove_attr_with_key('HEADER_SEARCH_PATHS')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
remove_system_option_in_other_cflags
|
26
|
+
end
|
27
|
+
def remove_system_option_in_other_cflags
|
28
|
+
flags = @attributes['OTHER_CFLAGS']
|
29
|
+
if flags
|
30
|
+
new_flags = ''
|
31
|
+
skip = false
|
32
|
+
flags.split(' ').each do |substr|
|
33
|
+
if skip
|
34
|
+
skip = false
|
35
|
+
next
|
36
|
+
end
|
37
|
+
if substr == '-isystem'
|
38
|
+
skip = true
|
39
|
+
next
|
40
|
+
end
|
41
|
+
if new_flags.length > 0
|
42
|
+
new_flags += ' '
|
43
|
+
end
|
44
|
+
new_flags += substr
|
45
|
+
end
|
46
|
+
if new_flags.length > 0
|
47
|
+
@attributes['OTHER_CFLAGS'] = new_flags
|
48
|
+
else
|
49
|
+
remove_attr_with_key('OTHER_CFLAGS')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
def reset_header_search_with_relative_hmap_path(hmap_path)
|
54
|
+
# remove all search paths
|
55
|
+
remove_header_search_path
|
56
|
+
# add build flags
|
57
|
+
new_paths = Array["${PODS_ROOT}/#{hmap_path}"]
|
58
|
+
header_search_paths = @attributes['HEADER_SEARCH_PATHS']
|
59
|
+
if header_search_paths
|
60
|
+
new_paths.concat(header_search_paths.split(' '))
|
61
|
+
end
|
62
|
+
@attributes['HEADER_SEARCH_PATHS'] = new_paths.join(' ')
|
63
|
+
end
|
64
|
+
def set_use_hmap(use=false)
|
65
|
+
@attributes['USE_HEADERMAP'] = (use ? 'YES' : 'NO')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/cocoapods_plugin.rb
CHANGED
@@ -1,92 +1,50 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
# !/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'cocoapods-project-hmap/podfile_dsl'
|
4
|
+
require 'cocoapods-project-hmap/pod_target'
|
5
|
+
require 'cocoapods-project-hmap/post_install_hook_context'
|
6
|
+
require 'cocoapods-project-hmap/hmap_generator'
|
7
|
+
|
8
|
+
module ProjectHeaderMap
|
9
|
+
Pod::HooksManager.register('cocoapods-project-hmap', :post_install) do |post_context|
|
10
|
+
generate_type = $strict_mode ? HmapGenerator::ANGLE_BRACKET : HmapGenerator::BOTH
|
11
|
+
hmaps_dir=post_context.sandbox_root + '/prebuilt-hmaps'
|
12
|
+
unless File.exist?(hmaps_dir)
|
13
|
+
Dir.mkdir(hmaps_dir)
|
7
14
|
end
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
15
|
+
|
16
|
+
post_context.aggregate_targets.each do |one|
|
17
|
+
pods_hmap = HmapGenerator.new
|
18
|
+
Pod::UI.message "- hanlding headers of aggregate target :#{one.name}".green
|
19
|
+
one.pod_targets.each do |target|
|
20
|
+
Pod::UI.message "- hanlding headers of target :#{target.name}"
|
21
|
+
pods_hmap.add_hmap_with_header_mapping(target.public_header_mappings_by_file_accessor, generate_type, target.name)
|
22
|
+
unless $hmap_black_pod_list.include?(target.name) || $prebuilt_hmap_for_pod_targets == false
|
23
|
+
target_hmap = HmapGenerator.new
|
24
|
+
# set project header for current target
|
25
|
+
target_hmap.add_hmap_with_header_mapping(target.header_mappings_by_file_accessor, HmapGenerator::BOTH, target.name)
|
26
|
+
target.dependent_targets.each do |depend_target|
|
27
|
+
# set public header for dependent target
|
28
|
+
target_hmap.add_hmap_with_header_mapping(depend_target.public_header_mappings_by_file_accessor, generate_type, depend_target.name)
|
22
29
|
end
|
23
|
-
|
24
|
-
|
30
|
+
|
31
|
+
target_hmap_name="#{target.name}.hmap"
|
32
|
+
target_hmap_path = hmaps_dir + "/#{target_hmap_name}"
|
33
|
+
relative_hmap_path = "prebuilt-hmaps/#{target_hmap_name}"
|
34
|
+
if target_hmap.save_to(target_hmap_path)
|
35
|
+
target.reset_header_search_with_relative_hmap_path(relative_hmap_path)
|
25
36
|
end
|
26
|
-
new_flags += substr
|
27
|
-
end
|
28
|
-
if new_flags.length > 0
|
29
|
-
@attributes['OTHER_CFLAGS'] = new_flags
|
30
37
|
else
|
31
|
-
|
38
|
+
Pod::UI.message "- skip handling headers of target :#{target.name}"
|
32
39
|
end
|
33
40
|
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
module Pod
|
39
|
-
class Installer
|
40
|
-
class PostInstallHooksContext
|
41
|
-
attr_accessor :aggregate_targets
|
42
|
-
def self.generate(sandbox, pods_project, aggregate_targets)
|
43
|
-
context = super
|
44
|
-
UI.info "[#] generate method of post install hook context override"
|
45
|
-
context.aggregate_targets = aggregate_targets
|
46
|
-
context
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
module ProjectHeaderMap
|
51
|
-
HooksManager.register('cocoapods-project-hmap', :post_install) do |post_context|
|
52
|
-
post_context.aggregate_targets.each do |one|
|
53
|
-
hmap = Hash.new
|
54
|
-
one.pod_targets.each do |target|
|
55
|
-
target.public_header_mappings_by_file_accessor.each do |facc, headers|
|
56
|
-
headers.each do |key, value|
|
57
|
-
value.each do |path|
|
58
|
-
pn = Pathname.new(path)
|
59
|
-
name = pn.basename.to_s
|
60
|
-
dirname = pn.dirname.to_s + '/'
|
61
|
-
# construct hmap hash info
|
62
|
-
path_info = Hash['suffix' => name, 'prefix' => dirname]
|
63
|
-
# import with quote
|
64
|
-
hmap[name] = path_info
|
65
|
-
# import with angle bracket
|
66
|
-
hmap["#{target.name}/#{name}"] = path_info
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
41
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
system("hmap convert #{path} #{path_hmap}")
|
79
|
-
# delete json file
|
80
|
-
File.delete(path)
|
81
|
-
# override xcconfig
|
82
|
-
one.xcconfigs.each do |config_name, config_file|
|
83
|
-
config_file << Hash['OTHER_CFLAGS' => "-I ${PODS_ROOT}/#{one.name}.hmap"]
|
84
|
-
config_file << Hash['OTHER_SWIFT_FLAGS' => "-Xcc -I${PODS_ROOT}/#{one.name}.hmap"]
|
85
|
-
config_file.remove_header_search_path
|
86
|
-
xcconfig_path = one.xcconfig_path(config_name)
|
87
|
-
config_file.save_as(xcconfig_path)
|
88
|
-
end
|
89
|
-
end
|
42
|
+
pods_hmap_name = "#{one.name}.hmap"
|
43
|
+
pods_hmap_path = hmaps_dir + "/#{pods_hmap_name}"
|
44
|
+
relative_hmap_path = "prebuilt-hmaps/#{pods_hmap_name}"
|
45
|
+
if pods_hmap.save_to(pods_hmap_path)
|
46
|
+
# override xcconfig
|
47
|
+
one.reset_header_search_with_relative_hmap_path(relative_hmap_path)
|
90
48
|
end
|
91
49
|
end
|
92
50
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cocoapods-project-hmap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- chenxGen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,7 +38,8 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
description: A
|
41
|
+
description: A cocoapods plugin which using hmap instead of header search paths to
|
42
|
+
improve preprocess time.
|
42
43
|
email:
|
43
44
|
- chenxGen@outlook.com
|
44
45
|
executables: []
|
@@ -49,10 +50,16 @@ files:
|
|
49
50
|
- Gemfile
|
50
51
|
- LICENSE.txt
|
51
52
|
- README.md
|
53
|
+
- README_en.md
|
52
54
|
- Rakefile
|
53
55
|
- cocoapods-project-hmap.gemspec
|
54
56
|
- lib/cocoapods-project-hmap.rb
|
55
57
|
- lib/cocoapods-project-hmap/gem_version.rb
|
58
|
+
- lib/cocoapods-project-hmap/hmap_generator.rb
|
59
|
+
- lib/cocoapods-project-hmap/pod_target.rb
|
60
|
+
- lib/cocoapods-project-hmap/podfile_dsl.rb
|
61
|
+
- lib/cocoapods-project-hmap/post_install_hook_context.rb
|
62
|
+
- lib/cocoapods-project-hmap/xcconfig.rb
|
56
63
|
- lib/cocoapods_plugin.rb
|
57
64
|
homepage: https://github.com/chenxGen/cocoapods-project-hmap
|
58
65
|
licenses:
|
@@ -76,5 +83,6 @@ requirements: []
|
|
76
83
|
rubygems_version: 3.0.3
|
77
84
|
signing_key:
|
78
85
|
specification_version: 4
|
79
|
-
summary: A
|
86
|
+
summary: A cocoapods plugin which using hmap instead of header search paths to improve
|
87
|
+
preprocess time.
|
80
88
|
test_files: []
|