Class: Pod::Sandbox

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods/sandbox.rb,
lib/cocoapods/sandbox/path_list.rb,
lib/cocoapods/sandbox/file_accessor.rb,
lib/cocoapods/sandbox/headers_store.rb,
lib/cocoapods/sandbox/podspec_finder.rb,
lib/cocoapods/sandbox/pod_dir_cleaner.rb

Overview

The sandbox provides support for the directory that CocoaPods uses for an installation. In this directory the Pods projects, the support files and the sources of the Pods are stored.

CocoaPods assumes to have control of the sandbox.

Once completed the sandbox will have the following file structure:

Pods
|
+-- Headers
|   +-- Private
|   |   +-- [Pod Name]
|   +-- Public
|       +-- [Pod Name]
|
+-- Local Podspecs
|   +-- External Sources
|   +-- Normal Sources
|
+-- Target Support Files
|   +-- [Target Name]
|       +-- Pods-acknowledgements.markdown
|       +-- Pods-acknowledgements.plist
|       +-- Pods-dummy.m
|       +-- Pods-prefix.pch
|       +-- Pods.xcconfig
|
+-- [Pod Name]
|
+-- Manifest.lock
|
+-- Pods.xcodeproj

Defined Under Namespace

Classes: FileAccessor, HeadersStore, PathList, PodDirCleaner, PodspecFinder

Pods information collapse

Instance Attribute Summary collapse

Paths collapse

Specification store collapse

Pods information collapse

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ Sandbox

Initialize a new instance

Parameters:

  • root (String, Pathname)

    @see #root



57
58
59
60
61
62
63
64
65
66
# File 'lib/cocoapods/sandbox.rb', line 57

def initialize(root)
  FileUtils.mkdir_p(root)
  @root = Pathname.new(root).realpath
  @public_headers = HeadersStore.new(self, 'Public', :public)
  @predownloaded_pods = []
  @checkout_sources = {}
  @development_pods = {}
  @pods_with_absolute_path = []
  @stored_podspecs = {}
end

Instance Attribute Details

#checkout_sourcesHash{String=>Hash} (readonly)

Returns The options necessary to recreate the exact checkout of a given Pod grouped by its name.

Returns:

  • (Hash{String=>Hash})

    The options necessary to recreate the exact checkout of a given Pod grouped by its name.



352
353
354
# File 'lib/cocoapods/sandbox.rb', line 352

def checkout_sources
  @checkout_sources
end

#development_podsHash{String=>Pathname} (readonly)

Returns The path of the Pods’ podspecs with a local source grouped by their root name.

Returns:

  • (Hash{String=>Pathname})

    The path of the Pods’ podspecs with a local source grouped by their root name.



379
380
381
# File 'lib/cocoapods/sandbox.rb', line 379

def development_pods
  @development_pods
end

#manifestLockfile

Returns the manifest which contains the information about the installed pods.

Returns:

  • (Lockfile)

    the manifest which contains the information about the installed pods.



71
72
73
# File 'lib/cocoapods/sandbox.rb', line 71

def manifest
  @manifest
end

#predownloaded_podsArray<String> (readonly)

Returns The names of the pods that have been pre-downloaded from an external source.

Returns:

  • (Array<String>)

    The names of the pods that have been pre-downloaded from an external source.



304
305
306
# File 'lib/cocoapods/sandbox.rb', line 304

def predownloaded_pods
  @predownloaded_pods
end

#projectProject

Returns the Pods project.

Returns:



81
82
83
# File 'lib/cocoapods/sandbox.rb', line 81

def project
  @project
end

#public_headersHeadersStore (readonly)

Returns the header directory for the user targets.

Returns:

  • (HeadersStore)

    the header directory for the user targets.



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

def public_headers
  @public_headers
end

#rootPathname (readonly)

Returns the root of the sandbox.

Returns:

  • (Pathname)

    the root of the sandbox.



47
48
49
# File 'lib/cocoapods/sandbox.rb', line 47

def root
  @root
end

Instance Method Details

#clean_pod(name) ⇒ void

This method returns an undefined value.

Removes the files of the Pod with the given name from the sandbox.



87
88
89
90
91
92
93
94
95
# File 'lib/cocoapods/sandbox.rb', line 87

def clean_pod(name)
  root_name = Specification.root_name(name)
  unless local?(root_name)
    path = pod_dir(name)
    path.rmtree if path.exist?
  end
  podspec_path = specification_path(name)
  podspec_path.rmtree if podspec_path
end

#headers_rootPathname

Returns The directory where headers are stored.

Returns:

  • (Pathname)

    The directory where headers are stored.



