lg_pod_plugin 1.1.7.4 → 1.1.8.2
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 +4 -4
- data/lib/command/init.rb +1 -1
- data/lib/lg_pod_plugin/db/database.rb +1 -1
- data/lib/lg_pod_plugin/downloader/downloader.rb +9 -48
- data/lib/lg_pod_plugin/downloader/l_cache.rb +79 -62
- data/lib/lg_pod_plugin/downloader/overload_cache.rb +1 -296
- data/lib/lg_pod_plugin/downloader/request.rb +2 -5
- data/lib/lg_pod_plugin/git/github_api.rb +2 -49
- data/lib/lg_pod_plugin/git/github_archive.rb +14 -32
- data/lib/lg_pod_plugin/git/gitlab_api.rb +45 -46
- data/lib/lg_pod_plugin/git/gitlab_archive.rb +7 -80
- data/lib/lg_pod_plugin/git/http_download.rb +3 -8
- data/lib/lg_pod_plugin/installer/PodDownload +0 -0
- data/lib/lg_pod_plugin/installer/install.rb +15 -13
- data/lib/lg_pod_plugin/installer/main.rb +5 -0
- data/lib/lg_pod_plugin/net/l_uri.rb +1 -34
- data/lib/lg_pod_plugin/pod/external_pod.rb +0 -1
- data/lib/lg_pod_plugin/pod/release-pod.rb +4 -4
- data/lib/lg_pod_plugin/utils/file_path.rb +5 -0
- data/lib/lg_pod_plugin/utils/l_util.rb +0 -24
- data/lib/lg_pod_plugin/version.rb +1 -1
- data/lib/lg_pod_plugin.rb +1 -1
- metadata +9 -26
- data/lib/lg_pod_plugin/config/lockfile_model.rb +0 -58
- data/lib/lg_pod_plugin/config/podspec.rb +0 -266
- data/lib/lg_pod_plugin/utils/aes-crypt.rb +0 -82
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: aafc9f0e84eb60f2f5a215573e20d4496446d31ad7fa4e8829c309872ad682cc
|
|
4
|
+
data.tar.gz: a1d6ef6d263704e67e90de93cd4d756e52e67ad385eaebfb2907691c1f83db4e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7a002fe8a446c71ebc2d82f2d95f860571a58a68dfecf5816b01258c550e3ba2dceaf4765227f6caed75af4829908a195da4c9efa1875c0fa24e11d9e309f48f
|
|
7
|
+
data.tar.gz: f143f3a417584ef027c445d7ebaf6130187f4cce2b75d780fc3a4af1f8ac22f27e676bebacd85c5bac6efc805c2ab2d50129b4376b312d03c59a1ba348842ad9
|
data/lib/command/init.rb
CHANGED
|
@@ -38,7 +38,7 @@ module LgPodPlugin
|
|
|
38
38
|
refresh_token = ""
|
|
39
39
|
expires_in = 7879680
|
|
40
40
|
created_at = Time.now.to_i
|
|
41
|
-
encrypt_access_token =
|
|
41
|
+
encrypt_access_token = self.token
|
|
42
42
|
hash = {"access_token": encrypt_access_token}
|
|
43
43
|
hash["token_type"] = "Bearer"
|
|
44
44
|
hash["expires_in"] = expires_in
|
|
@@ -15,27 +15,18 @@ module LgPodPlugin
|
|
|
15
15
|
# 预下载处理
|
|
16
16
|
def pre_download_pod
|
|
17
17
|
name = self.request.name
|
|
18
|
-
|
|
19
|
-
podspec = self.request.lg_spec.spec
|
|
20
|
-
else
|
|
21
|
-
podspec = nil
|
|
22
|
-
end
|
|
18
|
+
podspec = self.request.podspec
|
|
23
19
|
checkout_options = Hash.new.merge!(self.request.checkout_options)
|
|
24
20
|
http = checkout_options[:http]
|
|
25
21
|
git = checkout_options[:git]
|
|
26
22
|
tag = checkout_options[:tag]
|
|
27
23
|
branch = checkout_options[:branch]
|
|
28
24
|
checkout_options[:name] = name if name
|
|
29
|
-
checkout_options[:spec] = self.request.lg_spec if podspec
|
|
30
25
|
unless branch
|
|
31
26
|
branch = self.request.params[:branch] if self.request.params[:branch]
|
|
32
27
|
checkout_options[:branch] = branch if branch
|
|
33
28
|
end
|
|
34
29
|
commit = checkout_options[:commit]
|
|
35
|
-
# unless commit
|
|
36
|
-
# commit = self.request.params[:commit] if self.request.params[:commit]
|
|
37
|
-
# checkout_options[:commit] = commit if commit
|
|
38
|
-
# end
|
|
39
30
|
if branch
|
|
40
31
|
LgPodPlugin.log_green "Using `#{name}` (#{branch})"
|
|
41
32
|
elsif tag
|
|
@@ -49,10 +40,13 @@ module LgPodPlugin
|
|
|
49
40
|
LgPodPlugin.log_green "Using `#{name}`"
|
|
50
41
|
end
|
|
51
42
|
hash_map = self.request.get_cache_key_params
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
43
|
+
if request.single_git
|
|
44
|
+
commit = hash_map[:commit] unless commit
|
|
45
|
+
checkout_options[:commit] = commit if commit
|
|
46
|
+
pod_is_exist, destination, cache_pod_spec = LCache.new.pod_cache_exist(name, {:git => git}, podspec, self.request.released_pod)
|
|
47
|
+
else
|
|
48
|
+
pod_is_exist, destination, cache_pod_spec = LCache.new.pod_cache_exist(name, hash_map, podspec, self.request.released_pod)
|
|
49
|
+
end
|
|
56
50
|
if pod_is_exist
|
|
57
51
|
LgPodPlugin.log_green "find the cache of `#{name}`, you can use it now."
|
|
58
52
|
return nil
|
|
@@ -62,42 +56,9 @@ module LgPodPlugin
|
|
|
62
56
|
# 本地 git 下载 pod 目录
|
|
63
57
|
download_params = self.pre_download_git_repository(checkout_options)
|
|
64
58
|
if download_params && download_params.is_a?(Hash)
|
|
59
|
+
download_params["dirname"] = destination.dirname
|
|
65
60
|
download_params["destination"] = destination
|
|
66
61
|
download_params["cache_pod_spec_path"] = cache_pod_spec
|
|
67
|
-
podspec = download_params["podspec"]
|
|
68
|
-
podspec_content = download_params["podspec_content"]
|
|
69
|
-
if podspec
|
|
70
|
-
podspec_json = podspec.to_pretty_json
|
|
71
|
-
download_params["podspec_json"] = podspec_json if podspec
|
|
72
|
-
download_params["prepare_command"] = podspec.prepare_command if podspec
|
|
73
|
-
download_params.delete("podspec")
|
|
74
|
-
unless self.request.lg_spec
|
|
75
|
-
self.request.lg_spec = podspec
|
|
76
|
-
end
|
|
77
|
-
elsif podspec_content
|
|
78
|
-
path = download_params["path"]
|
|
79
|
-
podspec_path = path + "/#{name}.podspec"
|
|
80
|
-
begin
|
|
81
|
-
File.open(podspec_path,"w+") do|f|
|
|
82
|
-
f.write podspec_content
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
if File.exist?(podspec_path)
|
|
86
|
-
lg_spec = LgPodPlugin::PodSpec.form_file podspec_path
|
|
87
|
-
if lg_spec
|
|
88
|
-
self.request.lg_spec = lg_spec
|
|
89
|
-
download_params["podspec_json"] = lg_spec.to_pretty_json
|
|
90
|
-
download_params["source_files"] = lg_spec.source_files.keys
|
|
91
|
-
download_params["prepare_command"] = lg_spec.prepare_command if lg_spec.prepare_command
|
|
92
|
-
download_params.delete("podspec_content")
|
|
93
|
-
else
|
|
94
|
-
download_params["source_files"] = ["All"]
|
|
95
|
-
download_params["prepare_command"] = nil
|
|
96
|
-
download_params["podspec_json"] = podspec_content
|
|
97
|
-
download_params.delete("podspec_content")
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
62
|
return download_params
|
|
102
63
|
elsif File.exist?(download_params.to_s) && download_params
|
|
103
64
|
FileUtils.chdir download_params
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
2
|
require 'cocoapods/downloader'
|
|
3
3
|
require 'cocoapods/downloader/cache'
|
|
4
4
|
require 'cocoapods/downloader/response'
|
|
@@ -12,32 +12,34 @@ module LgPodPlugin
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
public
|
|
15
|
+
|
|
15
16
|
def pod_cache_exist(name, options, spec = nil, released_pod = false)
|
|
16
17
|
# 参数为空不执行下载任务, 交给 cocoapods 处理下载
|
|
17
18
|
if options.nil?
|
|
18
|
-
return
|
|
19
|
+
return [true, nil, nil]
|
|
19
20
|
end
|
|
20
|
-
|
|
21
21
|
destination, cache_pod_spec = self.find_pod_cache name, options, spec, released_pod
|
|
22
|
-
lock_temp_file = destination.to_path+ ".lock"
|
|
22
|
+
lock_temp_file = destination.to_path + ".lock"
|
|
23
23
|
if File.exist?(lock_temp_file)
|
|
24
24
|
FileUtils.rm_rf lock_temp_file
|
|
25
25
|
end
|
|
26
|
-
if
|
|
26
|
+
if destination && destination.exist? && !destination.children.empty?
|
|
27
27
|
return [true, destination, cache_pod_spec]
|
|
28
28
|
else
|
|
29
29
|
return [false, destination, cache_pod_spec]
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
# 判断缓存是否存在且有效命中缓存
|
|
34
|
+
|
|
34
35
|
public
|
|
36
|
+
|
|
35
37
|
def find_pod_cache(name, options, spec = nil, released_pod = false)
|
|
36
38
|
hash_map = Hash.new.merge!(options)
|
|
37
39
|
if hash_map.has_key?(:version)
|
|
38
40
|
hash_map.delete(:version)
|
|
39
41
|
end
|
|
40
|
-
request = LCache.
|
|
42
|
+
request = LCache.create_download_request(name, hash_map, spec, released_pod)
|
|
41
43
|
destination = LCache.path_for_pod(request)
|
|
42
44
|
cache_pod_spec = LCache.path_for_spec(request)
|
|
43
45
|
[destination, cache_pod_spec]
|
|
@@ -48,53 +50,72 @@ module LgPodPlugin
|
|
|
48
50
|
Pathname(path)
|
|
49
51
|
end
|
|
50
52
|
|
|
51
|
-
def self.
|
|
53
|
+
def self.create_download_request(name, params, spec = nil, released_pod = false)
|
|
52
54
|
if released_pod
|
|
53
|
-
Pod::Downloader::Request.new(spec: spec, released: true
|
|
55
|
+
Pod::Downloader::Request.new(spec: spec, released: true, name: name, params: params)
|
|
54
56
|
else
|
|
55
|
-
Pod::Downloader::Request.new(spec: nil, released: false
|
|
57
|
+
Pod::Downloader::Request.new(spec: nil, released: false, name: name, params: params)
|
|
56
58
|
end
|
|
57
59
|
end
|
|
58
|
-
#MARK - 缓存方法
|
|
59
|
-
def self.path_for_pod(request, slug_opts = {})
|
|
60
|
-
root = self.root_path
|
|
61
|
-
root + request.slug(**slug_opts)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def self.path_for_spec(request, slug_opts = {})
|
|
65
|
-
root = self.root_path
|
|
66
|
-
path = root + 'Specs' + request.slug(**slug_opts)
|
|
67
|
-
Pathname.new(path.to_path + '.podspec.json')
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
# def self.cached_spec(request)
|
|
71
|
-
# path = path_for_spec(request)
|
|
72
|
-
# path.file? && Specification.from_file(path)
|
|
73
|
-
# rescue JSON::ParserError
|
|
74
|
-
# nil
|
|
75
|
-
# end
|
|
76
60
|
|
|
77
|
-
def self.
|
|
61
|
+
def self.create_downloader_manager(request, target)
|
|
78
62
|
result = Pod::Downloader::Response.new
|
|
63
|
+
result.checkout_options = request.params
|
|
79
64
|
result.location = target
|
|
65
|
+
|
|
80
66
|
if request.released_pod?
|
|
81
67
|
result.spec = request.spec
|
|
82
|
-
|
|
83
|
-
return [request, local_specs]
|
|
68
|
+
podspecs = { request.name => request.spec }
|
|
84
69
|
else
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
pods_pecs.each do |name, spec|
|
|
70
|
+
podspecs = Pod::Sandbox::PodspecFinder.new(target).podspecs
|
|
71
|
+
podspecs[request.name] = request.spec if request.spec
|
|
72
|
+
podspecs.each do |name, spec|
|
|
89
73
|
if request.name == name
|
|
90
74
|
result.spec = spec
|
|
91
|
-
local_specs[request.name] = spec
|
|
92
75
|
end
|
|
93
76
|
end
|
|
94
77
|
end
|
|
95
|
-
|
|
78
|
+
|
|
79
|
+
[result, podspecs]
|
|
96
80
|
end
|
|
97
81
|
|
|
82
|
+
# def self.root_cache
|
|
83
|
+
# cache_path = LFileManager.cache_root_path
|
|
84
|
+
# return Pod::Downloader::Cache.new(cache_path)
|
|
85
|
+
# end
|
|
86
|
+
|
|
87
|
+
# MARK - 缓存方法
|
|
88
|
+
def self.path_for_pod(request, slug_opts = {})
|
|
89
|
+
root_path + request.slug(**slug_opts)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def self.path_for_spec(request, slug_opts = {})
|
|
93
|
+
path = root_path + 'Specs' + request.slug(**slug_opts)
|
|
94
|
+
return Pathname.new(path.to_path + '.podspec.json')
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
#
|
|
98
|
+
# def self.get_local_spec(request, target)
|
|
99
|
+
# result = Pod::Downloader::Response.new
|
|
100
|
+
# result.location = target
|
|
101
|
+
# if request.released_pod?
|
|
102
|
+
# result.spec = request.spec
|
|
103
|
+
# local_specs = { request.name => request.spec }
|
|
104
|
+
# return [request, local_specs]
|
|
105
|
+
# else
|
|
106
|
+
# local_specs = {}
|
|
107
|
+
# pods_pecs = Pod::Sandbox::PodspecFinder.new(target).podspecs
|
|
108
|
+
# pods_pecs[request.name] = request.spec if request.spec
|
|
109
|
+
# pods_pecs.each do |name, spec|
|
|
110
|
+
# if request.name == name
|
|
111
|
+
# result.spec = spec
|
|
112
|
+
# local_specs[request.name] = spec
|
|
113
|
+
# end
|
|
114
|
+
# end
|
|
115
|
+
# end
|
|
116
|
+
# [result, local_specs]
|
|
117
|
+
# end
|
|
118
|
+
|
|
98
119
|
def self.group_subspecs_by_platform(spec)
|
|
99
120
|
specs_by_platform = {}
|
|
100
121
|
[spec, *spec.recursive_subspecs].each do |ss|
|
|
@@ -107,36 +128,27 @@ module LgPodPlugin
|
|
|
107
128
|
end
|
|
108
129
|
|
|
109
130
|
def self.copy_and_clean(source, destination, spec)
|
|
110
|
-
|
|
131
|
+
attributes_hash = spec.send(:attributes_hash) || {}
|
|
132
|
+
name = attributes_hash["name"] ||= ""
|
|
133
|
+
specs_by_platform = self.group_subspecs_by_platform(spec)
|
|
111
134
|
destination.parent.mkpath
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
def self.clean_pod_unused_files(destination, spec)
|
|
121
|
-
specs_by_platform = group_subspecs_by_platform(spec)
|
|
122
|
-
destination.parent.mkpath
|
|
123
|
-
self.write_lock(destination) do
|
|
135
|
+
should_copy = source && source.exist? && !source.children.empty?
|
|
136
|
+
Pod::Downloader::Cache.write_lock(destination) do
|
|
137
|
+
if should_copy
|
|
138
|
+
FileUtils.rm_rf(destination)
|
|
139
|
+
FileUtils.cp_r(source, destination)
|
|
140
|
+
LgPodPlugin.log_green "-> Copy #{name} from #{source} to #{destination}"
|
|
141
|
+
end
|
|
124
142
|
Pod::Installer::PodSourcePreparer.new(spec, destination).prepare!
|
|
125
143
|
Pod::Sandbox::PodDirCleaner.new(destination, specs_by_platform).clean!
|
|
126
144
|
end
|
|
127
145
|
end
|
|
128
146
|
|
|
129
|
-
def self.write_lock(location, &block)
|
|
130
|
-
Pod::Downloader::Cache.lock(location, File::LOCK_SH, &block)
|
|
131
|
-
end
|
|
132
|
-
|
|
133
147
|
public
|
|
134
148
|
def self.write_spec(spec, path)
|
|
135
149
|
path.dirname.mkpath
|
|
136
150
|
Pod::Downloader::Cache.write_lock(path) do
|
|
137
|
-
path.open('w') { |f|
|
|
138
|
-
f.write spec.to_pretty_json
|
|
139
|
-
}
|
|
151
|
+
path.open('w') { |f| f.write spec.to_pretty_json }
|
|
140
152
|
end
|
|
141
153
|
end
|
|
142
154
|
|
|
@@ -146,11 +158,11 @@ module LgPodPlugin
|
|
|
146
158
|
checkout_options = Hash.new.deep_merge(options).reject do |key, val|
|
|
147
159
|
!key || !val
|
|
148
160
|
end
|
|
149
|
-
request =
|
|
150
|
-
|
|
151
|
-
pods_pecs.each do |
|
|
152
|
-
destination = path_for_pod
|
|
153
|
-
if !
|
|
161
|
+
request = create_download_request(name, checkout_options, spec, released_pod)
|
|
162
|
+
result, pods_pecs = create_downloader_manager(request, target)
|
|
163
|
+
pods_pecs.each do |name, s_spec|
|
|
164
|
+
destination = path_for_pod request, { :name => name, :params => checkout_options }
|
|
165
|
+
if !destination.exist? || destination.children.empty?
|
|
154
166
|
LgPodPlugin.log_green "Copying #{name} from `#{target}` to `#{destination}` "
|
|
155
167
|
copy_and_clean(target, destination, s_spec)
|
|
156
168
|
end
|
|
@@ -158,8 +170,13 @@ module LgPodPlugin
|
|
|
158
170
|
unless File.exist?(cache_pod_spec)
|
|
159
171
|
write_spec(s_spec, cache_pod_spec)
|
|
160
172
|
end
|
|
173
|
+
if request.name == name
|
|
174
|
+
result.location = destination
|
|
175
|
+
end
|
|
161
176
|
end
|
|
162
177
|
|
|
178
|
+
result
|
|
179
|
+
|
|
163
180
|
end
|
|
164
181
|
|
|
165
182
|
end
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'cocoapods'
|
|
4
1
|
require 'fileutils'
|
|
5
2
|
require 'tmpdir'
|
|
6
3
|
|
|
@@ -10,155 +7,9 @@ module Pod
|
|
|
10
7
|
# them in a cache directory.
|
|
11
8
|
#
|
|
12
9
|
class Cache
|
|
13
|
-
# @return [Pathname] The root directory where this cache store its
|
|
14
|
-
# downloads.
|
|
15
|
-
#
|
|
16
|
-
attr_reader :root
|
|
17
|
-
|
|
18
|
-
# Initialize a new instance
|
|
19
|
-
#
|
|
20
|
-
# @param [Pathname,String] root
|
|
21
|
-
# see {#root}
|
|
22
|
-
#
|
|
23
|
-
def initialize(root)
|
|
24
|
-
@root = Pathname(root)
|
|
25
|
-
ensure_matching_version
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
# Downloads the Pod from the given `request`
|
|
29
|
-
#
|
|
30
|
-
# @param [Request] request
|
|
31
|
-
# the request to be downloaded.
|
|
32
|
-
#
|
|
33
|
-
# @return [Response] the response from downloading `request`
|
|
34
|
-
#
|
|
35
|
-
def download_pod(request)
|
|
36
|
-
cached_pod(request) || uncached_pod(request)
|
|
37
|
-
rescue Informative
|
|
38
|
-
raise
|
|
39
|
-
rescue
|
|
40
|
-
UI.puts("\n[!] Error installing #{request.name}".red)
|
|
41
|
-
raise
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
# @return [Hash<String, Hash<Symbol, String>>]
|
|
45
|
-
# A hash whose keys are the pod name
|
|
46
|
-
# And values are a hash with the following keys:
|
|
47
|
-
# :spec_file : path to the spec file
|
|
48
|
-
# :name : name of the pod
|
|
49
|
-
# :version : pod version
|
|
50
|
-
# :release : boolean to tell if that's a release pod
|
|
51
|
-
# :slug : the slug path where the pod cache is located
|
|
52
|
-
#
|
|
53
|
-
def cache_descriptors_per_pod
|
|
54
|
-
specs_dir = root + 'Specs'
|
|
55
|
-
release_specs_dir = specs_dir + 'Release'
|
|
56
|
-
return {} unless specs_dir.exist?
|
|
57
|
-
|
|
58
|
-
spec_paths = specs_dir.find.select { |f| f.fnmatch('*.podspec.json') }
|
|
59
|
-
spec_paths.reduce({}) do |hash, spec_path|
|
|
60
|
-
spec = Specification.from_file(spec_path)
|
|
61
|
-
hash[spec.name] ||= []
|
|
62
|
-
is_release = spec_path.to_s.start_with?(release_specs_dir.to_s)
|
|
63
|
-
request = Downloader::Request.new(:spec => spec, :released => is_release)
|
|
64
|
-
hash[spec.name] << {
|
|
65
|
-
:spec_file => spec_path,
|
|
66
|
-
:name => spec.name,
|
|
67
|
-
:version => spec.version,
|
|
68
|
-
:release => is_release,
|
|
69
|
-
:slug => root + request.slug,
|
|
70
|
-
}
|
|
71
|
-
hash
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
10
|
|
|
75
|
-
# Convenience method for acquiring a shared lock to safely read from the
|
|
76
|
-
# cache. See `Cache.lock` for more details.
|
|
77
|
-
#
|
|
78
|
-
# @param [Pathname] location
|
|
79
|
-
# the path to require a lock for.
|
|
80
|
-
#
|
|
81
|
-
# @param [block] &block
|
|
82
|
-
# the block to execute inside the lock.
|
|
83
|
-
#
|
|
84
|
-
# @return [void]
|
|
85
|
-
#
|
|
86
|
-
def self.read_lock(location, &block)
|
|
87
|
-
Cache.lock(location, File::LOCK_SH, &block)
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
# Convenience method for acquiring an exclusive lock to safely write to
|
|
91
|
-
# the cache. See `Cache.lock` for more details.
|
|
92
|
-
#
|
|
93
|
-
# @param [Pathname] location
|
|
94
|
-
# the path to require a lock for.
|
|
95
|
-
#
|
|
96
|
-
# @param [block] &block
|
|
97
|
-
# the block to execute inside the lock.
|
|
98
|
-
#
|
|
99
|
-
# @return [void]
|
|
100
|
-
#
|
|
101
|
-
def self.write_lock(location, &block)
|
|
102
|
-
Cache.lock(location, File::LOCK_EX, &block)
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
# Creates a .lock file at `location`, aquires a lock of type
|
|
106
|
-
# `lock_type`, checks that it is valid, and executes passed block while
|
|
107
|
-
# holding on to that lock. Afterwards, the .lock file is deleted, which is
|
|
108
|
-
# why validation of the lock is necessary, as you might have a lock on a
|
|
109
|
-
# file that doesn't exist on the filesystem anymore.
|
|
110
|
-
#
|
|
111
|
-
# @param [Pathname] location
|
|
112
|
-
# the path to require a lock for.
|
|
113
|
-
#
|
|
114
|
-
# @param [locking_constant] lock_type
|
|
115
|
-
# the type of lock, either exclusive (File::LOCK_EX) or shared
|
|
116
|
-
# (File::LOCK_SH).
|
|
117
|
-
#
|
|
118
|
-
# @return [void]
|
|
119
|
-
#
|
|
120
|
-
def self.lock(location, lock_type)
|
|
121
|
-
raise ArgumentError, 'no block given' unless block_given?
|
|
122
|
-
lockfile = "#{location}.lock"
|
|
123
|
-
f = nil
|
|
124
|
-
loop do
|
|
125
|
-
f.close if f
|
|
126
|
-
f = File.open(lockfile, File::CREAT, 0o644)
|
|
127
|
-
f.flock(lock_type)
|
|
128
|
-
break if Cache.valid_lock?(f, lockfile)
|
|
129
|
-
end
|
|
130
|
-
begin
|
|
131
|
-
yield location
|
|
132
|
-
ensure
|
|
133
|
-
if lock_type == File::LOCK_SH
|
|
134
|
-
f.flock(File::LOCK_EX)
|
|
135
|
-
File.delete(lockfile) if Cache.valid_lock?(f, lockfile)
|
|
136
|
-
else
|
|
137
|
-
File.delete(lockfile)
|
|
138
|
-
end
|
|
139
|
-
f.close
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
# Checks that the lock is on a file that still exists on the filesystem.
|
|
144
|
-
#
|
|
145
|
-
# @param [File] file
|
|
146
|
-
# the actual file that we have a lock for.
|
|
147
|
-
#
|
|
148
|
-
# @param [String] filename
|
|
149
|
-
# the filename of the file that we have a lock for.
|
|
150
|
-
#
|
|
151
|
-
# @return [Boolean]
|
|
152
|
-
# true if `filename` still exists and is the same file as `file`
|
|
153
|
-
#
|
|
154
|
-
def self.valid_lock?(file, filename)
|
|
155
|
-
file.stat.ino == File.stat(filename).ino
|
|
156
|
-
rescue Errno::ENOENT
|
|
157
|
-
false
|
|
158
|
-
end
|
|
159
11
|
|
|
160
12
|
private
|
|
161
|
-
|
|
162
13
|
# Ensures the cache on disk was created with the same CocoaPods version as
|
|
163
14
|
# is currently running.
|
|
164
15
|
#
|
|
@@ -178,152 +29,6 @@ module Pod
|
|
|
178
29
|
end
|
|
179
30
|
end
|
|
180
31
|
|
|
181
|
-
# @param [Request] request
|
|
182
|
-
# the request to be downloaded.
|
|
183
|
-
#
|
|
184
|
-
# @param [Hash<Symbol,String>] slug_opts
|
|
185
|
-
# the download options that should be used in constructing the
|
|
186
|
-
# cache slug for this request.
|
|
187
|
-
#
|
|
188
|
-
# @return [Pathname] The path for the Pod downloaded from the given
|
|
189
|
-
# `request`.
|
|
190
|
-
#
|
|
191
|
-
def path_for_pod(request, slug_opts = {})
|
|
192
|
-
root + request.slug(**slug_opts)
|
|
193
|
-
end
|
|
194
|
-
|
|
195
|
-
# @param [Request] request
|
|
196
|
-
# the request to be downloaded.
|
|
197
|
-
#
|
|
198
|
-
# @param [Hash<Symbol,String>] slug_opts
|
|
199
|
-
# the download options that should be used in constructing the
|
|
200
|
-
# cache slug for this request.
|
|
201
|
-
#
|
|
202
|
-
# @return [Pathname] The path for the podspec downloaded from the given
|
|
203
|
-
# `request`.
|
|
204
|
-
#
|
|
205
|
-
def path_for_spec(request, slug_opts = {})
|
|
206
|
-
path = root + 'Specs' + request.slug(**slug_opts)
|
|
207
|
-
Pathname.new(path.to_path + '.podspec.json')
|
|
208
|
-
end
|
|
209
|
-
|
|
210
|
-
# @param [Request] request
|
|
211
|
-
# the request to be downloaded.
|
|
212
|
-
#
|
|
213
|
-
# @return [Response] The download response for the given `request` that
|
|
214
|
-
# was found in the download cache.
|
|
215
|
-
#
|
|
216
|
-
def cached_pod(request)
|
|
217
|
-
cached_spec = cached_spec(request)
|
|
218
|
-
path = path_for_pod(request)
|
|
219
|
-
|
|
220
|
-
return unless cached_spec && path.directory?
|
|
221
|
-
spec = request.spec || cached_spec
|
|
222
|
-
Response.new(path, spec, request.params)
|
|
223
|
-
end
|
|
224
|
-
|
|
225
|
-
# @param [Request] request
|
|
226
|
-
# the request to be downloaded.
|
|
227
|
-
#
|
|
228
|
-
# @return [Specification] The cached specification for the given
|
|
229
|
-
# `request`.
|
|
230
|
-
#
|
|
231
|
-
def cached_spec(request)
|
|
232
|
-
path = path_for_spec(request)
|
|
233
|
-
path.file? && Specification.from_file(path)
|
|
234
|
-
rescue JSON::ParserError
|
|
235
|
-
nil
|
|
236
|
-
end
|
|
237
|
-
|
|
238
|
-
# @param [Request] request
|
|
239
|
-
# the request to be downloaded.
|
|
240
|
-
#
|
|
241
|
-
# @return [Response] The download response for the given `request` that
|
|
242
|
-
# was not found in the download cache.
|
|
243
|
-
#
|
|
244
|
-
def uncached_pod(request)
|
|
245
|
-
in_tmpdir do |target|
|
|
246
|
-
result, podspecs = download(request, target)
|
|
247
|
-
result.location = nil
|
|
248
|
-
|
|
249
|
-
podspecs.each do |name, spec|
|
|
250
|
-
destination = path_for_pod(request, :name => name, :params => result.checkout_options)
|
|
251
|
-
copy_and_clean(target, destination, spec)
|
|
252
|
-
write_spec(spec, path_for_spec(request, :name => name, :params => result.checkout_options))
|
|
253
|
-
if request.name == name
|
|
254
|
-
result.location = destination
|
|
255
|
-
end
|
|
256
|
-
end
|
|
257
|
-
|
|
258
|
-
result
|
|
259
|
-
end
|
|
260
|
-
end
|
|
261
|
-
|
|
262
|
-
def download(request, target)
|
|
263
|
-
Downloader.download_request(request, target)
|
|
264
|
-
end
|
|
265
|
-
|
|
266
|
-
# Performs the given block inside a temporary directory,
|
|
267
|
-
# which is removed at the end of the block's scope.
|
|
268
|
-
#
|
|
269
|
-
# @return [Object] The return value of the given block
|
|
270
|
-
#
|
|
271
|
-
def in_tmpdir(&blk)
|
|
272
|
-
tmpdir = Pathname(Dir.mktmpdir)
|
|
273
|
-
blk.call(tmpdir)
|
|
274
|
-
ensure
|
|
275
|
-
FileUtils.remove_entry(tmpdir, :force => true) if tmpdir && tmpdir.exist?
|
|
276
|
-
end
|
|
277
|
-
|
|
278
|
-
# Copies the `source` directory to `destination`, cleaning the directory
|
|
279
|
-
# of any files unused by `spec`.
|
|
280
|
-
#
|
|
281
|
-
# @param [Pathname] source
|
|
282
|
-
#
|
|
283
|
-
# @param [Pathname] destination
|
|
284
|
-
#
|
|
285
|
-
# @param [Specification] spec
|
|
286
|
-
#
|
|
287
|
-
# @return [Void]
|
|
288
|
-
#
|
|
289
|
-
def copy_and_clean(source, destination, spec)
|
|
290
|
-
specs_by_platform = group_subspecs_by_platform(spec)
|
|
291
|
-
destination.parent.mkpath
|
|
292
|
-
Cache.write_lock(destination) do
|
|
293
|
-
FileUtils.rm_rf(destination)
|
|
294
|
-
FileUtils.cp_r(source, destination)
|
|
295
|
-
Pod::Installer::PodSourcePreparer.new(spec, destination).prepare!
|
|
296
|
-
Sandbox::PodDirCleaner.new(destination, specs_by_platform).clean!
|
|
297
|
-
end
|
|
298
|
-
end
|
|
299
|
-
|
|
300
|
-
def group_subspecs_by_platform(spec)
|
|
301
|
-
specs_by_platform = {}
|
|
302
|
-
[spec, *spec.recursive_subspecs].each do |ss|
|
|
303
|
-
ss.available_platforms.each do |platform|
|
|
304
|
-
specs_by_platform[platform] ||= []
|
|
305
|
-
specs_by_platform[platform] << ss
|
|
306
|
-
end
|
|
307
|
-
end
|
|
308
|
-
specs_by_platform
|
|
309
|
-
end
|
|
310
|
-
|
|
311
|
-
# Writes the given `spec` to the given `path`.
|
|
312
|
-
#
|
|
313
|
-
# @param [Specification] spec
|
|
314
|
-
# the specification to be written.
|
|
315
|
-
#
|
|
316
|
-
# @param [Pathname] path
|
|
317
|
-
# the path the specification is to be written to.
|
|
318
|
-
#
|
|
319
|
-
# @return [Void]
|
|
320
|
-
#
|
|
321
|
-
def write_spec(spec, path)
|
|
322
|
-
path.dirname.mkpath
|
|
323
|
-
Cache.write_lock(path) do
|
|
324
|
-
path.open('w') { |f| f.write spec.to_pretty_json }
|
|
325
|
-
end
|
|
326
|
-
end
|
|
327
32
|
end
|
|
328
33
|
end
|
|
329
|
-
end
|
|
34
|
+
end
|
|
@@ -6,22 +6,19 @@ module LgPodPlugin
|
|
|
6
6
|
class LRequest
|
|
7
7
|
attr_reader :target
|
|
8
8
|
attr_reader :name
|
|
9
|
-
attr_accessor :
|
|
9
|
+
attr_accessor :podspec
|
|
10
10
|
attr_reader :released_pod
|
|
11
11
|
attr_accessor :single_git
|
|
12
12
|
attr_accessor :config
|
|
13
13
|
attr_accessor :net_ping
|
|
14
14
|
attr_accessor :params
|
|
15
|
-
# attr_accessor :lockfile
|
|
16
15
|
attr_accessor :checkout_options
|
|
17
16
|
def initialize(pod)
|
|
18
17
|
@name = pod.name
|
|
18
|
+
@podspec = pod.spec
|
|
19
19
|
@target = pod.target
|
|
20
20
|
@released_pod = pod.released_pod
|
|
21
21
|
@checkout_options = pod.checkout_options
|
|
22
|
-
if pod.spec
|
|
23
|
-
@lg_spec = pod.spec
|
|
24
|
-
end
|
|
25
22
|
self.preprocess_request
|
|
26
23
|
end
|
|
27
24
|
|