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

Pods Helpers 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
# 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 = []
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.



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

def checkout_sources
  @checkout_sources
end

#development_podsHash{String=>Pathname} (readonly)

TODO:

Rename (e.g. `pods_with_local_path`)

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.



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

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.



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

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.



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

def predownloaded_pods
  @predownloaded_pods
end

#projectProject

Returns the Pods project.

Returns:



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

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.



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

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

#create_file_accessors(pod_targets) ⇒ Object

Creates the file accessors for the given Pod Targets.

Parameters:

  • pod_targets (Array<PodTarget>)

    The Pod Targets to create file accessors for.



406
407
408
409
410
411
412
413
414
415
416
# File 'lib/cocoapods/sandbox.rb', line 406

def create_file_accessors(pod_targets)
  pod_targets.each do |pod_target|
    pod_root = pod_dir(pod_target.root_spec.name)
    path_list = PathList.new(pod_root)
    file_accessors = pod_target.specs.map do |spec|
      FileAccessor.new(path_list, spec.consumer(pod_target.platform))
    end
    pod_target.file_accessors ||= []
    pod_target.file_accessors.concat(file_accessors)
  end
end

#headers_rootPathname

Returns The directory where headers are stored.

Returns:

  • (Pathname)

    The directory where headers are stored.



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

def headers_root
  root + 'Headers'
end

#inspectString

Returns a string representation suitable for debugging.

Returns:

  • (String)

    a string representation suitable for debugging.



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

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.



381
382
383
# File 'lib/cocoapods/sandbox.rb', line 381

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



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

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



390
391
392
393
# File 'lib/cocoapods/sandbox.rb', line 390

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.



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

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.



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

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.



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

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.



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

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.



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

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.



335
336
337
338
# File 'lib/cocoapods/sandbox.rb', line 335

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.



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

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:



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

def specification(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.



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

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.



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

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.



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

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.



360
361
362
363
364
365
# File 'lib/cocoapods/sandbox.rb', line 360

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)

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



252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/cocoapods/sandbox.rb', line 252

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.



287
288
289
290
# File 'lib/cocoapods/sandbox.rb', line 287

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.



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

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.



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

def target_support_files_root
  root + 'Target Support Files'
end