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

Configuration collapse

Instance Attribute Summary collapse

Attributes included from InstallationOptions::Mixin

#installation_options

Configuration collapse

Analysis steps collapse

Analysis internal products collapse

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) ⇒ 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



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/cocoapods/installer/analyzer.rb', line 47

def initialize(sandbox, podfile, lockfile = nil, plugin_sources = nil)
  @sandbox  = sandbox
  @podfile  = podfile
  @lockfile = lockfile
  @plugin_sources = plugin_sources

  @update = false
  @allow_pre_downloads = true
  @has_dependencies = true
  @test_pod_target_analyzer_cache = {}
  @test_pod_target_key = Struct.new(:name, :pod_targets)
  @podfile_dependency_cache = PodfileDependencyCache.from_podfile(podfile)
end

Instance Attribute Details

#allow_pre_downloadsBool Also known as: allow_pre_downloads?

Note:

This flag should not be used in installations.

Note:

This is used by the `pod outdated` command to prevent modification of the sandbox in the resolution process.

Returns Whether the analysis allows pre-downloads and thus modifications to the sandbox.

Returns:

  • (Bool)

    Whether the analysis allows pre-downloads and thus modifications to the sandbox.



170
171
172
# File 'lib/cocoapods/installer/analyzer.rb', line 170

def allow_pre_downloads
  @allow_pre_downloads
end

#has_dependenciesBool 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.



179
180
181
# File 'lib/cocoapods/installer/analyzer.rb', line 179

def has_dependencies
  @has_dependencies
end

#lockfileLockfile (readonly)

Returns The Lockfile that stores the information about the Pods previously installed on any machine.

Returns:

  • (Lockfile)

    The Lockfile that stores the information about the Pods previously installed on any machine.



34
35
36
# File 'lib/cocoapods/installer/analyzer.rb', line 34

def lockfile
  @lockfile
end

#plugin_sourcesArray<Source> (readonly)

Returns Sources provided by plugins

Returns:

  • (Array<Source>)

    Sources provided by plugins



38
39
40
# File 'lib/cocoapods/installer/analyzer.rb', line 38

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.



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

def podfile
  @podfile
end

#resultObject

Returns the value of attribute result



101
102
103
# File 'lib/cocoapods/installer/analyzer.rb', line 101

def result
  @result
end

#sandboxSandbox (readonly)

Returns The sandbox where the Pods should be installed.

Returns:

  • (Sandbox)

    The sandbox where the Pods should be installed.



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

def sandbox
  @sandbox
end

#updateHash, ...

Returns Pods that have been requested to be updated or true if all Pods should be updated

Returns:

  • (Hash, Boolean, nil)

    Pods that have been requested to be updated or true if all Pods should be updated



140
141
142
# File 'lib/cocoapods/installer/analyzer.rb', line 140

def update
  @update
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:



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

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

  store_existing_checkout_options
  fetch_external_sources if allow_fetches

  @locked_dependencies = generate_version_locking_dependencies
  resolver_specs_by_target = resolve_dependencies
  validate_platforms(resolver_specs_by_target)
  @result.specifications  = generate_specifications(resolver_specs_by_target)
  @result.targets         = generate_targets(resolver_specs_by_target)
  @result.sandbox_state   = generate_sandbox_state
  @result.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
  @result.specs_by_source = Hash[resolver_specs_by_target.values.flatten(1).group_by(&:source).map { |source, specs| [source, specs.map(&:spec).uniq] }]
  sources.each { |s| @result.specs_by_source[s] ||= [] }
  @result
end

#needs_install?Bool

Returns Whether an installation should be performed or this CocoaPods project is already up to date.

Returns:

  • (Bool)

    Whether an installation should be performed or this CocoaPods project is already up to date.



106
107
108
109
# File 'lib/cocoapods/installer/analyzer.rb', line 106

def needs_install?
  analysis_result = analyze(false)
  podfile_needs_install?(analysis_result) || sandbox_needs_install?(analysis_result)
end

#podfile_needs_install?(analysis_result) ⇒ Bool

Returns Whether the podfile has changes respect to the lockfile.

Parameters:

  • analysis_result (AnalysisResult)

    the analysis result to check for changes

Returns:

  • (Bool)

    Whether the podfile has changes respect to the lockfile.



116
117
118
119
120
# File 'lib/cocoapods/installer/analyzer.rb', line 116

def podfile_needs_install?(analysis_result)
  state = analysis_result.podfile_state
  needing_install = state.added + state.changed + state.deleted
  !needing_install.empty?
end

#sandbox_needs_install?(analysis_result) ⇒ Bool

Returns Whether the sandbox is in synch with the lockfile.

Parameters:

  • analysis_result (AnalysisResult)

    the analysis result to check for changes

Returns:

  • (Bool)

    Whether the sandbox is in synch with the lockfile.



127
128
129
130
131
# File 'lib/cocoapods/installer/analyzer.rb', line 127

def sandbox_needs_install?(analysis_result)
  state = analysis_result.sandbox_state
  needing_install = state.added + state.changed + state.deleted
  !needing_install.empty?
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. available sources (Pod::Installer::Analyzer.configconfig.sources_managerconfig.sources_manager.all).

Returns:

  • (Array<Source>)

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



855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
# File 'lib/cocoapods/installer/analyzer.rb', line 855

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_dependency_cache.podfile_dependencies.map(&:podspec_repo).compact
    all_dependencies_have_sources = dependency_sources.count == @podfile_dependency_cache.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_modeSymbol

Returns Whether and how the dependencies in the Podfile should be updated.

Returns:

  • (Symbol)

    Whether and how the dependencies in the Podfile should be updated.



152
153
154
155
156
157
158
159
160
# File 'lib/cocoapods/installer/analyzer.rb', line 152

def update_mode
  if !update
    :none
  elsif update == true
    :all
  elsif !update[:pods].nil?
    :selected
  end
end

#update_mode?Bool

Returns Whether the version of the dependencies which did not change in the Podfile should be locked.

Returns:

  • (Bool)

    Whether the version of the dependencies which did not change in the Podfile should be locked.



145
146
147
# File 'lib/cocoapods/installer/analyzer.rb', line 145

def update_mode?
  update != nil
end

#update_repositoriesObject

Updates the git source repositories.



249
250
251
252
253
254
255
256
257
258
# File 'lib/cocoapods/installer/analyzer.rb', line 249

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