Skip to content

Commit 5518f6a

Browse files
authored
Merge pull request #25 from leavez/keepSource
add flag to keep source files to speed up pod install
2 parents fa30f90 + 0918862 commit 5518f6a

File tree

4 files changed

+38
-10
lines changed

4 files changed

+38
-10
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,11 @@ end
5555

5656
If you want to disable binary for a specific pod when using `all_binary!`, place a `:binary => false` to it.
5757

58+
If your `Pods` folder is excluded from git, you may add `keep_source_code_for_prebuilt_frameworks!` in the head of Podfile to speed up pod install, as it won't download all the sources every time prebuilt pods have changes.
59+
5860
If bitcode is needed, add a `enable_bitcode_for_prebuilt_frameworks!` before all targets in Podfile
5961

62+
6063
#### Known Issues
6164

6265
- doesn't support watchos now

lib/cocoapods-binary/Main.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,22 @@ def enable_bitcode_for_prebuilt_frameworks!
1717
DSL.bitcode_enabled = true
1818
end
1919

20+
# Don't remove source code of prebuilt pods
21+
# It may speed up the pod install if git didn't
22+
# include the `Pods` folder
23+
def keep_source_code_for_prebuilt_frameworks!
24+
DSL.dont_remove_source_code = true
25+
end
26+
2027
private
2128
class_attr_accessor :prebuild_all
2229
prebuild_all = false
2330

2431
class_attr_accessor :bitcode_enabled
2532
bitcode_enabled = false
33+
34+
class_attr_accessor :dont_remove_source_code
35+
dont_remove_source_code = false
2636
end
2737
end
2838
end

lib/cocoapods-binary/Prebuild.rb

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,6 @@ def prebuild_frameworks!
166166
end
167167

168168
# Remove useless files
169-
# only keep manifest.lock and framework folder in _Prebuild
170-
to_remain_files = ["Manifest.lock", File.basename(existed_framework_folder)]
171-
to_delete_files = sandbox_path.children.select do |file|
172-
filename = File.basename(file)
173-
not to_remain_files.include?(filename)
174-
end
175-
to_delete_files.each do |path|
176-
path.rmtree if path.exist?
177-
end
178169
# remove useless pods
179170
all_needed_names = self.pod_targets.map(&:name).uniq
180171
useless_names = sandbox.exsited_framework_names.reject do |name|
@@ -185,6 +176,24 @@ def prebuild_frameworks!
185176
path.rmtree if path.exist?
186177
end
187178

179+
if not Podfile::DSL.dont_remove_source_code
180+
# only keep manifest.lock and framework folder in _Prebuild
181+
to_remain_files = ["Manifest.lock", File.basename(existed_framework_folder)]
182+
to_delete_files = sandbox_path.children.select do |file|
183+
filename = File.basename(file)
184+
not to_remain_files.include?(filename)
185+
end
186+
to_delete_files.each do |path|
187+
path.rmtree if path.exist?
188+
end
189+
else
190+
# just remove the tmp files
191+
path = sandbox.root + 'Manifest.lock.tmp'
192+
path.rmtree if path.exist?
193+
end
194+
195+
196+
188197
end
189198

190199

test/change_podfile.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ def save_to_podfile(text):
3030
def initial():
3131
return (wrapper(
3232
"""
33+
keep_source_code_for_prebuilt_frameworks!
34+
3335
pod "Masonry"
3436
"""),
3537
"""
@@ -39,6 +41,8 @@ def initial():
3941
def addSwiftPod():
4042
return (wrapper(
4143
"""
44+
keep_source_code_for_prebuilt_frameworks!
45+
4246
pod "RxCocoa", :binary => true
4347
pod "Literal", :binary => true
4448
"""),
@@ -50,6 +54,8 @@ def addSwiftPod():
5054
def revertToSourceCode():
5155
return (wrapper(
5256
"""
57+
keep_source_code_for_prebuilt_frameworks!
58+
5359
pod "RxCocoa", :binary => true
5460
pod "Literal"
5561
"""),
@@ -132,5 +138,5 @@ def universalFlag():
132138

133139
if __name__ == "__main__":
134140
arg = sys.argv[1]
135-
print("change Podfile to: " + arg)
141+
print("===================\nchange Podfile to: " + arg + "\n")
136142
save_to_podfile(globals()[arg]())

0 commit comments

Comments
 (0)