cocoapods 0.16.4 → 0.17.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +108 -0
- data/README.md +3 -3
- data/bin/pod +1 -1
- data/lib/cocoapods.rb +31 -31
- data/lib/cocoapods/command.rb +62 -107
- data/lib/cocoapods/command/inter_process_communication.rb +103 -0
- data/lib/cocoapods/command/list.rb +45 -44
- data/lib/cocoapods/command/outdated.rb +28 -25
- data/lib/cocoapods/command/project.rb +90 -0
- data/lib/cocoapods/command/push.rb +50 -32
- data/lib/cocoapods/command/repo.rb +125 -155
- data/lib/cocoapods/command/search.rb +23 -12
- data/lib/cocoapods/command/setup.rb +103 -64
- data/lib/cocoapods/command/spec.rb +329 -90
- data/lib/cocoapods/config.rb +197 -44
- data/lib/cocoapods/downloader.rb +47 -34
- data/lib/cocoapods/executable.rb +98 -41
- data/lib/cocoapods/external_sources.rb +325 -0
- data/lib/cocoapods/file_list.rb +8 -1
- data/lib/cocoapods/gem_version.rb +7 -0
- data/lib/cocoapods/generator/acknowledgements.rb +71 -7
- data/lib/cocoapods/generator/acknowledgements/markdown.rb +10 -9
- data/lib/cocoapods/generator/acknowledgements/plist.rb +9 -8
- data/lib/cocoapods/generator/copy_resources_script.rb +2 -2
- data/lib/cocoapods/generator/documentation.rb +153 -37
- data/lib/cocoapods/generator/prefix_header.rb +82 -0
- data/lib/cocoapods/generator/target_header.rb +58 -0
- data/lib/cocoapods/generator/xcconfig.rb +130 -0
- data/lib/cocoapods/hooks/installer_representation.rb +123 -0
- data/lib/cocoapods/hooks/library_representation.rb +79 -0
- data/lib/cocoapods/hooks/pod_representation.rb +74 -0
- data/lib/cocoapods/installer.rb +398 -147
- data/lib/cocoapods/installer/analyzer.rb +556 -0
- data/lib/cocoapods/installer/analyzer/sandbox_analyzer.rb +253 -0
- data/lib/cocoapods/installer/file_references_installer.rb +179 -0
- data/lib/cocoapods/installer/pod_source_installer.rb +289 -0
- data/lib/cocoapods/installer/target_installer.rb +307 -112
- data/lib/cocoapods/installer/user_project_integrator.rb +140 -176
- data/lib/cocoapods/installer/user_project_integrator/target_integrator.rb +193 -0
- data/lib/cocoapods/library.rb +195 -0
- data/lib/cocoapods/open_uri.rb +16 -14
- data/lib/cocoapods/project.rb +175 -52
- data/lib/cocoapods/resolver.rb +151 -164
- data/lib/cocoapods/sandbox.rb +276 -54
- data/lib/cocoapods/sandbox/file_accessor.rb +210 -0
- data/lib/cocoapods/sandbox/headers_store.rb +96 -0
- data/lib/cocoapods/sandbox/path_list.rb +178 -0
- data/lib/cocoapods/sources_manager.rb +218 -0
- data/lib/cocoapods/user_interface.rb +82 -18
- data/lib/cocoapods/{command → user_interface}/error_report.rb +5 -5
- data/lib/cocoapods/validator.rb +379 -0
- metadata +74 -55
- data/lib/cocoapods/command/install.rb +0 -55
- data/lib/cocoapods/command/linter.rb +0 -317
- data/lib/cocoapods/command/update.rb +0 -25
- data/lib/cocoapods/dependency.rb +0 -285
- data/lib/cocoapods/downloader/git.rb +0 -276
- data/lib/cocoapods/downloader/http.rb +0 -99
- data/lib/cocoapods/downloader/mercurial.rb +0 -26
- data/lib/cocoapods/downloader/subversion.rb +0 -42
- data/lib/cocoapods/local_pod.rb +0 -620
- data/lib/cocoapods/lockfile.rb +0 -274
- data/lib/cocoapods/platform.rb +0 -127
- data/lib/cocoapods/podfile.rb +0 -551
- data/lib/cocoapods/source.rb +0 -223
- data/lib/cocoapods/specification.rb +0 -579
- data/lib/cocoapods/specification/set.rb +0 -175
- data/lib/cocoapods/specification/statistics.rb +0 -112
- data/lib/cocoapods/user_interface/ui_pod.rb +0 -130
- data/lib/cocoapods/version.rb +0 -26
@@ -1,25 +0,0 @@
|
|
1
|
-
module Pod
|
2
|
-
class Command
|
3
|
-
class Update < Install
|
4
|
-
def self.banner
|
5
|
-
%{Updating dependencies of a project:
|
6
|
-
|
7
|
-
$ pod update
|
8
|
-
|
9
|
-
Updates all dependencies.}
|
10
|
-
end
|
11
|
-
|
12
|
-
def initialize(argv)
|
13
|
-
config.skip_repo_update = argv.option('--no-update')
|
14
|
-
super unless argv.empty?
|
15
|
-
end
|
16
|
-
|
17
|
-
def run
|
18
|
-
verify_podfile_exists!
|
19
|
-
verify_lockfile_exists!
|
20
|
-
run_install_with_update(true)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
data/lib/cocoapods/dependency.rb
DELETED
@@ -1,285 +0,0 @@
|
|
1
|
-
require 'cocoapods/open_uri'
|
2
|
-
|
3
|
-
module Pod
|
4
|
-
class Dependency < Gem::Dependency
|
5
|
-
|
6
|
-
attr_reader :head
|
7
|
-
alias :head? :head
|
8
|
-
attr_accessor :specification, :external_source
|
9
|
-
|
10
|
-
def initialize(*name_and_version_requirements, &block)
|
11
|
-
if name_and_version_requirements.empty? && block
|
12
|
-
@inline_podspec = true
|
13
|
-
@specification = Specification.new(&block)
|
14
|
-
super(@specification.name, @specification.version)
|
15
|
-
|
16
|
-
elsif !name_and_version_requirements.empty? && block.nil?
|
17
|
-
version = name_and_version_requirements.last
|
18
|
-
if name_and_version_requirements.last.is_a?(Hash)
|
19
|
-
@external_source = ExternalSources.from_params(name_and_version_requirements[0].split('/').first, name_and_version_requirements.pop)
|
20
|
-
elsif version.is_a?(Symbol) && version == :head || version.is_a?(Version) && version.head?
|
21
|
-
name_and_version_requirements.pop
|
22
|
-
@head = true
|
23
|
-
end
|
24
|
-
|
25
|
-
super(*name_and_version_requirements)
|
26
|
-
|
27
|
-
if head? && !latest_version?
|
28
|
-
raise Informative, "A `:head' dependency may not specify version requirements."
|
29
|
-
end
|
30
|
-
|
31
|
-
else
|
32
|
-
raise Informative, "A dependency needs either a name and version requirements, " \
|
33
|
-
"a source hash, or a block which defines a podspec."
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def latest_version?
|
38
|
-
versions = @version_requirements.requirements.map(&:last)
|
39
|
-
versions == [Gem::Version.new('0')]
|
40
|
-
end
|
41
|
-
|
42
|
-
def ==(other)
|
43
|
-
super && (head? == other.head?) && (@specification ? @specification == other.specification : @external_source == other.external_source)
|
44
|
-
end
|
45
|
-
|
46
|
-
def subspec_dependency?
|
47
|
-
@name.include?('/')
|
48
|
-
end
|
49
|
-
|
50
|
-
def inline?
|
51
|
-
@inline_podspec
|
52
|
-
end
|
53
|
-
|
54
|
-
def external?
|
55
|
-
!@external_source.nil?
|
56
|
-
end
|
57
|
-
|
58
|
-
# In case this is a dependency for a subspec, e.g. 'RestKit/Networking',
|
59
|
-
# this returns 'RestKit', which is what the Pod::Source needs to know to
|
60
|
-
# retrieve the correct Set from disk.
|
61
|
-
def top_level_spec_name
|
62
|
-
subspec_dependency? ? @name.split('/').first : @name
|
63
|
-
end
|
64
|
-
|
65
|
-
# Returns a copy of the dependency, but with the name of the top level
|
66
|
-
# spec. This is used by Pod::Specification::Set to merge dependencies on
|
67
|
-
# the complete set, irrespective of what spec in the set wil be used.
|
68
|
-
def to_top_level_spec_dependency
|
69
|
-
dep = dup
|
70
|
-
dep.name = top_level_spec_name
|
71
|
-
dep
|
72
|
-
end
|
73
|
-
|
74
|
-
def to_s
|
75
|
-
version = ''
|
76
|
-
if external?
|
77
|
-
version << @external_source.description
|
78
|
-
elsif inline?
|
79
|
-
version << 'defined in Podfile'
|
80
|
-
elsif head?
|
81
|
-
version << 'HEAD'
|
82
|
-
elsif @version_requirements != Gem::Requirement.default
|
83
|
-
version << @version_requirements.to_s
|
84
|
-
end
|
85
|
-
result = @name.dup
|
86
|
-
result << " (#{version})" unless version.empty?
|
87
|
-
result
|
88
|
-
end
|
89
|
-
|
90
|
-
def specification_from_sandbox(sandbox, platform)
|
91
|
-
@external_source.specification_from_sandbox(sandbox, platform)
|
92
|
-
end
|
93
|
-
|
94
|
-
def match_version?(version)
|
95
|
-
match?(name, version) && (version.head? == head?)
|
96
|
-
end
|
97
|
-
|
98
|
-
# Taken from RubyGems 1.3.7
|
99
|
-
unless public_method_defined?(:match?)
|
100
|
-
def match?(spec_name, spec_version)
|
101
|
-
pattern = name
|
102
|
-
|
103
|
-
if Regexp === pattern
|
104
|
-
return false unless pattern =~ spec_name
|
105
|
-
else
|
106
|
-
return false unless pattern == spec_name
|
107
|
-
end
|
108
|
-
|
109
|
-
return true if requirement.to_s == ">= 0"
|
110
|
-
|
111
|
-
requirement.satisfied_by? Gem::Version.new(spec_version)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
# Taken from a newer version of RubyGems
|
116
|
-
unless public_method_defined?(:merge)
|
117
|
-
def merge other
|
118
|
-
unless name == other.name then
|
119
|
-
raise ArgumentError,
|
120
|
-
"#{self} and #{other} have different names"
|
121
|
-
end
|
122
|
-
|
123
|
-
default = Gem::Requirement.default
|
124
|
-
self_req = self.requirement
|
125
|
-
other_req = other.requirement
|
126
|
-
|
127
|
-
return self.class.new name, self_req if other_req == default
|
128
|
-
return self.class.new name, other_req if self_req == default
|
129
|
-
|
130
|
-
self.class.new name, self_req.as_list.concat(other_req.as_list)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
module ExternalSources
|
135
|
-
def self.from_params(name, params)
|
136
|
-
return unless name && params
|
137
|
-
if params.key?(:git)
|
138
|
-
GitSource.new(name, params)
|
139
|
-
elsif params.key?(:hg)
|
140
|
-
MercurialSource.new(name, params)
|
141
|
-
elsif params.key?(:svn)
|
142
|
-
SvnSource.new(name, params)
|
143
|
-
elsif params.key?(:podspec)
|
144
|
-
PodspecSource.new(name, params)
|
145
|
-
elsif params.key?(:local)
|
146
|
-
LocalSource.new(name, params)
|
147
|
-
else
|
148
|
-
raise Informative, "Unknown external source parameters for #{name}: #{params}"
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
class AbstractExternalSource
|
153
|
-
include Config::Mixin
|
154
|
-
|
155
|
-
attr_reader :name, :params
|
156
|
-
|
157
|
-
def initialize(name, params)
|
158
|
-
@name, @params = name, params
|
159
|
-
end
|
160
|
-
|
161
|
-
def specification_from_sandbox(sandbox, platform)
|
162
|
-
specification_from_local(sandbox, platform) || specification_from_external(sandbox, platform)
|
163
|
-
end
|
164
|
-
|
165
|
-
def specification_from_local(sandbox, platform)
|
166
|
-
if local_pod = sandbox.installed_pod_named(name, platform)
|
167
|
-
local_pod.top_specification
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
def specification_from_external(sandbox, platform)
|
172
|
-
podspec = copy_external_source_into_sandbox(sandbox, platform)
|
173
|
-
spec = specification_from_local(sandbox, platform)
|
174
|
-
raise Informative, "No podspec found for `#{name}' in #{description}" unless spec
|
175
|
-
spec
|
176
|
-
end
|
177
|
-
|
178
|
-
# Can store from a pathname or a string
|
179
|
-
#
|
180
|
-
def store_podspec(sandbox, podspec)
|
181
|
-
output_path = sandbox.root + "Local Podspecs/#{name}.podspec"
|
182
|
-
output_path.dirname.mkpath
|
183
|
-
if podspec.is_a?(String)
|
184
|
-
raise Informative, "No podspec found for `#{name}' in #{description}" unless podspec.include?('Spec.new')
|
185
|
-
output_path.open('w') { |f| f.puts(podspec) }
|
186
|
-
else
|
187
|
-
raise Informative, "No podspec found for `#{name}' in #{description}" unless podspec.exist?
|
188
|
-
FileUtils.copy(podspec, output_path)
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
def ==(other)
|
193
|
-
return if other.nil?
|
194
|
-
name == other.name && params == other.params
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
class DownloaderSource < AbstractExternalSource
|
199
|
-
def copy_external_source_into_sandbox(sandbox, platform)
|
200
|
-
UI.info("->".green + " Pre-downloading: '#{name}'") do
|
201
|
-
target = sandbox.root + name
|
202
|
-
target.rmtree if target.exist?
|
203
|
-
downloader = Downloader.for_target(sandbox.root + name, @params)
|
204
|
-
downloader.download
|
205
|
-
store_podspec(sandbox, target + "#{name}.podspec")
|
206
|
-
if local_pod = sandbox.installed_pod_named(name, platform)
|
207
|
-
local_pod.downloaded = true
|
208
|
-
end
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
class GitSource < DownloaderSource
|
214
|
-
def description
|
215
|
-
"from `#{@params[:git]}'".tap do |description|
|
216
|
-
description << ", commit `#{@params[:commit]}'" if @params[:commit]
|
217
|
-
description << ", branch `#{@params[:branch]}'" if @params[:branch]
|
218
|
-
description << ", tag `#{@params[:tag]}'" if @params[:tag]
|
219
|
-
end
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
class MercurialSource < DownloaderSource
|
224
|
-
def description
|
225
|
-
"from `#{@params[:hg]}'".tap do |description|
|
226
|
-
description << ", revision `#{@params[:revision]}'" if @params[:revision]
|
227
|
-
end
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
class SvnSource < DownloaderSource
|
232
|
-
def description
|
233
|
-
"from `#{@params[:svn]}'".tap do |description|
|
234
|
-
description << ", folder `#{@params[:folder]}'" if @params[:folder]
|
235
|
-
description << ", tag `#{@params[:tag]}'" if @params[:tag]
|
236
|
-
description << ", revision `#{@params[:revision]}'" if @params[:revision]
|
237
|
-
end
|
238
|
-
end
|
239
|
-
end
|
240
|
-
|
241
|
-
# can be http, file, etc
|
242
|
-
class PodspecSource < AbstractExternalSource
|
243
|
-
def copy_external_source_into_sandbox(sandbox, _)
|
244
|
-
UI.info("->".green + " Fetching podspec for `#{name}' from: #{@params[:podspec]}") do
|
245
|
-
path = @params[:podspec]
|
246
|
-
path = Pathname.new(path).expand_path if path.start_with?("~")
|
247
|
-
open(path) { |io| store_podspec(sandbox, io.read) }
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
def description
|
252
|
-
"from `#{@params[:podspec]}'"
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
|
-
class LocalSource < AbstractExternalSource
|
257
|
-
def pod_spec_path
|
258
|
-
path = Pathname.new(@params[:local]).expand_path
|
259
|
-
path += "#{name}.podspec"# unless path.to_s.include?("#{name}.podspec")
|
260
|
-
raise Informative, "No podspec found for `#{name}' in `#{@params[:local]}'" unless path.exist?
|
261
|
-
path
|
262
|
-
end
|
263
|
-
|
264
|
-
def copy_external_source_into_sandbox(sandbox, _)
|
265
|
-
store_podspec(sandbox, pod_spec_path)
|
266
|
-
end
|
267
|
-
|
268
|
-
def specification_from_local(sandbox, platform)
|
269
|
-
specification_from_external(sandbox, platform)
|
270
|
-
end
|
271
|
-
|
272
|
-
def specification_from_external(sandbox, platform)
|
273
|
-
copy_external_source_into_sandbox(sandbox, platform)
|
274
|
-
spec = Specification.from_file(pod_spec_path)
|
275
|
-
spec.source = @params
|
276
|
-
spec
|
277
|
-
end
|
278
|
-
|
279
|
-
def description
|
280
|
-
"from `#{@params[:local]}'"
|
281
|
-
end
|
282
|
-
end
|
283
|
-
end
|
284
|
-
end
|
285
|
-
end
|
@@ -1,276 +0,0 @@
|
|
1
|
-
require 'open-uri'
|
2
|
-
# require 'tempfile'
|
3
|
-
require 'zlib'
|
4
|
-
require 'digest/sha1'
|
5
|
-
|
6
|
-
module Pod
|
7
|
-
class Downloader
|
8
|
-
|
9
|
-
# Concreted Downloader class that provides support for specifications with
|
10
|
-
# git sources.
|
11
|
-
#
|
12
|
-
class Git < Downloader
|
13
|
-
include Config::Mixin
|
14
|
-
|
15
|
-
executable :git
|
16
|
-
|
17
|
-
def download
|
18
|
-
create_cache unless cache_exist?
|
19
|
-
UI.section(' > Cloning git repo', '', 1) do
|
20
|
-
if options[:tag]
|
21
|
-
download_tag
|
22
|
-
elsif options[:branch]
|
23
|
-
download_branch
|
24
|
-
elsif options[:commit]
|
25
|
-
download_commit
|
26
|
-
else
|
27
|
-
download_head
|
28
|
-
end
|
29
|
-
Dir.chdir(target_path) { git! "submodule update --init" } if options[:submodules]
|
30
|
-
end
|
31
|
-
prune_cache
|
32
|
-
end
|
33
|
-
|
34
|
-
|
35
|
-
# @!group Download implementations
|
36
|
-
|
37
|
-
# @return [Pathname] The clone URL, which resolves to the cache path.
|
38
|
-
#
|
39
|
-
def clone_url
|
40
|
-
cache_path
|
41
|
-
end
|
42
|
-
|
43
|
-
# @return [void] Convenience method to perform clones operations.
|
44
|
-
#
|
45
|
-
def clone(from, to)
|
46
|
-
UI.section(" > Cloning to Pods folder",'',1) do
|
47
|
-
git! %Q|clone "#{from}" "#{to}"|
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
# @return [void] Checkouts the HEAD of the git source in the destination
|
52
|
-
# path.
|
53
|
-
#
|
54
|
-
def download_head
|
55
|
-
if cache_exist?
|
56
|
-
update_cache
|
57
|
-
else
|
58
|
-
create_cache
|
59
|
-
end
|
60
|
-
|
61
|
-
clone(clone_url, target_path)
|
62
|
-
Dir.chdir(target_path) { git! "submodule update --init" } if options[:submodules]
|
63
|
-
end
|
64
|
-
|
65
|
-
# @return [void] Checkouts a specific tag of the git source in the
|
66
|
-
# destination path.
|
67
|
-
#
|
68
|
-
def download_tag
|
69
|
-
ensure_ref_exists(options[:tag])
|
70
|
-
Dir.chdir(target_path) do
|
71
|
-
git! "init"
|
72
|
-
git! "remote add origin '#{clone_url}'"
|
73
|
-
git! "fetch origin tags/#{options[:tag]}"
|
74
|
-
git! "reset --hard FETCH_HEAD"
|
75
|
-
git! "checkout -b activated-pod-commit"
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
# @return [void] Checkouts a specific commit of the git source in the
|
80
|
-
# destination path.
|
81
|
-
#
|
82
|
-
def download_commit
|
83
|
-
ensure_ref_exists(options[:commit])
|
84
|
-
clone(clone_url, target_path)
|
85
|
-
Dir.chdir(target_path) do
|
86
|
-
git! "checkout -b activated-pod-commit #{options[:commit]}"
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
# @return [void] Checkouts the HEAD of a specific branch of the git
|
91
|
-
# source in the destination path.
|
92
|
-
#
|
93
|
-
def download_branch
|
94
|
-
ensure_remote_branch_exists(options[:branch])
|
95
|
-
clone(clone_url, target_path)
|
96
|
-
Dir.chdir(target_path) do
|
97
|
-
git! "remote add upstream '#{@url}'" # we need to add the original url, not the cache url
|
98
|
-
git! "fetch -q upstream" # refresh the branches
|
99
|
-
git! "checkout --track -b activated-pod-commit upstream/#{options[:branch]}" # create a new tracking branch
|
100
|
-
UI.message("Just downloaded and checked out branch: #{options[:branch]} from upstream #{clone_url}")
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
# @!group Checking references
|
107
|
-
|
108
|
-
# @return [Bool] Wether a reference (commit SHA or tag)
|
109
|
-
#
|
110
|
-
def ref_exists?(ref)
|
111
|
-
Dir.chdir(cache_path) { git "rev-list --max-count=1 #{ref}" }
|
112
|
-
$? == 0
|
113
|
-
end
|
114
|
-
|
115
|
-
# @return [void] Checks if a reference exists in the cache and updates
|
116
|
-
# only if necessary.
|
117
|
-
#
|
118
|
-
# @raises if after the update the reference can't be found.
|
119
|
-
#
|
120
|
-
def ensure_ref_exists(ref)
|
121
|
-
return if ref_exists?(ref)
|
122
|
-
update_cache
|
123
|
-
raise Informative, "[!] Cache unable to find git reference `#{ref}' for `#{url}'.".red unless ref_exists?(ref)
|
124
|
-
end
|
125
|
-
|
126
|
-
# @return [Bool] Wether a branch exists in the cache.
|
127
|
-
#
|
128
|
-
def branch_exists?(branch)
|
129
|
-
Dir.chdir(cache_path) { git "branch --all | grep #{branch}$" } # check for remote branch and do suffix matching ($ anchor)
|
130
|
-
$? == 0
|
131
|
-
end
|
132
|
-
|
133
|
-
# @return [void] Checks if a branch exists in the cache and updates
|
134
|
-
# only if necessary.
|
135
|
-
#
|
136
|
-
# @raises if after the update the branch can't be found.
|
137
|
-
#
|
138
|
-
def ensure_remote_branch_exists(branch)
|
139
|
-
return if branch_exists?(branch)
|
140
|
-
update_cache
|
141
|
-
raise Informative, "[!] Cache unable to find git reference `#{branch}' for `#{url}' (#{$?}).".red unless branch_exists?(branch)
|
142
|
-
end
|
143
|
-
|
144
|
-
|
145
|
-
# @!group Cache
|
146
|
-
|
147
|
-
# The maximum allowed size for the cache expressed in Mb.
|
148
|
-
#
|
149
|
-
MAX_CACHE_SIZE = 500
|
150
|
-
|
151
|
-
# @return [Pathname] The directory where the cache for the current git
|
152
|
-
# repo is stored.
|
153
|
-
#
|
154
|
-
# @note The name of the directory is the SHA1 hash value of the URL of
|
155
|
-
# the git repo.
|
156
|
-
#
|
157
|
-
def cache_path
|
158
|
-
@cache_path ||= caches_root + "#{Digest::SHA1.hexdigest(url.to_s)}"
|
159
|
-
end
|
160
|
-
|
161
|
-
# @return [Pathname] The directory where the git caches are stored.
|
162
|
-
#
|
163
|
-
def caches_root
|
164
|
-
Pathname.new(File.expand_path("~/Library/Caches/CocoaPods/Git"))
|
165
|
-
end
|
166
|
-
|
167
|
-
# @return [Integer] The global size of the git cache expressed in Mb.
|
168
|
-
#
|
169
|
-
def caches_size
|
170
|
-
`du -cm`.split("\n").last.to_i
|
171
|
-
end
|
172
|
-
|
173
|
-
# @return [Bool] Wether the cache exits.
|
174
|
-
#
|
175
|
-
# @note The previous implementation of the cache didn't use a barebone
|
176
|
-
# git repo. This method takes into account this fact and checks
|
177
|
-
# that the cache is actually a barebone repo. If the cache was not
|
178
|
-
# barebone it will be deleted and recreated.
|
179
|
-
#
|
180
|
-
def cache_exist?
|
181
|
-
cache_path.exist? &&
|
182
|
-
cache_origin_url(cache_path).to_s == url.to_s &&
|
183
|
-
Dir.chdir(cache_path) { git("config core.bare").chomp == "true" }
|
184
|
-
end
|
185
|
-
|
186
|
-
# @return [String] The origin URL of the cache with the given directory.
|
187
|
-
#
|
188
|
-
# @param [String] dir The directory of the cache.
|
189
|
-
#
|
190
|
-
def cache_origin_url(dir)
|
191
|
-
Dir.chdir(dir) { `git config remote.origin.url`.chomp }
|
192
|
-
end
|
193
|
-
|
194
|
-
# @return [void] Creates the barebone repo that will serve as the cache
|
195
|
-
# for the current repo.
|
196
|
-
#
|
197
|
-
def create_cache
|
198
|
-
UI.section(" > Creating cache git repo (#{cache_path})",'',1) do
|
199
|
-
cache_path.rmtree if cache_path.exist?
|
200
|
-
cache_path.mkpath
|
201
|
-
git! %Q|clone --mirror "#{url}" "#{cache_path}"|
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
# @return [void] Updates the barebone repo used as a cache against its
|
206
|
-
# remote.
|
207
|
-
#
|
208
|
-
def update_cache
|
209
|
-
UI.section(" > Updating cache git repo (#{cache_path})",'',1) do
|
210
|
-
Dir.chdir(cache_path) { git! "remote update" }
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
# @return [void] Deletes the oldest caches until they the global size is
|
215
|
-
# below the maximum allowed.
|
216
|
-
#
|
217
|
-
def prune_cache
|
218
|
-
return unless caches_root.exist?
|
219
|
-
Dir.chdir(caches_root) do
|
220
|
-
repos = Pathname.new(caches_root).children.select { |c| c.directory? }.sort_by(&:ctime)
|
221
|
-
while caches_size >= MAX_CACHE_SIZE && !repos.empty?
|
222
|
-
dir = repos.shift
|
223
|
-
UI.message "#{'->'.yellow} Removing git cache for `#{cache_origin_url(dir)}'"
|
224
|
-
dir.rmtree
|
225
|
-
end
|
226
|
-
end
|
227
|
-
end
|
228
|
-
end
|
229
|
-
|
230
|
-
# This class allows to download tarballs from GitHub and is not currently
|
231
|
-
# being used by CocoaPods as the git cache is preferable.
|
232
|
-
#
|
233
|
-
class GitHub < Git
|
234
|
-
def download_head
|
235
|
-
download_only? ? download_and_extract_tarball('master') : super
|
236
|
-
end
|
237
|
-
|
238
|
-
def download_tag
|
239
|
-
download_only? ? download_and_extract_tarball(options[:tag]) : super
|
240
|
-
end
|
241
|
-
|
242
|
-
def download_commit
|
243
|
-
download_only? ? download_and_extract_tarball(options[:commit]) : super
|
244
|
-
end
|
245
|
-
|
246
|
-
def download_branch
|
247
|
-
download_only? ? download_and_extract_tarball(options[:branch]) : super
|
248
|
-
end
|
249
|
-
|
250
|
-
def tarball_url_for(id)
|
251
|
-
original_url, username, reponame = *(url.match(/[:\/]([\w\-]+)\/([\w\-]+)\.git/))
|
252
|
-
"https://github.com/#{username}/#{reponame}/tarball/#{id}"
|
253
|
-
end
|
254
|
-
|
255
|
-
def tmp_path
|
256
|
-
target_path + "tarball.tar.gz"
|
257
|
-
end
|
258
|
-
|
259
|
-
private
|
260
|
-
|
261
|
-
def download_only?
|
262
|
-
@options[:download_only]
|
263
|
-
end
|
264
|
-
|
265
|
-
def download_and_extract_tarball(id)
|
266
|
-
File.open(tmp_path, "w+") do |tmpfile|
|
267
|
-
open tarball_url_for(id) do |archive|
|
268
|
-
tmpfile.write Zlib::GzipReader.new(archive).read
|
269
|
-
end
|
270
|
-
|
271
|
-
system "tar xf #{tmpfile.path} -C #{target_path} --strip-components 1"
|
272
|
-
end
|
273
|
-
end
|
274
|
-
end
|
275
|
-
end
|
276
|
-
end
|