Class: Pod::Command::Ybin::Link
- Inherits:
-
Pod::Command::Ybin
- Object
- Pod::Command
- Pod::Command::Ybin
- Pod::Command::Ybin::Link
- Defined in:
- lib/cocoapods-ybin/command/ybin/link.rb
Class Method Summary collapse
Instance Method Summary collapse
- #check_linked(lib_path, sourcePath, lib_name) ⇒ Object
-
#initialize(argv) ⇒ Link
constructor
A new instance of Link.
- #link_source_code(lib_path, sourcePath, lib_name) ⇒ Object
-
#linked_list ⇒ Object
查询映射列表.
-
#linked_remove ⇒ Object
移除单个映射.
-
#linked_remove_all ⇒ Object
移除所有映射.
-
#linkLibSource ⇒ Object
映射源码.
- #run ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(argv) ⇒ Link
Returns a new instance of Link.
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/cocoapods-ybin/command/ybin/link.rb', line 25 def initialize(argv) # @name = argv.shift_argument @names = argv.arguments! unless argv.arguments.empty? @list = argv.flag?('list', false) @link = argv.flag?('link', false) @remove = argv.flag?('remove', false) @remove_all = argv.flag?('remove-all', false) @lib_version = argv.flag?('lib-version', false) @config = Pod::Config.instance super end |
Class Method Details
.options ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/cocoapods-ybin/command/ybin/link.rb', line 16 def self. [ ['--list', '查询所有已映射源码库'], ['--remove', '删除源码映射(多个空格隔开)'], ['--remove-all', '删除所有源码映射'], ['--lib-version', '查询 Podfile 所有依赖库的版本'] ] end |
Instance Method Details
#check_linked(lib_path, sourcePath, lib_name) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/cocoapods-ybin/command/ybin/link.rb', line 162 def check_linked(lib_path, sourcePath, lib_name) source_path = `dwarfdump "#{lib_path}" | grep -E "DW_AT_decl_file.*#{lib_name}.*\\.m|\\.c" | head -1 | cut -d \\" -f2` source_path = source_path.chomp.strip if File.exist?(source_path) UI.puts "🍺🍺🍺 Successfully! 源码映射成功\n".green recordLinknSuccessLib(lib_name, lib_path, sourcePath) else UI.puts "[Error] 源码 #{source_path} 不存在, 请检查源码版本 或 存储位置\n".red end end |
#link_source_code(lib_path, sourcePath, lib_name) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/cocoapods-ybin/command/ybin/link.rb', line 126 def link_source_code(lib_path, sourcePath, lib_name) comp_dir_path = `dwarfdump "#{lib_path}" | grep "AT_comp_dir" | head -1 | cut -d \\" -f2` if comp_dir_path == nil || comp_dir_path == "" UI.puts "\n[Error] #{lib_name} 不支持映射源码\n".red return end lib_debug_path = comp_dir_path.chomp.strip if File.exist?(lib_debug_path) || File.directory?(lib_debug_path) if File.symlink?(lib_debug_path) print "源码映射已存在, 无法重复映射,请删除后重新映射: #{lib_debug_path}" else print "源码映射目录已存在, 请检查 #{lib_debug_path} 目录(可能存在以下情况):" UI.puts "\n1、开发源码(无需映射,即可调试) \n2、其他重复文件, 请手动移动/移除\n".red end else begin FileUtils.mkdir_p(lib_debug_path) rescue SystemCallError array = lib_debug_path.split('/') if array.length > 3 root_path = '/' + array[1] + '/' + array[2] unless File.exist?(root_path) UI.puts "[Error] 无权限创建文件夹,请手动创建#{root_path}文件夹,再重试\n".red end end end FileUtils.rm_rf(lib_debug_path) File.symlink(sourcePath, lib_debug_path) check_linked(lib_path, lib_debug_path, lib_name) end end |
#linked_list ⇒ Object
查询映射列表
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/cocoapods-ybin/command/ybin/link.rb', line 223 def linked_list if File.exist?(source_record_file_path) records = JSON.parse(File.read(source_record_file_path)) if records.count > 0 records.each.with_index(1) do |record, index| lib_version_s = record["lib_version"] lib_version_s = (lib_version_s == nil || lib_version_s == '') ? "" : "(#{lib_version_s})" UI.puts "#{index}. #{record["lib_name"]} #{lib_version_s} ".green "Source: #{record["source_path"]}".yellow end else UI.puts "\n无记录".green end else UI.puts "\n无记录".green end print "\n" end |
#linked_remove ⇒ Object
移除单个映射
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/cocoapods-ybin/command/ybin/link.rb', line 175 def linked_remove if @names.nil? UI.puts "[Error] 请输入要删除的组件库. 实例: $ pod ybin --remove xxx yyy zzz\n".red return end @names.each do |name| lib_linked_path = get_lib_linked_path(name) if lib_linked_path.nil? || lib_linked_path == "" UI.puts "[Error] #{name} 的映射不存在, 无需移除".red else if File.exist?(lib_linked_path) && File.symlink?(lib_linked_path) FileUtils.rm_rf(lib_linked_path) removeLinkedFileRecord(name) UI.puts "#{name} 成功移除".green else UI.puts "[Error] #{name} 的映射不存在, 请手动核查: #{lib_linked_path}".red end end end print "\n" end |
#linked_remove_all ⇒ Object
移除所有映射
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/cocoapods-ybin/command/ybin/link.rb', line 200 def linked_remove_all if File.exist?(source_record_file_path) records = JSON.parse(File.read(source_record_file_path)) if records.count > 0 records.each.with_index(0) do |record, index| lib_linked_path = record["source_path"] lib_name = record["lib_name"] if File.exist?(lib_linked_path) && File.symlink?(lib_linked_path) FileUtils.rm_rf(lib_linked_path) removeLinkedFileRecord(lib_name) UI.puts "#{lib_name} removing...".green end end UI.puts "\n已全部移除\n".green else UI.puts "\n无记录\n".green end end end |
#linkLibSource ⇒ Object
映射源码
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/cocoapods-ybin/command/ybin/link.rb', line 74 def linkLibSource if @names.nil? UI.puts "[Error] 请输入需要映射的组件库. 示例: $ pod ybin link foo\n".red return else if @names.count > 1 UI.puts "[Error] 不支持一次映射多个源码. 示例: $ pod ybin link foo\n".red return end end user_lib_name = @names.first.chomp.strip lib_version = get_lib_version(user_lib_name) if lib_version == nil || lib_version == "" print "\n[!]Podfile 无法获取".yellow " #{user_lib_name} ".green "版本号, 但仍支持源码映射\n".yellow else is_contain_lib = linked_list_contain(user_lib_name) if is_contain_lib print "\n[Error] #{user_lib_name} 已映射 (#{lib_version}), 如需重新映射,请先删除\n\n".red return else print "\n#{project_name} Using ".green "#{user_lib_name} (#{lib_version})\n".green end end config = config_with_asker lib_path = config["libPath"] sourcePath = config["sourcePath"] lib_name = source_lib_name(lib_path) lib_real_path = "" if Pathname.new(lib_path).extname == ".framework" lib_real_path = "#{lib_path}/#{lib_name}" elsif Pathname.new(lib_path).extname == ".a" lib_real_path = lib_path end if lib_real_path == "" || !File.exist?(lib_real_path) UI.puts "\n[Error] 二进制文件不存在, 请检查文件位置!\n".red return end if sourcePath == "" || !File.exist?(sourcePath) UI.puts "\n[Error] 源码文件不存在, 请检查文件位置!\n".red return end link_source_code(lib_real_path, sourcePath, lib_name) end |
#run ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/cocoapods-ybin/command/ybin/link.rb', line 45 def run if @link && @list && @remove && @remove_all && @lib_version UI.puts "[Error] 请选择合适的命令, 不支持同时多个Option\n".red help! return end if @list analyzerPodFileLock linked_list elsif @remove analyzerPodFileLock linked_remove elsif @remove_all analyzerPodFileLock linked_remove_all elsif @lib_version analyzerPodFileLock read_podfile_lock_version elsif @names analyzerPodFileLock linkLibSource else help! end end |
#validate! ⇒ Object
39 40 41 42 43 |
# File 'lib/cocoapods-ybin/command/ybin/link.rb', line 39 def validate! super # help! 'A Pod option is required.' unless @name if @help end |