1、CocoaPods/lib/cocoapods/command/install.rb
module Pod
class Command
class Install < Command
# 1、包含模块
# CocoaPods/lib/cocoapods/command/options/repo_update.rb 定义的模块
include RepoUpdate
# CocoaPods/lib/cocoapods/command/options/project_directory.rb 定义的模块
include ProjectDirectory
# 2、
self.summary = 'Install project dependencies according to versions from a Podfile.lock'
self.description = <<-DESC
Downloads all dependencies defined in `Podfile` and creates an Xcode
Pods library project in `./Pods`.
The Xcode project file should be specified in your `Podfile` like this:
project 'path/to/XcodeProject.xcodeproj'
If no project is specified, then a search for an Xcode project will
be made. If more than one Xcode project is found, the command will
raise an error.
This will configure the project to reference the Pods static library,
add a build configuration file, and add a post build script to copy
Pod resources.
This may return one of several error codes if it encounters problems.
* `1` Generic error code
* `31` Spec not found (i.e out-of-date source repos, mistyped Pod name etc...)
DESC
# 3、添加 --repo-update 选项
def self.options
[
['--repo-update', 'Force running `pod repo update` before install'],
].concat(super).reject { |(name, _)| name == '--no-repo-update' }
end
# 4、命令行参数解析完毕后的回调处理
def run
# 4.1、检测Podfile是否存在
verify_podfile_exists!
# 4.2、获取 Installer 对象
# ➜ cocoapods-1.5.3 cd lib
# ➜ lib grep 'installer_for_config' . -rn
# ./cocoapods/command/install.rb:38: installer = installer_for_config
# ./cocoapods/command/update.rb:87: installer = installer_for_config
# ./cocoapods/command.rb:140: def installer_for_config
# ➜ lib
# command.rb 中定义的方法:
# def installer_for_config
# Installer.new(config.sandbox, config.podfile, config.lockfile)
# end
# installer_for_config() 返回一个 Installer 对象
installer = installer_for_config
# 4.3、调用RepoUpdate模块中定义的 repo_update()
# def repo_update?(default: false)
# if @repo_update.nil?
# default
# else
# @repo_update
# end
# end
installer.repo_update = repo_update?(:default => false) # 指定参数default=false
# installer.repo_update = repo_update?(false) 同上
# 4.4、不执行 pod [update]
installer.update = false
# 4.5、install()
installer.install!
end
end
end
end
2、要点总结
--repo-update # Force running `pod repo update` before install
- 2、pod install 不更新 pod repo
installer.repo_update = repo_update?(:default => false) # 传入参数值:false => 不更新 repo
installer.update = false