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/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, 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) ⇒ Analyzer

Initialize a new instance

Parameters:

  • sandbox (Sandbox)

    @see sandbox

  • podfile (Podfile)

    @see podfile

  • lockfile (Lockfile) (defaults to: nil)

    @see lockfile



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/cocoapods/installer/analyzer.rb', line 41

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

  @update = false
  @allow_pre_downloads = true
  @has_dependencies = true
  @test_pod_target_analyzer_cache = {}
  @test_pod_target_key = Struct.new(:name, :pod_targets)
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.



155
156
157
# File 'lib/cocoapods/installer/analyzer.rb', line 155

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.



164
165
166
# File 'lib/cocoapods/installer/analyzer.rb', line 164

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.



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

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.



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

def podfile
  @podfile
end

#resultObject

Returns the value of attribute result



86
87
88
# File 'lib/cocoapods/installer/analyzer.rb', line 86

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.



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

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



125
126
127
# File 'lib/cocoapods/installer/analyzer.rb', line 125

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:



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/cocoapods/installer/analyzer.rb', line 64

def analyze(allow_fetches = true)
  validate_podfile!
  validate_lockfile_version!
  @result = AnalysisResult.new
  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
  @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.



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

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.



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

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.



112
113
114
115
116
# File 'lib/cocoapods/installer/analyzer.rb', line 112

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 (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.



845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
# File 'lib/cocoapods/installer/analyzer.rb', line 845

def sources
  @sources ||= begin
    sources = podfile.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?
      sources = ['https://github.com/CocoaPods/Specs.git']
    else
      sources += dependency_sources
    end

    sources.uniq.map do |source_url|
      config.sources_manager.find_or_create_source_with_url(source_url)
    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.



137
138
139
140
141
142
143
144
145
# File 'lib/cocoapods/installer/analyzer.rb', line 137

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.



130
131
132
# File 'lib/cocoapods/installer/analyzer.rb', line 130

def update_mode?
  update != nil
end

#update_repositoriesObject

Updates the git source repositories.



234
235
236
237
238
239
240
241
242
243
# File 'lib/cocoapods/installer/analyzer.rb', line 234

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