Class: Pod::Installer::Analyzer

Inherits:
Object
  • Object
show all
Includes:
Config::Mixin
Defined in:
lib/cocoapods/installer/analyzer.rb,
lib/cocoapods/installer/analyzer/specs_state.rb,
lib/cocoapods/installer/analyzer/analysis_result.rb,
lib/cocoapods/installer/analyzer/sandbox_analyzer.rb,
lib/cocoapods/installer/analyzer/target_inspector.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, SandboxAnalyzer, SpecsState, TargetInspectionResult, TargetInspector

Configuration collapse

Instance Attribute Summary collapse

Configuration collapse

Analysis steps collapse

Analysis internal products collapse

Instance Method Summary collapse

Methods included from Config::Mixin

#config

Constructor Details

#initialize(sandbox, podfile, lockfile = nil) ⇒ Analyzer

Initialize a new instance

Parameters:

  • sandbox (Sandbox)

    @see sandbox

  • podfile (Podfile)

    @see podfile

  • lockfile (Lockfile) (defaults to: nil)

    @see lockfile



36
37
38
39
40
41
42
43
# File 'lib/cocoapods/installer/analyzer.rb', line 36

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

  @update = false
  @allow_pre_downloads = true
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.



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

def allow_pre_downloads
  @allow_pre_downloads
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.



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

def lockfile
  @lockfile
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.



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

def podfile
  @podfile
end

#resultObject

Returns the value of attribute result.



77
78
79
# File 'lib/cocoapods/installer/analyzer.rb', line 77

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.



18
19
20
# File 'lib/cocoapods/installer/analyzer.rb', line 18

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



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

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:



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/cocoapods/installer/analyzer.rb', line 56

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

  store_existing_checkout_options
  fetch_external_sources if allow_fetches
  @result.specs_by_target = validate_platforms(resolve_dependencies)
  @result.specifications  = generate_specifications
  @result.targets         = generate_targets
  @result.sandbox_state   = generate_sandbox_state
  @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.



82
83
84
85
# File 'lib/cocoapods/installer/analyzer.rb', line 82

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.



92
93
94
95
96
# File 'lib/cocoapods/installer/analyzer.rb', line 92

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.



103
104
105
106
107
# File 'lib/cocoapods/installer/analyzer.rb', line 103

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 are defined, this defaults to the master spec repository. available sources (SourcesManager.all).

Returns:

  • (Array<Source>)

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



608
609
610
611
612
613
614
615
616
617
618
619
620
# File 'lib/cocoapods/installer/analyzer.rb', line 608

def sources
  @sources ||= begin
    sources = podfile.sources
    if sources.empty?
      url = 'https://github.com/CocoaPods/Specs.git'
      [SourcesManager.find_or_create_source_with_url(url)]
    else
      sources.map do |source_url|
        SourcesManager.find_or_create_source_with_url(source_url)
      end
    end
  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.



128
129
130
131
132
133
134
135
136
# File 'lib/cocoapods/installer/analyzer.rb', line 128

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.



121
122
123
# File 'lib/cocoapods/installer/analyzer.rb', line 121

def update_mode?
  update != nil
end

#update_repositoriesObject

Updates the git source repositories unless the config indicates to skip it.



210
211
212
213
214
215
216
217
218
# File 'lib/cocoapods/installer/analyzer.rb', line 210

def update_repositories
  sources.each do |source|
    if SourcesManager.git_repo?(source.repo)
      SourcesManager.update(source.name)
    else
      UI.message "Skipping `#{source.name}` update because the repository is not a git source repository."
    end
  end
end