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')
  @predownloaded_pods = []
  @head_pods = []
  @checkout_sources = {}
  @development_pods = {}
  @pods_with_absolute_path = []
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.



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

def checkout_sources
  @checkout_sources
end

#development_podsHash{String=>String} (readonly)

TODO:

Rename (e.g. ‘pods_with_local_path`)

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

Returns:

  • (Hash{String=>String})

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



406
407
408
# File 'lib/cocoapods/sandbox.rb', line 406

def development_pods
  @development_pods
end

#head_podsArray<String> (readonly)

Returns The names of the pods that have been marked as head.

Returns:

  • (Array<String>)

    The names of the pods that have been marked as head.



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

def head_pods
  @head_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.



299
300
301
# File 'lib/cocoapods/sandbox.rb', line 299

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
  podspe_path = specification_path(name)
  podspe_path.rmtree if podspe_path
end

#head_pod?(name) ⇒ Bool

Checks if a Pod should attempt to use the head source of the git repo.

Parameters:

  • name (String)

    The name of the Pod.

Returns:

  • (Bool)

    Whether the Pod has been marked as head.



340
341
342
343
# File 'lib/cocoapods/sandbox.rb', line 340

def head_pod?(name)
  root_name = Specification.root_name(name)
  head_pods.include?(root_name)
end

#headers_rootPathname

Returns The directory where headers are stored.

Returns:

  • (Pathname)

    The directory where headers are stored.



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

def headers_root
  root + 'Headers'
end

#inspectString

Returns a string representation suitable for debugging.

Returns:

  • (String)

    a string representation suitable for debugging.



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

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.



415
416
417
418
# File 'lib/cocoapods/sandbox.rb', line 415

def local?(name)
  root_name = Specification.root_name(name)
  !development_pods[root_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



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

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

#manifest_pathPathname

Returns the path of the manifest.

Returns:

  • (Pathname)

    the path of the manifest.



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

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.



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

def pod_dir(name)
  root_name = Specification.root_name(name)
  if local?(root_name)
    Pathname.new(development_pods[root_name])
  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.



309
310
311
312
# File 'lib/cocoapods/sandbox.rb', line 309

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
108
# File 'lib/cocoapods/sandbox.rb', line 100

def prepare
  FileUtils.rm_rf(headers_root)
  FileUtils.rm_rf(target_support_files_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.



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

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.



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

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.



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

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:



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

def specification(name)
  if file = specification_path(name)
    original_path = development_pods[name]
    Dir.chdir(original_path || Dir.pwd) { Specification.from_file(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.



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

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.



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

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.



358
359
360
361
# File 'lib/cocoapods/sandbox.rb', line 358

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

#store_head_pod(name) ⇒ void

This method returns an undefined value.

Marks a Pod as head.

Parameters:

  • name (String)

    The name of the Pod.



323
324
325
326
# File 'lib/cocoapods/sandbox.rb', line 323

def store_head_pod(name)
  root_name = Specification.root_name(name)
  head_pods << root_name
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 (#to_s)

    The local path where the Pod is stored.

  • was_absolute (Bool) (defaults to: false)

    True if the specified local path was absolute.



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

def store_local_path(name, path, was_absolute = false)
  root_name = Specification.root_name(name)
  development_pods[root_name] = path.to_s
  @pods_with_absolute_path << root_name if was_absolute
end

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

TODO:

Store all the specifications (including those not originating from external sources) so users can check them.

This method returns an undefined value.

Stores a specification in the ‘Local Podspecs` folder.

Parameters:

  • sandbox (Sandbox)

    the sandbox where the podspec should be stored.

  • podspec (String, Pathname)

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



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

def store_podspec(name, podspec, _external_source = false, json = false)
  file_name = json ? "#{name}.podspec.json" : "#{name}.podspec"
  output_path = specifications_root + file_name
  output_path.dirname.mkpath
  if podspec.is_a?(String)
    output_path.open('w') { |f| f.puts(podspec) }
  else
    unless podspec.exist?
      raise Informative, "No podspec found for `#{name}` in #{podspec}"
    end
    FileUtils.copy(podspec, output_path)
  end

  Dir.chdir(podspec.is_a?(Pathname) ? File.dirname(podspec) : Dir.pwd) do
    spec = Specification.from_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
  end
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.



291
292
293
294
# File 'lib/cocoapods/sandbox.rb', line 291

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.



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

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.



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

def target_support_files_root
  root + 'Target Support Files'
end