Class: Pod::Command::Bin::Update

Inherits:
Pod::Command::Bin show all
Includes:
Pod, Podfile::DSL
Defined in:
lib/cocoapods-imy-bin/command/bin/update.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Podfile::DSL

#allow_prerelease!, #set_configuration_env, #set_use_source_pods, #use_binaries!, #use_binaries_with_spec_selector!

Methods included from Pod

match_version?

Methods inherited from Pod::Command::Bin

#validate!

Methods included from CBin::SpecFilesHelper

#binary_spec, #binary_spec_files, #binary_template_spec, #binary_template_spec_file, #binary_template_spec_files, #clear_binary_spec_file_if_needed, #code_spec, #code_spec_files, #create_binary_spec_file, #find_spec_file, #spec_files

Methods included from CBin::SourcesHelper

#binary_source, #code_source, #sources_manager, #sources_option, #valid_sources

Constructor Details

#initialize(argv) ⇒ Update

Returns a new instance of Update.



33
34
35
36
37
# File 'lib/cocoapods-imy-bin/command/bin/update.rb', line 33

def initialize(argv)
  @update = argv.flag?('update')
  super
  @additional_args = argv.remainder!
end

Class Method Details

.load_local_podfileObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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
125
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
# 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

.optionsObject



21
22
23
24
25
26
27
28
29
30
31
# 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

Instance Method Details

#runObject



39
40
41
42
43
44
45
46
47
48
49
# 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