From 6307bf8053cf3cd7768cf5de9dc31aa4928a17a6 Mon Sep 17 00:00:00 2001 From: leavez Date: Wed, 16 May 2018 23:53:35 +0800 Subject: [PATCH 1/3] add keep_source_code_for_prebuilt_frameworks! --- lib/cocoapods-binary/Main.rb | 10 ++++++++++ lib/cocoapods-binary/Prebuild.rb | 27 ++++++++++++++++++--------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/lib/cocoapods-binary/Main.rb b/lib/cocoapods-binary/Main.rb index 1903382..d45ae85 100644 --- a/lib/cocoapods-binary/Main.rb +++ b/lib/cocoapods-binary/Main.rb @@ -17,12 +17,22 @@ def enable_bitcode_for_prebuilt_frameworks! DSL.bitcode_enabled = true end + # Don't remove source code of prebuilt pods + # It may speed up the pod install if git didn't + # include the `Pods` folder + def keep_source_code_for_prebuilt_frameworks! + DSL.dont_remove_source_code = true + end + private class_attr_accessor :prebuild_all prebuild_all = false class_attr_accessor :bitcode_enabled bitcode_enabled = false + + class_attr_accessor :dont_remove_source_code + dont_remove_source_code = false end end end diff --git a/lib/cocoapods-binary/Prebuild.rb b/lib/cocoapods-binary/Prebuild.rb index 51ffaf3..979563e 100644 --- a/lib/cocoapods-binary/Prebuild.rb +++ b/lib/cocoapods-binary/Prebuild.rb @@ -166,15 +166,6 @@ def prebuild_frameworks! end # Remove useless files - # only keep manifest.lock and framework folder in _Prebuild - to_remain_files = ["Manifest.lock", File.basename(existed_framework_folder)] - to_delete_files = sandbox_path.children.select do |file| - filename = File.basename(file) - not to_remain_files.include?(filename) - end - to_delete_files.each do |path| - path.rmtree if path.exist? - end # remove useless pods all_needed_names = self.pod_targets.map(&:name).uniq useless_names = sandbox.exsited_framework_names.reject do |name| @@ -185,6 +176,24 @@ def prebuild_frameworks! path.rmtree if path.exist? end + if not Podfile::DSL.dont_remove_source_code + # only keep manifest.lock and framework folder in _Prebuild + to_remain_files = ["Manifest.lock", File.basename(existed_framework_folder)] + to_delete_files = sandbox_path.children.select do |file| + filename = File.basename(file) + not to_remain_files.include?(filename) + end + to_delete_files.each do |path| + path.rmtree if path.exist? + end + else + # just remove the tmp files + path = sandbox.root + 'Manifest.lock.tmp' + path.rmtree if path.exist? + end + + + end From 2d6bf2025570ea3722130da36f0255a226144ef4 Mon Sep 17 00:00:00 2001 From: leavez Date: Wed, 16 May 2018 23:53:57 +0800 Subject: [PATCH 2/3] add test case --- test/change_podfile.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/change_podfile.py b/test/change_podfile.py index 42dea4d..25d5c36 100644 --- a/test/change_podfile.py +++ b/test/change_podfile.py @@ -30,6 +30,8 @@ def save_to_podfile(text): def initial(): return (wrapper( """ +keep_source_code_for_prebuilt_frameworks! + pod "Masonry" """), """ @@ -39,6 +41,8 @@ def initial(): def addSwiftPod(): return (wrapper( """ +keep_source_code_for_prebuilt_frameworks! + pod "RxCocoa", :binary => true pod "Literal", :binary => true """), @@ -50,6 +54,8 @@ def addSwiftPod(): def revertToSourceCode(): return (wrapper( """ +keep_source_code_for_prebuilt_frameworks! + pod "RxCocoa", :binary => true pod "Literal" """), @@ -132,5 +138,5 @@ def universalFlag(): if __name__ == "__main__": arg = sys.argv[1] - print("change Podfile to: " + arg) + print("===================\nchange Podfile to: " + arg + "\n") save_to_podfile(globals()[arg]()) \ No newline at end of file From 0918862b76c69b245898d121f87a76e1dd726052 Mon Sep 17 00:00:00 2001 From: leavez Date: Thu, 17 May 2018 00:01:03 +0800 Subject: [PATCH 3/3] update readme for keep_source_code_for_prebuilt_frameworks! --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 01bffc5..a54a5e2 100644 --- a/README.md +++ b/README.md @@ -55,8 +55,11 @@ end If you want to disable binary for a specific pod when using `all_binary!`, place a `:binary => false` to it. +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. + If bitcode is needed, add a `enable_bitcode_for_prebuilt_frameworks!` before all targets in Podfile + #### Known Issues - doesn't support watchos now