Class: Pod::Installer

Inherits:
Object
  • Object
show all
Includes:
Config::Mixin, InstallationOptions::Mixin
Defined in:
lib/cocoapods/installer.rb,
lib/cocoapods/installer/xcode.rb,
lib/cocoapods/installer/analyzer.rb,
lib/cocoapods/installer/podfile_validator.rb,
lib/cocoapods/installer/pod_source_preparer.rb,
lib/cocoapods/installer/analyzer/pod_variant.rb,
lib/cocoapods/installer/analyzer/specs_state.rb,
lib/cocoapods/installer/installation_options.rb,
lib/cocoapods/installer/pod_source_installer.rb,
lib/cocoapods/installer/xcode/target_validator.rb,
lib/cocoapods/installer/user_project_integrator.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/pre_install_hooks_context.rb,
lib/cocoapods/installer/post_install_hooks_context.rb,
lib/cocoapods/installer/xcode/pods_project_generator.rb,
lib/cocoapods/installer/source_provider_hooks_context.rb,
lib/cocoapods/installer/analyzer/target_inspection_result.rb,
lib/cocoapods/installer/analyzer/locking_dependency_analyzer.rb,
lib/cocoapods/installer/user_project_integrator/target_integrator.rb,
lib/cocoapods/installer/pods_project_integrator/pod_target_integrator.rb,
lib/cocoapods/installer/xcode/pods_project_generator/target_installer.rb,
lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb,
lib/cocoapods/installer/xcode/pods_project_generator/file_references_installer.rb,
lib/cocoapods/installer/xcode/pods_project_generator/aggregate_target_installer.rb,
lib/cocoapods/installer/user_project_integrator/target_integrator/xcconfig_integrator.rb

Overview

The Installer is responsible of taking a Podfile and transform it in the Pods libraries. It also integrates the user project so the Pods libraries can be used out of the box.

The Installer is capable of doing incremental updates to an existing Pod installation.

The Installer gets the information that it needs mainly from 3 files:

- Podfile: The specification written by the user that contains
  information about targets and Pods.
- Podfile.lock: Contains information about the pods that were previously
  installed and in concert with the Podfile provides information about
  which specific version of a Pod should be installed. This file is
  ignored in update mode.
- Manifest.lock: A file contained in the Pods folder that keeps track of
  the pods installed in the local machine. This files is used once the
  exact versions of the Pods has been computed to detect if that version
  is already installed. This file is not intended to be kept under source
  control and is a copy of the Podfile.lock.

The Installer is designed to work in environments where the Podfile folder is under source control and environments where it is not. The rest of the files, like the user project and the workspace are assumed to be under source control.

Defined Under Namespace

Classes: Analyzer, InstallationOptions, PodSourceInstaller, PodSourcePreparer, PodTargetIntegrator, PodfileValidator, PostInstallHooksContext, PreInstallHooksContext, SourceProviderHooksContext, UserProjectIntegrator, Xcode

Installation results collapse

Instance Attribute Summary collapse

Attributes included from InstallationOptions::Mixin

#installation_options

Installation results collapse

Hooks collapse

Instance Method Summary collapse

Methods included from InstallationOptions::Mixin

included

Methods included from Config::Mixin

#config

Constructor Details

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

Initialize a new instance



68
69
70
71
72
73
74
75
# File 'lib/cocoapods/installer.rb', line 68

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

  @use_default_plugins = true
  @has_dependencies = true
end

Instance Attribute Details

#aggregate_targetsArray<AggregateTarget> (readonly)



215
216
217
# File 'lib/cocoapods/installer.rb', line 215

def aggregate_targets
  @aggregate_targets
end

#analysis_resultAnalyzer (readonly)



201
202
203
# File 'lib/cocoapods/installer.rb', line 201

def analysis_result
  @analysis_result
end

#has_dependenciesBoolean Also known as: has_dependencies?



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

def has_dependencies
  @has_dependencies
end

#installed_specsArray<Specification>