174
175
176
# File 'lib/cocoapods/sandbox.rb', line 174

def headers_root
  root + 'Headers'
end

#inspectString

Returns a string representation suitable for debugging.

Returns:

  • (String)

    a string representation suitable for debugging.



111
112
113
# File 'lib/cocoapods/sandbox.rb', line 111

def inspect
  "#<#{self.class}> with root #{root}"
end

#local?(name) ⇒ Bool

Checks if a Pod is locally sourced?

Parameters:

  • name (String)

    The name of the Pod.

Returns:

  • (Bool)

    Whether the Pod is locally sourced.



388
389
390
# File 'lib/cocoapods/sandbox.rb', line 388

def local?(name)
  !local_podspec(name).nil?
end

#local_path_was_absolute?(name) ⇒ Bool

Returns true if the path as originally specified was absolute.

Parameters:

  • name (String)

Returns:

  • (Bool)

    true if originally absolute



168
169
170
# File 'lib/cocoapods/sandbox.rb', line 168

def local_path_was_absolute?(name)
  @pods_with_absolute_path.include? name
end

#local_podspec(name) ⇒ Pathname

Returns Path to the local Podspec of the Pod.

Parameters:

  • name (String)

    The name of a locally specified Pod

Returns:

  • (Pathname)

    Path to the local Podspec of the Pod



397
398
399
400
# File 'lib/cocoapods/sandbox.rb', line 397

def local_podspec(name)
  root_name = Specification.root_name(name)
  development_pods[root_name]
end

#manifest_pathPathname

Returns the path of the manifest.

Returns:

  • (Pathname)

    the path of the manifest.



123
124
125
# File 'lib/cocoapods/sandbox.rb', line 123

def manifest_path
  root + 'Manifest.lock'
end

#pod_dir(name) ⇒ Pathname

Returns the path where the Pod with the given name is stored, taking into account whether the Pod is locally sourced.

Parameters:

  • name (String)

    The name of the Pod.

Returns:

  • (Pathname)

    the path of the Pod.



153
154
155
156
157
158
159
160
# File 'lib/cocoapods/sandbox.rb', line 153

def pod_dir(name)
  root_name = Specification.root_name(name)
  if local?(root_name)
    Pathname.new(development_pods[root_name].dirname)
  else
    sources_root + root_name
  end
end

#predownloaded?(name) ⇒ Bool

Checks if a Pod has been pre-downloaded by the resolver in order to fetch the podspec.

Parameters:

  • name (String)

    The name of the Pod.

Returns:

  • (Bool)

    Whether the Pod has been pre-downloaded.



314
315
316
317
# File 'lib/cocoapods/sandbox.rb', line 314

def predownloaded?(name)
  root_name = Specification.root_name(name)
  predownloaded_pods.include?(root_name)
end

#prepareObject

Prepares the sandbox for a new installation removing any file that will be regenerated and ensuring that the directories exists.



100
101
102
103
104
105
106
107
# File 'lib/cocoapods/sandbox.rb', line 100

def prepare
  FileUtils.rm_rf(headers_root)

  FileUtils.mkdir_p(headers_root)
  FileUtils.mkdir_p(sources_root)
  FileUtils.mkdir_p(specifications_root)
  FileUtils.mkdir_p(target_support_files_root)
end

#project_pathPathname

Returns the path of the Pods project.

Returns:

  • (Pathname)

    the path of the Pods project.



129
130
131
# File 'lib/cocoapods/sandbox.rb', line 129

def project_path
  root + 'Pods.xcodeproj'
end

#remove_checkout_source(name) ⇒ void

This method returns an undefined value.

Removes the checkout source of a Pod.

Parameters:

  • name (String)

    The name of the Pod.



344
345
346
347
# File 'lib/cocoapods/sandbox.rb', line 344

def remove_checkout_source(name)
  root_name = Specification.root_name(name)
  checkout_sources.delete(root_name)
end

#sources_rootPathname

Returns The directory where the downloaded sources of the Pods are stored.

Returns:

  • (Pathname)

    The directory where the downloaded sources of the Pods are stored.



181
182
183
# File 'lib/cocoapods/sandbox.rb', line 181

def sources_root
  root
end

#specification(name) ⇒ Specification

Returns the specification for the Pod with the given name.

Parameters:

  • name (String)

    the name of the Pod for which the specification is requested.

Returns:



212
213
214
215
216
217
# File 'lib/cocoapods/sandbox.rb', line 212

def specification(name)
  @stored_podspecs[name] ||= if file = specification_path(name)
                               original_path = development_pods[name]
                               Specification.from_file(original_path || file)
  end
