cocoapods-dev-env 2.0.2 → 2.2.1

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