Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
cocoapods
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
cocoapods
Commits
ff593f96
Commit
ff593f96
authored
Apr 05, 2015
by
Samuel E. Giddins
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Documentation] Document the new download cache
parent
d331e5a2
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
137 additions
and
6 deletions
+137
-6
downloader.rb
lib/cocoapods/downloader.rb
+15
-0
cache.rb
lib/cocoapods/downloader/cache.rb
+65
-2
request.rb
lib/cocoapods/downloader/request.rb
+46
-4
response.rb
lib/cocoapods/downloader/response.rb
+11
-0
No files found.
lib/cocoapods/downloader.rb
View file @
ff593f96
...
@@ -9,6 +9,21 @@ module Pod
...
@@ -9,6 +9,21 @@ module Pod
require
'cocoapods/downloader/request'
require
'cocoapods/downloader/request'
require
'cocoapods/downloader/response'
require
'cocoapods/downloader/response'
# Downloads a pod from the given `request` to the given `target` location.
#
# @return [Response] The download response for this download.
#
# @param [Request] request
# the request that describes this pod download.
#
# @param [Pathname,Nil] target
# the location to which this pod should be downloaded. If `nil`,
# then the pod will only be cached.
#
# @param [Pathname,Nil] cache_path
# the path used to cache pod downloads. If `nil`, then no caching
# will be done.
#
def
self
.
download
(
def
self
.
download
(
request
,
request
,
target
,
target
,
...
...
lib/cocoapods/downloader/cache.rb
View file @
ff593f96
...
@@ -3,15 +3,30 @@ require 'tmpdir'
...
@@ -3,15 +3,30 @@ require 'tmpdir'
module
Pod
module
Pod
module
Downloader
module
Downloader
# The class responsible for managing Pod downloads, transparently caching
# them in a cache directory.
#
class
Cache
class
Cache
# @return [Pathname] The root directory where this cache store its
# downloads.
#
attr_reader
:root
attr_reader
:root
# @param [Pathname,String] root
# see {#root}
#
def
initialize
(
root
)
def
initialize
(
root
)
@root
=
root
@root
=
Pathname
(
root
)
root
.
mkpath
unless
root
.
exist?
root
.
mkpath
unless
root
.
exist?
end
end
# Downloads the Pod from the given `request`
#
# @param [Request] request
# the request to be downloaded
#
# @return [Response] the response from downloading `request`
#
def
download_pod
(
request
)
def
download_pod
(
request
)
cached_pod
(
request
)
||
uncached_pod
(
request
)
cached_pod
(
request
)
||
uncached_pod
(
request
)
rescue
Informative
rescue
Informative
...
@@ -38,6 +53,9 @@ module Pod
...
@@ -38,6 +53,9 @@ module Pod
path
.
sub_ext
(
'.podspec.json'
)
path
.
sub_ext
(
'.podspec.json'
)
end
end
# @return [Response] The download response for the given `request` that
# was found in the download cache.
#
def
cached_pod
(
request
)
def
cached_pod
(
request
)
path
=
path_for_pod
(
request
)
path
=
path_for_pod
(
request
)
spec
=
request
.
spec
||
cached_spec
(
request
)
spec
=
request
.
spec
||
cached_spec
(
request
)
...
@@ -45,11 +63,17 @@ module Pod
...
@@ -45,11 +63,17 @@ module Pod
Response
.
new
(
path
,
spec
,
request
.
params
)
Response
.
new
(
path
,
spec
,
request
.
params
)
end
end
# @return [Specification] The cached specification for the given
# `request`.
#
def
cached_spec
(
request
)
def
cached_spec
(
request
)
path
=
path_for_spec
(
request
)
path
=
path_for_spec
(
request
)
path
.
file?
&&
Specification
.
from_file
(
path
)
path
.
file?
&&
Specification
.
from_file
(
path
)
end
end
# @return [Response] The download response for the given `request` that
# was not found in the download cache.
#
def
uncached_pod
(
request
)
def
uncached_pod
(
request
)
in_tmpdir
do
|
target
|
in_tmpdir
do
|
target
|
result
=
Response
.
new
result
=
Response
.
new
...
@@ -77,6 +101,19 @@ module Pod
...
@@ -77,6 +101,19 @@ module Pod
end
end
end
end
# Downloads a pod with the given `name` and `params` to `target`.
#
# @param [String] name
#
# @param [Pathname] target
#
# @param [Hash<Symbol,String>] params
#
# @param [Boolean] head
#
# @return [Hash] The checkout options required to re-download this exact
# same source.
#
def
download
(
name
,
target
,
params
,
head
)
def
download
(
name
,
target
,
params
,
head
)
downloader
=
Downloader
.
for_target
(
target
,
params
)
downloader
=
Downloader
.
for_target
(
target
,
params
)
if
head
if
head
...
@@ -97,6 +134,11 @@ module Pod
...
@@ -97,6 +134,11 @@ module Pod
end
end
end
end
# Performs the given block inside a temporary directory,
# which is removed at the end of the block's scope.
#
# @return [Object] The return value of the given block
#
def
in_tmpdir
(
&
blk
)
def
in_tmpdir
(
&
blk
)
tmpdir
=
Pathname
(
Dir
.
mktmpdir
)
tmpdir
=
Pathname
(
Dir
.
mktmpdir
)
blk
.
call
(
tmpdir
)
blk
.
call
(
tmpdir
)
...
@@ -104,6 +146,17 @@ module Pod
...
@@ -104,6 +146,17 @@ module Pod
FileUtils
.
remove_entry
(
tmpdir
)
if
tmpdir
.
exist?
FileUtils
.
remove_entry
(
tmpdir
)
if
tmpdir
.
exist?
end
end
# Copies the `source` directory to `destination`, cleaning the directory
# of any files unused by `spec`.
#
# @param [Pathname] source
#
# @param [Pathname] destination
#
# @param [Specification] spec
#
# @return [Void]
#
def
copy_and_clean
(
source
,
destination
,
spec
)
def
copy_and_clean
(
source
,
destination
,
spec
)
specs_by_platform
=
{}
specs_by_platform
=
{}
spec
.
available_platforms
.
each
do
|
platform
|
spec
.
available_platforms
.
each
do
|
platform
|
...
@@ -114,6 +167,16 @@ module Pod
...
@@ -114,6 +167,16 @@ module Pod
Sandbox
::
PodDirCleaner
.
new
(
destination
,
specs_by_platform
).
clean!
Sandbox
::
PodDirCleaner
.
new
(
destination
,
specs_by_platform
).
clean!
end
end
# Writes the given `spec` to the given `path`.
#
# @param [Specification] spec
# the specification to be written.
#
# @param [Pathname] path
# the path the specification is to be written to.
#
# @return [Void]
#
def
write_spec
(
spec
,
path
)
def
write_spec
(
spec
,
path
)
FileUtils
.
mkdir_p
path
.
dirname
FileUtils
.
mkdir_p
path
.
dirname
path
.
open
(
'w'
)
{
|
f
|
f
.
write
spec
.
to_pretty_json
}
path
.
open
(
'w'
)
{
|
f
|
f
.
write
spec
.
to_pretty_json
}
...
...
lib/cocoapods/downloader/request.rb
View file @
ff593f96
module
Pod
module
Pod
module
Downloader
module
Downloader
# This class represents a download request for a given Pod.
#
class
Request
class
Request
# @return [Specification,Nil] The specification for the pod whose download
# is being requested.
#
attr_reader
:spec
# @return [Boolean] Whether this download request is for a released pod.
#
attr_reader
:released_pod
attr_reader
:released_pod
alias_method
:released_pod?
,
:released_pod
alias_method
:released_pod?
,
:released_pod
attr_reader
:spec
# @return [String] The name of the pod whose dowload is being requested.
#
attr_reader
:name
# @return [Hash<Symbol, String>] The download parameters for this request.
#
attr_reader
:params
# @return [Boolean] Whether the download request is for a head download.
#
attr_reader
:head
attr_reader
:head
alias_method
:head?
,
:head
alias_method
:head?
,
:head
attr_reader
:params
attr_reader
:name
# @param [Specification,Nil] spec
# see {#spec}
#
# @param [Boolean] released
# see {#released_pod}
#
# @param [String,Nil] name
# see {#name}
#
# @param [Hash<Symbol,String>,Nil] params
# see {#params}
#
# @param [Boolean] head
# see {#head}
#
def
initialize
(
spec:
nil
,
released:
false
,
name:
nil
,
params:
false
,
head:
false
)
def
initialize
(
spec:
nil
,
released:
false
,
name:
nil
,
params:
false
,
head:
false
)
@released_pod
=
released
@released_pod
=
released
@spec
=
spec
@spec
=
spec
...
@@ -23,6 +52,15 @@ module Pod
...
@@ -23,6 +52,15 @@ module Pod
validate!
validate!
end
end
# @param [String] name
# the name of the pod being downloaded.
#
# @param [Hash<#to_s, #to_s>] params
# the download parameters of the pod being downloaded.
#
# @return [String] The slug used to store the files resulting from this
# download request.
#
def
slug
(
name:
self
.
name
,
params:
self
.
params
)
def
slug
(
name:
self
.
name
,
params:
self
.
params
)
if
released_pod?
if
released_pod?
checksum
=
spec
.
checksum
&&
'-'
<<
spec
.
checksum
.
limit
(
5
)
checksum
=
spec
.
checksum
&&
'-'
<<
spec
.
checksum
.
limit
(
5
)
...
@@ -35,6 +73,10 @@ module Pod
...
@@ -35,6 +73,10 @@ module Pod
private
private
# Validates that the given request is well-formed.
#
# @return [Void]
#
def
validate!
def
validate!
raise
ArgumentError
,
'Requires a name'
unless
name
raise
ArgumentError
,
'Requires a name'
unless
name
raise
ArgumentError
,
'Requires a version if released'
if
released_pod?
&&
!
spec
.
version
raise
ArgumentError
,
'Requires a version if released'
if
released_pod?
&&
!
spec
.
version
...
...
lib/cocoapods/downloader/response.rb
View file @
ff593f96
module
Pod
module
Pod
module
Downloader
module
Downloader
# A response to a download request.
#
# @attr [Pathname] location
# the location where this downloaded pod is stored on disk.
#
# @attr [Specification] spec
# the specification that describes this downloaded pod.
#
# @attr [Hash<Symbol, String>] checkout_options
# the downloader parameters necessary to recreate this exact download.
#
Response
=
Struct
.
new
(
:location
,
:spec
,
:checkout_options
)
Response
=
Struct
.
new
(
:location
,
:spec
,
:checkout_options
)
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment