Module: Pod::Private::PrivateCache
- Defined in:
- lib/cocoapods-modularization/private/private_cache.rb
Defined Under Namespace
Classes: BranchCache
Constant Summary collapse
- @@root_path =
Pathname.new(File.('~')) + 'Projects/Pods'
- @@path_map =
'.path_map.json'
- @@repo_map =
'.repo_map.json'
- @@path_map_path =
@@root_path + @@path_map
- @@repo_map_path =
@@root_path + @@repo_map
- @@binary_repo_key =
'binary'
- @@source_repo_key =
'source'
Class Method Summary collapse
- .binary_repo_url(name) ⇒ Object
- .cache_branch(branch_caches) ⇒ Object
- .cache_repo(repo_name, repo_url, is_binary) ⇒ Object
- .cached_branch_hash ⇒ Object
- .read_local_path(repo_name) ⇒ Object
- .root_path ⇒ Object
- .set_search_path(search_path) ⇒ Object
- .source_repo_url(name) ⇒ Object
- .start(repo_name) ⇒ Object
- .write_path_into_cache(repo_name, path) ⇒ Object
Class Method Details
.binary_repo_url(name) ⇒ Object
52 53 54 55 56 |
# File 'lib/cocoapods-modularization/private/private_cache.rb', line 52 def binary_repo_url(name) repo_url = repo_url(name, ".*?specs[-_]?binary") return nil unless repo_url.kind_of?(String) && repo_url.length > 0 repo_url end |
.cache_branch(branch_caches) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/cocoapods-modularization/private/private_cache.rb', line 68 def cache_branch(branch_caches) make_branch_cache_workspace_if_needed branch_hash = Hash.new branch_caches.each do |e| branch_hash[e.key] = {Meta::MetaConstants.branch_key => e.branch, Meta::MetaConstants.git_key => e.git} end File.open(Meta::MetaConstants.branch_cache_path, "w") { |io| io << branch_hash.to_yaml } end |
.cache_repo(repo_name, repo_url, is_binary) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/cocoapods-modularization/private/private_cache.rb', line 39 def cache_repo(repo_name, repo_url, is_binary) make_workspace repo_map = cached_repo_map if is_binary repo_map[@@binary_repo_key] = Hash[repo_name => repo_url] else repo_map[@@source_repo_key] = Hash[repo_name => repo_url] end File.open(@@repo_map_path, 'w') { |io| io << repo_map.to_json } end |
.cached_branch_hash ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/cocoapods-modularization/private/private_cache.rb', line 79 def cached_branch_hash unless File.exists?(Meta::MetaConstants.branch_cache_path) return Hash.new end yaml = YAML.load_file(Meta::MetaConstants.branch_cache_path) yaml end |
.read_local_path(repo_name) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/cocoapods-modularization/private/private_cache.rb', line 166 def read_local_path(repo_name) return "" unless File.exists?(@@path_map_path) content = File.open(@@path_map_path) json = JSON.load(content) local_path = json[repo_name] if json.kind_of?(Hash) return local_path if local_path.kind_of?(String) # 如果不存在, 先在search_path中寻找 local_path = locate_spec_in_search_path(repo_name) if local_path.kind_of?(String) write_path_into_cache(repo_name, local_path) return local_path end end |
.root_path ⇒ Object
64 65 66 |
# File 'lib/cocoapods-modularization/private/private_cache.rb', line 64 def root_path @@root_path end |
.set_search_path(search_path) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/cocoapods-modularization/private/private_cache.rb', line 88 def set_search_path(search_path) make_workspace() content = File.open(@@path_map_path) json = JSON.load(content) map = Hash.new if json.kind_of?(JSON) map = json.to_hash end map['search_path'] = search_path File.open(@@path_map_path, "w") { |io| io.puts map.to_json } end |
.source_repo_url(name) ⇒ Object
58 59 60 61 62 |
# File 'lib/cocoapods-modularization/private/private_cache.rb', line 58 def source_repo_url(name) repo_url = repo_url(name, ".*?specs[-_]?source") return nil unless repo_url.kind_of?(String) && repo_url.length > 0 repo_url end |
.start(repo_name) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/cocoapods-modularization/private/private_cache.rb', line 102 def start(repo_name) current_pwd = Dir.pwd # 1.检查repo_name合法性, 是否在repos中存在 repos_path = locate_repos_path(repo_name) raise "#{repo_name} not found in configured source, run 'pod mod config' or 'pod repo uppdate' at first" unless repos_path # 2.读取@@path_map缓存,是否有repo_name对应的pod的path存在 make_workspace() # 2.1 如果repo_name对应的path存在, 返回他 local_path = read_local_path(repo_name) return local_path if local_path.kind_of?(String) ## 2.3 使用repos的地址clone到@@root中并在@@path_map中写入缓存地址 version = Meta::MetaAccessor.version(repo_name) version_path = Pathname.new(repos_path) + repo_name raise "#{version}不存在, run `pod repo update #{File.basename(repos_path)}`" unless Dir.entries(version_path).include?(version) repo_spec_path = version_path + "#{version}/#{repo_name}.podspec" raise "#{repo_spec_path} 不存在, 不是一个合法的podspec" unless File.exists?(repo_spec_path) ## 切换workspace FileUtils.cd(@@root_path) ## 判断repo_name是否存在,如果存在,删除他,可能是一些临时文件 if File.exists?(repo_name) UI.puts '清空workspace' FileUtils.rm_rf(repo_name) end git_clone_command = package_clone_command(repo_spec_path, repo_name) UI.puts "clone #{repo_name} into #{@@root_path}" system_build(git_clone_command) ## 下载完成之后,把路径写入缓存 local_path = "#{@@root_path}/#{repo_name}" write_path_into_cache(repo_name, path) ## 结束后,重置pwd FileUtils.cd(current_pwd) return local_path end |
.write_path_into_cache(repo_name, path) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/cocoapods-modularization/private/private_cache.rb', line 145 def write_path_into_cache(repo_name, path) content = File.open(@@path_map_path) json = JSON.load(content) map = Hash.new if json.kind_of?(JSON) map = json.to_hash end map[repo_name] = path # path的上一级作为search_path search_path = json['search_path'] if search_path.kind_of?(String) && search_path.length > 0 map['search_path'] = search_path else map['search_path'] = Pathname.new(path).parent end File.open(@@path_map_path, "w") { |io| io.puts map.to_json } end |