Class: Pod::Installer::Analyzer::SandboxAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods/installer/analyzer/sandbox_analyzer.rb

Overview

Analyze the sandbox to detect which Pods should be removed, and which ones should be reinstalled.

The logic is the following:

Added

  • If not present in the sandbox lockfile.
  • The directory of the Pod doesn't exits.

Changed

  • The version of the Pod changed.
  • The SHA of the specification file changed.
  • The specific installed (sub)specs of the same Pod changed.
  • The specification is from an external source and the installation process is in update mode.
  • The directory of the Pod is empty.
  • The Pod has been pre-downloaded.

Removed

  • If a specification is present in the lockfile but not in the resolved specs.

Unchanged

  • If none of the above conditions match.

Instance Attribute Summary collapse

Pod state collapse

Private helpers collapse

Instance Method Summary collapse

Constructor Details

#initialize(sandbox, podfile, specs, update_mode) ⇒ SandboxAnalyzer

Init a new SandboxAnalyzer

Parameters:

  • sandbox (Sandbox)

    @see sandbox

  • podfile (Podfile)

    @see podfile

  • specs (Array<Specifications>)

    @see specs

  • update_mode (Boolean)

    @see update_mode



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

def initialize(sandbox, podfile, specs, update_mode)
  @sandbox = sandbox
  @podfile = podfile
  @specs = specs
  @update_mode = update_mode
end

Instance Attribute Details

#podfilePodfile (readonly)

Returns The Podfile to analyze dependencies.

Returns:

  • (Podfile)

    The Podfile to analyze dependencies.



36
37
38
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 36

def podfile
  @podfile
end

#sandboxSandbox (readonly)

Returns The sandbox to analyze.

Returns:

  • (Sandbox)

    The sandbox to analyze.



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

def sandbox
  @sandbox
end

#specsArray<Specifications> (readonly)

Returns The specifications returned by the resolver.

Returns:

  • (Array<Specifications>)

    The specifications returned by the resolver.



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

def specs
  @specs
end

#update_modeBoolean (readonly) Also known as: update_mode?

Returns Whether the installation is performed in update mode.

Returns:

  • (Boolean)

    Whether the installation is performed in update mode.



45
46
47
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 45

def update_mode
  @update_mode
end

Instance Method Details

#analyzevoid

This method returns an undefined value.

Performs the analysis to the detect the state of the sandbox respect to the resolved specifications.



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 68

def analyze
  state = SpecsState.new
  if sandbox_manifest
    all_names = (resolved_pods + sandbox_pods).uniq.sort
    all_names.sort.each do |name|
      state.add_name(name, pod_state(name))
    end
  else
    state.added.merge(resolved_pods)
  end
  state
end

#folder_empty?(pod) ⇒ Boolean (private)

Returns:

  • (Boolean)


260
261
262
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 260

def folder_empty?(pod)
  Dir.glob(sandbox.pod_dir(pod) + '*').empty?
end

#folder_exist?(pod) ⇒ Boolean (private)

--------------------------------------#

Returns:

  • (Boolean)


256
257
258
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 256

def folder_exist?(pod)
  sandbox.pod_dir(pod).exist?
end

#pod_added?(pod) ⇒ Boolean (private)

Note:

A Pod whose folder doesn't exists is considered added.

Returns whether the Pod with the given name should be installed.

Parameters:

  • pod (String)

    the name of the Pod.

Returns:

  • (Boolean)

    Whether the Pod is added.



110
111
112
113
114
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 110

def pod_added?(pod)
  return true if resolved_pods.include?(pod) && !sandbox_pods.include?(pod)
  return true if !sandbox.local?(pod) && !folder_exist?(pod)
  false
end

#pod_changed?(pod) ⇒ Boolean (private)

Note:

In update mode, as there is no way to know if a remote source hash changed the Pods from external sources are always marked as changed.

Note:

A Pod whose folder is empty is considered changed.

Returns whether the Pod with the given name should be considered changed and thus should be reinstalled.

Parameters:

  • pod (String)

    the name of the Pod.

Returns:

  • (Boolean)

    Whether the Pod is changed.



143
144
145
146
147
148
149
150
151
152
153
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 143

def pod_changed?(pod)
  spec = root_spec(pod)
  return true if spec.version != sandbox_version(pod)
  return true if spec.checksum != sandbox_checksum(pod)
  return true if resolved_spec_names(pod) != sandbox_spec_names(pod)
  podfile_dep = podfile_dependency(pod)&.tap { |dep| dep.podspec_repo = nil }
  return true if podfile_dep != sandbox_dependency(pod)
  return true if sandbox.predownloaded?(pod)
  return true if folder_empty?(pod)
  false
