Class: Pod::Installer

Inherits:
Object
  • Object
show all
Includes:
Config::Mixin
Defined in:
lib/cocoapods/installer.rb,
lib/cocoapods/installer/analyzer.rb,
lib/cocoapods/installer/target_installer.rb,
lib/cocoapods/installer/pod_source_installer.rb,
lib/cocoapods/installer/user_project_integrator.rb,
lib/cocoapods/installer/analyzer/sandbox_analyzer.rb,
lib/cocoapods/installer/file_references_installer.rb,
lib/cocoapods/installer/user_project_integrator/target_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, FileReferencesInstaller, PodSourceInstaller, TargetInstaller, UserProjectIntegrator

Installation results collapse

Instance Attribute Summary collapse

Hooks Data collapse

Instance Method Summary collapse

Methods included from Config::Mixin

#config

Constructor Details

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

Returns a new instance of Installer.

Parameters:

  • sandbox (Sandbox)

    @see sandbox

  • podfile (Podfile)

    @see podfile

  • lockfile (Lockfile) (defaults to: nil)

    @see lockfile



57
58
59
60
61
# File 'lib/cocoapods/installer.rb', line 57

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

Instance Attribute Details

#analysis_resultAnalyzer (readonly)

Returns the analyzer which provides the information about what needs to be installed.

Returns:

  • (Analyzer)

    the analyzer which provides the information about what needs to be installed.



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

def analysis_result
  @analysis_result
end

#installed_specsArray<Specification>

Returns The specifications that where installed.

Returns:

  • (Array<Specification>)

    The specifications that where installed.



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

def installed_specs
  @installed_specs
end

#librariesArray<Library> (readonly)

Returns The libraries generated by the installation process.

Returns:

  • (Array<Library>)

    The libraries generated by the installation process.



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

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



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

def lockfile
  @lockfile
end

#names_of_pods_to_installArray<String> (readonly)

Returns The Pods that should be installed.

Returns:

  • (Array<String>)

    The Pods that should be installed.



135
136
137
# File 'lib/cocoapods/installer.rb', line 135

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



46
47
48
# File 'lib/cocoapods/installer.rb', line 46

def podfile
  @podfile
end

#pods_projectPod::Project (readonly)

Returns the ‘Pods/Pods.xcodeproj` project.

Returns:



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

def pods_project
  @pods_project
end

#sandboxSandbox (readonly)

Returns The sandbox where the Pods should be installed.

Returns:

  • (Sandbox)

    The sandbox where the Pods should be installed.



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

def sandbox
  @sandbox
end

#update_modeBool

Returns Whether the installer is in update mode. In update mode the contents of the Lockfile are not taken into account for deciding what Pods to install.

Returns:

  • (Bool)

    Whether the installer is in update mode. In update mode the contents of the Lockfile are not taken into account for deciding what Pods to install.



67
68
69
# File 'lib/cocoapods/installer.rb', line 67

def update_mode
  @update_mode
end

Instance Method Details

#download_dependenciesObject



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

def download_dependencies
  UI.section "Downloading dependencies" do
    create_file_accessors
    install_pod_sources
    run_pre_install_hooks
    clean_pod_sources
  end
end

#generate_pods_projectObject



107
108
109
110
111
112
113
114
115
116
# File 'lib/cocoapods/installer.rb', line 107

def generate_pods_project
  UI.section "Generating Pods project" do
    prepare_pods_project
    install_file_references
    install_targets
    run_post_install_hooks
    write_pod_project
    write_lockfiles
  end
end

#install!void

This method returns an undefined value.

Installs the Pods.

The installation process of is mostly linear with 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).



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

def install!
  resolve_dependencies
  download_dependencies
  generate_pods_project
  integrate_user_project if config.integrate_targets?
end

#installer_repInstallerRepresentation

Returns:

  • (InstallerRepresentation)


503
504
505
# File 'lib/cocoapods/installer.rb', line 503

def installer_rep
  Hooks::InstallerRepresentation.new(self)
end

#libraries_using_spec(spec) ⇒ Array<Library>

Returns the libraries which use the given specification.

Parameters:

  • spec (Specification)

    The specification for which the client libraries are needed.

Returns:

  • (Array<Library>)

    The library.



545
546
547
# File 'lib/cocoapods/installer.rb', line 545

def libraries_using_spec(spec)
  libraries.select { |lib| lib.specs.include?(spec) }
end

#library_rep(library) ⇒ LibraryRepresentation

Returns:

  • (LibraryRepresentation)


522
523
524
# File 'lib/cocoapods/installer.rb', line 522

def library_rep(library)
  Hooks::LibraryRepresentation.new(sandbox, library)
end

#library_repsArray<LibraryRepresentation>

Returns:

  • (Array<LibraryRepresentation>)


528
529
530
# File 'lib/cocoapods/installer.rb', line 528

def library_reps
  @library_reps ||= libraries.map { |lib| library_rep(lib) }
end

#pod_rep(pod) ⇒ PodRepresentation

Parameters:

  • pod (String)

    The name of the pod.

Returns:

  • (PodRepresentation)

    The hook representation of a Pod.

  • (PodRepresentation)

    The pod representation.



514
515
516
517
518
# File 'lib/cocoapods/installer.rb', line 514

def pod_rep(pod)
  all_file_accessors = libraries.map(&:file_accessors).flatten.compact
  file_accessors = all_file_accessors.select { |fa| fa.spec.root.name == pod }
  Hooks::PodRepresentation.new(pod, file_accessors)
end

#pod_repsArray<PodRepresentation>

Returns:

  • (Array<PodRepresentation>)


534
535
536
# File 'lib/cocoapods/installer.rb', line 534

def pod_reps
  root_specs.sort_by { |spec| spec.name }.map { |spec| pod_rep(spec.name) }
end

#resolve_dependenciesObject



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

def resolve_dependencies
  UI.section "Analyzing dependencies" do
    analyze
    prepare_for_legacy_compatibility
    clean_sandbox
  end
end