class Pod::Command::Bin::Update

Public Class Methods

load_local_podfile() click to toggle source
# File lib/cocoapods-imy-bin/command/bin/update.rb, line 51
def self.load_local_podfile
  # 同步 Podfile_local 文件
  project_root = Pod::Config.instance.project_root
  path = File.join(project_root.to_s, 'Podfile_local')
  unless File.exist?(path)
    path = File.join(project_root.to_s, 'Podfile_local')
  end

  if File.exist?(path)
    contents = File.open(path, 'r:utf-8', &:read)

    podfile = Pod::Config.instance.podfile
    local_podfile = Podfile.from_file(path)

    if local_podfile
      local_pre_install_callback = nil
      local_post_install_callback = nil
      local_podfile.instance_eval do
        local_pre_install_callback = @pre_install_callback
        local_post_install_callback = @post_install_callback
      end
    end

    podfile.instance_eval do
      begin

        # podfile HASH_KEYS才有plugins字段,否则会被限制
        if local_podfile.plugins.any?
          hash_plugins = podfile.plugins || {}
          hash_plugins = hash_plugins.merge(local_podfile.plugins)
          set_hash_value(%w[plugins].first, hash_plugins)

          # 加入源码白名单,避免本地库被二进制了
          podfile.set_use_source_pods(local_podfile.use_source_pods) if local_podfile.use_source_pods
          podfile.use_binaries!(local_podfile.use_binaries?)
        end

        # 在target把local-target中到dependencies值删除了,再设置
        # 把本地和原始到dependencies 合并,设置dependencies
        local_podfile&.target_definition_list&.each do |local_target|
          next if local_target.name == 'Pods'

          target_definition_list.each do |target|

            unless target.name == local_target.name &&
                (local_target.to_hash['dependencies'] &&local_target.to_hash['dependencies'].any?)
              next
            end



            target.instance_exec do
              # 在target把local-target中到dependencies值删除了,再设置

              local_dependencies = local_target.to_hash['dependencies']
              target_dependencies = target.to_hash['dependencies']

              local_dependencies.each do |local_dependency|
                unless local_dependency.is_a?(Hash) && local_dependency.keys.first
                  next
                end

                target_dependencies.each do |target_dependency|
                  next unless target_dependency.is_a?(Hash) &&
                              target_dependency.keys.first &&
                              target_dependency.keys.first == local_dependency.keys.first

                  target_dependencies.delete target_dependency
                  break
                end
              end
              # 把本地和原始到dependencies 合并,设置dependencies
              local_dependencies.each do |d|
                UI.message "Development Pod #{d.to_yaml}"
                if podfile.plugins.keys.include?('cocoapods-imy-hycan-bin')
                  podfile.set_use_source_pods(d.keys.first) if (d.is_a?(Hash) && d.keys.first)
                end
              end
              new_dependencies = target_dependencies + local_dependencies
              set_hash_value(%w[dependencies].first, new_dependencies)

            end
          end

        end

        if local_pre_install_callback
          @pre_install_callback = local_pre_install_callback
        end
        if local_post_install_callback
          @post_install_callback = local_post_install_callback
        end
      rescue Exception => e
        message = "Invalid `#{path}` file: #{e.message}"
        raise Pod::DSLError.new(message, path, e, contents)
      end
    end

  end
end
new(argv) click to toggle source
Calls superclass method Pod::Command::Bin::new
# File lib/cocoapods-imy-bin/command/bin/update.rb, line 33
def initialize(argv)
  @update = argv.flag?('update')
  super
  @additional_args = argv.remainder!
end
options() click to toggle source
Calls superclass method
# File lib/cocoapods-imy-bin/command/bin/update.rb, line 21
def self.options
  [
    ["--sources=#{Pod::TrunkSource::TRUNK_REPO_URL}", 'The sources from which to update dependent pods. ' \
      'Multiple sources must be comma-delimited'],
    ['--exclude-pods=podName', 'Pods to exclude during update. Multiple pods must be comma-delimited'],
    ['--clean-install', 'Ignore the contents of the project cache and force a full pod installation. This only ' \
      'applies to projects that have enabled incremental installation'],
    ['--project-directory=/project/dir/', 'The path to the root of the project directory'],
    ['--no-repo-update', 'Skip running `pod repo update` before install']
  ].concat(super)
end

Public Instance Methods

run() click to toggle source
# File lib/cocoapods-imy-bin/command/bin/update.rb, line 39
def run
  Update.load_local_podfile

  argvs = [
    *@additional_args
  ]

  gen = Pod::Command::Update.new(CLAide::ARGV.new(argvs))
  gen.validate!
  gen.run
end