cocoapods-yaml 1.0.0 → 1.1.0
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/CHANGELOG.md +33 -0
- data/README.md +41 -5
- data/lib/cocoapods/yaml.rb +6 -1
- data/lib/cocoapods_plugin.rb +17 -6
- data/lib/core/check/project.rb +53 -17
- data/lib/core/check/xcodeproj.rb +6 -2
- data/lib/core/check/yaml_lint.rb +116 -0
- data/lib/core/check/yaml_status.rb +175 -0
- data/lib/core/command/yaml_lint.rb +28 -0
- data/lib/core/command/yaml_relation.rb +1 -1
- data/lib/core/command/yaml_status.rb +45 -0
- data/lib/core/logger.rb +3 -0
- data/lib/core/setup/podfile_setup.rb +132 -16
- data/lib/core/thin/compatibility.rb +93 -0
- data/lib/core/thin/installer.rb +30 -11
- data/lib/core/thin/local.rb +6 -2
- data/lib/core/thin/shell.rb +3 -0
- data/lib/core/yaml/working_directory.rb +51 -0
- data/lib/core/yaml/yaml_dependencies.rb +264 -68
- data/lib/version.rb +24 -1
- metadata +38 -5
|
@@ -11,6 +11,62 @@ require 'shellwords'
|
|
|
11
11
|
module Pod
|
|
12
12
|
class YamlDependencies
|
|
13
13
|
|
|
14
|
+
# 依赖文件通用顶层字段
|
|
15
|
+
COMMON_TOP_LEVEL_KEYS = %w[SOURCES PODS].freeze
|
|
16
|
+
|
|
17
|
+
# 仅在 LocalDependencies.yaml 中生效的顶层字段
|
|
18
|
+
LOCAL_ONLY_TOP_LEVEL_KEYS = %w[
|
|
19
|
+
TRIM_UNUSED_POD ENABLE_TRUNK DISABLE_CHECK_PODSPEC
|
|
20
|
+
PARALLEL_POD_DOWNLOADS PARALLEL_POD_DOWNLOAD_THREAD_POOL_SIZE
|
|
21
|
+
INCREMENTAL_INSTALLATION GENERATE_MULTIPLE_POD_PROJECTS
|
|
22
|
+
].freeze
|
|
23
|
+
|
|
24
|
+
# 字符串真值视为false的取值(用于"false"这类带引号的写法)
|
|
25
|
+
FALSE_LIKE_VALUES = %w[false no off 0].freeze
|
|
26
|
+
|
|
27
|
+
# 跳过"路径仓库 SNAPSHOT tag 自动同步"(该功能会修改本地仓库的 .git/config)
|
|
28
|
+
TAG_SYNC_SKIP_ENV = 'COCOAPODS_YAML_SKIP_TAG_SYNC'
|
|
29
|
+
|
|
30
|
+
# 允许强制更新已移动 tag 的 fetch refspec
|
|
31
|
+
TAG_SYNC_REFSPEC = '+refs/tags/*:refs/tags/*'
|
|
32
|
+
|
|
33
|
+
# 校验失败信号。
|
|
34
|
+
# 默认(安装流程)直接 exit! 终止进程,保持原有行为;
|
|
35
|
+
# lint 模式下改为抛出,由逐文件调用方 rescue 后继续校验下一个文件。
|
|
36
|
+
class ValidationError < StandardError; end
|
|
37
|
+
|
|
38
|
+
# 是否处于仅校验、不退出进程的 lint 模式
|
|
39
|
+
def lint_mode?
|
|
40
|
+
!!@lint_mode
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# 开启 lint 模式
|
|
44
|
+
def enable_lint_mode
|
|
45
|
+
@lint_mode = true
|
|
46
|
+
lint_errors
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# lint 模式累计的错误信息
|
|
50
|
+
# @return [Array<String>]
|
|
51
|
+
def lint_errors
|
|
52
|
+
@lint_errors ||= []
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# 统一的校验失败出口
|
|
56
|
+
# @param message [String] 错误描述
|
|
57
|
+
# @param detail_lines [Array<String>] 错误后面跟随的提示行
|
|
58
|
+
def fail!(message, detail_lines = [])
|
|
59
|
+
log.error(message)
|
|
60
|
+
detail_lines.each { |line| log.info(line) }
|
|
61
|
+
|
|
62
|
+
if lint_mode?
|
|
63
|
+
lint_errors << message
|
|
64
|
+
raise ValidationError, message
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
exit!
|
|
68
|
+
end
|
|
69
|
+
|
|
14
70
|
# 需要集成依赖的主工程target列表(application/app扩展)
|
|
15
71
|
# @return [Array]
|
|
16
72
|
attr_accessor :targets
|
|
@@ -63,6 +119,9 @@ module Pod
|
|
|
63
119
|
# 将YAML中声明的私有源注册为Podfile顶层source,屏蔽CocoaPods隐式追加的CDN trunk源
|
|
64
120
|
configure_private_sources(podfile)
|
|
65
121
|
|
|
122
|
+
# 注入 CocoaPods 安装选项(并发下载/增量安装/线程池)
|
|
123
|
+
configure_install_options(podfile)
|
|
124
|
+
|
|
66
125
|
install_dependencies(targets_dependencies, podfile) do|name|
|
|
67
126
|
yield(name) if block_given?
|
|
68
127
|
end
|
|
@@ -72,7 +131,7 @@ module Pod
|
|
|
72
131
|
# 由LocalDependencies.yaml顶层 ENABLE_TRUNK 控制(工程级,不提交git,只影响本工程),默认false
|
|
73
132
|
def trunk_enabled?
|
|
74
133
|
content = read_yaml_content(local_yaml_name)
|
|
75
|
-
content
|
|
134
|
+
yaml_bool(content && content['ENABLE_TRUNK'], false)
|
|
76
135
|
end
|
|
77
136
|
|
|
78
137
|
# Podfile未声明任何顶层source时,CocoaPods会隐式加入CDN trunk源(cdn.cocoapods.org)。
|
|
@@ -112,6 +171,53 @@ module Pod
|
|
|
112
171
|
log.info('')
|
|
113
172
|
end
|
|
114
173
|
|
|
174
|
+
# 从 LocalDependencies.yaml 读取 CocoaPods install! 选项,合并用户已在 Podfile 中手动指定的选项。
|
|
175
|
+
# 插件默认开启并发下载(线程池20);增量安装、多项目默认关闭,按需在 LocalDependencies.yaml 中打开。
|
|
176
|
+
# generate_multiple_pod_projects 是 incremental_installation 的硬依赖(CocoaPods 会校验),
|
|
177
|
+
# 因此只要最终增量安装为 true 就自动把它设为 true(除非用户显式指定了 false)
|
|
178
|
+
# PARALLEL_POD_DOWNLOADS: true/false 默认 true
|
|
179
|
+
# PARALLEL_POD_DOWNLOAD_THREAD_POOL_SIZE: Integer 默认 20
|
|
180
|
+
# INCREMENTAL_INSTALLATION: true/false 默认 false
|
|
181
|
+
# GENERATE_MULTIPLE_POD_PROJECTS: true/false 默认 false(增量安装开启时自动联动)
|
|
182
|
+
def configure_install_options(podfile)
|
|
183
|
+
yaml_content = read_yaml_content(local_yaml_name) || {}
|
|
184
|
+
|
|
185
|
+
# LocalDependencies.yaml 里显式写的值(未写则不纳入 options,让插件默认值生效)
|
|
186
|
+
yaml_overrides = {}
|
|
187
|
+
yaml_overrides[:parallel_pod_downloads] = yaml_content['PARALLEL_POD_DOWNLOADS'] if yaml_content.key?('PARALLEL_POD_DOWNLOADS')
|
|
188
|
+
yaml_overrides[:parallel_pod_download_thread_pool_size] = yaml_content['PARALLEL_POD_DOWNLOAD_THREAD_POOL_SIZE'].to_i if yaml_content.key?('PARALLEL_POD_DOWNLOAD_THREAD_POOL_SIZE')
|
|
189
|
+
yaml_overrides[:incremental_installation] = yaml_content['INCREMENTAL_INSTALLATION'] if yaml_content.key?('INCREMENTAL_INSTALLATION')
|
|
190
|
+
yaml_overrides[:generate_multiple_pod_projects] = yaml_content['GENERATE_MULTIPLE_POD_PROJECTS'] if yaml_content.key?('GENERATE_MULTIPLE_POD_PROJECTS')
|
|
191
|
+
|
|
192
|
+
# 用户在 Podfile 里手动写的 install! 选项
|
|
193
|
+
_, user_options = podfile.installation_method
|
|
194
|
+
|
|
195
|
+
# 合并优先级: Podfile手动指定 > LocalDependencies.yaml > 插件默认值
|
|
196
|
+
plugin_defaults = {
|
|
197
|
+
parallel_pod_downloads: true,
|
|
198
|
+
parallel_pod_download_thread_pool_size: 20
|
|
199
|
+
}
|
|
200
|
+
merged = plugin_defaults.merge(yaml_overrides).merge(user_options)
|
|
201
|
+
|
|
202
|
+
# incremental_installation 依赖 generate_multiple_pod_projects,
|
|
203
|
+
# 如果增量安装开启且 generate_multiple_pod_projects 未被用户显式指定为 false,则自动联动开启
|
|
204
|
+
if merged[:incremental_installation] && merged[:generate_multiple_pod_projects] != false
|
|
205
|
+
merged[:generate_multiple_pod_projects] = true
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
podfile.install!('cocoapods', merged)
|
|
209
|
+
|
|
210
|
+
# 打印最终生效的选项
|
|
211
|
+
yaml_changed = plugin_defaults.merge(yaml_overrides) != plugin_defaults
|
|
212
|
+
user_changed = !user_options.empty? && (plugin_defaults.merge(yaml_overrides) != plugin_defaults.merge(yaml_overrides).merge(user_options))
|
|
213
|
+
detail_lines = []
|
|
214
|
+
detail_lines << "并发下载: #{merged[:parallel_pod_downloads]}"
|
|
215
|
+
detail_lines << "线程池: #{merged[:parallel_pod_download_thread_pool_size]}"
|
|
216
|
+
detail_lines << "多项目: #{merged[:generate_multiple_pod_projects]}"
|
|
217
|
+
detail_lines << "增量安装: #{merged[:incremental_installation]}"
|
|
218
|
+
log.detail("CocoaPods安装选项: #{detail_lines.join(', ')}#{yaml_changed ? ' (LocalDependencies.yaml覆盖)' : ''}#{user_changed ? ' (Podfile已手动指定)' : ''}")
|
|
219
|
+
end
|
|
220
|
+
|
|
115
221
|
# SNAPSHOT 同名 tag 每次发布会被删除后前移,而 git 默认 fetch 不会覆盖本地已存在的 tag,
|
|
116
222
|
# 导致本地/同事本地的组件仓 tag 停留在旧位置。
|
|
117
223
|
# 这里仅对 LocalDependencies.yaml 中以 path 方式引用、且本身是 git 仓库的目录,
|
|
@@ -119,12 +225,20 @@ module Pod
|
|
|
119
225
|
# 1. fetch refspec 对 tags 加 '+' 前缀,允许强制更新已移动的 tag
|
|
120
226
|
# 2. tagOpt=--no-tags 关闭默认的 tag 自动跟随,避免与上面的显式 refspec 冲突
|
|
121
227
|
# (否则会报 multiple updates for ref 'refs/tags/xxx' not allowed)
|
|
228
|
+
#
|
|
229
|
+
# 这会修改用户仓库的本地配置,属于持久副作用:变更后必须明确告知改了什么、
|
|
230
|
+
# 如何跳过(环境变量)、如何撤销,避免同事在不知情的情况下被改了仓库设置。
|
|
122
231
|
def ensure_local_path_tag_sync
|
|
232
|
+
if ENV.fetch(TAG_SYNC_SKIP_ENV, '').strip != ''
|
|
233
|
+
log.detail("已跳过路径仓库的SNAPSHOT tag自动同步(#{TAG_SYNC_SKIP_ENV}已设置)")
|
|
234
|
+
return
|
|
235
|
+
end
|
|
236
|
+
|
|
123
237
|
local_deps = yaml_deps[local_yaml_name]
|
|
124
238
|
return unless local_deps.is_a?(Hash)
|
|
125
239
|
|
|
126
|
-
|
|
127
|
-
|
|
240
|
+
configured_paths = []
|
|
241
|
+
overridden_tag_opts = []
|
|
128
242
|
|
|
129
243
|
local_deps.values.map(&:path).compact.uniq.each do |raw_path|
|
|
130
244
|
repo_path = File.expand_path(raw_path)
|
|
@@ -132,10 +246,12 @@ module Pod
|
|
|
132
246
|
|
|
133
247
|
begin
|
|
134
248
|
existing = `git -C #{Shellwords.escape(repo_path)} config --get-all remote.origin.fetch 2>/dev/null`.to_s
|
|
135
|
-
next if existing.lines.map(&:strip).include?(
|
|
249
|
+
next if existing.lines.map(&:strip).include?(TAG_SYNC_REFSPEC)
|
|
250
|
+
|
|
251
|
+
existing_tag_opt = `git -C #{Shellwords.escape(repo_path)} config --get remote.origin.tagOpt 2>/dev/null`.to_s.strip
|
|
136
252
|
|
|
137
253
|
# 数组形式system避免路径/refs注入,并检查退出码,失败不静默
|
|
138
|
-
add_ok = system('git', '-C', repo_path, 'config', '--add', 'remote.origin.fetch',
|
|
254
|
+
add_ok = system('git', '-C', repo_path, 'config', '--add', 'remote.origin.fetch', TAG_SYNC_REFSPEC,
|
|
139
255
|
out: File::NULL, err: File::NULL)
|
|
140
256
|
tag_ok = add_ok && system('git', '-C', repo_path, 'config', 'remote.origin.tagOpt', '--no-tags',
|
|
141
257
|
out: File::NULL, err: File::NULL)
|
|
@@ -144,15 +260,34 @@ module Pod
|
|
|
144
260
|
next
|
|
145
261
|
end
|
|
146
262
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
263
|
+
unless existing_tag_opt.empty? || existing_tag_opt == '--no-tags'
|
|
264
|
+
overridden_tag_opts << [repo_path, existing_tag_opt]
|
|
265
|
+
end
|
|
266
|
+
configured_paths << repo_path
|
|
150
267
|
rescue => e
|
|
151
268
|
log.warn("配置路径仓库tag同步失败(#{repo_path}): #{e.message}")
|
|
152
269
|
end
|
|
153
270
|
end
|
|
154
271
|
|
|
155
|
-
|
|
272
|
+
report_tag_sync_changes(configured_paths, overridden_tag_opts)
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
# 打印本次对本地仓库 git 配置的改动,以及跳过/撤销方式
|
|
276
|
+
def report_tag_sync_changes(configured_paths, overridden_tag_opts)
|
|
277
|
+
return if configured_paths.empty?
|
|
278
|
+
|
|
279
|
+
log.info('')
|
|
280
|
+
log.warn("已修改#{configured_paths.size}个本地组件仓库的 git 配置(SNAPSHOT tag 自动前移)")
|
|
281
|
+
log.info(" 变更(仅本地 .git/config,不影响远端): remote.origin.fetch += #{TAG_SYNC_REFSPEC},remote.origin.tagOpt = --no-tags")
|
|
282
|
+
log.info(" 跳过: 设置环境变量 #{TAG_SYNC_SKIP_ENV}=1 后重新执行")
|
|
283
|
+
log.info(' 撤销(对下面每个仓库执行):')
|
|
284
|
+
log.info(" git -C <仓库路径> config --unset remote.origin.fetch '\\+refs/tags/\\*:refs/tags/\\*'")
|
|
285
|
+
log.info(' git -C <仓库路径> config --unset remote.origin.tagOpt')
|
|
286
|
+
configured_paths.each { |path| log.info(" - #{path}") }
|
|
287
|
+
overridden_tag_opts.each do |path, value|
|
|
288
|
+
log.warn(" 注意: #{path} 原有 remote.origin.tagOpt=#{value},已被覆盖为 --no-tags")
|
|
289
|
+
end
|
|
290
|
+
log.info('')
|
|
156
291
|
end
|
|
157
292
|
|
|
158
293
|
def install_dependencies(targets_dependencies, podfile)
|
|
@@ -313,28 +448,30 @@ module Pod
|
|
|
313
448
|
return
|
|
314
449
|
end
|
|
315
450
|
|
|
316
|
-
|
|
317
|
-
|
|
451
|
+
# 缺 PODS 字段多半是拼写错误。原实现只打 detail 日志(默认不显示)后返回,
|
|
452
|
+
# 结果是该target解析出0个依赖,pod install 会静默把已有依赖全部卸载。
|
|
453
|
+
unless yaml_content.key?("PODS")
|
|
454
|
+
log.warn("#{yaml_name} 未配置 PODS 字段,该target将不集成任何依赖(正确字段名是 PODS)。若无依赖请显式写 PODS: []")
|
|
455
|
+
return
|
|
456
|
+
end
|
|
457
|
+
|
|
458
|
+
unless yaml_content["PODS"].is_a?(Array)
|
|
459
|
+
log.warn("#{yaml_name} 的 PODS 字段必须是数组(例如 PODS: [] 或 - pod: 组件名),当前为 #{yaml_content["PODS"].class},该target将不集成任何依赖")
|
|
318
460
|
return
|
|
319
461
|
end
|
|
320
462
|
|
|
321
|
-
if yaml_content["PODS"].
|
|
322
|
-
log.detail("#{yaml_name}共0个依赖(
|
|
463
|
+
if yaml_content["PODS"].empty?
|
|
464
|
+
log.detail("#{yaml_name}共0个依赖(PODS为空数组)")
|
|
323
465
|
return
|
|
324
466
|
end
|
|
325
467
|
|
|
326
468
|
if yaml_name != local_yaml_name
|
|
327
469
|
sources = yaml_content["SOURCES"]
|
|
328
|
-
#
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
log.error("#{yaml_name}的SOURCES字段必须是非空数组,例如: SOURCES: ['git@xxx_binary.git', 'git@xxx_source.git']")
|
|
332
|
-
exit!
|
|
333
|
-
end
|
|
334
|
-
end
|
|
335
|
-
if sources.is_a?(Array) and sources.all? { |s| s.to_s.strip != "" }
|
|
336
|
-
file_sources[yaml_name] = sources.map(&:to_s).map(&:strip)
|
|
470
|
+
# 走到这里说明该文件已声明依赖,SOURCES 必须是非空字符串数组
|
|
471
|
+
if sources.class != Array or sources.empty? or sources.any? { |s| s.to_s.strip.empty? }
|
|
472
|
+
fail!("#{yaml_name}的SOURCES字段必须是非空数组,例如: SOURCES: ['git@xxx_binary.git', 'git@xxx_source.git']")
|
|
337
473
|
end
|
|
474
|
+
file_sources[yaml_name] = sources.map(&:to_s).map(&:strip)
|
|
338
475
|
end
|
|
339
476
|
|
|
340
477
|
# 依赖未显式指定source时,默认使用SOURCES中的第一个源(通常把二进制源放在第一位)
|
|
@@ -351,18 +488,20 @@ module Pod
|
|
|
351
488
|
# 遍历依赖库列表
|
|
352
489
|
dependencies_pods.each { |dependency|
|
|
353
490
|
|
|
354
|
-
|
|
491
|
+
begin
|
|
492
|
+
check_pod(dependency, yaml_name, dependencies_name)
|
|
493
|
+
rescue ValidationError
|
|
494
|
+
# lint 模式下单条校验失败只跳过该条,继续校验同文件中的其它条目;
|
|
495
|
+
# 安装模式下 fail! 直接 exit! 不会走到这里
|
|
496
|
+
next
|
|
497
|
+
end
|
|
355
498
|
|
|
356
499
|
# source: 显式指定优先,否则取默认源;LocalDependencies无SOURCES时允许为空(path/podspec引用不需要)
|
|
357
500
|
source = dependency['source'].to_s.strip
|
|
358
501
|
source = default_source if source.empty? && default_source
|
|
359
502
|
|
|
360
503
|
# inhibit_warnings: target依赖文件默认true(远程库警告不好修改),本地覆盖文件默认false(开发时能看到本地库警告)
|
|
361
|
-
inhibit_warnings =
|
|
362
|
-
!!dependency['inhibit_warnings']
|
|
363
|
-
else
|
|
364
|
-
yaml_name != local_yaml_name
|
|
365
|
-
end
|
|
504
|
+
inhibit_warnings = yaml_bool(dependency['inhibit_warnings'], yaml_name != local_yaml_name)
|
|
366
505
|
|
|
367
506
|
# configurations和subspecs cocoapods不能同时支持,所以要展开
|
|
368
507
|
if Array(dependency['subspecs']).size > 0 and Array(dependency['configurations']).size > 0
|
|
@@ -402,8 +541,7 @@ module Pod
|
|
|
402
541
|
def check_pod(dependency, yaml_name, dependencies_name)
|
|
403
542
|
# 依赖条目必须是keyValue形式;写成"- Foo"这种纯字符串时后续each_key会抛原始堆栈,这里前置拦截
|
|
404
543
|
unless dependency.is_a?(Hash)
|
|
405
|
-
|
|
406
|
-
exit!
|
|
544
|
+
fail!("#{yaml_name}: 依赖条目必须为keyValue形式(每项以 - pod: 开头),当前条目: #{dependency.inspect}")
|
|
407
545
|
end
|
|
408
546
|
|
|
409
547
|
# 不支持提醒
|
|
@@ -411,17 +549,15 @@ module Pod
|
|
|
411
549
|
dependency.each_key { |key|
|
|
412
550
|
unless available_keys.include?(key)
|
|
413
551
|
gem_name = "cocoapods-yaml"
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
exit!
|
|
552
|
+
fail!("#{yaml_name}: 当前#{gem_name}版本(#{CocoaPods::Yaml::VERSION})不支持字段#{key}",
|
|
553
|
+
["请检查对应字段或尝试执行如下命令升级",
|
|
554
|
+
"gem uninstall #{gem_name} && gem install #{gem_name}"])
|
|
418
555
|
end
|
|
419
556
|
}
|
|
420
557
|
|
|
421
558
|
# 校验字段
|
|
422
559
|
unless dependency['pod']
|
|
423
|
-
|
|
424
|
-
exit!
|
|
560
|
+
fail!("#{yaml_name}: pod 字段(组件名字)必须存在,请检查:")
|
|
425
561
|
end
|
|
426
562
|
|
|
427
563
|
current_type = nil
|
|
@@ -432,36 +568,40 @@ module Pod
|
|
|
432
568
|
current_type = check_only_one_dep(dependency, "branch", current_type, yaml_name)
|
|
433
569
|
|
|
434
570
|
unless current_type
|
|
435
|
-
|
|
436
|
-
|
|
571
|
+
fail!("#{yaml_name} - #{dependency['pod']}: path/podspec/version/git/tag/branch 字段请指定其中一个")
|
|
572
|
+
end
|
|
573
|
+
|
|
574
|
+
# git 与 path/podspec/version 不能共存。
|
|
575
|
+
# YamlPod#option 的取值顺序是 path -> podspec -> version -> git,同时配置时 git 会被静默忽略,
|
|
576
|
+
# 表现为"以为在拉分支代码,实际用的是私有源里的版本号",且不会有任何提示。
|
|
577
|
+
if dependency['git']
|
|
578
|
+
%w[path podspec version].each do |conflict_key|
|
|
579
|
+
next unless dependency[conflict_key]
|
|
580
|
+
fail!("#{yaml_name} - #{dependency['pod']}: git 与 #{conflict_key} 不能同时使用(git引用请用tag/branch指定版本),当前#{conflict_key}会覆盖git导致git被忽略")
|
|
581
|
+
end
|
|
437
582
|
end
|
|
438
583
|
|
|
439
584
|
unless dependency['git']
|
|
440
585
|
if dependency['tag']
|
|
441
|
-
|
|
442
|
-
exit!
|
|
586
|
+
fail!("#{yaml_name} - #{dependency['pod']}: 你指定了tag,但未配置git地址,请为此组件配置git字段")
|
|
443
587
|
end
|
|
444
588
|
if dependency['branch']
|
|
445
|
-
|
|
446
|
-
exit!
|
|
589
|
+
fail!("#{yaml_name} - #{dependency['pod']}: 你指定了branch,但未配置git地址,请为此组件配置git字段")
|
|
447
590
|
end
|
|
448
591
|
end
|
|
449
592
|
|
|
450
593
|
# 检查数据类型
|
|
451
594
|
if dependency['configurations'] and dependency['configurations'].class != Array
|
|
452
|
-
|
|
453
|
-
exit!
|
|
595
|
+
fail!("#{yaml_name} - #{dependency['pod']} - #{dependency['configurations']}: configurations字段必须是数组,例如:['Debug','Release']")
|
|
454
596
|
end
|
|
455
597
|
|
|
456
598
|
if dependency['subspecs'] and dependency['subspecs'].class != Array
|
|
457
|
-
|
|
458
|
-
exit!
|
|
599
|
+
fail!("#{yaml_name} - #{dependency['pod']} - #{dependency['subspecs']}: subspecs字段必须是数组,例如:['A','B','C']")
|
|
459
600
|
end
|
|
460
601
|
|
|
461
602
|
# 校验自身文件重复
|
|
462
603
|
if dependencies_name.include?(dependency['pod'])
|
|
463
|
-
|
|
464
|
-
exit!
|
|
604
|
+
fail!("发现#{yaml_name}内重复组件:#{dependency['pod']},请检查并删除重复依赖")
|
|
465
605
|
else
|
|
466
606
|
dependencies_name << dependency['pod']
|
|
467
607
|
end
|
|
@@ -479,8 +619,7 @@ module Pod
|
|
|
479
619
|
def check_only_one_dep(dependency, key, current_type, yaml_name)
|
|
480
620
|
if dependency[key]
|
|
481
621
|
if current_type
|
|
482
|
-
|
|
483
|
-
exit!
|
|
622
|
+
fail!("#{yaml_name} - #{dependency['pod']}: #{current_type}字段和#{key}只能使用其中一个,请删除不需要的一个")
|
|
484
623
|
else
|
|
485
624
|
return key
|
|
486
625
|
end
|
|
@@ -497,10 +636,10 @@ module Pod
|
|
|
497
636
|
begin
|
|
498
637
|
# aliases: true 支持YAML锚点变量(SOURCES上的 &binary/&source 锚点被组件的 *source 引用)
|
|
499
638
|
yaml_content = YAML.load_file(yaml_name, aliases: true)
|
|
500
|
-
rescue
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
639
|
+
rescue ::StandardError => e
|
|
640
|
+
# 必须写 ::StandardError:Pod 命名空间下存在 Pod::StandardError(CocoaPods 自己的类),
|
|
641
|
+
# 裸写会解析到它,导致普通解析异常接不住
|
|
642
|
+
fail!(e.to_s, ["#{yaml_name}文件解析异常, 请检查 ⬆️"])
|
|
504
643
|
end
|
|
505
644
|
|
|
506
645
|
unless yaml_content.class == Hash
|
|
@@ -508,9 +647,55 @@ module Pod
|
|
|
508
647
|
return nil
|
|
509
648
|
end
|
|
510
649
|
|
|
650
|
+
validate_top_level_keys(yaml_content, yaml_name)
|
|
651
|
+
|
|
511
652
|
yaml_content
|
|
512
653
|
end
|
|
513
654
|
|
|
655
|
+
# 顶层字段校验。
|
|
656
|
+
# 完全未知的字段直接报错退出:PODS 拼成 POD 这类笔误会让文件解析出0个依赖却不报错,
|
|
657
|
+
# 随后 pod install 会把该target已安装的依赖全部卸载,属于最难排查的一类事故。
|
|
658
|
+
# 仅在LocalDependencies生效的字段出现在target依赖文件中时,给出告警(不阻断)。
|
|
659
|
+
def validate_top_level_keys(yaml_content, yaml_name)
|
|
660
|
+
allowed_keys = COMMON_TOP_LEVEL_KEYS + LOCAL_ONLY_TOP_LEVEL_KEYS
|
|
661
|
+
|
|
662
|
+
unknown_keys = yaml_content.keys.reject { |key| allowed_keys.include?(key) }
|
|
663
|
+
unless unknown_keys.empty?
|
|
664
|
+
fail!("#{yaml_name}: 存在不支持的顶层字段 #{unknown_keys.join('、')}",
|
|
665
|
+
["当前支持的顶层字段: #{allowed_keys.join('、')}",
|
|
666
|
+
'如果是 PODS 拼写错误请修正;顶层字段拼错会导致该文件解析出0个依赖且不报错'])
|
|
667
|
+
end
|
|
668
|
+
|
|
669
|
+
return if yaml_name == local_yaml_name
|
|
670
|
+
|
|
671
|
+
misplaced_keys = yaml_content.keys.select { |key| LOCAL_ONLY_TOP_LEVEL_KEYS.include?(key) }
|
|
672
|
+
unless misplaced_keys.empty?
|
|
673
|
+
log.warn("#{yaml_name}: 字段 #{misplaced_keys.join('、')} 仅在#{local_yaml_name}中生效,本文件中的配置将被忽略")
|
|
674
|
+
end
|
|
675
|
+
end
|
|
676
|
+
|
|
677
|
+
# 统一的布尔开关解析。
|
|
678
|
+
# 三种取值习惯并存(YAML布尔、带引号的"false"、yes/no/0),原先各处判断标准不一致
|
|
679
|
+
# (有 == true、有 !!),导致 "false" 在不同开关上表现相反。
|
|
680
|
+
# @param value 原始值
|
|
681
|
+
# @param default [Boolean] value 为 nil 时的默认值
|
|
682
|
+
def yaml_bool(value, default = false)
|
|
683
|
+
case value
|
|
684
|
+
when nil
|
|
685
|
+
default
|
|
686
|
+
when true, false
|
|
687
|
+
value
|
|
688
|
+
when String
|
|
689
|
+
normalized = value.strip.downcase
|
|
690
|
+
return default if normalized.empty?
|
|
691
|
+
!FALSE_LIKE_VALUES.include?(normalized)
|
|
692
|
+
when Numeric
|
|
693
|
+
value != 0
|
|
694
|
+
else
|
|
695
|
+
!value.nil?
|
|
696
|
+
end
|
|
697
|
+
end
|
|
698
|
+
|
|
514
699
|
def print_targets_deps
|
|
515
700
|
log.step('读取依赖文件')
|
|
516
701
|
yaml_deps.each do |yaml_name, deps|
|
|
@@ -562,28 +747,29 @@ module Pod
|
|
|
562
747
|
if dependency.subspecs
|
|
563
748
|
puts_result += ", :subspecs => ['#{dependency.subspecs.join("','")}']"
|
|
564
749
|
end
|
|
565
|
-
# inhibit_warnings
|
|
566
|
-
|
|
750
|
+
# inhibit_warnings: target依赖文件默认true,本地覆盖文件默认false;仅与默认值不一致时打印
|
|
751
|
+
inhibit_default = dependency.from_local ? false : true
|
|
752
|
+
if dependency.inhibit_warnings != inhibit_default
|
|
753
|
+
puts_result += ", :inhibit_warnings => #{dependency.inhibit_warnings}"
|
|
754
|
+
end
|
|
567
755
|
# source默认取SOURCES第一个,仅版本号引用且使用非默认源时打印
|
|
568
756
|
if dependency.version and dependency.source and dependency.source != default_source
|
|
569
757
|
puts_result += ", :source => '#{dependency.source}'"
|
|
570
758
|
end
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
puts_result += " [本地覆盖]"
|
|
575
|
-
end
|
|
759
|
+
|
|
760
|
+
# 仅新增组件打印[新增]标记,本地覆盖不再单独提示
|
|
761
|
+
injected_tag = dependency.local_injected ? " [新增]" : ""
|
|
576
762
|
|
|
577
763
|
if dependency.path
|
|
578
764
|
branch = repo_branch(dependency.path)
|
|
579
765
|
modify = repo_modify(dependency.path)
|
|
580
|
-
#
|
|
581
|
-
log.info(
|
|
766
|
+
# 路径依赖默认色,分支名青色,[有修改]红色醒目区分
|
|
767
|
+
log.info(puts_result + injected_tag + colorize(branch, :cyan) + colorize(modify, :red))
|
|
582
768
|
|
|
583
769
|
elsif dependency.branch
|
|
584
|
-
log.info(colorize(puts_result, :yellow))
|
|
770
|
+
log.info(colorize(puts_result + injected_tag, :yellow))
|
|
585
771
|
else
|
|
586
|
-
log.info(puts_result)
|
|
772
|
+
log.info(puts_result + injected_tag)
|
|
587
773
|
end
|
|
588
774
|
|
|
589
775
|
}
|
|
@@ -629,6 +815,16 @@ module Pod
|
|
|
629
815
|
content = content + "# 如本工程确需trunk,把下行改为true(仅本工程生效)\n"
|
|
630
816
|
content = content + "ENABLE_TRUNK: false\n\n"
|
|
631
817
|
|
|
818
|
+
content = content + "# CocoaPods安装性能选项(插件默认全开启,一般无需改动)\n"
|
|
819
|
+
content = content + "# 并发下载pod,加速pod install拉取阶段(默认为true)\n"
|
|
820
|
+
content = content + "# PARALLEL_POD_DOWNLOADS: true\n"
|
|
821
|
+
content = content + "# 并发下载线程池大小(默认20)\n"
|
|
822
|
+
content = content + "# PARALLEL_POD_DOWNLOAD_THREAD_POOL_SIZE: 20\n"
|
|
823
|
+
content = content + "# 每个pod生成独立Xcode工程(增量安装的硬依赖,增量开则自动开)\n"
|
|
824
|
+
content = content + "# GENERATE_MULTIPLE_POD_PROJECTS: true\n"
|
|
825
|
+
content = content + "# 增量安装,只重新生成有变化的pod target(默认为true)\n"
|
|
826
|
+
content = content + "# INCREMENTAL_INSTALLATION: true\n\n"
|
|
827
|
+
|
|
632
828
|
content = content + "PODS: []\n\n"
|
|
633
829
|
|
|
634
830
|
content = content + "# 示例:\n"
|
|
@@ -730,7 +926,7 @@ module Pod
|
|
|
730
926
|
# git -C 在子进程中切换目录,避免全局Dir.chdir的副作用;
|
|
731
927
|
# 传仓库工作副本根目录,submodule/worktree由git自身通过.git文件定位真实git目录
|
|
732
928
|
status = %x(git -C #{Shellwords.escape(File.expand_path(path))} status -suno 2>/dev/null)
|
|
733
|
-
status.size > 0 ? "[
|
|
929
|
+
status.size > 0 ? "[有修改]" : ""
|
|
734
930
|
end
|
|
735
931
|
|
|
736
932
|
# 读取主工程需要集成依赖的target列表
|
|
@@ -744,13 +940,13 @@ module Pod
|
|
|
744
940
|
def trim_unused_pod?
|
|
745
941
|
yaml_content = read_yaml_content(local_yaml_name)
|
|
746
942
|
return $trim_unused_pod unless $trim_unused_pod.nil?
|
|
747
|
-
yaml_content
|
|
943
|
+
yaml_bool(yaml_content && yaml_content["TRIM_UNUSED_POD"], false)
|
|
748
944
|
end
|
|
749
945
|
|
|
750
946
|
#是否禁用检查podspec文件
|
|
751
947
|
def disable_check_podspec
|
|
752
948
|
yaml_content = read_yaml_content(local_yaml_name)
|
|
753
|
-
disable_check_podspec = yaml_content
|
|
949
|
+
disable_check_podspec = yaml_bool(yaml_content && yaml_content["DISABLE_CHECK_PODSPEC"], false)
|
|
754
950
|
if disable_check_podspec
|
|
755
951
|
log.warn("已关闭podspec文件检查,如需开启,请在#{local_yaml_name}里设置DISABLE_CHECK_PODSPEC为false")
|
|
756
952
|
end
|
data/lib/version.rb
CHANGED
|
@@ -2,6 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
module CocoaPods
|
|
4
4
|
module Yaml
|
|
5
|
-
VERSION = "1.
|
|
5
|
+
VERSION = "1.1.0"
|
|
6
|
+
|
|
7
|
+
# 已验证可用的 CocoaPods 版本区间。
|
|
8
|
+
# gemspec 的依赖约束与 trim 的运行时能力探测共用这一份定义,避免两处漂移。
|
|
9
|
+
# 裁剪功能依赖 Installer 的私有接口,升级 CocoaPods 大版本前必须先回归再放开上限。
|
|
10
|
+
COCOAPODS_VERSION_REQUIREMENTS = ['>= 1.13', '< 1.18'].freeze
|
|
11
|
+
|
|
12
|
+
# 本地调试构建的标记文件,由 scripts/install_local.rb 写入已安装 gem 的根目录。
|
|
13
|
+
# 从 rubygems 正式安装时该文件不存在(gem 重新安装会重建目录),因此可用来区分
|
|
14
|
+
# "本地改的代码"和"线上拉的发布版"——两者版本号可能相同。
|
|
15
|
+
LOCAL_BUILD_MARKER = '.local_build'
|
|
16
|
+
|
|
17
|
+
class << self
|
|
18
|
+
# 当前加载的是否本地构建版本
|
|
19
|
+
def local_build?
|
|
20
|
+
File.exist?(File.expand_path("../#{LOCAL_BUILD_MARKER}", __dir__))
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# 日志中展示的版本号:本地构建追加标识,避免与发布版同号时无法区分
|
|
24
|
+
# @return [String]
|
|
25
|
+
def version_display
|
|
26
|
+
local_build? ? "#{VERSION} (本地构建)" : VERSION
|
|
27
|
+
end
|
|
28
|
+
end
|
|
6
29
|
end
|
|
7
30
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cocoapods-yaml
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- wsp
|
|
@@ -18,7 +18,7 @@ dependencies:
|
|
|
18
18
|
version: '1.13'
|
|
19
19
|
- - "<"
|
|
20
20
|
- !ruby/object:Gem::Version
|
|
21
|
-
version: '
|
|
21
|
+
version: '1.18'
|
|
22
22
|
type: :runtime
|
|
23
23
|
prerelease: false
|
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -28,7 +28,7 @@ dependencies:
|
|
|
28
28
|
version: '1.13'
|
|
29
29
|
- - "<"
|
|
30
30
|
- !ruby/object:Gem::Version
|
|
31
|
-
version: '
|
|
31
|
+
version: '1.18'
|
|
32
32
|
- !ruby/object:Gem::Dependency
|
|
33
33
|
name: xcodeproj
|
|
34
34
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -63,13 +63,40 @@ dependencies:
|
|
|
63
63
|
- - "~>"
|
|
64
64
|
- !ruby/object:Gem::Version
|
|
65
65
|
version: '3.1'
|
|
66
|
+
- !ruby/object:Gem::Dependency
|
|
67
|
+
name: minitest
|
|
68
|
+
requirement: !ruby/object:Gem::Requirement
|
|
69
|
+
requirements:
|
|
70
|
+
- - "~>"
|
|
71
|
+
- !ruby/object:Gem::Version
|
|
72
|
+
version: '5.0'
|
|
73
|
+
type: :development
|
|
74
|
+
prerelease: false
|
|
75
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
76
|
+
requirements:
|
|
77
|
+
- - "~>"
|
|
78
|
+
- !ruby/object:Gem::Version
|
|
79
|
+
version: '5.0'
|
|
80
|
+
- !ruby/object:Gem::Dependency
|
|
81
|
+
name: rake
|
|
82
|
+
requirement: !ruby/object:Gem::Requirement
|
|
83
|
+
requirements:
|
|
84
|
+
- - "~>"
|
|
85
|
+
- !ruby/object:Gem::Version
|
|
86
|
+
version: '13.0'
|
|
87
|
+
type: :development
|
|
88
|
+
prerelease: false
|
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
90
|
+
requirements:
|
|
91
|
+
- - "~>"
|
|
92
|
+
- !ruby/object:Gem::Version
|
|
93
|
+
version: '13.0'
|
|
66
94
|
description: |-
|
|
67
95
|
1、iOS端按target以yaml文件管理依赖(本地/二方/三方统一)
|
|
68
|
-
2、pod yaml relation
|
|
96
|
+
2、pod yaml relation/status/lint: 查询依赖关系、对比声明与实际安装、离线校验依赖文件
|
|
69
97
|
3、检查import写法错误问题
|
|
70
98
|
4、检查未被使用的依赖库和间接依赖的依赖库
|
|
71
99
|
5、TRIM_UNUSED_POD/pod install/update --trim 自动移除未使用依赖以加速编译
|
|
72
|
-
6、其他功能开发中...
|
|
73
100
|
email:
|
|
74
101
|
- wsp810@163.com
|
|
75
102
|
executables: []
|
|
@@ -87,9 +114,13 @@ files:
|
|
|
87
114
|
- lib/core/check/simulator_arch.rb
|
|
88
115
|
- lib/core/check/util.rb
|
|
89
116
|
- lib/core/check/xcodeproj.rb
|
|
117
|
+
- lib/core/check/yaml_lint.rb
|
|
118
|
+
- lib/core/check/yaml_status.rb
|
|
90
119
|
- lib/core/command/trim_mode.rb
|
|
91
120
|
- lib/core/command/yaml_init.rb
|
|
121
|
+
- lib/core/command/yaml_lint.rb
|
|
92
122
|
- lib/core/command/yaml_relation.rb
|
|
123
|
+
- lib/core/command/yaml_status.rb
|
|
93
124
|
- lib/core/dep/find.rb
|
|
94
125
|
- lib/core/indirect/indirect.rb
|
|
95
126
|
- lib/core/logger.rb
|
|
@@ -99,11 +130,13 @@ files:
|
|
|
99
130
|
- lib/core/reference/project.rb
|
|
100
131
|
- lib/core/reference/unused.rb
|
|
101
132
|
- lib/core/setup/podfile_setup.rb
|
|
133
|
+
- lib/core/thin/compatibility.rb
|
|
102
134
|
- lib/core/thin/installer.rb
|
|
103
135
|
- lib/core/thin/local.rb
|
|
104
136
|
- lib/core/thin/pod_target.rb
|
|
105
137
|
- lib/core/thin/shell.rb
|
|
106
138
|
- lib/core/variable.rb
|
|
139
|
+
- lib/core/yaml/working_directory.rb
|
|
107
140
|
- lib/core/yaml/yaml_dependencies.rb
|
|
108
141
|
- lib/core/yaml/yaml_pod.rb
|
|
109
142
|
- lib/core_helper.rb
|