cocoapods源码5.3 - command/install.rb

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、要点总结

  • 1、强制更新 pod repo
--repo-update # Force running `pod repo update` before install
  • 2、pod install 不更新 pod repo
installer.repo_update = repo_update?(:default => false) # 传入参数值:false => 不更新 repo
  • 3、pod install 不执行 update
installer.update = false
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容