end

#specification_path(name) ⇒ Pathname, Nil

Returns the path of the specification for the Pod with the given name, if one is stored.

Parameters:

  • name (String)

    the name of the Pod for which the podspec file is requested.

Returns:

  • (Pathname)

    the path or nil.

  • (Nil)

    if the podspec is not stored.



228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/cocoapods/sandbox.rb', line 228

def specification_path(name)
  name = Specification.root_name(name)
  path = specifications_root + "#{name}.podspec"
  if path.exist?
    path
  else
    path = specifications_root + "#{name}.podspec.json"
    if path.exist?
      path
    end
  end
end

#specifications_rootPathname

Returns the path for the directory where the specifications are stored.

Returns:

  • (Pathname)

    the path for the directory where the specifications are stored.



188
189
190
# File 'lib/cocoapods/sandbox.rb', line 188

def specifications_root
  root + 'Local Podspecs'
end

#store_checkout_source(name, source) ⇒ void

This method returns an undefined value.

Stores the local path of a Pod.

Parameters:

  • name (String)

    The name of the Pod.

  • source (Hash)

    The hash which contains the options as returned by the downloader.



332
333
334
335
# File 'lib/cocoapods/sandbox.rb', line 332

def store_checkout_source(name, source)
  root_name = Specification.root_name(name)
  checkout_sources[root_name] = source
end

#store_local_path(name, path, was_absolute = false) ⇒ void

This method returns an undefined value.

Stores the local path of a Pod.

Parameters:

  • name (String)

    The name of the Pod.

  • path (Pathname, String)

    The path to the local Podspec

  • was_absolute (Bool) (defaults to: false)

    True if the specified local path was absolute.



369
370
371
372
373
374
# File 'lib/cocoapods/sandbox.rb', line 369

def store_local_path(name, path, was_absolute = false)
  root_name = Specification.root_name(name)
  path = Pathname.new(path) unless path.is_a?(Pathname)
  development_pods[root_name] = path
  @pods_with_absolute_path << root_name if was_absolute
end

#store_podspec(name, podspec, _external_source = false, json = false) ⇒ void

This method returns an undefined value.

Stores a specification in the ‘Local Podspecs` folder.

Parameters:

  • name (String)

    the name of the pod

  • podspec (String, Pathname, Specification)

    The contents of the specification (String) or the path to a podspec file (Pathname).



253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/cocoapods/sandbox.rb', line 253

def store_podspec(name, podspec, _external_source = false, json = false)
  file_name = json ? "#{name}.podspec.json" : "#{name}.podspec"
  output_path = specifications_root + file_name

  case podspec
  when String
    output_path.open('w') { |f| f.puts(podspec) }
  when Pathname
    unless podspec.exist?
      raise Informative, "No podspec found for `#{name}` in #{podspec}"
    end
    spec = Specification.from_file(podspec)
    FileUtils.copy(podspec, output_path)
  when Specification
    raise ArgumentError, 'can only store Specification objects as json' unless json
    output_path.open('w') { |f| f.puts(podspec.to_pretty_json) }
    spec = podspec.dup
  else
    raise ArgumentError, "Unknown type for podspec: #{podspec.inspect}"
  end

  spec ||= Specification.from_file(output_path)
  spec.defined_in_file ||= output_path

  unless spec.name == name
    raise Informative, "The name of the given podspec `#{spec.name}` doesn't match the expected one `#{name}`"
  end
  @stored_podspecs[spec.name] = spec
end

#store_pre_downloaded_pod(name) ⇒ void

This method returns an undefined value.

Marks a Pod as pre-downloaded

Parameters:

  • name (String)

    The name of the Pod.



296
297
298
299
# File 'lib/cocoapods/sandbox.rb', line 296

def store_pre_downloaded_pod(name)
  root_name = Specification.root_name(name)
  predownloaded_pods << root_name
end

#target_support_files_dir(name) ⇒ Pathname

Returns the path for the directory where the support files of a target are stored.

Parameters:

  • name (String)

    The name of the target.

Returns:

  • (Pathname)

    the path of the support files.



141
142
143
# File 'lib/cocoapods/sandbox.rb', line 141

def target_support_files_dir(name)
  target_support_files_root + name
end

#target_support_files_rootPathname

Returns The directory where the files generated by CocoaPods to support the umbrella targets are stored.

Returns:

  • (Pathname)

    The directory where the files generated by CocoaPods to support the umbrella targets are stored.



195
196
197
# File 'lib/cocoapods/sandbox.rb', line 195

def target_support_files_root
  root + 'Target Support Files'
end