Class: Pod::Installer::Analyzer

Inherits:
Object
  • Object
show all
Includes:
Config::Mixin, InstallationOptions::Mixin
Defined in:
lib/cocoapods/installer/analyzer.rb,
lib/cocoapods/installer/analyzer/pod_variant.rb,
lib/cocoapods/installer/analyzer/specs_state.rb,
lib/cocoapods/installer/analyzer/analysis_result.rb,
lib/cocoapods/installer/analyzer/pod_variant_set.rb,
lib/cocoapods/installer/analyzer/sandbox_analyzer.rb,
lib/cocoapods/installer/analyzer/target_inspector.rb,
lib/cocoapods/installer/analyzer/podfile_dependency_cache.rb,
lib/cocoapods/installer/analyzer/target_inspection_result.rb,
lib/cocoapods/installer/analyzer/locking_dependency_analyzer.rb

Overview

Analyzes the Podfile, the Lockfile, and the sandbox manifest to generate the information relative to a CocoaPods installation.

Defined Under Namespace

Modules: LockingDependencyAnalyzer Classes: AnalysisResult, PodVariant, PodVariantSet, PodfileDependencyCache, SandboxAnalyzer, SpecsState, TargetInspectionResult, TargetInspector

Instance Attribute Summary collapse

Attributes included from InstallationOptions::Mixin

#installation_options

Instance Method Summary collapse

Methods included from InstallationOptions::Mixin

included

Methods included from Config::Mixin

#config

Constructor Details

#initialize(sandbox, podfile, lockfile = nil, plugin_sources = nil, has_dependencies = true, pods_to_update = false) ⇒ Analyzer

Initialize a new instance

Parameters:

  • sandbox (Sandbox)

    @see #sandbox

  • podfile (Podfile)

    @see #podfile

  • lockfile (Lockfile) (defaults to: nil)

    @see #lockfile

  • plugin_sources (Array<Source>) (defaults to: nil)

    @see #plugin_sources

  • has_dependencies (Boolean) (defaults to: true)

    @see #has_dependencies

  • pods_to_update (Hash, Boolean, nil) (defaults to: false)

    @see #pods_to_update



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/cocoapods/installer/analyzer.rb', line 59

def initialize(sandbox, podfile, lockfile = nil, plugin_sources = nil, has_dependencies = true,
               pods_to_update = false)
  @sandbox  = sandbox
  @podfile  = podfile
  @lockfile = lockfile
  @plugin_sources = plugin_sources
  @has_dependencies = has_dependencies
  @pods_to_update = pods_to_update
  @podfile_dependency_cache = PodfileDependencyCache.from_podfile(podfile)
  @result = nil
end

Instance Attribute Details

#has_dependenciesBool (readonly) Also known as: has_dependencies?

Note:

This is used by the ‘pod lib lint` command to prevent update of specs when not needed.

Returns Whether the analysis has dependencies and thus sources must be configured.

Returns:

  • (Bool)

    Whether the analysis has dependencies and thus sources must be configured.



42
43
44
# File 'lib/cocoapods/installer/analyzer.rb', line 42

def has_dependencies
  @has_dependencies
end

#lockfileLockfile (readonly)

Returns The Lockfile, if available, that stores the information about the Pods previously installed.

Returns:

  • (Lockfile)

    The Lockfile, if available, that stores the information about the Pods previously installed.



32
33
34
# File 'lib/cocoapods/installer/analyzer.rb', line 32

def lockfile
  @lockfile
end

#plugin_sourcesArray<Source> (readonly)

Returns Sources provided by plugins or ‘nil`.

