Class: Pod::Installer::Analyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-meitu-bin/native/analyzer.rb,
lib/cocoapods-meitu-bin/native/sandbox_analyzer.rb

Defined Under Namespace

Classes: SandboxAnalyzer

Instance Method Summary collapse

Instance Method Details

#dependencies_for_specs(specs, platform, all_specs) ⇒ Object



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
# File 'lib/cocoapods-meitu-bin/native/analyzer.rb', line 96

def dependencies_for_specs(specs, platform, all_specs)
  dependent_specs = {
    :debug => Set.new,
    :release => Set.new,
  }

  podfile = Pod::Config.instance.podfile

  if !specs.empty? && !all_specs.empty?
    specs.each do |s|
      s.dependencies(platform).each do |dep|
        # use_binary = podfile.use_binaries? && !podfile.use_source_pods.include?(dep.root_name)
        # key = use_binary ? dep.root_name : dep.name
        all_specs[dep.name].each do |spec|
          if spec.non_library_specification?
            if s.test_specification? && spec.name == s.consumer(platform).app_host_name && spec.app_specification?
              # This needs to be handled separately, since we _don't_ want to treat this as a "normal" dependency
              next
            end
            raise Informative, "`#{s}` depends upon `#{spec}`, which is a `#{spec.spec_type}` spec."
          end

          dependent_specs.each do |config, set|
            next unless s.dependency_whitelisted_for_configuration?(dep, config)
            set << spec
          end
        end unless all_specs[dep.name].nil? # 解决 dep.name = xxx/binary 时,all_specs[dep.name]返回的是nil,导致调用 each 方法报错
      end
    end
  end

  Hash[dependent_specs.map { |k, v| [k, (v - specs).group_by(&:root)] }].freeze
end

#fetch_external_source(dependency, use_lockfile_options) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cocoapods-meitu-bin/native/analyzer.rb', line 33

def fetch_external_source(dependency, use_lockfile_options)
  # 检查 lockfile 中的 checkout_options 是否有效
  if use_lockfile_options && lockfile
    checkout_options = lockfile.checkout_options_for_pod_named(dependency.root_name)
    if checkout_options
      # 检查 checkout_options 是否有效(必须有 :git, :path, 或 :podspec)
      has_valid_source = checkout_options[:git] || checkout_options[:path] || checkout_options[:podspec]
      unless has_valid_source
        # 无效的 checkout_options(只有 :commit 没有 :git),强制使用 dependency.external_source
        use_lockfile_options = false
      end
    end
  end
  
  old_fetch_external_source(dependency, use_lockfile_options)
end

#fetch_external_sources(podfile_state) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/cocoapods-meitu-bin/native/analyzer.rb', line 9

def fetch_external_sources(podfile_state)
  verify_no_pods_with_different_sources!
  deps = dependencies_to_fetch(podfile_state)
  pods = pods_to_fetch(podfile_state)
  return if deps.empty?

  UI.section 'Fetching external sources' do
    if installation_options.install_with_multi_threads
      thread_count = installation_options.multi_threads_count
      Parallel.each(deps.sort, in_threads: thread_count) do |dependency|
        fetch_external_source(dependency, !pods.include?(dependency.root_name))
      end
    else
      deps.sort.each do |dependency|
        fetch_external_source(dependency, !pods.include?(dependency.root_name))
      end
    end
  end
end

#old_dependencies_for_specsObject

解决 dep.name = xxx/binary 时,all_specs 返回nil,导致调用 each 方法报错



95
# File 'lib/cocoapods-meitu-bin/native/analyzer.rb', line 95

alias old_dependencies_for_specs dependencies_for_specs

#old_fetch_external_sourceObject

关键修复:覆盖 fetch_external_source 方法过滤 Podfile.lock 中只有 :commit 没有 :git 的无效 checkout_options 这种情况发生在 mbox activate 激活本地库时,lockfile 保留了旧的 commit 信息



32
# File 'lib/cocoapods-meitu-bin/native/analyzer.rb', line 32

alias old_fetch_external_source fetch_external_source

#old_fetch_external_sourcesObject



8
# File 'lib/cocoapods-meitu-bin/native/analyzer.rb', line 8

alias old_fetch_external_sources fetch_external_sources

#old_update_repositoriesObject

> 1.5.3 版本rewrite update_repositories



74
# File 'lib/cocoapods-meitu-bin/native/analyzer.rb', line 74

alias old_update_repositories update_repositories

#update_repositoriesObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/cocoapods-meitu-bin/native/analyzer.rb', line 75

def update_repositories
  if installation_options.update_source_with_multi_threads
    # 并发更新私有源
    # 这里多线程会导致 pod update 额外输出 --verbose 的内容
    # 不知道为什么?
    thread_count = installation_options.multi_threads_count
    Parallel.each(sources.uniq(&:url), in_threads: thread_count) do |source|
      if source.updateable?
        sources_manager.update(source.name, true)
      else
        UI.message "Skipping `#{source.name}` update because the repository is not an updateable repository."
      end
    end
    @specs_updated = true
  else
    old_update_repositories
  end
end