CocoaPods github地址
CocoaPods 官网地址
执行pod命令以后,调用了/usr/local/bin/pod文件,然后/usr/local/bin/pod又跳到了
/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.1/bin/pod,看看这个文件。
$ vi /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.1/bin/pod
1 #!/usr/bin/env ruby
2
3 if Encoding.default_external != Encoding::UTF_8
4
5 if ARGV.include? '--no-ansi'
6 STDERR.puts <<-DOC
7 WARNING: CocoaPods requires your terminal to be using UTF-8 encoding.
8 Consider adding the following to ~/.profile:
9
10 export LANG=en_US.UTF-8
11 DOC
12 else
13 STDERR.puts <<-DOC
14 \e[33mWARNING: CocoaPods requires your terminal to be using UTF-8 encoding.
15 Consider adding the following to ~/.profile:
16
17 export LANG=en_US.UTF-8
18 \e[0m
19 DOC
20 end
21
22 end
23
24 if $PROGRAM_NAME == __FILE__ && !ENV['COCOAPODS_NO_BUNDLER']
25 ENV['BUNDLE_GEMFILE'] = File.expand_path('../../Gemfile', __FILE__)
26 require 'rubygems'
27 require 'bundler/setup'
28 $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
29 puts "line 29"
30 elsif ENV['COCOAPODS_NO_BUNDLER']
31 require 'rubygems'
32 gem 'cocoapods'
33 puts "line 33"
34 end
35
36 STDOUT.sync = true if ENV['CP_STDOUT_SYNC'] == 'TRUE'
37
38 require 'cocoapods'
39
40 if profile_filename = ENV['PROFILE']
41 puts "line 41"
42 require 'ruby-prof'
43 reporter =
44 case (profile_extname = File.extname(profile_filename))
45 when '.txt'
46 RubyProf::FlatPrinterWithLineNumbers
47 when '.html'
48 RubyProf::GraphHtmlPrinter
49 when '.callgrind'
50 RubyProf::CallTreePrinter
51 else
52 raise "Unknown profiler format indicated by extension: #{profile_extname}"
53 end
54 File.open(profile_filename, 'w') do |io|
55 reporter.new(RubyProf.profile { Pod::Command.run(ARGV) }).print(io)
56 end
57 else
58 puts "line 58"
59 Pod::Command.run(ARGV)
60 end
因为有些地方不是太清楚,所以在这个文件里加入了一些输出语句,如puts "line 58",看看最后那些分支被执行了。我的环境,输入只有 line 58,也就是最终执行了
Pod::Command.run(ARGV)
Pod是一个module,类似于命名空间吧,Command是一个类,run是方法名,ARGV是参数。也就是pod命令最终交给Podx下面的Command类的run方法去处理了,先看看Pod::Command这个类。
参考文章 CocoaPods 都做了什么?
网友评论