end

#pod_deleted?(pod) ⇒ Boolean (private)

Returns whether the Pod with the given name should be removed from the installation.

Parameters:

  • pod (String)

    the name of the Pod.

Returns:

  • (Boolean)

    Whether the Pod is deleted.



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

def pod_deleted?(pod)
  return true if !resolved_pods.include?(pod) && sandbox_pods.include?(pod)
  false
end

#pod_state(pod) ⇒ Symbol (private)

Returns the state of the Pod with the given name.

Parameters:

  • pod (String)

    the name of the Pod.

Returns:

  • (Symbol)

    The state



94
95
96
97
98
99
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 94

def pod_state(pod)
  return :deleted if pod_deleted?(pod)
  return :added   if pod_added?(pod)
  return :changed if pod_changed?(pod)
  :unchanged
end

#podfile_dependency(pod) ⇒ Dependency? (private)

Returns The dependency with the given name from the podfile.

Parameters:

  • pod (String)

    the name of the Pod.

Returns:

  • (Dependency, nil)

    The dependency with the given name from the podfile.



250
251
252
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 250

def podfile_dependency(pod)
  podfile.dependencies.find { |d| d.name == pod }
end

#resolved_podsArray<String> (private)

Returns The name of the resolved Pods.

Returns:

  • (Array<String>)

    The name of the resolved Pods.



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

def resolved_pods
  @resolved_pods ||= specs.map { |spec| spec.root.name }.uniq
end

#resolved_spec_names(pod) ⇒ Array<String> (private)

Returns The name of the resolved specifications (includes subspecs).

Parameters:

  • pod (String)

    the name of the Pod.

Returns:

  • (Array<String>)

    The name of the resolved specifications (includes subspecs).



188
189
190
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 188

def resolved_spec_names(pod)
  specs.select { |s| s.root.name == pod }.map(&:name).uniq.sort
end

#root_spec(pod) ⇒ Specification (private)

Returns The root specification for the Pod with the given name.

Parameters:

  • pod (String)

    the name of the Pod.

Returns:

  • (Specification)

    The root specification for the Pod with the given name.



208
209
210
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 208

def root_spec(pod)
  specs.find { |s| s.root.name == pod }.root
end

#sandbox_checksum(pod) ⇒ String (private)

Returns The checksum of the specification of the Pod with the given name stored in the sandbox.

Parameters:

  • pod (String)

    the name of the Pod.

Returns:

  • (String)

    The checksum of the specification of the Pod with the given name stored in the sandbox.



230
231
232
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 230

def sandbox_checksum(pod)
  sandbox_manifest.checksum(pod)
end

#sandbox_dependency(pod) ⇒ Dependency? (private)

Returns The dependency with the given name stored in the sandbox.

Parameters:

  • pod (String)

    the name of the Pod.

Returns:

  • (Dependency, nil)

    The dependency with the given name stored in the sandbox.



239
240
241
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 239

def sandbox_dependency(pod)
  sandbox_manifest.dependencies.find { |d| d.name == pod }
end

#sandbox_manifestLockfile (private)

Returns The manifest to use for the sandbox.

Returns:

  • (Lockfile)

    The manifest to use for the sandbox.



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

def sandbox_manifest
  sandbox.manifest
end

#sandbox_podsArray<String> (private)

Returns The name of the Pods stored in the sandbox manifest.

Returns:

  • (Array<String>)

    The name of the Pods stored in the sandbox manifest.



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

def sandbox_pods
  @sandbox_pods ||= sandbox_manifest.pod_names.map { |name| Specification.root_name(name) }.uniq
end

#sandbox_spec_names(pod) ⇒ Array<String> (private)

Returns The name of the specifications stored in the sandbox manifest (includes subspecs).

Parameters:

  • pod (String)

    the name of the Pod.

Returns:

  • (Array<String>)

    The name of the specifications stored in the sandbox manifest (includes subspecs).



198
199
200
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 198

def sandbox_spec_names(pod)
  sandbox_manifest.pod_names.select { |name| Specification.root_name(name) == pod }.uniq.sort
end

#sandbox_version(pod) ⇒ Version (private)

Returns The version of Pod with the given name stored in the sandbox.

Parameters:

  • pod (String)

    the name of the Pod.

Returns:

  • (Version)

    The version of Pod with the given name stored in the sandbox.



220
221
222
# File 'lib/cocoapods/installer/analyzer/sandbox_analyzer.rb', line 220

def sandbox_version(pod)
  sandbox_manifest.version(pod)
end