Returns:

  • (Array<Source>)

    Sources provided by plugins or ‘nil`.



36
37
38
# File 'lib/cocoapods/installer/analyzer.rb', line 36

def plugin_sources
  @plugin_sources
end

#podfilePodfile (readonly)

Returns The Podfile specification that contains the information of the Pods that should be installed.

Returns:

  • (Podfile)

    The Podfile specification that contains the information of the Pods that should be installed.



28
29
30
# File 'lib/cocoapods/installer/analyzer.rb', line 28

def podfile
  @podfile
end

#pods_to_updateHash, ... (readonly)

Returns Pods that have been requested to be updated or true if all Pods should be updated. This can be false if no pods should be updated.

Returns:

  • (Hash, Boolean, nil)

    Pods that have been requested to be updated or true if all Pods should be updated. This can be false if no pods should be updated.



48
49
50
# File 'lib/cocoapods/installer/analyzer.rb', line 48

def pods_to_update
  @pods_to_update
end

#sandboxSandbox (readonly)

Returns The sandbox to use for this analysis.

Returns:

  • (Sandbox)

    The sandbox to use for this analysis.



24
25
26
# File 'lib/cocoapods/installer/analyzer.rb', line 24

def sandbox
  @sandbox
end

Instance Method Details

#analyze(allow_fetches = true) ⇒ AnalysisResult

Performs the analysis.

The Podfile and the Lockfile provide the information necessary to compute which specification should be installed. The manifest of the sandbox returns which specifications are installed.

Parameters:

  • allow_fetches (Bool) (defaults to: true)

    whether external sources may be fetched

Returns:



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
# File 'lib/cocoapods/installer/analyzer.rb', line 82

def analyze(allow_fetches = true)
  return @result if @result
  validate_podfile!
  validate_lockfile_version!
  if installation_options.integrate_targets?
    target_inspections = inspect_targets_to_integrate
  else
    verify_platforms_specified!
    target_inspections = {}
  end
  podfile_state = generate_podfile_state

  store_existing_checkout_options
  fetch_external_sources(podfile_state) if allow_fetches

  locked_dependencies = generate_version_locking_dependencies(podfile_state)
  resolver_specs_by_target = resolve_dependencies(locked_dependencies)
  validate_platforms(resolver_specs_by_target)
  specifications  = generate_specifications(resolver_specs_by_target)
  targets         = generate_targets(resolver_specs_by_target, target_inspections)
  pod_targets     = calculate_pod_targets(targets)
  sandbox_state   = generate_sandbox_state(specifications)
  specs_by_target = resolver_specs_by_target.each_with_object({}) do |rspecs_by_target, hash|
    hash[rspecs_by_target[0]] = rspecs_by_target[1].map(&:spec)
  end
  specs_by_source = Hash[resolver_specs_by_target.values.flatten(1).group_by(&:source).map do |source, specs|
    [source, specs.map(&:spec).uniq]
  end]
  sources.each { |s| specs_by_source[s] ||= [] }
  @result = AnalysisResult.new(podfile_state, specs_by_target, specs_by_source, specifications, sandbox_state,
                               targets, pod_targets, @podfile_dependency_cache)
end

#sourcesArray<Source>

Returns the sources used to query for specifications.

When no explicit Podfile sources or plugin sources are defined, this defaults to the master spec repository.

Returns:

  • (Array<Source>)

    the sources to be used in finding specifications, as specified by the podfile or all sources.



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/cocoapods/installer/analyzer.rb', line 135

def sources
  @sources ||= begin
    sources = podfile.sources
    plugin_sources = @plugin_sources || []

    # Add any sources specified using the :source flag on individual dependencies.
    dependency_sources = podfile_dependencies.map(&:podspec_repo).compact
    all_dependencies_have_sources = dependency_sources.count == podfile_dependencies.count

    if all_dependencies_have_sources
      sources = dependency_sources
    elsif has_dependencies? && sources.empty? && plugin_sources.empty?
      sources = ['https://github.com/CocoaPods/Specs.git']
    else
      sources += dependency_sources
    end

    result = sources.uniq.map do |source_url|
      config.sources_manager.find_or_create_source_with_url(source_url)
    end
    unless plugin_sources.empty?
      result.insert(0, *plugin_sources)
    end
    result
  end
end

#update_repositoriesObject

Updates the git source repositories.



117
118
119
120
121
122
123
124
125
126
# File 'lib/cocoapods/installer/analyzer.rb', line 117

def update_repositories
  sources.each do |source|
    if source.git?
      config.sources_manager.update(source.name, true)
    else
      UI.message "Skipping `#{source.name}` update because the repository is not a git source repository."
    end
  end
  @specs_updated = true
end