Class: Pod::Sandbox
- Inherits:
-
Object
- Object
- Pod::Sandbox
- 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
-
#checkout_sources ⇒ Hash{String=>Hash}
readonly
The options necessary to recreate the exact checkout of a given Pod grouped by its name.
-
#development_pods ⇒ Hash{String=>String}
readonly
The path of the Pods with a local source grouped by their root name.
-
#head_pods ⇒ Array<String>
readonly
The names of the pods that have been marked as head.
-
#predownloaded_pods ⇒ Array<String>
readonly
The names of the pods that have been pre-downloaded from an external source.
Instance Attribute Summary collapse
-
#manifest ⇒ Lockfile
The manifest which contains the information about the installed pods.
-
#project ⇒ Project
The Pods project.
-
#public_headers ⇒ HeadersStore
readonly
The header directory for the user targets.
-
#root ⇒ Pathname
readonly
The root of the sandbox.
Paths collapse
-
#headers_root ⇒ Pathname
The directory where headers are stored.
-
#local_path_was_absolute?(name) ⇒ Bool
Returns true if the path as originally specified was absolute.
-
#manifest_path ⇒ Pathname
The path of the manifest.
-
#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.
-
#project_path ⇒ Pathname
The path of the Pods project.
-
#sources_root ⇒ Pathname
The directory where the downloaded sources of the Pods are stored.
-
#specifications_root ⇒ Pathname
The path for the directory where the specifications are stored.
-
#target_support_files_dir(name) ⇒ Pathname
Returns the path for the directory where the support files of a target are stored.
-
#target_support_files_root ⇒ Pathname
The directory where the files generated by CocoaPods to support the umbrella targets are stored.
Specification store collapse
-
#specification(name) ⇒ Specification
Returns the specification for the Pod with the given name.
-
#specification_path(name) ⇒ Pathname, Nil
Returns the path of the specification for the Pod with the given name, if one is stored.
-
#store_podspec(name, podspec, _external_source = false, json = false) ⇒ void
Stores a specification in the ‘Local Podspecs` folder.
Pods information collapse
-
#head_pod?(name) ⇒ Bool
Checks if a Pod should attempt to use the head source of the git repo.
-
#local?(name) ⇒ Bool
Checks if a Pod is locally sourced?.
-
#predownloaded?(name) ⇒ Bool
Checks if a Pod has been pre-downloaded by the resolver in order to fetch the podspec.
-
#remove_checkout_source(name) ⇒ void
Removes the checkout source of a Pod.
-
#store_checkout_source(name, source) ⇒ void
Stores the local path of a Pod.
-
#store_head_pod(name) ⇒ void
Marks a Pod as head.
-
#store_local_path(name, path, was_absolute = false) ⇒ void
Stores the local path of a Pod.
-
#store_pre_downloaded_pod(name) ⇒ void
Marks a Pod as pre-downloaded.
Instance Method Summary collapse
-
#clean_pod(name) ⇒ void
Removes the files of the Pod with the given name from the sandbox.
-
#initialize(root) ⇒ Sandbox
constructor
Initialize a new instance.
-
#inspect ⇒ String
A string representation suitable for debugging.
-
#prepare ⇒ Object
Prepares the sandbox for a new installation removing any file that will be regenerated and ensuring that the directories exists.
Constructor Details
#initialize(root) ⇒ Sandbox
Initialize a new instance
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_sources ⇒ Hash{String=>Hash} (readonly)
Returns 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_pods ⇒ Hash{String=>String} (readonly)
Rename (e.g. ‘pods_with_local_path`)
Returns 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_pods ⇒ Array<String> (readonly)
Returns 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 |
#manifest ⇒ Lockfile
Returns 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_pods ⇒ Array<String> (readonly)
Returns 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 |
#project ⇒ Project
Returns the Pods project.
81 82 83 |
# File 'lib/cocoapods/sandbox.rb', line 81 def project @project end |
#public_headers ⇒ HeadersStore (readonly)
Returns the header directory for the user targets.
51 52 53 |
# File 'lib/cocoapods/sandbox.rb', line 51 def public_headers @public_headers end |
#root ⇒ Pathname (readonly)
Returns 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.
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_root ⇒ Pathname
Returns The directory where headers are stored.
175 176 177 |
# File 'lib/cocoapods/sandbox.rb', line 175 def headers_root root + 'Headers' end |
#inspect ⇒ String
Returns 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?
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.
169 170 171 |
# File 'lib/cocoapods/sandbox.rb', line 169 def local_path_was_absolute?(name) @pods_with_absolute_path.include? name end |
#manifest_path ⇒ Pathname
Returns 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.
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.
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 |
#prepare ⇒ Object
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_path ⇒ Pathname
Returns 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.
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_root ⇒ Pathname
Returns 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.
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.
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_root ⇒ Pathname
Returns 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.
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.
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.
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
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.
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
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.
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_root ⇒ Pathname
Returns 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 |