cocoapods-miBin 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.rakeTasks +7 -0
  4. data/Gemfile +13 -0
  5. data/Gemfile.lock +104 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +522 -0
  8. data/Rakefile +13 -0
  9. data/cocoapods-miBin.gemspec +27 -0
  10. data/lib/cocoapods-miBin.rb +4 -0
  11. data/lib/cocoapods-miBin/command.rb +3 -0
  12. data/lib/cocoapods-miBin/command/bin.rb +60 -0
  13. data/lib/cocoapods-miBin/command/bin/archive.rb +134 -0
  14. data/lib/cocoapods-miBin/command/bin/init.rb +71 -0
  15. data/lib/cocoapods-miBin/command/bin/lib.rb +14 -0
  16. data/lib/cocoapods-miBin/command/bin/lib/lint.rb +69 -0
  17. data/lib/cocoapods-miBin/command/bin/list.rb +50 -0
  18. data/lib/cocoapods-miBin/command/bin/open.rb +61 -0
  19. data/lib/cocoapods-miBin/command/bin/repo.rb +15 -0
  20. data/lib/cocoapods-miBin/command/bin/repo/push.rb +116 -0
  21. data/lib/cocoapods-miBin/command/bin/repo/update.rb +42 -0
  22. data/lib/cocoapods-miBin/command/bin/search.rb +69 -0
  23. data/lib/cocoapods-miBin/command/bin/spec.rb +15 -0
  24. data/lib/cocoapods-miBin/command/bin/spec/create.rb +75 -0
  25. data/lib/cocoapods-miBin/command/bin/spec/lint.rb +111 -0
  26. data/lib/cocoapods-miBin/command/bin/umbrella.rb +55 -0
  27. data/lib/cocoapods-miBin/config/config.rb +81 -0
  28. data/lib/cocoapods-miBin/config/config_asker.rb +58 -0
  29. data/lib/cocoapods-miBin/gem_version.rb +11 -0
  30. data/lib/cocoapods-miBin/helpers.rb +5 -0
  31. data/lib/cocoapods-miBin/helpers/framework.rb +64 -0
  32. data/lib/cocoapods-miBin/helpers/framework_builder.rb +227 -0
  33. data/lib/cocoapods-miBin/helpers/sources_helper.rb +33 -0
  34. data/lib/cocoapods-miBin/helpers/spec_creator.rb +159 -0
  35. data/lib/cocoapods-miBin/helpers/spec_files_helper.rb +77 -0
  36. data/lib/cocoapods-miBin/native.rb +21 -0
  37. data/lib/cocoapods-miBin/native/acknowledgements.rb +27 -0
  38. data/lib/cocoapods-miBin/native/analyzer.rb +53 -0
  39. data/lib/cocoapods-miBin/native/installation_options.rb +26 -0
  40. data/lib/cocoapods-miBin/native/installer.rb +116 -0
  41. data/lib/cocoapods-miBin/native/linter.rb +26 -0
  42. data/lib/cocoapods-miBin/native/path_source.rb +33 -0
  43. data/lib/cocoapods-miBin/native/pod_source_installer.rb +19 -0
  44. data/lib/cocoapods-miBin/native/pod_target.rb +8 -0
  45. data/lib/cocoapods-miBin/native/podfile.rb +79 -0
  46. data/lib/cocoapods-miBin/native/podfile_env.rb +36 -0
  47. data/lib/cocoapods-miBin/native/podspec_finder.rb +25 -0
  48. data/lib/cocoapods-miBin/native/resolver.rb +200 -0
  49. data/lib/cocoapods-miBin/native/sandbox_analyzer.rb +34 -0
  50. data/lib/cocoapods-miBin/native/source.rb +35 -0
  51. data/lib/cocoapods-miBin/native/sources_manager.rb +20 -0
  52. data/lib/cocoapods-miBin/native/specification.rb +31 -0
  53. data/lib/cocoapods-miBin/native/validator.rb +16 -0
  54. data/lib/cocoapods-miBin/source_provider_hook.rb +21 -0
  55. data/lib/cocoapods_plugin.rb +5 -0
  56. data/spec/command/bin_spec.rb +12 -0
  57. data/spec/spec_helper.rb +50 -0
  58. metadata +173 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a6c9981cb11c54d9fe8665e8d772c39ea84a3273fcb63e74e69a8ee39ff1810e
