cocoapods-imy-bin 0.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.
- checksums.yaml +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +541 -0
- data/lib/cocoapods-imy-bin.rb +2 -0
- data/lib/cocoapods-imy-bin/command.rb +2 -0
- data/lib/cocoapods-imy-bin/command/bin.rb +60 -0
- data/lib/cocoapods-imy-bin/command/bin/archive.rb +184 -0
- data/lib/cocoapods-imy-bin/command/bin/auto.rb +188 -0
- data/lib/cocoapods-imy-bin/command/bin/code.rb +237 -0
- data/lib/cocoapods-imy-bin/command/bin/imy.rb +46 -0
- data/lib/cocoapods-imy-bin/command/bin/init.rb +69 -0
- data/lib/cocoapods-imy-bin/command/bin/initHotKey.rb +70 -0
- data/lib/cocoapods-imy-bin/command/bin/install.rb +44 -0
- data/lib/cocoapods-imy-bin/command/bin/lib/lint.rb +69 -0
- data/lib/cocoapods-imy-bin/command/bin/local.rb +156 -0
- data/lib/cocoapods-imy-bin/command/bin/repo/update.rb +43 -0
- data/lib/cocoapods-imy-bin/command/bin/spec/create.rb +73 -0
- data/lib/cocoapods-imy-bin/command/bin/spec/push.rb +114 -0
- data/lib/cocoapods-imy-bin/command/bin/update.rb +148 -0
- data/lib/cocoapods-imy-bin/config/config.rb +137 -0
- data/lib/cocoapods-imy-bin/config/config_asker.rb +57 -0
- data/lib/cocoapods-imy-bin/config/config_builder.rb +179 -0
- data/lib/cocoapods-imy-bin/config/config_hot_key.rb +103 -0
- data/lib/cocoapods-imy-bin/config/config_hot_key_asker.rb +57 -0
- data/lib/cocoapods-imy-bin/gem_version.rb +10 -0
- data/lib/cocoapods-imy-bin/helpers.rb +4 -0
- data/lib/cocoapods-imy-bin/helpers/build_helper.rb +150 -0
- data/lib/cocoapods-imy-bin/helpers/framework.rb +62 -0
- data/lib/cocoapods-imy-bin/helpers/framework_builder.rb +307 -0
- data/lib/cocoapods-imy-bin/helpers/library.rb +54 -0
- data/lib/cocoapods-imy-bin/helpers/library_builder.rb +90 -0
- data/lib/cocoapods-imy-bin/helpers/local/loca_llibrary.rb +57 -0
- data/lib/cocoapods-imy-bin/helpers/local/local_build_helper.rb +146 -0
- data/lib/cocoapods-imy-bin/helpers/local/local_framework.rb +65 -0
- data/lib/cocoapods-imy-bin/helpers/local/local_framework_builder.rb +174 -0
- data/lib/cocoapods-imy-bin/helpers/local/local_library_builder.rb +92 -0
- data/lib/cocoapods-imy-bin/helpers/sources_helper.rb +33 -0
- data/lib/cocoapods-imy-bin/helpers/spec_creator.rb +170 -0
- data/lib/cocoapods-imy-bin/helpers/spec_files_helper.rb +77 -0
- data/lib/cocoapods-imy-bin/helpers/spec_source_creator.rb +171 -0
- data/lib/cocoapods-imy-bin/helpers/upload_helper.rb +84 -0
- data/lib/cocoapods-imy-bin/native.rb +19 -0
- data/lib/cocoapods-imy-bin/native/acknowledgements.rb +27 -0
- data/lib/cocoapods-imy-bin/native/analyzer.rb +53 -0
- data/lib/cocoapods-imy-bin/native/installation_options.rb +25 -0
- data/lib/cocoapods-imy-bin/native/installer.rb +115 -0
- data/lib/cocoapods-imy-bin/native/linter.rb +26 -0
- data/lib/cocoapods-imy-bin/native/path_source.rb +33 -0
- data/lib/cocoapods-imy-bin/native/pod_source_installer.rb +19 -0
- data/lib/cocoapods-imy-bin/native/podfile.rb +91 -0
- data/lib/cocoapods-imy-bin/native/podfile_env.rb +37 -0
- data/lib/cocoapods-imy-bin/native/podfile_generator.rb +190 -0
- data/lib/cocoapods-imy-bin/native/podspec_finder.rb +25 -0
- data/lib/cocoapods-imy-bin/native/resolver.rb +230 -0
- data/lib/cocoapods-imy-bin/native/sandbox_analyzer.rb +34 -0
- data/lib/cocoapods-imy-bin/native/source.rb +35 -0
- data/lib/cocoapods-imy-bin/native/sources_manager.rb +20 -0
- data/lib/cocoapods-imy-bin/native/specification.rb +31 -0
- data/lib/cocoapods-imy-bin/native/validator.rb +77 -0
- data/lib/cocoapods-imy-bin/source_provider_hook.rb +54 -0
- data/lib/cocoapods_plugin.rb +3 -0
- data/spec/command/bin_spec.rb +12 -0
- data/spec/spec_helper.rb +50 -0
- metadata +180 -0
@@ -0,0 +1,60 @@
|
|
1
|
+
|
2
|
+
require 'cocoapods-imy-bin/command/bin/initHotKey'
|
3
|
+
require 'cocoapods-imy-bin/command/bin/init'
|
4
|
+
require 'cocoapods-imy-bin/command/bin/archive'
|
5
|
+
require 'cocoapods-imy-bin/command/bin/auto'
|
6
|
+
require 'cocoapods-imy-bin/command/bin/code'
|
7
|
+
require 'cocoapods-imy-bin/command/bin/local'
|
8
|
+
require 'cocoapods-imy-bin/command/bin/update'
|
9
|
+
require 'cocoapods-imy-bin/command/bin/install'
|
10
|
+
require 'cocoapods-imy-bin/command/bin/imy'
|
11
|
+
|
12
|
+
require 'cocoapods-imy-bin/helpers'
|
13
|
+
|
14
|
+
module Pod
|
15
|
+
class Command
|
16
|
+
# This is an example of a cocoapods plugin adding a top-level subcommand
|
17
|
+
# to the 'pod' command.
|
18
|
+
#
|
19
|
+
# You can also create subcommands of existing or new commands. Say you
|
20
|
+
# wanted to add a subcommand to `list` to show newly deprecated pods,
|
21
|
+
# (e.g. `pod list deprecated`), there are a few things that would need
|
22
|
+
# to change.
|
23
|
+
#
|
24
|
+
# - move this file to `lib/pod/command/list/deprecated.rb` and update
|
25
|
+
# the class to exist in the the Pod::Command::List namespace
|
26
|
+
# - change this class to extend from `List` instead of `Command`. This
|
27
|
+
# tells the plugin system that it is a subcommand of `list`.
|
28
|
+
# - edit `lib/cocoapods_plugins.rb` to require this file
|
29
|
+
#
|
30
|
+
# @todo Create a PR to add your plugin to CocoaPods/cocoapods.org
|
31
|
+
# in the `plugins.json` file, once your plugin is released.
|
32
|
+
#
|
33
|
+
class Bin < Command
|
34
|
+
include CBin::SourcesHelper
|
35
|
+
include CBin::SpecFilesHelper
|
36
|
+
|
37
|
+
self.abstract_command = true
|
38
|
+
|
39
|
+
self.default_subcommand = 'open'
|
40
|
+
self.summary = '组件二进制化插件.'
|
41
|
+
self.description = <<-DESC
|
42
|
+
组件二进制化插件。利用源码私有源与二进制私有源实现对组件依赖类型的切换。
|
43
|
+
DESC
|
44
|
+
|
45
|
+
def initialize(argv)
|
46
|
+
require 'cocoapods-imy-bin/native'
|
47
|
+
|
48
|
+
@help = argv.flag?('help')
|
49
|
+
super
|
50
|
+
end
|
51
|
+
|
52
|
+
def validate!
|
53
|
+
super
|
54
|
+
# 这里由于 --help 是在 validate! 方法中提取的,会导致 --help 失效
|
55
|
+
# pod lib create 也有这个问题
|
56
|
+
banner! if @help
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,184 @@
|
|
1
|
+
require 'cocoapods-imy-bin/native/podfile'
|
2
|
+
require 'cocoapods/command/gen'
|
3
|
+
require 'cocoapods/generate'
|
4
|
+
require 'cocoapods-imy-bin/helpers/framework_builder'
|
5
|
+
require 'cocoapods-imy-bin/helpers/library_builder'
|
6
|
+
require 'cocoapods-imy-bin/helpers/build_helper'
|
7
|
+
require 'cocoapods-imy-bin/helpers/spec_source_creator'
|
8
|
+
require 'cocoapods-imy-bin/config/config_builder'
|
9
|
+
require 'cocoapods-imy-bin/command/bin/lib/lint'
|
10
|
+
|
11
|
+
module Pod
|
12
|
+
class Command
|
13
|
+
class Bin < Command
|
14
|
+
class Archive < Bin
|
15
|
+
|
16
|
+
@@missing_binary_specs = []
|
17
|
+
|
18
|
+
self.summary = '将组件归档为静态库 .a.'
|
19
|
+
self.description = <<-DESC
|
20
|
+
将组件归档为静态库 framework,仅支持 iOS 平台
|
21
|
+
此静态 framework 不包含依赖组件的 symbol
|
22
|
+
DESC
|
23
|
+
|
24
|
+
def self.options
|
25
|
+
[
|
26
|
+
['--all-make', '对该组件的依赖库,全部制作为二进制组件'],
|
27
|
+
['--code-dependencies', '使用源码依赖'],
|
28
|
+
['--no-clean', '保留构建中间产物'],
|
29
|
+
['--sources', '私有源地址,多个用分号区分'],
|
30
|
+
['--framework-output', '输出framework文件'],
|
31
|
+
['--no-zip', '不压缩静态库 为 zip'],
|
32
|
+
['--env', "该组件上传的环境 %w[dev debug_iphoneos release_iphoneos]"]
|
33
|
+
].concat(Pod::Command::Gen.options).concat(super).uniq
|
34
|
+
end
|
35
|
+
|
36
|
+
self.arguments = [
|
37
|
+
CLAide::Argument.new('NAME.podspec', false)
|
38
|
+
]
|
39
|
+
|
40
|
+
def initialize(argv)
|
41
|
+
@env = argv.option('env') || 'dev'
|
42
|
+
CBin.config.set_configuration_env(@env)
|
43
|
+
UI.warn "====== cocoapods-imy-bin #{CBin::VERSION} 版本 ======== \n "
|
44
|
+
UI.warn "====== #{@env} 环境 ======== \n "
|
45
|
+
|
46
|
+
@code_dependencies = argv.flag?('code-dependencies')
|
47
|
+
@framework_output = argv.flag?('framework-output', false )
|
48
|
+
@clean = argv.flag?('no-clean', false)
|
49
|
+
@zip = argv.flag?('zip', true)
|
50
|
+
@all_make = argv.flag?('all-make', false )
|
51
|
+
@sources = argv.option('sources') || []
|
52
|
+
@platform = Platform.new(:ios)
|
53
|
+
|
54
|
+
@framework_path
|
55
|
+
super
|
56
|
+
|
57
|
+
@additional_args = argv.remainder!
|
58
|
+
@build_finshed = false
|
59
|
+
end
|
60
|
+
|
61
|
+
def run
|
62
|
+
#清除之前的缓存
|
63
|
+
zip_dir = CBin::Config::Builder.instance.zip_dir
|
64
|
+
FileUtils.rm_rf(zip_dir) if File.exist?(zip_dir)
|
65
|
+
|
66
|
+
@spec = Specification.from_file(spec_file)
|
67
|
+
generate_project
|
68
|
+
|
69
|
+
build_root_spec
|
70
|
+
|
71
|
+
sources_sepc = Array.new
|
72
|
+
sources_sepc << @spec
|
73
|
+
sources_sepc.concat(build_dependencies) if @all_make
|
74
|
+
|
75
|
+
sources_sepc
|
76
|
+
end
|
77
|
+
|
78
|
+
def build_root_spec
|
79
|
+
builder = CBin::Build::Helper.new(@spec,
|
80
|
+
@platform,
|
81
|
+
@framework_output,
|
82
|
+
@zip,
|
83
|
+
@spec,
|
84
|
+
CBin::Config::Builder.instance.white_pod_list.include?(@spec.name))
|
85
|
+
builder.build
|
86
|
+
builder.clean_workspace if @clean && !@all_make
|
87
|
+
end
|
88
|
+
|
89
|
+
def build_dependencies
|
90
|
+
@build_finshed = true
|
91
|
+
#如果没要求,就清空依赖库数据
|
92
|
+
sources_sepc = []
|
93
|
+
@@missing_binary_specs.uniq.each do |spec|
|
94
|
+
next if spec.name.include?('/')
|
95
|
+
next if spec.name == @spec.name
|
96
|
+
#过滤白名单
|
97
|
+
next if CBin::Config::Builder.instance.white_pod_list.include?(spec.name)
|
98
|
+
#过滤 git
|
99
|
+
if spec.source[:git] && spec.source[:git]
|
100
|
+
spec_git = spec.source[:git]
|
101
|
+
spec_git_res = false
|
102
|
+
CBin::Config::Builder.instance.ignore_git_list.each do |ignore_git|
|
103
|
+
spec_git_res = spec_git.include?(ignore_git)
|
104
|
+
break if spec_git_res
|
105
|
+
end
|
106
|
+
next if spec_git_res
|
107
|
+
end
|
108
|
+
UI.warn "#{spec.name}.podspec 带有 vendored_frameworks 字段,请检查是否有效!!!" if spec.attributes_hash['vendored_frameworks']
|
109
|
+
next if spec.attributes_hash['vendored_frameworks'] && @spec.name != spec.name #过滤带有vendored_frameworks的
|
110
|
+
next if spec.attributes_hash['ios.vendored_frameworks'] && @spec.name != spec.name #过滤带有vendored_frameworks的
|
111
|
+
#获取没有制作二进制版本的spec集合
|
112
|
+
sources_sepc << spec
|
113
|
+
end
|
114
|
+
|
115
|
+
fail_build_specs = []
|
116
|
+
sources_sepc.uniq.each do |spec|
|
117
|
+
begin
|
118
|
+
builder = CBin::Build::Helper.new(spec,
|
119
|
+
@platform,
|
120
|
+
@framework_output,
|
121
|
+
@zip,
|
122
|
+
@spec)
|
123
|
+
builder.build
|
124
|
+
rescue
|
125
|
+
fail_build_specs << spec
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
if fail_build_specs.any?
|
130
|
+
fail_build_specs.uniq.each do |spec|
|
131
|
+
UI.warn "【#{spec.name} | #{spec.version}】组件二进制版本编译失败 ."
|
132
|
+
end
|
133
|
+
end
|
134
|
+
sources_sepc - fail_build_specs
|
135
|
+
end
|
136
|
+
|
137
|
+
# 解析器传过来的
|
138
|
+
def Archive.missing_binary_specs(missing_binary_specs)
|
139
|
+
@@missing_binary_specs = missing_binary_specs unless @build_finshed
|
140
|
+
end
|
141
|
+
|
142
|
+
private
|
143
|
+
|
144
|
+
def generate_project
|
145
|
+
Podfile.execute_with_bin_plugin do
|
146
|
+
Podfile.execute_with_use_binaries(!@code_dependencies) do
|
147
|
+
argvs = [
|
148
|
+
"--sources=#{sources_option(@code_dependencies, @sources)}",
|
149
|
+
"--gen-directory=#{CBin::Config::Builder.instance.gen_dir}",
|
150
|
+
'--clean',
|
151
|
+
*@additional_args
|
152
|
+
]
|
153
|
+
|
154
|
+
argvs << spec_file if spec_file
|
155
|
+
|
156
|
+
gen = Pod::Command::Gen.new(CLAide::ARGV.new(argvs))
|
157
|
+
gen.validate!
|
158
|
+
gen.run
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
|
164
|
+
def spec_file
|
165
|
+
@spec_file ||= begin
|
166
|
+
if @podspec
|
167
|
+
find_spec_file(@podspec)
|
168
|
+
else
|
169
|
+
if code_spec_files.empty?
|
170
|
+
raise Informative, '当前目录下没有找到可用源码 podspec.'
|
171
|
+
end
|
172
|
+
|
173
|
+
spec_file = code_spec_files.first
|
174
|
+
spec_file
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
@@ -0,0 +1,188 @@
|
|
1
|
+
|
2
|
+
require 'cocoapods-imy-bin/command/bin/auto'
|
3
|
+
require 'cocoapods-imy-bin/helpers/upload_helper'
|
4
|
+
|
5
|
+
module Pod
|
6
|
+
class Command
|
7
|
+
class Bin < Command
|
8
|
+
class Auto < Bin
|
9
|
+
self.summary = '打开 workspace 工程.'
|
10
|
+
|
11
|
+
self.arguments = [
|
12
|
+
CLAide::Argument.new('NAME.podspec', false)
|
13
|
+
]
|
14
|
+
def self.options
|
15
|
+
[
|
16
|
+
['--code-dependencies', '使用源码依赖'],
|
17
|
+
['--allow-prerelease', '允许使用 prerelease 的版本'],
|
18
|
+
['--no-clean', '保留构建中间产物'],
|
19
|
+
['--framework-output', '输出framework文件'],
|
20
|
+
['--no-zip', '不压缩静态 framework 为 zip'],
|
21
|
+
['--all-make', '对该组件的依赖库,全部制作为二进制组件'],
|
22
|
+
['--env', "该组件上传的环境 %w[dev debug_iphoneos release_iphoneos]"]
|
23
|
+
]
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize(argv)
|
27
|
+
|
28
|
+
@env = argv.option('env') || 'dev'
|
29
|
+
CBin.config.set_configuration_env(@env)
|
30
|
+
|
31
|
+
@podspec = argv.shift_argument || find_podspec
|
32
|
+
@specification = Specification.from_file(@podspec)
|
33
|
+
|
34
|
+
@code_dependencies = argv.flag?('code-dependencies')
|
35
|
+
@allow_prerelease = argv.flag?('allow-prerelease')
|
36
|
+
@framework_output = argv.flag?('framework-output', false )
|
37
|
+
@clean = argv.flag?('clean', true)
|
38
|
+
@zip = argv.flag?('zip', true)
|
39
|
+
@all_make = argv.flag?('all-make', false )
|
40
|
+
@verbose = argv.flag?('verbose',true)
|
41
|
+
super
|
42
|
+
end
|
43
|
+
|
44
|
+
def run
|
45
|
+
|
46
|
+
unless @podspec
|
47
|
+
raise Informative, "未找到 podspec文件"
|
48
|
+
end
|
49
|
+
sources_sepc = run_archive
|
50
|
+
|
51
|
+
fail_push_specs = []
|
52
|
+
sources_sepc.uniq.each do |spec|
|
53
|
+
begin
|
54
|
+
fail_push_specs << spec unless CBin::Upload::Helper.new(spec,@code_dependencies,@sources).upload
|
55
|
+
rescue
|
56
|
+
fail_push_specs << spec
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
if fail_push_specs.any?
|
61
|
+
fail_push_specs.uniq.each do |spec|
|
62
|
+
UI.warn "【#{spec.name} | #{spec.version}】组件spec push失败 ."
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
success_specs = sources_sepc - fail_push_specs
|
67
|
+
if success_specs.any?
|
68
|
+
auto_success = ""
|
69
|
+
success_specs.uniq.each do |spec|
|
70
|
+
auto_success += "#{spec.name} | #{spec.version}\n"
|
71
|
+
UI.warn "===【 #{spec.name} | #{spec.version} 】二进制组件制作完成 !!! "
|
72
|
+
end
|
73
|
+
puts "============== auto_success"
|
74
|
+
puts auto_success
|
75
|
+
ENV['auto_success'] = auto_success
|
76
|
+
end
|
77
|
+
#pod repo update
|
78
|
+
UI.section("\nUpdating Spec Repositories\n".yellow) do
|
79
|
+
Pod::Command::Bin::Repo::Update.new(CLAide::ARGV.new([])).run
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
#制作二进制包
|
85
|
+
# `pod bin archive --verbose --code-dependencies --no-clean --sources=https://gitlab.xxx.com/iOS/imyspecs.git,https://cdn.cocoapods.org/ --use-libraries`
|
86
|
+
def run_archive
|
87
|
+
argvs = [
|
88
|
+
"--sources=#{sources_option(@code_dependencies, @sources)},https:\/\/cdn.cocoapods.org",
|
89
|
+
"--use-libraries",
|
90
|
+
"--verbose"
|
91
|
+
]
|
92
|
+
|
93
|
+
argvs << spec_file if spec_file
|
94
|
+
|
95
|
+
unless @clean
|
96
|
+
argvs += ['--no-clean']
|
97
|
+
end
|
98
|
+
if @code_dependencies
|
99
|
+
argvs += ['--code-dependencies']
|
100
|
+
end
|
101
|
+
if @verbose
|
102
|
+
argvs += ['--verbose']
|
103
|
+
end
|
104
|
+
if @allow_prerelease
|
105
|
+
argvs += ['--allow-prerelease']
|
106
|
+
end
|
107
|
+
if @framework_output
|
108
|
+
argvs += ['--framework-output']
|
109
|
+
end
|
110
|
+
if @all_make
|
111
|
+
argvs += ['--all-make']
|
112
|
+
end
|
113
|
+
if @env
|
114
|
+
argvs += ["--env=#{@env}"]
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
archive = Pod::Command::Bin::Archive.new(CLAide::ARGV.new(argvs))
|
119
|
+
archive.validate!
|
120
|
+
sources_sepc = archive.run
|
121
|
+
sources_sepc
|
122
|
+
end
|
123
|
+
|
124
|
+
|
125
|
+
def code_podsepc_extname
|
126
|
+
'.podsepc'
|
127
|
+
end
|
128
|
+
|
129
|
+
def binary_podsepc_json
|
130
|
+
"#{@specification.name}.binary.podspec.json"
|
131
|
+
end
|
132
|
+
|
133
|
+
def binary_template_podsepc
|
134
|
+
"#{@specification.name}.binary-template.podspec"
|
135
|
+
end
|
136
|
+
|
137
|
+
def template_spec_file
|
138
|
+
@template_spec_file ||= begin
|
139
|
+
if @template_podspec
|
140
|
+
find_spec_file(@template_podspec)
|
141
|
+
else
|
142
|
+
binary_template_spec_file
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def spec_file
|
148
|
+
@spec_file ||= begin
|
149
|
+
if @podspec
|
150
|
+
find_spec_file(@podspec) || @podspec
|
151
|
+
else
|
152
|
+
if code_spec_files.empty?
|
153
|
+
raise Informative, '当前目录下没有找到可用源码 podspec.'
|
154
|
+
end
|
155
|
+
|
156
|
+
spec_file = if @binary
|
157
|
+
code_spec = Pod::Specification.from_file(code_spec_files.first)
|
158
|
+
if template_spec_file
|
159
|
+
template_spec = Pod::Specification.from_file(template_spec_file)
|
160
|
+
end
|
161
|
+
create_binary_spec_file(code_spec, template_spec)
|
162
|
+
else
|
163
|
+
code_spec_files.first
|
164
|
+
end
|
165
|
+
spec_file
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
#Dir.glob 可替代
|
171
|
+
def find_podspec
|
172
|
+
Pathname.pwd.children.each do |child|
|
173
|
+
puts child
|
174
|
+
if File.file?(child)
|
175
|
+
if child.extname == '.podspec'
|
176
|
+
name = File.basename(child)
|
177
|
+
unless name.include?("binary-template")
|
178
|
+
return name
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
@@ -0,0 +1,237 @@
|
|
1
|
+
|
2
|
+
module Pod
|
3
|
+
class Command
|
4
|
+
class Bin < Command
|
5
|
+
class Code < Bin
|
6
|
+
self.summary = '通过将二进制对应源码放置在临时目录中,让二进制出现断点时可以跳到对应的源码,方便调试。'
|
7
|
+
|
8
|
+
self.description = <<-DESC
|
9
|
+
通过将二进制对应源码放置在临时目录中,让二进制出现断点时可以跳到对应的源码,方便调试。
|
10
|
+
在不删除二进制的情况下为某个组件添加源码调试能力,多个组件名称用空格分隔
|
11
|
+
DESC
|
12
|
+
|
13
|
+
self.arguments = [
|
14
|
+
CLAide::Argument.new('NAME', false)
|
15
|
+
]
|
16
|
+
def self.options
|
17
|
+
[
|
18
|
+
['--all-clean', '删除所有已经下载的源码'],
|
19
|
+
['--clean', '删除所有指定下载的源码'],
|
20
|
+
['--list', '展示所有一级下载的源码以及其大小'],
|
21
|
+
['--source', '源码路径,本地路径,会去自动链接本地源码']
|
22
|
+
]
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(argv)
|
26
|
+
@codeSource = argv.option('source') || nil
|
27
|
+
@names = argv.arguments! unless argv.arguments.empty?
|
28
|
+
@list = argv.flag?('list', false )
|
29
|
+
@all_clean = argv.flag?('all-clean', false )
|
30
|
+
@clean = argv.flag?('clean', false )
|
31
|
+
|
32
|
+
@config = Pod::Config.instance
|
33
|
+
|
34
|
+
super
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def run
|
39
|
+
|
40
|
+
podfile_lock = File.join(Pathname.pwd,"Podfile.lock")
|
41
|
+
raise "podfile.lock,不存在,请先pod install/update" unless File.exist?(podfile_lock)
|
42
|
+
@lockfile ||= Lockfile.from_file(Pathname.new(podfile_lock) )
|
43
|
+
|
44
|
+
if @list
|
45
|
+
list
|
46
|
+
elsif @clean
|
47
|
+
clean
|
48
|
+
elsif @all_clean
|
49
|
+
all_clean
|
50
|
+
elsif @names
|
51
|
+
add
|
52
|
+
end
|
53
|
+
|
54
|
+
if @list && @clean && @names
|
55
|
+
raise "请选择您要执行的命令。"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
#==========================begin add ==============
|
60
|
+
|
61
|
+
def add
|
62
|
+
if @names == nil
|
63
|
+
raise "请输入要调试组件名,多个组件名称用空格分隔"
|
64
|
+
end
|
65
|
+
|
66
|
+
@names.each do |name|
|
67
|
+
lib_file = get_lib_path(name)
|
68
|
+
unless File.exist?(lib_file)
|
69
|
+
raise "找不到 #{lib_file}"
|
70
|
+
end
|
71
|
+
UI.puts "#{lib_file}"
|
72
|
+
|
73
|
+
target_path = @codeSource || download_source(name)
|
74
|
+
|
75
|
+
link(lib_file,target_path,name)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
#下载源码到本地
|
80
|
+
def download_source(name)
|
81
|
+
target_path = File.join(source_root, name)
|
82
|
+
UI.puts target_path
|
83
|
+
FileUtils.rm_rf(target_path)
|
84
|
+
|
85
|
+
find_dependency = find_dependency(name)
|
86
|
+
# 意义不大,需要可以使用--source参数 对 github-ios 仓库对做特殊处理
|
87
|
+
# if find_dependency && find_dependency.external_source[:podspec].include?(http_gitlib_GitHub_iOS_path)
|
88
|
+
# github_ios = find_dependency.external_source[:podspec]
|
89
|
+
# find_dependency.external_source[:podspec] = github_ios.gsub(http_gitlib_GitHub_iOS_path,http_gitlib_iOS_path)
|
90
|
+
# end
|
91
|
+
|
92
|
+
spec = fetch_external_source(find_dependency, @config.podfile,@config.lockfile, @config.sandbox,true )
|
93
|
+
|
94
|
+
download_request = Pod::Downloader::Request.new(:name => name, :spec => spec)
|
95
|
+
Downloader.download(download_request, Pathname.new(target_path), :can_cache => true)
|
96
|
+
|
97
|
+
target_path
|
98
|
+
end
|
99
|
+
|
100
|
+
#找出依赖
|
101
|
+
def find_dependency (name)
|
102
|
+
find_dependency = nil
|
103
|
+
@config.podfile.dependencies.each do |dependency|
|
104
|
+
if dependency.root_name.downcase == name.downcase
|
105
|
+
find_dependency = dependency
|
106
|
+
break
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
find_dependency
|
111
|
+
end
|
112
|
+
|
113
|
+
# 获取external_source 下的仓库
|
114
|
+
# @return spec
|
115
|
+
def fetch_external_source(dependency ,podfile , lockfile, sandbox,use_lockfile_options)
|
116
|
+
source = ExternalSources.from_dependency(dependency, podfile.defined_in_file, true)
|
117
|
+
source.fetch(sandbox)
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
#==========================link begin ==============
|
122
|
+
|
123
|
+
#链接,.a文件位置, 源码目录,工程名=IMYFoundation
|
124
|
+
def link(lib_file,target_path,basename)
|
125
|
+
dir = (`dwarfdump "#{lib_file}" | grep "AT_comp_dir" | head -1 | cut -d \\" -f2 `)
|
126
|
+
sub_path = "#{basename}/bin-archive/#{basename}"
|
127
|
+
dir = dir.gsub(sub_path, "").chomp
|
128
|
+
# UI.puts "dir = #{dir}"
|
129
|
+
|
130
|
+
unless File.exist?(dir)
|
131
|
+
# UI.puts "不存在 = #{dir}"
|
132
|
+
begin
|
133
|
+
FileUtils.mkdir_p(dir)
|
134
|
+
rescue SystemCallError
|
135
|
+
#判断用户目录是否存在
|
136
|
+
array = dir.split('/')
|
137
|
+
if array.length > 3
|
138
|
+
root_path = '/' + array[1] + '/' + array[2]
|
139
|
+
unless File.exist?(root_path)
|
140
|
+
raise "由于权限不足,请手动创建#{root_path} 后重试"
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
if Pathname.new(lib_file).extname == ".a"
|
147
|
+
FileUtils.rm_rf(File.join(dir,basename))
|
148
|
+
`ln -s #{target_path} #{dir}`
|
149
|
+
else
|
150
|
+
FileUtils.rm_rf(File.join(dir,basename))
|
151
|
+
`ln -s #{target_path} #{dir}/#{basename}`
|
152
|
+
end
|
153
|
+
check(lib_file,dir,basename)
|
154
|
+
end
|
155
|
+
|
156
|
+
def check(lib_file,dir,basename)
|
157
|
+
file = `dwarfdump "#{lib_file}" | grep -E "DW_AT_decl_file.*#{basename}.*\\.m|\\.c" | head -1 | cut -d \\" -f2`
|
158
|
+
if File.exist?(file)
|
159
|
+
raise "#{file} 不存在 请检测代码源是否正确~"
|
160
|
+
end
|
161
|
+
UI.puts "link successfully!"
|
162
|
+
UI.puts "view linked source at path: #{dir}"
|
163
|
+
end
|
164
|
+
|
165
|
+
def get_lib_path(name)
|
166
|
+
dir = Pathname.new(File.join(Pathname.pwd,"Pods",name))
|
167
|
+
lib_name = "lib#{name}.a"
|
168
|
+
lib_path = File.join(dir,lib_name)
|
169
|
+
|
170
|
+
unless File.exist?(lib_path)
|
171
|
+
lib_path = File.join(dir.children.first,lib_name)
|
172
|
+
end
|
173
|
+
|
174
|
+
lib_path
|
175
|
+
end
|
176
|
+
|
177
|
+
#源码地址
|
178
|
+
# def get_gitlib_iOS_path(name)
|
179
|
+
# "git@gitlab.xxx.com:iOS/#{name}.git"
|
180
|
+
# end
|
181
|
+
#要转换的地址,Github-iOS默认都是静态库
|
182
|
+
# def git_gitlib_iOS_path
|
183
|
+
# 'git@gitlab.xxx.com:Github-iOS/'
|
184
|
+
# end
|
185
|
+
|
186
|
+
|
187
|
+
#要转换的地址,Github-iOS默认都是静态库
|
188
|
+
# def http_gitlib_GitHub_iOS_path
|
189
|
+
# 'https://gitlab.xxx.com/Github-iOS/'
|
190
|
+
# end
|
191
|
+
|
192
|
+
#要转换的地址,iOS默认都是静态库
|
193
|
+
# def http_gitlib_iOS_path
|
194
|
+
# 'https://gitlab.xxx.com/iOS/'
|
195
|
+
# end
|
196
|
+
|
197
|
+
#==========================list begin ==============
|
198
|
+
|
199
|
+
def list
|
200
|
+
Dir.entries(source_root).each do |sub|
|
201
|
+
UI.puts "- #{sub}" unless sub.include?('.')
|
202
|
+
end
|
203
|
+
UI.puts "加载完成"
|
204
|
+
end
|
205
|
+
|
206
|
+
|
207
|
+
#==========================clean begin ==============
|
208
|
+
def all_clean
|
209
|
+
FileUtils.rm_rf(source_root) if File.directory?(source_root)
|
210
|
+
UI.puts "清理完成 #{source_root}"
|
211
|
+
end
|
212
|
+
|
213
|
+
def clean
|
214
|
+
raise "请输入要删除的组件库" if @names.nil?
|
215
|
+
@names.each do |name|
|
216
|
+
full_path = File.join(source_root,name)
|
217
|
+
if File.directory?(full_path)
|
218
|
+
FileUtils.rm_rf(full_path)
|
219
|
+
else
|
220
|
+
UI.puts "找不到 #{full_path}".yellow
|
221
|
+
end
|
222
|
+
end
|
223
|
+
UI.puts "清理完成 #{@names.to_s}"
|
224
|
+
end
|
225
|
+
|
226
|
+
private
|
227
|
+
|
228
|
+
def source_root
|
229
|
+
dir = File.join(@config.cache_root,"Source")
|
230
|
+
FileUtils.mkdir_p(dir) unless File.exist? dir
|
231
|
+
dir
|
232
|
+
end
|
233
|
+
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|