cocoapods-dev-env 2.1.8 → 2.1.9

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.
@@ -0,0 +1,389 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cocoapods'
4
+ require 'file_processer'
5
+ require 'luna-binary-uploader'
6
+ require 'dev_env_utils'
7
+
8
+ Pod::HooksManager.register('cocoapods-dev-env', :pre_install) do |installer|
9
+ # puts installer.instance_variables
10
+ # forbidden submodule not cloned
11
+ # 会引起submodule HEAD回滚,不靠谱,先注释掉
12
+ # `
13
+ # git submodule update --init --recursive
14
+ # `
15
+ end
16
+
17
+ Pod::HooksManager.register('cocoapods-dev-env', :post_install) do |installer|
18
+ # puts installer.instance_variables
19
+ end
20
+
21
+
22
+ $processedPodsState = Hash.new
23
+ $processedPodsOptions = Hash.new
24
+
25
+ $podFileContentPodNameHash = Hash.new
26
+
27
+ $devEnvUseBinaryHash = Hash.new
28
+
29
+ # for universal dependency 子库引用父文件夹中的podFile或lock文件的相对路径
30
+ $parrentPath = '../../../'
31
+
32
+
33
+ module Pod
34
+
35
+ class DevEnv
36
+ def self.keyword
37
+ :dev_env # 'dev'/'beta'/'release'
38
+ end
39
+ def self.binary_key
40
+ :dev_env_use_binary # true / false
41
+ end
42
+ UI.puts "🎉 plugin cocoapods-dev-env loaded 🎉".green
43
+ end
44
+ class Podfile
45
+
46
+ class TargetDefinition
47
+ attr_reader :binary_repo_url
48
+ attr_reader :binary_source
49
+
50
+ ## --- hook的入口函数 ---
51
+ def parse_pod_dev_env(name, requirements)
52
+ options = requirements.last
53
+ pod_name = Specification.root_name(name)
54
+ last_options = $processedPodsOptions[pod_name]
55
+ $podFileContentPodNameHash[pod_name] = true
56
+
57
+ if (last_options != nil)
58
+ UI.message "#{name.green} use last_options: #{last_options.to_s.green}"
59
+ if options != nil && options.is_a?(Hash)
60
+ requirements[requirements.length - 1] = last_options
61
+ else
62
+ requirements.push(last_options)
63
+ end
64
+ elsif options.is_a?(Hash)
65
+ use_binary = options.delete(Pod::DevEnv::binary_key)
66
+ dev_env = options.delete(Pod::DevEnv::keyword)
67
+
68
+ # 主功能,根据dev_env标记来管理使用代码的方式
69
+ deal_dev_env_with_options(dev_env, options, pod_name, name, requirements)
70
+
71
+ # 处理二进制
72
+ if dev_env != 'dev'
73
+ binary_processer(dev_env, pod_name, use_binary, options, requirements)
74
+ end
75
+
76
+
77
+ if dev_env || use_binary
78
+ $processedPodsOptions[pod_name] = options.clone
79
+ requirements.pop if options.empty?
80
+ end
81
+ end
82
+ end
83
+
84
+ ## --- 主功能函数 ---
85
+ def deal_dev_env_with_options(dev_env, options, pod_name, name, requirements)
86
+ if dev_env == nil
87
+ return
88
+ end
89
+
90
+ defaultLocalPath = "./developing_pods/#{pod_name}"
91
+ UI.message "pod #{name.green} dev-env: #{dev_env.green}"
92
+ if dev_env == 'parent'
93
+ parentPodInfo = $parentPodlockDependencyHash[pod_name]
94
+ if parentPodInfo != nil
95
+ if parentPodInfo.external_source != nil
96
+ git = parentPodInfo.external_source[:git]
97
+ if git != nil
98
+ options[:git] = git
99
+ end
100
+ tag = parentPodInfo.external_source[:tag]
101
+ if tag != nil
102
+ options[:tag] = tag
103
+ end
104
+ defaultLocalPath = $parrentPath + defaultLocalPath
105
+ else
106
+ UI.puts 'XXXXXXXXXXXXXXXX123' + parentPodInfo.requirement.to_s()
107
+ requirements.insert(0, parentPodInfo.requirement.to_s)
108
+ options[:source] = parentPodInfo.podspec_repo
109
+ end
110
+
111
+ # dependency.setRequirement(parentPodInfo.requirement
112
+ end
113
+ return
114
+ elsif options[:git] == nil
115
+ podfilePath = $parrentPath + '/Podfile'
116
+ temp = `grep \\'#{pod_name}\\' #{podfilePath} | grep ':dev_env'`
117
+ if temp != nil && temp.length > 0
118
+ UI.puts temp
119
+ git = /(:git.*?').*?(?=')/.match(temp)[0]
120
+ git = git.gsub(/:git.*?'/, '')
121
+ branch = /(:branch.*?').*?(?=')/.match(temp)[0]
122
+ branch = branch.gsub(/:branch.*?'/, '')
123
+ tag = /(:tag.*?').*?(?=')/.match(temp)[0]
124
+ tag = tag.gsub(/:tag.*?'/, '')
125
+ path = /(:path.*?').*?(?=')/.match(temp)
126
+ if path != nil
127
+ path = path[0]
128
+ path = path.gsub(/:path.*?'/, '')
129
+ end
130
+ options[:git] = git
131
+ options[:branch] = branch
132
+ options[:tag] = tag
133
+ if path != nil
134
+ options[:path] = $parrentPath + path
135
+ else
136
+ options[:path] = $parrentPath + defaultLocalPath
137
+ end
138
+ UI.puts "#{pod_name.green}采用了父组件的配置,并修改开发状态为#{dev_env.green}"
139
+ end
140
+ end
141
+
142
+
143
+
144
+ git = options.delete(:git)
145
+ branch = options.delete(:branch)
146
+ tag = options.delete(:tag)
147
+ path = options.delete(:path)
148
+ if path == nil
149
+ path = defaultLocalPath
150
+ end
151
+ if git == nil || git.length == 0
152
+ raise "💔 #{pod_name.yellow} 未定义:git => 'xxx'库地址"
153
+ end
154
+ if branch == nil || branch.length == 0
155
+ raise "💔 #{pod_name.yellow} 未定义:branch => 'xxx'"
156
+ end
157
+ if tag == nil || tag.length == 0
158
+ raise "💔 #{pod_name.yellow} 未定义:tag => 'xxx', tag 将会作为 dev模式下载最新代码检查的依据,beta模式引用的tag 以及 release模式引用的版本号"
159
+ end
160
+
161
+ if dev_env == 'subtree'
162
+ if !File.directory?(path)
163
+ _toplevelDir = `git rev-parse --show-toplevel`
164
+ _currentDir = `pwd`
165
+ _subtreeDir = path
166
+ if _currentDir != _toplevelDir
167
+ Dir.chdir(_toplevelDir)
168
+ _end = path
169
+ if _end[0,2] == './'
170
+ _end = _end[1, _end.length - 1]
171
+ else
172
+ _end = '/' + _end
173
+ end
174
+ _subtreeDir = './' + _currentDir[_toplevelDir.length, _currentDir.length - _toplevelDir.length] + path
175
+ end
176
+ _cmd = "git subtree add --prefix #{_subtreeDir} #{git} #{branch} --squash"
177
+ UI.puts _cmd
178
+ system(_cmd)
179
+ Dir.chdir(_currentDir)
180
+ end
181
+ options[:path] = path
182
+ if requirements.length >= 2
183
+ requirements.delete_at(0)
184
+ end
185
+ UI.message "pod #{pod_name.green} enabled #{"subtree".green}-mode 🍺"
186
+ elsif dev_env == 'dev'
187
+ # 开发模式,使用path方式引用本地的submodule git库
188
+ if !File.directory?(path)
189
+ UI.puts "add submodule for #{pod_name.green}".yellow
190
+ _cmd = "git submodule add --force -b #{branch} #{git} #{path}"
191
+ UI.puts _cmd
192
+ system(_cmd)
193
+
194
+ _currentDir = Dir.pwd
195
+ Dir.chdir(path)
196
+
197
+ curGitRemoteUrl = `git remote get-url origin`.rstrip()
198
+ if curGitRemoteUrl == git
199
+ _cmd = "git reset --hard"
200
+ UI.puts _cmd
201
+ system(_cmd)
202
+ _cmd = "git pull"
203
+ UI.puts _cmd
204
+ system(_cmd)
205
+ end
206
+ Dir.chdir(_currentDir)
207
+
208
+ # if DevEnvUtils.inputNeedJumpForReson("本地库#{pod_name} 开发模式加载完成,是否自动打开Example工程")
209
+ # DevEnvUtils.searchAndOpenLocalExample(path)
210
+ # end
211
+ if !DevEnvUtils.checkTagIsEqualToHead(tag, path) && !DevEnvUtils.checkTagIsEqualToHead("#{tag}_beta", path)
212
+ raise "💔 #{pod_name.yellow} branch:#{branch.yellow} 与 tag:#{tag.yellow}[_beta] 内容不同步,请自行确认所用分支和tag后重新执行 pod install"
213
+ end
214
+ else
215
+ # if DevEnvUtils.inputNeedJumpForReson("本地库#{pod_name} 处于开发模式,是否自动打开Example工程")
216
+ # DevEnvUtils.searchAndOpenLocalExample(path)
217
+ # end
218
+ end
219
+ options[:path] = path
220
+ if requirements.length >= 2
221
+ requirements.delete_at(0)
222
+ end
223
+ UI.message "pod #{pod_name.green} enabled #{"dev".green}-mode 🍺"
224
+ elsif dev_env == 'beta'
225
+ # Beta模式,使用tag引用远端git库的代码
226
+ originTag = tag
227
+ tag = "#{tag}_beta"
228
+ if File.directory?(path)
229
+ # 从Dev模式刚刚切换过来,需要打tag并且push
230
+ UI.puts "try to release beta-version for #{pod_name.green}".yellow
231
+ _currentDir = Dir.pwd
232
+ Dir.chdir(path)
233
+ # 已经进入到podspec的文件夹中了
234
+ DevEnvUtils.checkGitStatusAndPush(pod_name) # push一下
235
+ ret = DevEnvUtils.checkRemoteTagExist(tag)
236
+ if ret == true
237
+ # tag已经存在,要么没改动,要么已经手动打过tag,要么是需要引用老版本tag的代码
238
+ if DevEnvUtils.checkTagOrBranchIsEqalToHead(tag, "./")
239
+ UI.puts "#{pod_name.green} 检测到未做任何调整,或已手动打过Tag,直接引用远端库"
240
+ else
241
+ if !DevEnvUtils.inputNeedJumpForReson("#{pod_name.green} 检测到已经存在#{tag.yellow}的tag,且与当前本地节点不同,是否跳过beta发布并删除本地submodule(直接引用远端库)")
242
+ raise "💔 #{pod_name.yellow} tag:#{tag.yellow} 已存在, 且与当前Commit不对应. 请确认拉到本地之后已经在podfile中手动修改tag版本号"
243
+ end
244
+ end
245
+ else
246
+ # tag不存在,
247
+ DevEnvUtils.changeVersionInCocoapods(pod_name, originTag)
248
+ DevEnvUtils.checkGitStatusAndPush(pod_name) # 再push一下
249
+ DevEnvUtils.addGitTagAndPush(tag, pod_name)
250
+ end
251
+ Dir.chdir(_currentDir)
252
+ DevEnvUtils.checkAndRemoveSubmodule(path)
253
+ UI.puts "🍺🍺 #{pod_name.green} #{tag.green} release successfully!!"
254
+ end
255
+ options[:git] = git
256
+ options[:tag] = tag
257
+ if requirements.length >= 2
258
+ requirements.delete_at(0)
259
+ end
260
+ UI.message "enabled #{"beta".green}-mode for #{pod_name.green}"
261
+ elsif dev_env == 'release'
262
+ # Release模式,直接使用远端对应的版本
263
+ if File.directory?(path)
264
+ UI.puts "release release-version for #{pod_name.green}".yellow
265
+ _currentDir = Dir.pwd
266
+ Dir.chdir(path)
267
+ verboseParamStr = ""
268
+ if Config.instance.verbose
269
+ verboseParamStr = " --verbose"
270
+ end
271
+ ret = system("pod lib lint --skip-import-validation --fail-fast --allow-warnings#{getReposStrForLint()}#{verboseParamStr}")
272
+ if ret != true
273
+ raise "💔 #{pod_name.yellow} lint 失败"
274
+ end
275
+ DevEnvUtils.checkGitStatusAndPush(pod_name)
276
+ DevEnvUtils.changeVersionInCocoapods(pod_name, tag)
277
+ DevEnvUtils.checkGitStatusAndPush(pod_name)
278
+ ret = DevEnvUtils.addGitTagAndPush(tag, pod_name)
279
+ if ret == false
280
+ if DevEnvUtils.checkTagOrBranchIsEqalToHead(tag, "./")
281
+ UI.puts "#{pod_name.green} 已经打过tag".yellow
282
+ else
283
+ raise "💔 #{pod_name.yellow} tag:#{tag.yellow} 已存在, 请确认已经手动修改tag版本号"
284
+ end
285
+ end
286
+ ## TODO:: 发布到的目标库名称需要用变量设置
287
+ repoAddrs = getUserRepoAddress()
288
+ cmd = "pod repo push #{repoAddrs} #{pod_name}.podspec --skip-import-validation --allow-warnings --use-modular-headers#{getReposStrForLint()}#{verboseParamStr}"
289
+ UI.puts cmd.green
290
+ ret = system(cmd)
291
+ if ret != true
292
+ raise "💔 #{pod_name.yellow} 发布失败"
293
+ end
294
+ ## 到最后统一执行,判断如果当次release过
295
+ `pod repo update`
296
+ Dir.chdir(_currentDir)
297
+ DevEnvUtils.checkAndRemoveSubmodule(path)
298
+ end
299
+ if requirements.length < 2
300
+ requirements.insert(0, "#{DevEnvUtils.get_pure_version(tag)}")
301
+ end
302
+ UI.message "enabled #{"release".green}-mode for #{pod_name.green}"
303
+ else
304
+ raise "💔 :dev_env 必须要设置成 dev/beta/release之一,不接受其他值"
305
+ end
306
+ end
307
+
308
+ def binary_processer(dev_env, pod_name, use_binary, options, requirements)
309
+ if use_binary && use_binary == true
310
+ if options[:tag] != nil
311
+ begin
312
+ version = DevEnvUtils.get_pure_version(options[:tag])
313
+ spec = binary_source.specification_path(pod_name, Version.new(version))
314
+ if spec
315
+ if requirements.length < 2
316
+ options.delete(:git)
317
+ options.delete(:path)
318
+ options.delete(:tag)
319
+ options[:source] = binary_repo_url
320
+ requirements.insert(0, "#{version}")
321
+ UI.puts "pod '#{pod_name.green}' 使用了二进制"
322
+ else
323
+ UI.puts "pod '#{pod_name}' :tag => #{options[:tag]} version: #{version} 对应的版本,但是已经标记版本号#{requirements}, 不知道用哪个".red
324
+ end
325
+ else
326
+ UI.puts "pod '#{pod_name}' :tag => #{options[:tag]} version: #{version} 没有找到: tag 对应的版本".red
327
+ end
328
+ rescue => exception
329
+ UI.puts "pod '#{pod_name}' :tag => #{options[:tag]} version: #{version} 没有找到: tag 对应的版本".red
330
+ else
331
+
332
+ end
333
+ else
334
+ UI.puts "pod '#{pod_name.green}使用了二进制"
335
+ ## TODO:: 这里不适合处理,在这里处理的时候还不知道最终的版本号,
336
+ ## 无法拿到准确的版本,就不能确定二进制库里是否有对应的framework
337
+ ## 或者在这边预处理后,在后边的reslove的过程中找不到时再拯救一下??
338
+ options.delete(:git)
339
+ options.delete(:path)
340
+ options.delete(:tag)
341
+ options[:source] = binary_repo_url
342
+ end
343
+ end
344
+ UI.message "#{pod_name.green} :source=> #{options[:source].green} by cocoapods-dev-env" if options[:source] != nil
345
+ UI.message "#{pod_name.yellow} options #{options} by cocoapods-dev-env" if options[:source] != nil
346
+ UI.message "#{pod_name.yellow} requirements #{requirements} by cocoapods-dev-env" if options[:source] != nil
347
+ end
348
+
349
+ def binary_repo_url
350
+ if @binary_repo_url == nil
351
+ @binary_repo_url = Luna::Binary::Common.instance.binary_repo_url #从luna-binary-uploader里获取binary_repo_url
352
+ end
353
+ return @binary_repo_url
354
+ end
355
+
356
+ def binary_source
357
+ if @binary_source == nil
358
+ @binary_source = Pod::Config.instance.sources_manager.all.detect{|item| item.url.downcase == binary_repo_url.downcase}
359
+ end
360
+ return @binary_source
361
+ end
362
+
363
+ def find_pod_repos(pod_name) #等同pod search
364
+ sets = Pod::Config.instance.sources_manager.search_by_name(pod_name)
365
+ if sets.count == 1
366
+ set = sets.first
367
+ elsif sets.map(&:name).include?(pod_name)
368
+ set = sets.find { |s| s.name == pod_name }
369
+ else
370
+ names = sets.map(&:name) * ', '
371
+ raise Informative, "More than one spec found for '#{pod_name}':\n#{names}"
372
+ end
373
+ return set
374
+ end
375
+
376
+ # ---- patch method ----
377
+ # We want modify `store_pod` method, but it's hard to insert a line in the
378
+ # implementation. So we patch a method called in `store_pod`.
379
+ old_method = instance_method(:parse_inhibit_warnings)
380
+
381
+ define_method(:parse_inhibit_warnings) do |name, requirements|
382
+ parse_pod_dev_env(name, requirements)
383
+ old_method.bind(self).(name, requirements)
384
+ end
385
+
386
+ end
387
+ end
388
+ end
389
+
@@ -0,0 +1,169 @@
1
+ require 'cocoapods'
2
+
3
+ class DevEnvUtils
4
+
5
+ def self.searchAndOpenLocalExample(path)
6
+ _currentDir = Dir.pwd
7
+ Dir.chdir(path)
8
+ Dir.chdir("Example")
9
+ `pod install`
10
+ projPaths = Dir::glob("*.xcworkspace")
11
+ if projPaths.count > 0
12
+ `open -a Terminal ./`
13
+ `open #{projPaths[0]}`
14
+ end
15
+ Dir.chdir(_currentDir)
16
+ end
17
+
18
+ def self.checkAndRemoveSubmodule(path)
19
+ _currentDir = Dir.pwd
20
+ Dir.chdir(path)
21
+ output = `git status -s`
22
+ puts output
23
+ if output.length == 0
24
+ output = `git status`
25
+ if output.include?("push")
26
+ raise "submodule #{path} 移除失败,有推送的修改"
27
+ end
28
+ else
29
+ raise "submodule #{path} 移除失败,有未提交的修改"
30
+ end
31
+ Dir.chdir(_currentDir)
32
+ `
33
+ git submodule deinit #{path}
34
+ rm -rf #{path}
35
+ git rm #{path}
36
+ `
37
+ end
38
+
39
+ def self.checkTagIsEqualToHead(tag, path)
40
+ _currentDir = Dir.pwd
41
+ Dir.chdir(path)
42
+ result = `git describe --abbrev=4 HEAD`
43
+ Dir.chdir(_currentDir)
44
+ if result.include?(tag)
45
+ return true
46
+ else
47
+ return checkTagOrBranchIsEqalToHead(tag, path)
48
+ end
49
+ end
50
+
51
+ # 这个函数有问题有时候拿不到相同的commit id
52
+ def self.checkTagOrBranchIsEqalToHead(branchOrTag, path)
53
+ _currentDir = Dir.pwd
54
+ Dir.chdir(path)
55
+ headCommitID = `git rev-parse HEAD`
56
+ tagCommitID = `git rev-parse #{branchOrTag}`
57
+ Pod::UI.puts "#{`pwd`} headCommitID:#{headCommitID} \n #{branchOrTag}ComitID:#{tagCommitID}"
58
+ Dir.chdir(_currentDir)
59
+ return (headCommitID.length > 0 && headCommitID == tagCommitID)
60
+ end
61
+
62
+ def self.checkGitStatusAndPush(pod_name)
63
+ output = `git status -s`
64
+ puts output
65
+ if output.length == 0
66
+ output = `git status`
67
+ if output.include?("push")
68
+ ret = system("git push")
69
+ if ret != true
70
+ raise "💔 #{pod_name.yellow} push 失败"
71
+ end
72
+ end
73
+ else
74
+ raise "💔 #{pod_name.yellow} 有未提交的数据"
75
+ end
76
+ end
77
+
78
+ def self.checkRemoteTagExist(tag)
79
+ `git push --tags`
80
+ ret = system("git ls-remote --exit-code origin refs/tags/#{tag}")
81
+ return ret
82
+ end
83
+
84
+ def self.addGitTagAndPush(tag, pod_name)
85
+ ret = system("git tag #{tag}")
86
+ if ret == true
87
+ ret = system("git push origin #{tag}")
88
+ if ret != true
89
+ raise "💔 #{pod_name.yellow} push tag 失败"
90
+ end
91
+ end
92
+ return ret
93
+ end
94
+
95
+ def self.inputNeedJumpForReson(str)
96
+ if ARGV.include? '--silent'
97
+ return false
98
+ end
99
+
100
+ puts str.green
101
+ puts '是(Y), 任意其他输入或直接回车跳过'.green
102
+ input = STDIN.gets
103
+ if input[0,1] == "Y"
104
+ return true
105
+ else
106
+ return false
107
+ end
108
+ end
109
+
110
+ def self.changeVersionInCocoapods(name, newVersion)
111
+ if (newVersion == nil)
112
+ Pod::UI.puts "💔 传入的修改目标版本号为空,无法设置版本号".yellow
113
+ return
114
+ end
115
+ newVersion = get_pure_version(newVersion)
116
+ specName = name + ".podspec"
117
+ FileProcesserManager.new(specName,
118
+ [
119
+ FileProcesser.new(-> (fileContent) {
120
+ return fileContent.gsub(/(\.version *= *')(.*')/, "\\1" + newVersion + "'")
121
+ })
122
+ ]).process()
123
+ `git add #{specName}
124
+ git commit -m "Mod: 修改版本号为:#{newVersion} by cocoapods_dev_env plugin"`
125
+ end
126
+
127
+ def self.get_pure_version(version)
128
+ return version.split.last.scan(/\d+/).join('.')
129
+ end
130
+ end
131
+
132
+
133
+ class Podfile
134
+
135
+ class TargetDefinition
136
+
137
+ def getReposStrForLint()
138
+ if podfile.sources.size == 0
139
+ return ""
140
+ end
141
+ str = " --sources="
142
+ podfile.sources.each do |source|
143
+ str += source
144
+ str += ","
145
+ end
146
+ Pod::UI.puts str
147
+ return str
148
+ end
149
+
150
+ def getUserRepoAddress()
151
+ if podfile.sources.size == 0
152
+ raise "💔 发布release必须配置仓库的地址, e.g.: source 'https://github.com/CocoaPods/Specs.git'"
153
+ end
154
+ index = nil
155
+ begin
156
+ Pod::UI.puts "\n\n⌨️ 请输入要发布到的cocoapods仓库序号, 按回车确认: ".yellow
157
+ num = 1
158
+ podfile.sources.each do |source|
159
+ Pod::UI.puts "#{num.to_s.yellow}. #{source.green}"
160
+ num += 1
161
+ end
162
+ index = STDIN.gets.to_i - 1
163
+ end until (index >= 0 && index < podfile.sources.size)
164
+ source = podfile.sources[index]
165
+ Pod::UI.puts "#{"选择了发布到: ".yellow}. #{source.green}(#{index + 1})"
166
+ return source
167
+ end
168
+ end
169
+ end
@@ -0,0 +1,116 @@
1
+ require 'cocoapods'
2
+
3
+ # 在这里处理二进制返回不指定源时系统不切换回原来的源的问题,效率相对比较高,不会反复进入
4
+ module Pod
5
+ class Lockfile
6
+ old_dependencies_to_lock_pod_named = instance_method(:dependencies_to_lock_pod_named)
7
+ define_method(:dependencies_to_lock_pod_named) do |name|
8
+ locked_pod_dependency = old_dependencies_to_lock_pod_named.bind(self).call(name)
9
+ repoUrl = spec_repo(name)
10
+ if (repoUrl != nil &&
11
+ repoUrl.downcase == 'git@gitlab.corp.youdao.com:luna-ios-framework/ios-framework-spec-repo.git')
12
+ locked_pod_dependency[0].external_source = repoUrl
13
+ end
14
+ locked_pod_dependency
15
+ end
16
+ end
17
+ end
18
+
19
+ module Pod
20
+ class Resolver
21
+ old_resolver_specs_by_target = instance_method(:resolver_specs_by_target)
22
+ define_method(:resolver_specs_by_target) do
23
+ specs_by_target = old_resolver_specs_by_target.bind(self).call
24
+
25
+ sources_manager = Config.instance.sources_manager
26
+ use_source_pods = podfile.use_source_pods
27
+
28
+ missing_binary_specs = []
29
+ specs_by_target.each do |target, rspecs|
30
+ # use_binaries 并且 use_source_pods 不包含 本地可过滤
31
+ use_binary_rspecs = ["SDWebImage"]
32
+
33
+ # # Parallel.map(rspecs, in_threads: 8) do |rspec|
34
+ # specs_by_target[target] = rspecs.map do |rspec|
35
+ # # 采用二进制依赖并且不为开发组件
36
+ # use_binary = use_binary_rspecs.include?(rspec)
37
+ # source = use_binary ? sources_manager.binary_source : sources_manager.code_source
38
+
39
+ # spec_version = rspec.spec.version
40
+ # UI.message 'cocoapods-imy-bin 插件'
41
+ # UI.message "- 开始处理 #{rspec.spec.name} #{spec_version} 组件."
42
+
43
+ # begin
44
+ # # 从新 source 中获取 spec,在bin archive中会异常,因为找不到
45
+ # specification = source.specification(rspec.root.name, spec_version)
46
+ # UI.message "#{rspec.root.name} #{spec_version} \r\n specification =#{specification} "
47
+ # # 组件是 subspec
48
+ # if rspec.spec.subspec?
49
+ # specification = specification.subspec_by_name(rspec.name, false, true)
50
+ # end
51
+ # # 这里可能出现分析依赖的 source 和切换后的 source 对应 specification 的 subspec 对应不上
52
+ # # 造成 subspec_by_name 返回 nil,这个是正常现象
53
+ # next unless specification
54
+
55
+ # used_by_only = if Pod.match_version?('~> 1.7')
56
+ # rspec.used_by_non_library_targets_only
57
+ # else
58
+ # rspec.used_by_tests_only
59
+ # end
60
+ # # used_by_only = rspec.respond_to?(:used_by_tests_only) ? rspec.used_by_tests_only : rspec.used_by_non_library_targets_only
61
+ # # 组装新的 rspec ,替换原 rspec
62
+ # if use_binary
63
+ # rspec = if Pod.match_version?('~> 1.4.0')
64
+ # ResolverSpecification.new(specification, used_by_only)
65
+ # else
66
+ # ResolverSpecification.new(specification, used_by_only, source)
67
+ # end
68
+ # UI.message "组装新的 rspec ,替换原 rspec #{rspec.root.name} #{spec_version} \r\n specification =#{specification} \r\n #{rspec} "
69
+
70
+ # end
71
+
72
+ # rescue Pod::StandardError => e
73
+ # # 没有从新的 source 找到对应版本组件,直接返回原 rspec
74
+
75
+ # # missing_binary_specs << rspec.spec if use_binary
76
+ # missing_binary_specs << rspec.spec
77
+ # rspec
78
+ # end
79
+
80
+ # rspec
81
+ # end.compact
82
+ end
83
+
84
+ # if missing_binary_specs.any?
85
+ # missing_binary_specs.uniq.each do |spec|
86
+ # UI.message "【#{spec.name} | #{spec.version}】组件无对应二进制版本 , 将采用源码依赖."
87
+ # end
88
+ # Pod::Command::Bin::Archive.missing_binary_specs(missing_binary_specs)
89
+
90
+ # #缓存没有二进制组件到spec文件,local_psec_dir 目录
91
+ # sources_sepc = []
92
+ # des_dir = CBin::Config::Builder.instance.local_psec_dir
93
+ # FileUtils.rm_f(des_dir) if File.exist?des_dir
94
+ # Dir.mkdir des_dir unless File.exist?des_dir
95
+ # missing_binary_specs.uniq.each do |spec|
96
+ # next if spec.name.include?('/')
97
+
98
+ # spec_git_res = false
99
+ # CBin::Config::Builder.instance.ignore_git_list.each do |ignore_git|
100
+ # spec_git_res = spec.source[:git] && spec.source[:git].include?(ignore_git)
101
+ # break if spec_git_res
102
+ # end
103
+ # next if spec_git_res
104
+
105
+ # #获取没有制作二进制版本的spec集合
106
+ # sources_sepc << spec
107
+ # unless spec.defined_in_file.nil?
108
+ # FileUtils.cp("#{spec.defined_in_file}", "#{des_dir}")
109
+ # end
110
+ # end
111
+ # end
112
+
113
+ specs_by_target
114
+ end
115
+ end
116
+ end