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

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
|
+-- User
| +-- [Target Name]-configuration.h
| +-- Specs
| +-- Scripts
|
+-- Generated
  +-- Headers
  |   +-- Private
  |   |   +-- [Pod Name]
  |   +-- Public
  |       +-- [Pod Name]
  |
  +-- Sources
  |   +-- [Pod Name]
  |
  +-- Specs
  |   +-- External Sources
  |   +-- Normal Sources
  |
  +-- Target Support Files
  |   +-- [Target Name]
  |       +-- Pods-acknowledgements.markdown
  |       +-- Pods-acknowledgements.plist
  |       +-- Pods-dummy.m
  |       +-- Pods-prefix.pch
  |       +-- Pods.xcconfig
  |
  +-- Manifest.lock
  |
  +-- Pods.xcodeproj

See #833

Defined Under Namespace

Classes: FileAccessor, HeadersStore, PathList

Pods information collapse

Instance Attribute Summary collapse

Paths collapse

Specification store collapse

Pods information collapse

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ Sandbox

Returns a new instance of Sandbox.

Parameters:

  • root (String, Pathname)

    @see root



68
69
70
71
72
73
74
75
76
# File 'lib/cocoapods/sandbox.rb', line 68

def initialize(root)
  @root = Pathname.new(root)
  @build_headers  = HeadersStore.new(self, "BuildHeaders")
  @public_headers = HeadersStore.new(self, "Headers")
  @predownloaded_pods = []
  @checkout_sources = {}
  @local_pods = {}
  FileUtils.mkdir_p(@root)
end

Instance Attribute Details

#build_headersHeadersStore (readonly)

Returns the header directory for the Pods libraries.

Returns:

  • (HeadersStore)

    the header directory for the Pods libraries.



60
61
62
# File 'lib/cocoapods/sandbox.rb', line 60

def build_headers
  @build_headers
end

#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.



301
302
303
# File 'lib/cocoapods/sandbox.rb', line 301

def checkout_sources
  @checkout_sources
end

#local_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 name.

Returns:

  • (Hash{String=>String})

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



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

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



265
266
267
# File 'lib/cocoapods/sandbox.rb', line 265

def predownloaded_pods
  @predownloaded_pods
end

#projectProject

Returns the Pods project.

Returns:



87
88
89
# File 'lib/cocoapods/sandbox.rb', line 87

def project
  @project
end

#public_headersHeadersStore (readonly)

Returns the header directory for the user targets.

Returns:

  • (HeadersStore)

    the header directory for the user targets.



64
65
66
# File 'lib/cocoapods/sandbox.rb', line 64

def public_headers
  @public_headers
end

#rootPathname (readonly)

Returns the root of the sandbox.

Returns:

  • (Pathname)

    the root of the sandbox.



56
57
58
# File 'lib/cocoapods/sandbox.rb', line 56

def root
  @root
end

Instance Method Details

#clean_pod(name) ⇒ Object



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

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

#documentation_dirPathname

Returns the directory where to store the documentation.

Returns:

  • (Pathname)

    the directory where to store the documentation.



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

def documentation_dir
  root + 'Documentation'
end

#implodevoid

This method returns an undefined value.

Removes the sandbox.



93
94
95
# File 'lib/cocoapods/sandbox.rb', line 93

def implode
  root.rmtree
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

#library_support_files_dir(name) ⇒ Pathname

Returns the path for the directory where to store the support files of a target.

Parameters:

  • name (String)

    The name of the target.

Returns:

  • (Pathname)

    the path of the support files.



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

def library_support_files_dir(name)
  # root + "Target Support Files/#{name}"
  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.



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

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



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

def manifest
  Lockfile.from_file(manifest_path) if manifest_path.exist?
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.



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

def pod_dir(name)
  root_name = Specification.root_name(name)
  if local?(root_name)
    Pathname.new(local_pods[root_name])
  else
    # root + "Sources/#{name}"
    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.



275
276
277
278
# File 'lib/cocoapods/sandbox.rb', line 275

def predownloaded?(name)
  root_name = Specification.root_name(name)
  predownloaded_pods.include?(root_name)
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

#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:



184
185
186
187
188
# File 'lib/cocoapods/sandbox.rb', line 184

def specification(name)
  if file = specification_path(name)
    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.



210
211
212
213
# File 'lib/cocoapods/sandbox.rb', line 210

def specification_path(name)
  path = specifications_dir + "#{name}.podspec"
  path.exist? ? path : nil
end

#specifications_dir(external_source = false) ⇒ Pathname

TODO:

Migrate old installations and store the for all the pods. Two folders should be created ‘External Sources` and `Podspecs`.

Returns the path for the directory where to store the specifications.

Returns:

  • (Pathname)

    the path for the directory where to store the specifications.



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

def specifications_dir(external_source = false)
  # root + "Specifications"
  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.



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

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

#store_local_path(name, path) ⇒ 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.



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

def store_local_path(name, path)
  root_name = Specification.root_name(name)
  local_pods[root_name] = path.to_s
end

#store_podspec(name, podspec, external_source = false) ⇒ Object

TODO:

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

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).



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

def store_podspec(name, podspec, external_source = false)
  output_path = specifications_dir(external_source) + "#{name}.podspec"
  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
  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

#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.



257
258
259
260
# File 'lib/cocoapods/sandbox.rb', line 257

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