228
229
230
# File 'lib/cocoapods/installer.rb', line 228

def installed_specs
  @installed_specs
end

#lockfileLockfile (readonly)



60
61
62
# File 'lib/cocoapods/installer.rb', line 60

def lockfile
  @lockfile
end

#names_of_pods_to_installArray<String> (readonly)



209
210
211
# File 'lib/cocoapods/installer.rb', line 209

def names_of_pods_to_install
  @names_of_pods_to_install
end

#podfilePodfile (readonly)



55
56
57
# File 'lib/cocoapods/installer.rb', line 55

def podfile
  @podfile
end

#pods_projectPod::Project (readonly)



205
206
207
# File 'lib/cocoapods/installer.rb', line 205

def pods_project
  @pods_project
end

#repo_updateBoolean Also known as: repo_update?



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

def repo_update
  @repo_update
end

#sandboxSandbox (readonly)



50
51
52
# File 'lib/cocoapods/installer.rb', line 50

def sandbox
  @sandbox
end

#updateHash, ...



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

def update
  @update
end

#use_default_pluginsBoolean Also known as: use_default_plugins?



97
98
99
# File 'lib/cocoapods/installer.rb', line 97

def use_default_plugins
  @use_default_plugins
end

Instance Method Details

#development_pod_targetsArray<Library>



633
634
635
636
637
# File 'lib/cocoapods/installer.rb', line 633

def development_pod_targets
  pod_targets.select do |pod_target|
    sandbox.development_pods.keys.include?(pod_target.pod_name)
  end
end

#download_dependenciesObject



160
161
162
163
164
165
166
167
# File 'lib/cocoapods/installer.rb', line 160

def download_dependencies
  UI.section 'Downloading dependencies' do
    create_file_accessors
    install_pod_sources
    run_podfile_pre_install_hooks
    clean_pod_sources
  end
end

#install!void

This method returns an undefined value.

Installs the Pods.

The installation process is mostly linear with a few minor complications to keep in mind:

  • The stored podspecs need to be cleaned before the resolution step otherwise the sandbox might return an old podspec and not download the new one from an external source.

  • The resolver might trigger the download of Pods from external sources necessary to retrieve their podspec (unless it is instructed not to do it).



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

def install!
  prepare
  resolve_dependencies
  download_dependencies
  validate_targets
  generate_pods_project
  if installation_options.integrate_targets?
    integrate_user_project
  else
    UI.section 'Skipping User Project Integration'
  end
  perform_post_install_actions
end

#pod_targetsArray<PodTarget>



220
221
222
223
224
# File 'lib/cocoapods/installer.rb', line 220

def pod_targets
  aggregate_target_pod_targets = aggregate_targets.map(&:pod_targets).flatten
  test_dependent_targets = aggregate_target_pod_targets.map(&:test_dependent_targets).flatten
  (aggregate_target_pod_targets + test_dependent_targets).uniq
end

#prepareObject



128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/cocoapods/installer.rb', line 128

def prepare
  # Raise if pwd is inside Pods
  if Dir.pwd.start_with?(sandbox.root.to_path)
    message = 'Command should be run from a directory outside Pods directory.'
    message << "\n\n\tCurrent directory is #{UI.path(Pathname.pwd)}\n"
    raise Informative, message
  end
  UI.message 'Preparing' do
    deintegrate_if_different_major_version
    sandbox.prepare
    ensure_plugins_are_installed!
    run_plugins_pre_install_hooks
  end
end

#resolve_dependenciesObject



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/cocoapods/installer.rb', line 143

def resolve_dependencies
  analyzer = create_analyzer

  plugin_sources = run_source_provider_hooks
  analyzer.sources.insert(0, *plugin_sources)

  UI.section 'Updating local specs repositories' do
    analyzer.update_repositories
  end if repo_update?

  UI.section 'Analyzing dependencies' do
    analyze(analyzer)
    validate_build_configurations
    clean_sandbox
  end
end