From fb5749270972c83e95d9bf44abdc0db75aba38e9 Mon Sep 17 00:00:00 2001 From: leavez Date: Tue, 8 May 2018 00:18:34 +0800 Subject: [PATCH 1/5] fix #20 correctly --- lib/cocoapods-binary/Integration.rb | 4 +++- lib/cocoapods-binary/Prebuild.rb | 13 ++++++++++++- lib/cocoapods-binary/helper/passer.rb | 8 ++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/cocoapods-binary/Integration.rb b/lib/cocoapods-binary/Integration.rb index 8208895..9bd36f1 100644 --- a/lib/cocoapods-binary/Integration.rb +++ b/lib/cocoapods-binary/Integration.rb @@ -154,9 +154,11 @@ def remove_target_files_if_needed prebuilt_specs.each do |spec| # `spec` may be a subspec, so we use the root's name root_name = spec.root.name + + target = name_to_target_hash[root_name] + next if Prebuild::Passer.target_names_to_skip_integration_framework.include? target.pod_name # use the prebuilt framework - target = name_to_target_hash[root_name] original_vendored_frameworks = spec.attributes_hash["vendored_frameworks"] || [] if original_vendored_frameworks.kind_of?(String) original_vendored_frameworks = [original_vendored_frameworks] diff --git a/lib/cocoapods-binary/Prebuild.rb b/lib/cocoapods-binary/Prebuild.rb index 355f58b..e330fa5 100644 --- a/lib/cocoapods-binary/Prebuild.rb +++ b/lib/cocoapods-binary/Prebuild.rb @@ -153,6 +153,17 @@ def prebuild_frameworks! # copy vendored libraries and frameworks targets.each do |target| root_path = self.sandbox.pod_dir(target.name) + target_folder = sandbox.framework_folder_path_for_pod_name(target.name) + + # If target shouldn't build, we copy all the original files + # This is for target with only .a and .h files + if not target.should_build? + Prebuild::Passer.target_names_to_skip_integration_framework ||= [] + Prebuild::Passer.target_names_to_skip_integration_framework << target.pod_name + FileUtils.cp_r(root_path, target_folder, :remove_destination => true) + next + end + target.spec_consumers.each do |consumer| file_accessor = Sandbox::FileAccessor.new(root_path, consumer) lib_paths = file_accessor.vendored_frameworks || [] @@ -160,7 +171,7 @@ def prebuild_frameworks! # @TODO dSYM files lib_paths.each do |lib_path| relative = lib_path.relative_path_from(root_path) - destination = sandbox.framework_folder_path_for_pod_name(target.name) + relative + destination = target_folder + relative destination.dirname.mkpath unless destination.dirname.exist? FileUtils.cp_r(lib_path, destination, :remove_destination => true) end diff --git a/lib/cocoapods-binary/helper/passer.rb b/lib/cocoapods-binary/helper/passer.rb index 9b81764..25ec203 100644 --- a/lib/cocoapods-binary/helper/passer.rb +++ b/lib/cocoapods-binary/helper/passer.rb @@ -26,6 +26,14 @@ class ResourcePath # # @return [Hash] class_attr_accessor :resources_to_copy_for_static_framework + + # Some pod won't be build in prebuild stage even if it have `binary=>true`. + # The targets of this pods have `should_build? == true`. + # We should skip integration (patch spec) for this pods + # + # @return [Array] + class_attr_accessor :target_names_to_skip_integration_framework + end end end \ No newline at end of file From 851aa8559cfd54e24e2ad9a989e4b732019680ed Mon Sep 17 00:00:00 2001 From: leavez Date: Tue, 8 May 2018 00:25:08 +0800 Subject: [PATCH 2/5] add content in test --- test/change_podfile.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/change_podfile.py b/test/change_podfile.py index 10e101d..190a785 100644 --- a/test/change_podfile.py +++ b/test/change_podfile.py @@ -58,6 +58,7 @@ def addVendoredLibPod(): pod "Literal", :binary => true pod "AFNetworking/Reachability", :binary => true pod "Instabug", :binary => true +pod "GrowingID", :binary => true """) def deleteAPod(): From 8038a04b399f58b72d09a3dfdd61052da74f6b43 Mon Sep 17 00:00:00 2001 From: leavez Date: Tue, 8 May 2018 00:28:24 +0800 Subject: [PATCH 3/5] fix crash --- lib/cocoapods-binary/Prebuild.rb | 2 -- lib/cocoapods-binary/helper/passer.rb | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cocoapods-binary/Prebuild.rb b/lib/cocoapods-binary/Prebuild.rb index e330fa5..5b99b55 100644 --- a/lib/cocoapods-binary/Prebuild.rb +++ b/lib/cocoapods-binary/Prebuild.rb @@ -143,7 +143,6 @@ def prebuild_frameworks! object.target_file_path = path.gsub('${PODS_ROOT}', standard_sandbox_path.to_s) object end - Prebuild::Passer.resources_to_copy_for_static_framework ||= {} Prebuild::Passer.resources_to_copy_for_static_framework[target.name] = path_objects end end @@ -158,7 +157,6 @@ def prebuild_frameworks! # If target shouldn't build, we copy all the original files # This is for target with only .a and .h files if not target.should_build? - Prebuild::Passer.target_names_to_skip_integration_framework ||= [] Prebuild::Passer.target_names_to_skip_integration_framework << target.pod_name FileUtils.cp_r(root_path, target_folder, :remove_destination => true) next diff --git a/lib/cocoapods-binary/helper/passer.rb b/lib/cocoapods-binary/helper/passer.rb index 25ec203..55ea724 100644 --- a/lib/cocoapods-binary/helper/passer.rb +++ b/lib/cocoapods-binary/helper/passer.rb @@ -26,6 +26,7 @@ class ResourcePath # # @return [Hash] class_attr_accessor :resources_to_copy_for_static_framework + resources_to_copy_for_static_framework = {} # Some pod won't be build in prebuild stage even if it have `binary=>true`. # The targets of this pods have `should_build? == true`. @@ -33,6 +34,7 @@ class ResourcePath # # @return [Array] class_attr_accessor :target_names_to_skip_integration_framework + target_names_to_skip_integration_framework = [] end end From 4ca445dc4540910f7bcc7e15f1b4459b9d2bb605 Mon Sep 17 00:00:00 2001 From: leavez Date: Tue, 8 May 2018 00:43:40 +0800 Subject: [PATCH 4/5] add import in test compile --- test/Binary.xcodeproj/project.pbxproj | 83 ++++++++++++++++++++++++--- test/Binary/import.swift | 4 ++ test/change_podfile.py | 57 +++++++++++++++--- 3 files changed, 127 insertions(+), 17 deletions(-) create mode 100644 test/Binary/import.swift diff --git a/test/Binary.xcodeproj/project.pbxproj b/test/Binary.xcodeproj/project.pbxproj index c50bf59..500ac27 100644 --- a/test/Binary.xcodeproj/project.pbxproj +++ b/test/Binary.xcodeproj/project.pbxproj @@ -7,15 +7,21 @@ objects = { /* Begin PBXBuildFile section */ + 3E1E218020A0B66900EFA102 /* import.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E1E217F20A0B66900EFA102 /* import.swift */; }; 3E83E326207BC00E0057855A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E83E325207BC00E0057855A /* AppDelegate.swift */; }; 3E83E328207BC00E0057855A /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E83E327207BC00E0057855A /* ViewController.swift */; }; + AEBC61E3160A9AC38C3A210D /* Pods_Binary.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5687B1A81F152DBEF5CD4432 /* Pods_Binary.framework */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 1856F5E2BE44EDB1E470521A /* Pods-Binary.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Binary.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Binary/Pods-Binary.debug.xcconfig"; sourceTree = ""; }; + 3E1E217F20A0B66900EFA102 /* import.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = import.swift; sourceTree = ""; }; 3E83E322207BC00E0057855A /* Binary.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Binary.app; sourceTree = BUILT_PRODUCTS_DIR; }; 3E83E325207BC00E0057855A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 3E83E327207BC00E0057855A /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 3E83E331207BC0120057855A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 5687B1A81F152DBEF5CD4432 /* Pods_Binary.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Binary.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 7EB848DBE64BD495BCC04ECC /* Pods-Binary.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Binary.release.xcconfig"; path = "Pods/Target Support Files/Pods-Binary/Pods-Binary.release.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -23,6 +29,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + AEBC61E3160A9AC38C3A210D /* Pods_Binary.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -34,6 +41,8 @@ children = ( 3E83E324207BC00E0057855A /* Binary */, 3E83E323207BC00E0057855A /* Products */, + E8117D681BF19C1B3D847824 /* Pods */, + 8E13F0A6AED19C681C2CD7D5 /* Frameworks */, ); sourceTree = ""; }; @@ -50,11 +59,29 @@ children = ( 3E83E325207BC00E0057855A /* AppDelegate.swift */, 3E83E327207BC00E0057855A /* ViewController.swift */, + 3E1E217F20A0B66900EFA102 /* import.swift */, 3E83E331207BC0120057855A /* Info.plist */, ); path = Binary; sourceTree = ""; }; + 8E13F0A6AED19C681C2CD7D5 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 5687B1A81F152DBEF5CD4432 /* Pods_Binary.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; + E8117D681BF19C1B3D847824 /* Pods */ = { + isa = PBXGroup; + children = ( + 1856F5E2BE44EDB1E470521A /* Pods-Binary.debug.xcconfig */, + 7EB848DBE64BD495BCC04ECC /* Pods-Binary.release.xcconfig */, + ); + name = Pods; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -62,9 +89,11 @@ isa = PBXNativeTarget; buildConfigurationList = 3E83E334207BC0120057855A /* Build configuration list for PBXNativeTarget "Binary" */; buildPhases = ( + 3E002C27AE1ACBCE5F745FA7 /* [CP] Check Pods Manifest.lock */, 3E83E31E207BC00E0057855A /* Sources */, 3E83E31F207BC00E0057855A /* Frameworks */, 3E83E320207BC00E0057855A /* Resources */, + 9937F6A880D56826534273F0 /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -118,12 +147,54 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + 3E002C27AE1ACBCE5F745FA7 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-Binary-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; + 9937F6A880D56826534273F0 /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "${SRCROOT}/Pods/Target Support Files/Pods-Binary/Pods-Binary-frameworks.sh", + "${PODS_ROOT}/AFNetworking/AFNetworking.framework", + "${PODS_ROOT}/Literal/Literal.framework", + ); + name = "[CP] Embed Pods Frameworks"; + outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/AFNetworking.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Literal.framework", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Binary/Pods-Binary-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ 3E83E31E207BC00E0057855A /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( 3E83E328207BC00E0057855A /* ViewController.swift in Sources */, + 3E1E218020A0B66900EFA102 /* import.swift in Sources */, 3E83E326207BC00E0057855A /* AppDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -247,13 +318,11 @@ }; 3E83E335207BC0120057855A /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 1856F5E2BE44EDB1E470521A /* Pods-Binary.debug.xcconfig */; buildSettings = { CODE_SIGN_STYLE = Automatic; INFOPLIST_FILE = Binary/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = me.leavez.Binary; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 4.0; @@ -263,13 +332,11 @@ }; 3E83E336207BC0120057855A /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 7EB848DBE64BD495BCC04ECC /* Pods-Binary.release.xcconfig */; buildSettings = { CODE_SIGN_STYLE = Automatic; INFOPLIST_FILE = Binary/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - ); + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = me.leavez.Binary; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 4.0; diff --git a/test/Binary/import.swift b/test/Binary/import.swift new file mode 100644 index 0000000..e7f7ccb --- /dev/null +++ b/test/Binary/import.swift @@ -0,0 +1,4 @@ + +import Literal +import AFNetworking +import Instabug diff --git a/test/change_podfile.py b/test/change_podfile.py index 190a785..6c70715 100644 --- a/test/change_podfile.py +++ b/test/change_podfile.py @@ -16,65 +16,104 @@ def save_to_podfile(text): path = os.path.dirname(os.path.abspath(__file__)) path += "/Podfile" file = open(path, "w+") - file.write(text) + file.write(text[0]) + file.close() + + path = os.path.dirname(os.path.abspath(__file__)) + path += "/Binary/import.swift" + file = open(path, "w+") + file.write(text[1]) file.close() + def initial(): - return wrapper( + return (wrapper( """ pod "Masonry" +"""), +""" +import Masonry """) def addSwiftPod(): - return wrapper( + return (wrapper( """ pod "Masonry", :binary => true pod "Literal", :binary => true +"""), +""" +import Masonry +import Literal """) def addDifferentNamePod(): - return wrapper( + return (wrapper( """ enable_bitcode_for_prebuilt_frameworks! pod "Masonry", :binary => true pod "Literal", :binary => true pod "lottie-ios", :binary => true +"""), +""" +import Masonry +import Literal +import Lottie """) + def addSubPod(): - return wrapper( + return (wrapper( """ pod "Masonry", :binary => true pod "Literal", :binary => true pod "lottie-ios", :binary => true pod "AFNetworking/Reachability", :binary => true +""") , +""" +import Masonry +import Literal +import Lottie +import AFNetworking """) def addVendoredLibPod(): - return wrapper( + return (wrapper( """ pod "Literal", :binary => true pod "AFNetworking/Reachability", :binary => true pod "Instabug", :binary => true -pod "GrowingID", :binary => true +pod "GrowingIO", :binary => true +""") , +""" +import Literal +import AFNetworking +import Instabug """) def deleteAPod(): - return wrapper( + return (wrapper( """ pod "Literal", :binary => true pod "AFNetworking/Reachability", :binary => true +""") , +""" +import Literal +import AFNetworking """) def universalFlag(): - return wrapper( + return (wrapper( """ all_binary! pod "Literal" pod "AFNetworking/Reachability" +""") , +""" +import Literal +import AFNetworking """) From aecf130d7e3e32b72611f9c9b8d2c986279230ef Mon Sep 17 00:00:00 2001 From: leavez Date: Tue, 8 May 2018 00:43:45 +0800 Subject: [PATCH 5/5] fix crash --- lib/cocoapods-binary/helper/passer.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/cocoapods-binary/helper/passer.rb b/lib/cocoapods-binary/helper/passer.rb index 55ea724..9bb7e03 100644 --- a/lib/cocoapods-binary/helper/passer.rb +++ b/lib/cocoapods-binary/helper/passer.rb @@ -26,15 +26,15 @@ class ResourcePath # # @return [Hash] class_attr_accessor :resources_to_copy_for_static_framework - resources_to_copy_for_static_framework = {} + self.resources_to_copy_for_static_framework = {} # Some pod won't be build in prebuild stage even if it have `binary=>true`. - # The targets of this pods have `should_build? == true`. + # The targets of this pods have `oshould_build? == true`. # We should skip integration (patch spec) for this pods # # @return [Array] class_attr_accessor :target_names_to_skip_integration_framework - target_names_to_skip_integration_framework = [] + self.target_names_to_skip_integration_framework = [] end end