4
+ data.tar.gz: e116cf79f9975eec81c3d8a06878892268776631f84057799d1c816b5da2aaac
5
+ SHA512:
6
+ metadata.gz: 6c932e5b2c93e29e757f4324af3e82475cfc312518715d0b5744523a78b54c3ecca4c0204c9911684dd1f3f94e87b949655e564514dd5fc0ea8e473b5cb3315c
7
+ data.tar.gz: cb885ea07175d3a2fcc8c291dffe499d4a10cc0348dbc054d2e4ce313ee4bfbe43407926567fb2cb3a68c5a2a24fb60d3371871d5acc761983888e20aff7e6fd
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ pkg
3
+ .idea/
4
+ example/
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Settings><!--This file was automatically generated by Ruby plugin.
3
+ You are allowed to:
4
+ 1. Remove rake task
5
+ 2. Add existing rake tasks
6
+ To add existing rake tasks automatically delete this file and reload the project.
7
+ --><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Build cocoapods-miBin-0.1.24.gem into the pkg directory" fullCmd="build" taksId="build" /><RakeTask description="Remove any temporary products" fullCmd="clean" taksId="clean" /><RakeTask description="Remove any generated files" fullCmd="clobber" taksId="clobber" /><RakeTask description="Build and install cocoapods-miBin-0.1.24.gem into system gems" fullCmd="install" taksId="install" /><RakeGroup description="" fullCmd="" taksId="install"><RakeTask description="Build and install cocoapods-miBin-0.1.24.gem into system gems without network access" fullCmd="install:local" taksId="local" /></RakeGroup><RakeTask description="Create tag v0.1.24 and build and push cocoapods-miBin-0.1.24.gem to rubygems.org" fullCmd="release[remote]" taksId="release[remote]" /><RakeTask description="Runs all the specs" fullCmd="specs" taksId="specs" /></RakeGroup></Settings>
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cocoapods-miBin.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'cocoapods', '1.7.1'
8
+
9
+ gem 'mocha'
10
+ gem 'bacon'
11
+ gem 'mocha-on-bacon'
12
+ gem 'prettybacon'
13
+ end
@@ -0,0 +1,104 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cocoapods-miBin (0.1.24)
5
+ cocoapods (~> 1.4)
6
+ cocoapods-generate (~> 1.4)
7
+ parallel
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ CFPropertyList (3.0.1)
13
+ activesupport (4.2.11.1)
14
+ i18n (~> 0.7)
15
+ minitest (~> 5.1)
16
+ thread_safe (~> 0.3, >= 0.3.4)
17
+ tzinfo (~> 1.1)
18
+ atomos (0.1.3)
19
+ bacon (1.2.0)
20
+ claide (1.0.3)
21
+ cocoapods (1.7.1)
22
+ activesupport (>= 4.0.2, < 5)
23
+ claide (>= 1.0.2, < 2.0)
24
+ cocoapods-core (= 1.7.1)
25
+ cocoapods-deintegrate (>= 1.0.3, < 2.0)
26
+ cocoapods-downloader (>= 1.2.2, < 2.0)
27
+ cocoapods-plugins (>= 1.0.0, < 2.0)
28
+ cocoapods-search (>= 1.0.0, < 2.0)
29
+ cocoapods-stats (>= 1.0.0, < 2.0)
30
+ cocoapods-trunk (>= 1.3.1, < 2.0)
31
+ cocoapods-try (>= 1.1.0, < 2.0)
32
+ colored2 (~> 3.1)
33
+ escape (~> 0.0.4)
34
+ fourflusher (>= 2.2.0, < 3.0)
35
+ gh_inspector (~> 1.0)
36
+ molinillo (~> 0.6.6)
37
+ nap (~> 1.0)
38
+ ruby-macho (~> 1.4)
39
+ xcodeproj (>= 1.8.2, < 2.0)
40
+ cocoapods-core (1.7.1)
41
+ activesupport (>= 4.0.2, < 6)
42
+ fuzzy_match (~> 2.0.4)
43
+ nap (~> 1.0)
44
+ cocoapods-deintegrate (1.0.4)
45
+ cocoapods-disable-podfile-validations (0.1.1)
46
+ cocoapods-downloader (1.2.2)
47
+ cocoapods-generate (1.6.0)
48
+ cocoapods-disable-podfile-validations (~> 0.1.1)
49
+ cocoapods-plugins (1.0.0)
50
+ nap
51
+ cocoapods-search (1.0.0)
52
+ cocoapods-stats (1.1.0)
53
+ cocoapods-trunk (1.4.1)
54
+ nap (>= 0.8, < 2.0)
55
+ netrc (~> 0.11)
56
+ cocoapods-try (1.1.0)
57
+ colored2 (3.1.2)
58
+ concurrent-ruby (1.1.5)
59
+ escape (0.0.4)
60
+ fourflusher (2.3.1)
61
+ fuzzy_match (2.0.4)
62
+ gh_inspector (1.1.3)
63
+ i18n (0.9.5)
64
+ concurrent-ruby (~> 1.0)
65
+ metaclass (0.0.4)
66
+ minitest (5.12.1)
67
+ mocha (1.9.0)
68
+ metaclass (~> 0.0.1)
69
+ mocha-on-bacon (0.2.3)
70
+ mocha (>= 0.13.0)
71
+ molinillo (0.6.6)
72
+ nanaimo (0.2.6)
73
+ nap (1.1.0)
74
+ netrc (0.11.0)
75
+ parallel (1.18.0)
76
+ prettybacon (0.0.2)
77
+ bacon (~> 1.2)
78
+ rake (13.0.0)
79
+ ruby-macho (1.4.0)
80
+ thread_safe (0.3.6)
81
+ tzinfo (1.2.5)
82
+ thread_safe (~> 0.1)
83
+ xcodeproj (1.12.0)
84
+ CFPropertyList (>= 2.3.3, < 4.0)
85
+ atomos (~> 0.1.3)
86
+ claide (>= 1.0.2, < 2.0)
87
+ colored2 (~> 3.1)
88
+ nanaimo (~> 0.2.6)
89
+
90
+ PLATFORMS
91
+ ruby
92
+
93
+ DEPENDENCIES
94
+ bacon
95
+ bundler (~> 1.3)
96
+ cocoapods (= 1.7.1)
97
+ cocoapods-miBin!
98
+ mocha
99
+ mocha-on-bacon
100
+ prettybacon
101
+ rake
102
+
103
+ BUNDLED WITH
104
+ 1.17.3
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2018 tripleCC <triplec.linux@gmail.com>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,522 @@
1
+ # cocoapods-miBin
2
+
3
+ 组件二进制化插件。
4
+
5
+ [基于 CocoaPods 的组件二进制化实践](https://triplecc.github.io/2019/01/21/%E5%9F%BA%E4%BA%8ECocoaPods%E7%9A%84%E7%BB%84%E4%BB%B6%E4%BA%8C%E8%BF%9B%E5%88%B6%E5%8C%96%E5%AE%9E%E8%B7%B5/)
6
+
7
+ [Demo 工程](https://github.com/for-example-test/cocoapods-miBin-example)
8
+
9
+ ## 概要
10
+
11
+ 本插件所关联的组件二进制化策略:
12
+
13
+ 预先将打包成 `.a` 或者 `.framework` 的组件(目前接入此插件必须使用 `.framework`,最好是静态 framework)保存到静态服务器上,并在 `install` 时,去下载组件对应的二进制版本,以减少组件编译时间,达到加快 App 打包、组件 lint、组件发布等操作的目的。
14
+
15
+ 使用本插件需要提供以下资源:
16
+
17
+ - 静态资源服务器(可参考 [binary-server](https://github.com/tripleCC/binary-server.git))
18
+ - 源码私有源(保存组件源码版本 podspec)
19
+ - 二进制私有源(保存组件二进制版本 podspec)
20
+
21
+ 在所有组件都依赖二进制版本的情况下,本插件支持切换指定组件的依赖版本。
22
+
23
+ 推荐结合 GitLab CI 使用本插件,可以实现自动打包发布,并显著减少其 pipeline 耗时。关于 GitLab CI 的实践,可以参考 [火掌柜 iOS 团队 GitLab CI 集成实践](https://triplecc.github.io/2018/06/23/2018-06-23-ji-gitlabcide-ci-shi-jian/)。虽然后来对部分 stage 和脚本都进行了优化,但总体构建思路还是没变的。
24
+
25
+ ## 准备工作
26
+
27
+ 安装 `cocoapods-miBin`:
28
+
29
+ $ gem install cocoapods-miBin
30
+
31
+ 初始化插件:
32
+
33
+ ```shell
34
+ ➜ ~ pod bin init
35
+
36
+ 开始设置二进制化初始信息.
37
+ 所有的信息都会保存在 /Users/songruiwang/.cocoapods/bin.yml 文件中.
38
+ 你可以在对应目录下手动添加编辑该文件. 文件包含的配置信息样式如下:
39
+
40
+ ---
41
+ code_repo_url: git@git.xxxxxx.net:ios/cocoapods-spec.git
42
+ binary_repo_url: git@git.xxxxxx.net:ios/cocoapods-spec-binary.git
43
+ binary_download_url: http://iosframeworkserver-shopkeeperclient.app.2dfire.com/download/%s/%s.zip
44
+ download_file_type: zip
45
+
46
+
47
+ 源码私有源 Git 地址
48
+ 旧值:git@git.xxxxxx.net:ios/cocoapods-spec.git
49
+ >
50
+ ```
51
+
52
+ 按提示输入源码私有源、二进制私有源、二进制下载地址、下载文件类型后,插件就配置完成了。其中 `binary_download_url` 需要预留组件名称与组件版本占位符,插件内部会依次替换 `%s` 为相应组件的值。
53
+
54
+ `cococapod-bin` 也支持从 url 下载配置文件,方便对多台机器进行配置:
55
+
56
+ ```shell
57
+ ➜ ~ pod bin init --bin-url=http://git.xxxxxx.net/qingmu/cocoapods-tdfire-binary-config/raw/master/bin.yml
58
+ ```
59
+
60
+ 配置文件模版内容如下,根据不同团队的需求定制即可:
61
+
62
+ ```yaml
63
+ ---
64
+ code_repo_url: git@git.xxxxxx.net:ios/cocoapods-spec.git
65
+ binary_repo_url: git@git.xxxxxx.net:ios/cocoapods-spec-binary.git
66
+ binary_download_url: http://iosframeworkserver-shopkeeperclient.app.2dfire.com/download/%s/%s.zip
67
+ download_file_type: zip
68
+ ```
69
+
70
+ 配置时,不需要手动添加源码和二进制私有源的 repo,插件在找不到对应 repo 时会主动 clone。
71
+
72
+ 插件配置完后,就可以部署静态资源服务器了。对于静态资源服务器,这里不做赘述,只提示一点:在生成二进制 podspec 时,插件会根据 `download_file_type` 设置 source 的 `:type` 字段。在下载 http/https 资源时,CocoaPods 会根据 `:type` 字段的类型采取相应的解压方式,如果设置错误就会抛错。这里提到了 **二进制 podspec 的自动生成**,后面会详细介绍。
73
+
74
+ 这里额外说下打包工具 [cocoapods-packager](https://github.com/CocoaPods/cocoapods-packager) 和 [Carthage](https://github.com/Carthage/Carthage/issues) ,前者可以通过 podspec 进行打包,只要保证 lint 通过了,就可以打成 `.framework`,很方便,但是作者几乎不维护了,后者需要结合组件工程。具体使用哪个可以结合自身团队,甚至可以自己写打包脚本,或者使用本插件的打包命令。
75
+
76
+ ## 使用插件
77
+
78
+ 接入二进制版本后,常规的发布流程需要做如下变更:
79
+
80
+ ```shell
81
+ # 1 打出二进制产物 && 提交产物至静态文件服务器
82
+ pod bin archive YOUR_OPTIONS
83
+ curl xxxxxxx
84
+
85
+ # 2.1 发布二进制 podspec
86
+ pod bin repo push --binary YOUR_OPTIONS
87
+
88
+ # 2.2 发布源码 podspec
89
+ pod bin repo push YOUR_OPTIONS
90
+ ```
91
+
92
+ 如果团队内部集成了 CI 平台,那么上面的每大步都可以对应一个 CI stage,源码和二进制版本可并行发布,对应一个 stage 中的两个 job。
93
+
94
+ ### 基本信息
95
+
96
+ `cocoapods-miBin` 命令行信息可以输入以下命令查看:
97
+
98
+ ```shell
99
+ ➜ ~ pod bin --help
100
+ Usage:
101
+
102
+ $ pod bin [COMMAND]
103
+
104
+ 组件二进制化插件。利用源码私有源与二进制私有源实现对组件依赖类型的切换。
105
+
106
+ Commands:
107
+ + archive 将组件归档为静态 framework.
108
+ + init 初始化插件.
109
+ + lib 管理二进制 pod.
110
+ + list 展示二进制 pods .
111
+ > open 打开 workspace 工程.
112
+ + repo 管理 spec 仓库.
113
+ + search 查找二进制 spec.
114
+ + spec 管理二进制 spec.
115
+ + umbrella 生成伞头文件 .
116
+ ```
117
+
118
+ ### 构建二进制产物
119
+
120
+ ```shell
121
+ ➜ ~ pod bin archive --help
122
+ Usage:
123
+
124
+ $ pod bin archive [NAME.podspec]
125
+
126
+ 将组件归档为静态 framework,仅支持 iOS 平台 此静态 framework 不包含依赖组件的 symbol
127
+
128
+ Options:
129
+
130
+ --code-dependencies 使用源码依赖
131
+ --allow-prerelease 允许使用 prerelease 的版本
132
+ --use-modular-headers 使用 modular headers (modulemap)
133
+ --no-clean 保留构建中间产物
134
+ --no-zip 不压缩静态 framework 为 zip
135
+ ...
136
+ ```
137
+
138
+ `pod bin archive` 会根据 podspec 文件构建静态 framework ,此静态 framework 不会包含依赖组件的符号信息。命令内部利用 [cocoapods-generate](https://github.com/square/cocoapods-generate) 插件生成工程,并移植了 [cocoapods-packager](https://github.com/CocoaPods/cocoapods-packager) 插件的部分打包功能,以构建前者生成的工程,默认条件下,命令会生成一个 zip 压缩包。
139
+
140
+ ### 二进制 podspec
141
+
142
+ `cocoapods-miBin` 针对一个组件,同时使用了两种 podspec,分别为源码 podspec 和二进制 podspec,这种方式在没有工具支撑的情况下,势必会增加开发者维护组件的工作量。做为开发者来说,我是不希望同时维护两套 podspec 的。为了解决这个问题, 插件提供了自动生成二进制 podspec 功能,开发者依旧只需要关心源码 podspec 即可。
143
+
144
+ 一般来说,在接入插件前,组件源码 podspec 是已经存在的,所以我们只需要向二进制私有源推送组件的二进制 podspec 即可。如果有条件的话,二进制和源码 podspec 的发布可以走 GitLab CI ,这也是我推荐的做法。
145
+
146
+ 下面介绍下和二进制 podspec 相关的 `cocoapods-miBin` 命令。
147
+
148
+ #### pod bin spec create
149
+
150
+ ```shell
151
+ ➜ ~ pod bin spec create --help
152
+ Usage:
153
+
154
+ $ pod bin spec create
155
+
156
+ 根据源码 podspec 文件,创建对应的二进制 podspec 文件.
157
+
158
+ Options:
159
+
160
+ --platforms=ios 生成二进制 spec 支持的平台
161
+ --template-podspec=A.binary-template.podspec 生成拥有 subspec 的二进制 spec 需要的模版
162
+ podspec, 插件会更改 version 和 source
163
+ --no-overwrite 不允许覆盖
164
+ ...
165
+ ```
166
+
167
+ `pod bin spec create` 会根据源码 podspec ,创建出二进制 podspec 文件。如果组件存在 subspec ,需要开发者提供 podspec 模版信息,以生成二进制 podspec。插件会根据源码 podspec 更改模版中的 version 字段,并且根据插件配置的 `binary_download_url` 生成 source 字段,最终生成二进制 podspec。
168
+
169
+ 以 A 组件举例,如果 A 的 podspec 如下:
170
+
171
+ ```ruby
172
+ Pod::Spec.new do |s|
173
+ s.name = 'A'
174
+ s.version = '0.1.0'
175
+ s.summary = 'business A short description of A.'
176
+ s.description = <<-DESC
177
+ TODO: Add long description of the pod here.
178
+ DESC
179
+ s.homepage = 'http://git.2dfire-inc.com/ios/A'
180
+ s.license = { :type => 'MIT', :file => 'LICENSE' }
181
+ s.author = { 'qingmu' => 'qingmu@2dfire.com' }
182
+ s.source = { :git => 'http://git.2dfire-inc.com/qiandaojiang/A.git', :tag => s.version.to_s }
183
+ s.ios.deployment_target = '8.0'
184
+ s.source_files = 'A/Classes/**/*'
185
+ s.public_header_files = 'A/Classes/**/*.{h}'
186
+ s.resource_bundles = {
187
+ 'A' => ['A/Assets/*']
188
+ }
189
+ end
190
+ ```
191
+
192
+ 那么生成的 `A.binary.podspec.json` 如下:
193
+
194
+ ```json
195
+ {
196
+ "name": "A",
197
+ "version": "0.1.0",
198
+ "summary": "business A short description of A.",
199
+ "description": "TODO: Add long description of the pod here.",
200
+ "homepage": "http://git.2dfire-inc.com/ios/A",
201
+ "license": {
202
+ "type": "MIT",
203
+ "file": "LICENSE"
204
+ },
205
+ "authors": {
206
+ "qingmu": "qingmu@2dfire.com"
207
+ },
208
+ "source": {
209
+ "http": "http://iosframeworkserver-shopkeeperclient.app.2dfire.com/download/A/0.1.0.zip",
210
+ "type": "zip"
211
+ },
212
+ "platforms": {
213
+ "ios": "8.0"
214
+ },
215
+ "source_files": [
216
+ "A.framework/Headers/*",
217
+ "A.framework/Versions/A/Headers/*"
218
+ ],
219
+ "public_header_files": [
220
+ "A.framework/Headers/*",
221
+ "A.framework/Versions/A/Headers/*"
222
+ ],
223
+ "vendored_frameworks": "A.framework",
224
+ "resources": [
225
+ "A.framework/Resources/*.bundle",
226
+ "A.framework/Versions/A/Resources/*.bundle"
227
+ ]
228
+ }
229
+ ```
230
+
231
+ 如果 A 拥有 subspec:
232
+
233
+ ```ruby
234
+ Pod::Spec.new do |s|
235
+ s.name = 'A'
236
+ s.version = '0.1.0'
237
+ s.summary = 'business A short description of A.'
238
+ s.description = <<-DESC
239
+ TODO: Add long description of the pod here.
240
+ DESC
241
+ s.homepage = 'http://git.2dfire-inc.com/ios/A'
242
+ s.license = { :type => 'MIT', :file => 'LICENSE' }
243
+ s.author = { 'qingmu' => 'qingmu@2dfire.com' }
244
+ s.source = { :git => 'http://git.2dfire-inc.com/qiandaojiang/A.git', :tag => s.version.to_s }
245
+ s.ios.deployment_target = '8.0'
246
+ s.source_files = 'A/Classes/**/*'
247
+ s.public_header_files = 'A/Classes/**/*.{h}'
248
+ s.resource_bundles = {
249
+ 'A' => ['A/Assets/*']
250
+ }
251
+ s.subspec 'B' do |ss|
252
+ ss.dependency 'YYModel'
253
+ ss.source_files = 'A/Classes/**/*'
254
+ end
255
+ end
256
+
257
+ ```
258
+
259
+ 那么就需要开发者提供 `A.binary-template.podspec`(此模版中的写法假定组件的所有 subspec 都打进一个 `.framework` 里,如果 subpsec 都有属于自己的 `.framework` ,就可以采用其他写法。),**这里要注意源码版本 subspec 集合需要为二进制版本 subspec 集合的子集,否则会出现源码拉取失败或抛出 subspec 不存在错误的情况**:
260
+
261
+ ```ruby
262
+ Pod::Spec.new do |s|
263
+ s.name = 'A'
264
+ s.summary = 'business A short description of A.'
265
+ s.description = <<-DESC
266
+ TODO: Add long description of the pod here.
267
+ DESC
268
+ s.homepage = 'http://git.2dfire-inc.com/ios/A'
269
+ s.license = { :type => 'MIT', :file => 'LICENSE' }
270
+ s.author = { 'qingmu' => 'qingmu@2dfire.com' }
271
+ s.ios.deployment_target = '8.0'
272
+
273
+ s.subspec "Binary" do |ss|
274
+ ss.vendored_frameworks = "#{s.name}.framework"
275
+ ss.source_files = "#{s.name}.framework/Headers/*", "#{s.name}.framework/Versions/A/Headers/*"
276
+ ss.public_header_files = "#{s.name}.framework/Headers/*", "#{s.name}.framework/Versions/A/Headers/*"
277
+ # 结合实际打包后的资源产出文件类型编写
278
+ ss.resources = "#{s.name}.framework/Resources/*.{bundle}", "#{s.name}.framework/Versions/A/Resources/*.{bundle}"
279
+ ss.dependency 'YYModel'
280
+ end
281
+
282
+ s.subspec 'B' do |ss|
283
+ ss.dependency "#{s.name}/Binary"
284
+ end
285
+ end
286
+
287
+ ```
288
+
289
+ 最终生成的二进制 podspec 如下:
290
+
291
+ ```json
292
+ {
293
+ "name": "A",
294
+ "summary": "business A short description of A.",
295
+ "description": "TODO: Add long description of the pod here.",
296
+ "homepage": "http://git.2dfire-inc.com/ios/A",
297
+ "license": {
298
+ "type": "MIT",
299
+ "file": "LICENSE"
300
+ },
301
+ "authors": {
302
+ "qingmu": "qingmu@2dfire.com"
303
+ },
304
+ "platforms": {
305
+ "ios": "8.0"
306
+ },
307
+ "version": "0.1.0",
308
+ "source": {
309
+ "http": "http://iosframeworkserver-shopkeeperclient.app.2dfire.com/download/A/0.1.0.zip",
310
+ "type": "zip"
311
+ },
312
+ "subspecs": [
313
+ {
314
+ "name": "Binary",
315
+ "vendored_frameworks": "A.framework",
316
+ "source_files": [
317
+ "A.framework/Headers/*",
318
+ "A.framework/Versions/A/Headers/*"
319
+ ],
320
+ "public_header_files": [
321
+ "A.framework/Headers/*",
322
+ "A.framework/Versions/A/Headers/*"
323
+ ],
324
+ "resources": [
325
+ "A.framework/Resources/*.{bundle}",
326
+ "A.framework/Versions/A/Resources/*.{bundle}"
327
+ ],
328
+ "dependencies": {
329
+ "YYModel": [
330
+
331
+ ]
332
+ }
333
+ },
334
+ {
335
+ "name": "B",
336
+ "dependencies": {
337
+ "A/Binary": [
338
+
339
+ ]
340
+ }
341
+ }
342
+ ]
343
+ }
344
+ ```
345
+
346
+ #### pod bin spec lint
347
+
348
+ ```shell
349
+ ➜ ~ pod bin spec lint --help
350
+ Usage:
351
+
352
+ $ pod bin spec lint [NAME.podspec|DIRECTORY|http://PATH/NAME.podspec ...]
353
+
354
+ spec lint 二进制组件 / 源码组件
355
+
356
+ Options:
357
+
358
+ --binary lint 组件的二进制版本
359
+ --template-podspec=A.binary-template.podspec 生成拥有 subspec 的二进制 spec 需要的模版
360
+ podspec, 插件会更改 version 和 source
361
+ --reserve-created-spec 保留生成的二进制 spec 文件
362
+ --code-dependencies 使用源码依赖进行 lint
363
+ --loose-options 添加宽松的 options, 包括 --use-libraries
364
+ (可能会造成 entry point (start)
365
+ undefined)
366
+ ...
367
+ ```
368
+
369
+ `pod bin spec lint` 默认使用二进制依赖进行 lint,在添加 `--binary` 会去 lint 当前组件的二进制 podspec(动态生成)。在添加 `--code-dependencies` 将会使用源码依赖进行 lint ,个人推荐使用二进制依赖 lint,可以极大地减少编译时间。
370
+
371
+ #### pod bin repo push
372
+
373
+ ```shell
374
+
375
+ ➜ ~ pod bin repo push --help
376
+ Usage:
377
+
378
+ $ pod bin repo push [NAME.podspec]
379
+
380
+ 发布二进制组件 / 源码组件
381
+
382
+ Options:
383
+
384
+ --binary 发布组件的二进制版本
385
+ --template-podspec=A.binary-template.podspec 生成拥有 subspec 的二进制 spec 需要的模版
386
+ podspec, 插件会更改 version 和 source
387
+ --reserve-created-spec 保留生成的二进制 spec 文件
388
+ --code-dependencies 使用源码依赖进行 lint
389
+ --loose-options 添加宽松的 options, 包括
390
+ --use-libraries (可能会造成 entry
391
+ point (start) undefined)
392
+ ...
393
+ ```
394
+
395
+ `pod bin repo push` 用来发布组件,其余特性和 `pod bin spec lint` 一致。
396
+
397
+ ### Podfile DSL
398
+
399
+ 首先,开发者需要在 Podfile 中需要使用 `plugin 'cocoapods-miBin'` 语句引入插件 :
400
+
401
+ ```ruby
402
+ plugin 'cocoapods-miBin'
403
+ ```
404
+
405
+ 顺带可以删除 Podfile 中的 source ,因为插件内部会自动帮你添加两个私有源。
406
+
407
+ `cocoapods-miBin `插件提供二进制相关的配置语句有 `use_binaries!`、`use_binaries_with_spec_selector!` 以及 `set_use_source_pods`,下面会分别介绍。
408
+
409
+ #### use_binaries!
410
+
411
+ 全部组件使用二进制版本。
412
+
413
+ 支持传入布尔值控制是否使用二进制版本,比如 DEBUG 包使用二进制版本,正式包使用源码版本,Podfile 关联语句可以这样写:
414
+
415
+ ```ruby
416
+ use_binaries! (ENV['DEBUG'].nil? || ENV['DEBUG'] == 'true')
417
+ ```
418
+
419
+ 当组件没有二进制版本时,插件会强制工程依赖该组件的源码版本。开发者可以通过执行 `pod install--verbose` option ,在分析依赖步骤查看哪些组件没有二进制版本:
420
+
421
+ ```shell
422
+ ...
423
+ Resolving dependencies of `Podfile`
424
+ 【AMapFrameworks | 0.0.4】组件无对应二进制版本 , 将采用源码依赖.
425
+ 【ActivityForRestApp | 0.2.1】组件无对应二进制版本 , 将采用源码依赖.
426
+ 【AssemblyComponent | 0.5.9】组件无对应二进制版本 , 将采用源码依赖.
427
+ 【Bugly | 2.4.6】组件无对应二进制版本 , 将采用源码依赖.
428
+ 【Celebi | 0.6.4】组件无对应二进制版本 , 将采用源码依赖.
429
+ 【CocoaAsyncSocket/RunLoop | 7.4.3】组件无对应二进制版本 , 将采用源码依赖.
430
+ 【CocoaLumberjack | 3.4.1】组件无对应二进制版本 , 将采用源码依赖.
431
+ 【CocoaLumberjack/Default | 3.4.1】组件无对应二进制版本 , 将采用源码依赖.
432
+ 【CocoaLumberjack/Extensions | 3.4.1】组件无对应二进制版本 , 将采用源码依赖.
433
+ 【CodePush | 0.3.1】组件无对应二进制版本 , 将采用源码依赖.
434
+ 【CodePush/Core | 0.3.1】组件无对应二进制版本 , 将采用源码依赖.
435
+ 【CodePush/SSZipArchive | 0.3.1】组件无对应二进制版本 , 将采用源码依赖.
436
+ 【ESExchangeSkin | 0.3.2】组件无对应二进制版本 , 将采用源码依赖.
437
+ ...
438
+ ```
439
+
440
+ 也可以通过 Podfile.lock 中的 `SPEC REPOS` 字段,查看哪些组件采用了源码版本,哪些采用了二进制版本:
441
+
442
+ ```yaml
443
+ ...
444
+ SPEC REPOS:
445
+ "git@git.xxxxxx.net:ios/cocoapods-spec-binary.git":
446
+ - AFNetworking
447
+ - Aspects
448
+ - CocoaSecurity
449
+ - DACircularProgress
450
+ ...
451
+ "git@git.xxxxxx.net:ios/cocoapods-spec.git":
452
+ - ActivityForRestApp
453
+ - AMapFrameworks
454
+ - AssemblyComponent
455
+ ...
456
+ ...
457
+ ```
458
+
459
+
460
+ #### set_use_source_pods
461
+
462
+ 设置使用源码版本的组件。
463
+
464
+ 实际开发中,可能需要查看 YYModel 组件的源码,这时候可以这么设置:
465
+
466
+ ```ruby
467
+ set_use_source_pods ['YYModel']
468
+ ```
469
+
470
+ 如果 CocoaPods 版本为 1.5.3 ,终端会输出以下内容,表示 YYModel 的参照源从二进制私有源切换到了源码私有源:
471
+
472
+ ```shell
473
+ Analyzing dependencies
474
+ Fetching podspec for `A` from `../`
475
+ Downloading dependencies
476
+ Using A (0.1.0)
477
+ Installing YYModel 1.0.4.2 (source changed to `git@git.xxxxxx.net:ios/cocoapods-spec.git` from `git@git.xxxxxx.net:ios/cocoapods-spec-binary.git`)
478
+ Generating Pods project
479
+ Integrating client project
480
+ Sending stats
481
+ Pod installation complete! There is 1 dependency from the Podfile and 2 total pods installed.
482
+ ```
483
+
484
+ #### use_binaries_with_spec_selector!
485
+
486
+ 过滤出需要使用二进制版本组件。
487
+
488
+ 假如开发者只需要 `YYModel` 的二进制版本,那么他可以在 Podfile 中添加以下代码:
489
+
490
+ ```ruby
491
+ use_binaries_with_spec_selector! do |spec|
492
+ spec.name == 'YYModel'
493
+ end
494
+ ```
495
+
496
+ **需要注意的是,如果组件有 subspec ,使用组件名作为判断条件应如下**:
497
+
498
+ ```ruby
499
+ use_binaries_with_spec_selector! do |spec|
500
+ spec.name.start_with? == '组件名'
501
+ end
502
+ ```
503
+
504
+ 如果像上个代码块一样,**直接对比组件名,则插件会忽略此组件的所有 subspec,导致资源拉取错误**,这种场景下,最好通过 `set_use_source_pods` 语句配置依赖。
505
+
506
+ 一个实际应用是,三方组件采用二进制版本,团队编写的组件依旧采用源码版本。如果三方组件都在 `cocoapods-repo` 组下,就可以使用以下代码过滤出三方组件:
507
+
508
+ ```ruby
509
+ use_binaries_with_spec_selector! do |spec|
510
+ git = spec.source && spec.source['git']
511
+ git && git.include?('cocoapods-repo')
512
+ end
513
+ ```
514
+
515
+ #### 其他设置
516
+
517
+ 插件默认开启多线程下载组件资源,如果要禁用这个功能,Podfile 添加以下代码即可:
518
+
519
+ ```ruby
520
+ install! 'cocoapods', { install_with_multi_threads: false }
521
+ ```
522
+