cocoapods-bin-cache 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2309086892987cacb0dbda0a71142ba55cee8d0a1380d92b03b8e8aa2c5ed0ed
4
+ data.tar.gz: df110ea74f0390f05cb7bc96d3d44337392f1a8e5dbf49dabccdc515c63363e4
5
+ SHA512:
6
+ metadata.gz: 59a83cb71c056a5f4c80f111a1918ec412ab6113e9e66ca989ad47f75a95d2ed123e4a978bfd00c0ee106fa8cb17a7418e47e50c20d38efc2d9a2281bba72a3c
7
+ data.tar.gz: 92d443b6386ea6cb2505fc21262a1054591cb3c1c2cf9623fd1d8f6871384a3662ee5a7977d9bc25f1f1ea9adb9a295b4bafc395f131a84798cdebaca0425cc8
@@ -0,0 +1,3 @@
1
+ module CocoapodsBinCache
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1 @@
1
+ require 'cocoapods-bin-cache/gem_version'
@@ -0,0 +1,205 @@
1
+ require 'cocoapods-binary'
2
+
3
+ def patch_copy_bundle
4
+
5
+ Pod::Installer.define_method :prebuild_frameworks! do |*args|
6
+ puts "copy bundle fixed" .green << "\n"
7
+ Pod::Prebuild.check_one_pod_should_have_only_one_target(self.pod_targets)
8
+
9
+ # build options
10
+ sandbox_path = sandbox.root
11
+ existed_framework_folder = sandbox.generate_framework_path
12
+ bitcode_enabled = Pod::Podfile::DSL.bitcode_enabled
13
+ targets = []
14
+
15
+ if local_manifest != nil
16
+
17
+ changes = prebuild_pods_changes
18
+ added = changes.added
19
+ changed = changes.changed
20
+ unchanged = changes.unchanged
21
+ deleted = changes.deleted
22
+
23
+ existed_framework_folder.mkdir unless existed_framework_folder.exist?
24
+ exsited_framework_names = sandbox.exsited_framework_names
25
+
26
+ # additions
27
+ missing = unchanged.select do |pod_name|
28
+ not exsited_framework_names.include?(pod_name)
29
+ end
30
+
31
+
32
+ root_names_to_update = (added + changed + missing)
33
+
34
+ # transform names to targets
35
+ name_to_target_hash = self.pod_targets.reduce({}) do |sum, target|
36
+ sum[target.name] = target
37
+ sum
38
+ end
39
+ targets = root_names_to_update.map do |root_name|
40
+ t = name_to_target_hash[root_name]
41
+ raise "There's no target named (#{root_name}) in Pod.xcodeproj.\n #{name_to_target_hash.keys}" if t.nil?
42
+ t
43
+ end || []
44
+
45
+ # add the dendencies
46
+ dependency_targets = targets.map {|t| t.recursive_dependent_targets }.flatten.uniq || []
47
+ targets = (targets + dependency_targets).uniq
48
+ else
49
+ targets = self.pod_targets
50
+ end
51
+
52
+ targets = targets.reject {|pod_target| sandbox.local?(pod_target.pod_name) }
53
+
54
+
55
+ # build!
56
+ Pod::UI.puts "Prebuild frameworks (total #{targets.count})"
57
+ Pod::Prebuild.remove_build_dir(sandbox_path)
58
+ targets.each do |target|
59
+ if !target.should_build?
60
+ UI.puts "Prebuilding #{target.label}"
61
+ next
62
+ end
63
+
64
+ output_path = sandbox.framework_folder_path_for_pod_name(target.name)
65
+ output_path.mkpath unless output_path.exist?
66
+ Pod::Prebuild.build(sandbox_path, target, output_path, bitcode_enabled, Pod::Podfile::DSL.custom_build_options, Pod::Podfile::DSL.custom_build_options_simulator)
67
+
68
+ # save the resource paths for later installing
69
+ if target.static_framework? and !target.resource_paths.empty?
70
+ framework_path = output_path + target.framework_name
71
+ standard_sandbox_path = sandbox.standard_sanbox_path
72
+
73
+ resources = begin
74
+ if Pod::VERSION.start_with? "1.5"
75
+ target.resource_paths
76
+ else
77
+ # resource_paths is Hash{String=>Array<String>} on 1.6 and above
78
+ # (use AFNetworking to generate a demo data)
79
+ # https://github.com/leavez/cocoapods-binary/issues/50
80
+ target.resource_paths.values.flatten
81
+ end
82
+ end
83
+ raise "Wrong type: #{resources}" unless resources.kind_of? Array
84
+
85
+ path_objects = resources.map do |path|
86
+ object = Pod::Prebuild::Passer::ResourcePath.new
87
+ # object.real_file_path = framework_path + File.basename(path)
88
+ #liuao patch 修改resources的地址 xxx/xxx.framework/ => xxx/
89
+ object.real_file_path = sandbox.framework_folder_path_for_pod_name(target.name) + File.basename(path)
90
+ #liuao patch end
91
+ object.target_file_path = path.gsub('${PODS_ROOT}', standard_sandbox_path.to_s) if path.start_with? '${PODS_ROOT}'
92
+ object.target_file_path = path.gsub("${PODS_CONFIGURATION_BUILD_DIR}", standard_sandbox_path.to_s) if path.start_with? "${PODS_CONFIGURATION_BUILD_DIR}"
93
+ #liuao patch 如果是静态库且framework里没有bundle 从当前沙盒拷贝过去
94
+ realpath = object.target_file_path.gsub('Pods','Pods/_Prebuild')
95
+ if !object.real_file_path.exist? and target.static_framework? and Pathname(realpath).exist?
96
+ # byebug
97
+ FileUtils.cp_r(realpath, object.real_file_path, :remove_destination => true)
98
+ end
99
+ #liuao patch end
100
+ object
101
+ end
102
+ Pod::Prebuild::Passer.resources_to_copy_for_static_framework[target.name] = path_objects
103
+ end
104
+ end
105
+ Pod::Prebuild.remove_build_dir(sandbox_path)
106
+
107
+ # copy vendored libraries and frameworks
108
+ targets.each do |target|
109
+ root_path = self.sandbox.pod_dir(target.name)
110
+ target_folder = sandbox.framework_folder_path_for_pod_name(target.name)
111
+
112
+ # If target shouldn't build, we copy all the original files
113
+ # This is for target with only .a and .h files
114
+ if not target.should_build?
115
+ Prebuild::Passer.target_names_to_skip_integration_framework << target.pod_name
116
+ FileUtils.cp_r(root_path, target_folder, :remove_destination => true)
117
+ next
118
+ end
119
+
120
+ target.spec_consumers.each do |consumer|
121
+ file_accessor = Pod::Sandbox::FileAccessor.new(root_path, consumer)
122
+ lib_paths = file_accessor.vendored_frameworks || []
123
+ lib_paths += file_accessor.vendored_libraries
124
+ # @TODO dSYM files
125
+ lib_paths.each do |lib_path|
126
+ relative = lib_path.relative_path_from(root_path)
127
+ destination = target_folder + relative
128
+ destination.dirname.mkpath unless destination.dirname.exist?
129
+ FileUtils.cp_r(lib_path, destination, :remove_destination => true)
130
+ end
131
+ end
132
+ end
133
+
134
+ # Remove useless files
135
+ # remove useless pods
136
+ all_needed_names = self.pod_targets.map(&:name).uniq
137
+ useless_names = sandbox.exsited_framework_names.reject do |name|
138
+ all_needed_names.include? name
139
+ end
140
+ useless_names.each do |name|
141
+ path = sandbox.framework_folder_path_for_pod_name(name)
142
+ path.rmtree if path.exist?
143
+ end
144
+
145
+ if not Pod::Podfile::DSL.dont_remove_source_code
146
+ # only keep manifest.lock and framework folder in _Prebuild
147
+ to_remain_files = ["Manifest.lock", File.basename(existed_framework_folder)]
148
+ to_delete_files = sandbox_path.children.select do |file|
149
+ filename = File.basename(file)
150
+ not to_remain_files.include?(filename)
151
+ end
152
+ to_delete_files.each do |path|
153
+ path.rmtree if path.exist?
154
+ end
155
+ else
156
+ # just remove the tmp files
157
+ path = sandbox.root + 'Manifest.lock.tmp'
158
+ path.rmtree if path.exist?
159
+ end
160
+
161
+ end
162
+
163
+ end
164
+
165
+
166
+ def patch_copy_dysms
167
+ puts "copy dysms fixed" .green << "\n"
168
+ def patch(generated_projects)
169
+ generated_projects.each do |project|
170
+ project.targets.each do |target|
171
+ target.shell_script_build_phases.each do |phase|
172
+ script = phase.shell_script
173
+ if script.include? "-copy-dsyms.sh\""
174
+ script = script.delete_prefix "\"${PODS_ROOT}/"
175
+ script = script.delete_suffix "\"\n"
176
+ script = "Pods/" + script
177
+ contents = File.read(script)
178
+ contents = contents.gsub(/-av/, "-r -L -p -t -g -o -D -v")
179
+ File.open(script, "w") do |file|
180
+ file.puts contents
181
+ end
182
+ end
183
+ end
184
+ end
185
+ end
186
+ end
187
+
188
+ Pod::Installer.define_method :generate_pods_project do |*args|
189
+ stage_sandbox(sandbox, pod_targets)
190
+
191
+ cache_analysis_result = analyze_project_cache
192
+ pod_targets_to_generate = cache_analysis_result.pod_targets_to_generate
193
+ aggregate_targets_to_generate = cache_analysis_result.aggregate_targets_to_generate
194
+
195
+ clean_sandbox(pod_targets_to_generate)
196
+
197
+ create_and_save_projects(pod_targets_to_generate, aggregate_targets_to_generate,
198
+ cache_analysis_result.build_configurations, cache_analysis_result.project_object_version)
199
+ patch @generated_projects
200
+ Pod::Installer::SandboxDirCleaner.new(sandbox, pod_targets, aggregate_targets).clean!
201
+
202
+ update_project_cache(cache_analysis_result, target_installation_results)
203
+ end
204
+
205
+ end
@@ -0,0 +1,85 @@
1
+ require 'cocoapods-binary'
2
+ require_relative './cocoapods-binary-patch'
3
+ Pod::HooksManager.register('cocoapods-bin-cache', :post_install) do |installer_context|
4
+ if Pod::Podfile::DSL.cache_enabled
5
+ oldmethod = Pod::Prebuild.singleton_method(:build)
6
+ Pod::Prebuild.define_singleton_method :build do |*args|
7
+ target = args[1]
8
+ output_path = args[2]
9
+ prebuild_bin = Pathname(Pod::Podfile::DSL.cache_path + (target.name + target.version + '.zip'))
10
+ if prebuild_bin.exist?
11
+ def extract_zip(file, destination)
12
+ FileUtils.mkdir_p(destination) unless destination.exist?
13
+ `unzip -o #{file} -d #{destination}`
14
+ end
15
+ puts (target.name + ' prebuild cache hit,skip prebuilding🎉🎉') .green << "\n"
16
+ extract_zip(prebuild_bin,output_path)
17
+ else
18
+ puts (target.name + ' has no prebuild cache,start prebuilding🔧🔧') .yellow << "\n"
19
+ oldmethod.call(*args)
20
+ `pushd #{output_path} && zip -r #{prebuild_bin} . && popd`
21
+ end
22
+ end
23
+ end
24
+
25
+ if Pod::Podfile::DSL.copy_bunlde_fixed
26
+ patch_copy_bundle
27
+ end
28
+
29
+ if Pod::Podfile::DSL.copy_dysms_fixed
30
+ patch_copy_dysms
31
+ end
32
+
33
+ end
34
+
35
+
36
+ module Pod
37
+ class Podfile
38
+ module DSL
39
+ @@fix_copy_bundle = false
40
+ @@fix_copy_dysms = false
41
+ @@bin_cache_path = nil
42
+ @@enable_prebuild_cache = true
43
+ def self.cache_path
44
+ @@bin_cache_path ||= Pathname(File.expand_path('~') + '/.cocoapods-bin-cache')
45
+ FileUtils.mkdir_p(@@bin_cache_path) unless @@bin_cache_path.exist?
46
+ @@bin_cache_path
47
+ end
48
+
49
+ def self.cache_enabled
50
+ @@enable_prebuild_cache
51
+ end
52
+
53
+ def self.copy_bunlde_fixed
54
+ @@fix_copy_bundle
55
+ end
56
+
57
+ def self.copy_dysms_fixed
58
+ @@fix_copy_dysms
59
+ end
60
+
61
+ def enable_bin_cache
62
+ @@enable_prebuild_cache = true
63
+ end
64
+
65
+ def disable_bin_cache
66
+ @@enable_prebuild_cache = false
67
+ end
68
+
69
+ def fix_copy_bundle
70
+ @@fix_copy_bundle = true
71
+ end
72
+
73
+ def fix_copy_dysms
74
+ @@fix_copy_dysms = true
75
+ end
76
+
77
+
78
+ def set_bin_cache_path(path)
79
+ pathname = Pathname(path)
80
+ raise 'bin_cache_path not exist' unless pathname.exist?
81
+ @@bin_cache_path = pathname
82
+ end
83
+ end
84
+ end
85
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cocoapods-bin-cache
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - royliu1990
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-01-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A short description of cocoapods-bin-cache.
42
+ email:
43
+ - royliu.chengdu@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/cocoapods-bin-cache.rb
49
+ - lib/cocoapods-bin-cache/gem_version.rb
50
+ - lib/cocoapods-binary-patch.rb
51
+ - lib/cocoapods_plugin.rb
52
+ homepage: https://github.com/EXAMPLE/cocoapods-bin-cache
53
+ licenses:
54
+ - MIT
55
+ metadata: {}
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubygems_version: 3.0.3
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: A longer description of cocoapods-bin-cache.
75
+ test_files: []