From 2238d25dc295ce40e832a8006f012c7af8fafbdd Mon Sep 17 00:00:00 2001 From: leavez Date: Wed, 4 Jul 2018 23:59:53 +0800 Subject: [PATCH 01/25] remove filter for watchos --- lib/cocoapods-binary/helper/feature_switches.rb | 5 ----- lib/cocoapods-binary/helper/podfile_options.rb | 5 +---- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/lib/cocoapods-binary/helper/feature_switches.rb b/lib/cocoapods-binary/helper/feature_switches.rb index 643b7bb..388ef8c 100644 --- a/lib/cocoapods-binary/helper/feature_switches.rb +++ b/lib/cocoapods-binary/helper/feature_switches.rb @@ -38,11 +38,6 @@ def self.enable_prebuild_patch(value) end if should_prebuild and (not local) - if current_target_definition.platform == :watchos - # watchos isn't supported currently - Pod::UI.warn "Binary doesn't support watchos currently: #{name}. You can manually set `binary => false` for this pod to suppress this warning." - return - end old_method.bind(self).(name, *args) end end diff --git a/lib/cocoapods-binary/helper/podfile_options.rb b/lib/cocoapods-binary/helper/podfile_options.rb index 596ae61..432f2d4 100644 --- a/lib/cocoapods-binary/helper/podfile_options.rb +++ b/lib/cocoapods-binary/helper/podfile_options.rb @@ -23,9 +23,6 @@ def parse_prebuild_framework(name, requirements) def set_prebuild_for_pod(pod_name, should_prebuild) if should_prebuild == true - # watchos isn't supported currently - return if self.platform == :watchos - @prebuild_framework_names ||= [] @prebuild_framework_names.push pod_name else @@ -71,7 +68,7 @@ def prebuild_pod_targets all = [] - aggregate_targets = self.aggregate_targets.select { |a| a.platform != :watchos } + aggregate_targets = self.aggregate_targets aggregate_targets.each do |aggregate_target| target_definition = aggregate_target.target_definition targets = aggregate_target.pod_targets || [] From 69bc8c3788dae5fbb0ab9d82bf4d5d49da7a530d Mon Sep 17 00:00:00 2001 From: leavez Date: Sat, 7 Jul 2018 01:13:37 +0800 Subject: [PATCH 02/25] fix prebuild framework paths when have multiple platforms --- lib/cocoapods-binary/rome/build_framework.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/cocoapods-binary/rome/build_framework.rb b/lib/cocoapods-binary/rome/build_framework.rb index edbcd6f..b7840b1 100644 --- a/lib/cocoapods-binary/rome/build_framework.rb +++ b/lib/cocoapods-binary/rome/build_framework.rb @@ -19,7 +19,7 @@ def build_for_iosish_platform(sandbox, deployment_target = target.platform.deployment_target.to_s - target_label = target.label + target_label = target.label # name with platform if it's used in multiple platforms Pod::UI.puts "Prebuilding #{target_label}..." other_options = [] @@ -30,10 +30,9 @@ def build_for_iosish_platform(sandbox, xcodebuild(sandbox, target_label, simulator, deployment_target, other_options + ['ARCHS=x86_64', 'ONLY_ACTIVE_ARCH=NO']) # paths - root_name = target.pod_name module_name = target.product_module_name - device_framwork_path = "#{build_dir}/#{CONFIGURATION}-#{device}/#{root_name}/#{module_name}.framework" - simulator_framwork_path = "#{build_dir}/#{CONFIGURATION}-#{simulator}/#{root_name}/#{module_name}.framework" + device_framwork_path = "#{build_dir}/#{CONFIGURATION}-#{device}/#{target_label}/#{module_name}.framework" + simulator_framwork_path = "#{build_dir}/#{CONFIGURATION}-#{simulator}/#{target_label}/#{module_name}.framework" device_binary = device_framwork_path + "/#{module_name}" simulator_binary = simulator_framwork_path + "/#{module_name}" @@ -41,7 +40,7 @@ def build_for_iosish_platform(sandbox, # the device_lib path is the final output file path # combine the bianries - tmp_lipoed_binary_path = "#{build_dir}/#{root_name}" + tmp_lipoed_binary_path = "#{build_dir}/#{target_label}" lipo_log = `lipo -create -output #{tmp_lipoed_binary_path} #{device_binary} #{simulator_binary}` puts lipo_log unless File.exist?(tmp_lipoed_binary_path) FileUtils.mv tmp_lipoed_binary_path, device_binary, :force => true From cfe476404a559b410806e2ffb3fae56f61e9237a Mon Sep 17 00:00:00 2001 From: leavez Date: Sat, 7 Jul 2018 01:14:25 +0800 Subject: [PATCH 03/25] rome supports build watchos --- lib/cocoapods-binary/rome/build_framework.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/cocoapods-binary/rome/build_framework.rb b/lib/cocoapods-binary/rome/build_framework.rb index b7840b1..7986e6d 100644 --- a/lib/cocoapods-binary/rome/build_framework.rb +++ b/lib/cocoapods-binary/rome/build_framework.rb @@ -15,7 +15,8 @@ def build_for_iosish_platform(sandbox, target, device, simulator, - bitcode_enabled) + bitcode_enabled, + simulator_default_arch) deployment_target = target.platform.deployment_target.to_s @@ -27,7 +28,7 @@ def build_for_iosish_platform(sandbox, other_options += ['OTHER_CFLAGS="-fembed-bitcode"'] end xcodebuild(sandbox, target_label, device, deployment_target, other_options) - xcodebuild(sandbox, target_label, simulator, deployment_target, other_options + ['ARCHS=x86_64', 'ONLY_ACTIVE_ARCH=NO']) + xcodebuild(sandbox, target_label, simulator, deployment_target, other_options + ["ARCHS=#{simulator_default_arch}",'ONLY_ACTIVE_ARCH=NO']) # paths module_name = target.product_module_name @@ -92,10 +93,10 @@ def self.build(sandbox_root_path, target, output_path, bitcode_enabled = false) # -- build the framework case target.platform.name - when :ios then build_for_iosish_platform(sandbox, build_dir, output_path, target, 'iphoneos', 'iphonesimulator', bitcode_enabled) + when :ios then build_for_iosish_platform(sandbox, build_dir, output_path, target, 'iphoneos', 'iphonesimulator', bitcode_enabled, "x86_64") when :osx then xcodebuild(sandbox, target.label) # when :tvos then build_for_iosish_platform(sandbox, build_dir, target, 'appletvos', 'appletvsimulator') - # when :watchos then build_for_iosish_platform(sandbox, build_dir, target, 'watchos', 'watchsimulator') + when :watchos then build_for_iosish_platform(sandbox, build_dir, output_path, target, 'watchos', 'watchsimulator', true, "i386") else raise "Unsupported platform for '#{target.name}': '#{target.platform.name}'" end raise Pod::Informative, 'The build directory was not found in the expected location.' unless build_dir.directory? From 1e357dc10071751887e785f23845eade604e8921 Mon Sep 17 00:00:00 2001 From: leavez Date: Sat, 7 Jul 2018 01:41:46 +0800 Subject: [PATCH 04/25] simplify label with target.name --- lib/cocoapods-binary/rome/build_framework.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/cocoapods-binary/rome/build_framework.rb b/lib/cocoapods-binary/rome/build_framework.rb index 7986e6d..e8cb7e8 100644 --- a/lib/cocoapods-binary/rome/build_framework.rb +++ b/lib/cocoapods-binary/rome/build_framework.rb @@ -31,9 +31,10 @@ def build_for_iosish_platform(sandbox, xcodebuild(sandbox, target_label, simulator, deployment_target, other_options + ["ARCHS=#{simulator_default_arch}",'ONLY_ACTIVE_ARCH=NO']) # paths + target_name = target.name # equals target.label, like "AFNeworking-iOS" when AFNetworking is used in multiple platforms. module_name = target.product_module_name - device_framwork_path = "#{build_dir}/#{CONFIGURATION}-#{device}/#{target_label}/#{module_name}.framework" - simulator_framwork_path = "#{build_dir}/#{CONFIGURATION}-#{simulator}/#{target_label}/#{module_name}.framework" + device_framwork_path = "#{build_dir}/#{CONFIGURATION}-#{device}/#{target_name}/#{module_name}.framework" + simulator_framwork_path = "#{build_dir}/#{CONFIGURATION}-#{simulator}/#{target_name}/#{module_name}.framework" device_binary = device_framwork_path + "/#{module_name}" simulator_binary = simulator_framwork_path + "/#{module_name}" @@ -41,7 +42,7 @@ def build_for_iosish_platform(sandbox, # the device_lib path is the final output file path # combine the bianries - tmp_lipoed_binary_path = "#{build_dir}/#{target_label}" + tmp_lipoed_binary_path = "#{build_dir}/#{target_name}" lipo_log = `lipo -create -output #{tmp_lipoed_binary_path} #{device_binary} #{simulator_binary}` puts lipo_log unless File.exist?(tmp_lipoed_binary_path) FileUtils.mv tmp_lipoed_binary_path, device_binary, :force => true From 710839eafdaedc5d06321ac393612d604656b0eb Mon Sep 17 00:00:00 2001 From: leavez Date: Sat, 7 Jul 2018 02:04:09 +0800 Subject: [PATCH 05/25] rename framework_folder_path_for_pod_name to framework_folder_path_for_target_name --- lib/cocoapods-binary/Integration.rb | 2 +- lib/cocoapods-binary/Prebuild.rb | 6 +++--- lib/cocoapods-binary/helper/prebuild_sandbox.rb | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/cocoapods-binary/Integration.rb b/lib/cocoapods-binary/Integration.rb index 9bd36f1..997fc12 100644 --- a/lib/cocoapods-binary/Integration.rb +++ b/lib/cocoapods-binary/Integration.rb @@ -24,7 +24,7 @@ def install_for_prebuild!(standard_sanbox) # make a symlink to target folder prebuild_sandbox = Pod::PrebuildSandbox.from_standard_sandbox(standard_sanbox) - real_file_folder = prebuild_sandbox.framework_folder_path_for_pod_name(self.name) + real_file_folder = prebuild_sandbox.framework_folder_path_for_target_name(self.name) target_folder = standard_sanbox.pod_dir(self.name) target_folder.rmtree if target_folder.exist? diff --git a/lib/cocoapods-binary/Prebuild.rb b/lib/cocoapods-binary/Prebuild.rb index 979563e..9bcf412 100644 --- a/lib/cocoapods-binary/Prebuild.rb +++ b/lib/cocoapods-binary/Prebuild.rb @@ -117,8 +117,8 @@ def prebuild_frameworks! Pod::Prebuild.remove_build_dir(sandbox_path) targets.each do |target| next unless target.should_build? + output_path = sandbox.framework_folder_path_for_target_name(target.name) - output_path = sandbox.framework_folder_path_for_pod_name(target.name) output_path.mkpath unless output_path.exist? Pod::Prebuild.build(sandbox_path, target, output_path, bitcode_enabled) @@ -141,7 +141,7 @@ 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) + target_folder = sandbox.framework_folder_path_for_target_name(target.name) # If target shouldn't build, we copy all the original files # This is for target with only .a and .h files @@ -172,7 +172,7 @@ def prebuild_frameworks! all_needed_names.include? name end useless_names.each do |name| - path = sandbox.framework_folder_path_for_pod_name(name) + path = sandbox.framework_folder_path_for_target_name(name) path.rmtree if path.exist? end diff --git a/lib/cocoapods-binary/helper/prebuild_sandbox.rb b/lib/cocoapods-binary/helper/prebuild_sandbox.rb index 8bfb14b..8e84170 100644 --- a/lib/cocoapods-binary/helper/prebuild_sandbox.rb +++ b/lib/cocoapods-binary/helper/prebuild_sandbox.rb @@ -19,7 +19,7 @@ def generate_framework_path self.root + "GeneratedFrameworks" end - def framework_folder_path_for_pod_name(name) + def framework_folder_path_for_target_name(name) self.generate_framework_path + name end From a8985c52643e2684ae9f10ca757c768613e3dbf3 Mon Sep 17 00:00:00 2001 From: leavez Date: Sat, 7 Jul 2018 03:06:02 +0800 Subject: [PATCH 06/25] installing prebuild pod support multiple platforms --- lib/cocoapods-binary/Integration.rb | 77 ++++++++++++------- lib/cocoapods-binary/helper/names.rb | 62 +++++++++++++++ .../helper/prebuild_sandbox.rb | 2 + 3 files changed, 112 insertions(+), 29 deletions(-) create mode 100644 lib/cocoapods-binary/helper/names.rb diff --git a/lib/cocoapods-binary/Integration.rb b/lib/cocoapods-binary/Integration.rb index 997fc12..7c7cad7 100644 --- a/lib/cocoapods-binary/Integration.rb +++ b/lib/cocoapods-binary/Integration.rb @@ -2,6 +2,8 @@ require_relative 'helper/feature_switches' require_relative 'helper/prebuild_sandbox' require_relative 'helper/passer' +require_relative 'helper/names' + # NOTE: @@ -24,13 +26,10 @@ def install_for_prebuild!(standard_sanbox) # make a symlink to target folder prebuild_sandbox = Pod::PrebuildSandbox.from_standard_sandbox(standard_sanbox) - real_file_folder = prebuild_sandbox.framework_folder_path_for_target_name(self.name) - - target_folder = standard_sanbox.pod_dir(self.name) - target_folder.rmtree if target_folder.exist? - target_folder.mkdir - - # make a relatvie symbol link for all children + # if spec used in multiple platforms, it may return multiple paths + target_names = root_spec.prebuild_target_names_in_prebuild_sandbox(prebuild_sandbox) + + def walk(path, &action) path.children.each do |child| result = action.call(child, &action) @@ -50,31 +49,51 @@ def mirror_with_symlink(source, basefolder, target_folder) target = target_folder + source.relative_path_from(basefolder) make_link(source, target) end - - # symbol link copy all substructure - walk(real_file_folder) do |child| - source = child - # only make symlink to file and `.framework` folder - if child.directory? and child.extname == ".framework" - mirror_with_symlink(source, real_file_folder, target_folder) - next false # return false means don't go deeper - elsif child.file? - mirror_with_symlink(source, real_file_folder, target_folder) - next true - else - next true + + target_names.each do |name| + + # symbol link copy all substructure + real_file_folder = prebuild_sandbox.framework_folder_path_for_target_name(name) + + # If have only one platform, just place int the root folder of this pod. + # If have multiple paths, we use a sperated folder to store different + # platform frameworks. e.g. AFNetworking/AFNetworking-iOS/AFNetworking.framework + + target_folder = standard_sanbox.pod_dir(self.name) + if target_names.count > 1 + target_folder += real_file_folder.basename end - end + target_folder.rmtree if target_folder.exist? + target_folder.mkpath + + + walk(real_file_folder) do |child| + source = child + # only make symlink to file and `.framework` folder + if child.directory? and child.extname == ".framework" + mirror_with_symlink(source, real_file_folder, target_folder) + next false # return false means don't go deeper + elsif child.file? + mirror_with_symlink(source, real_file_folder, target_folder) + next true + else + next true + end + end + - # symbol link copy resource for static framework - hash = Prebuild::Passer.resources_to_copy_for_static_framework || {} - path_objects = hash[self.name] - if path_objects != nil - path_objects.each do |object| - make_link(object.real_file_path, object.target_file_path) + # symbol link copy resource for static framework + hash = Prebuild::Passer.resources_to_copy_for_static_framework || {} + + path_objects = hash[name] + if path_objects != nil + path_objects.each do |object| + make_link(object.real_file_path, object.target_file_path) + end end - end - end + end # of for each + + end # of method end end diff --git a/lib/cocoapods-binary/helper/names.rb b/lib/cocoapods-binary/helper/names.rb new file mode 100644 index 0000000..b5a2698 --- /dev/null +++ b/lib/cocoapods-binary/helper/names.rb @@ -0,0 +1,62 @@ +module Pod + + class Specification + + # Target name is different to spec name. One spec may map to multiple targets due to + # included by multiple platforms. This method return the possible names for targets. + # These name may not be existed actually, It's just a theorical combination. + def possible_target_names + suffixes = ["", "-iOS", "-watchOS", "-macOS"] + paths = suffixes.map do |s| + self.name + s + end + end + + # return the real targets names generated in prebuild sandbox + def prebuild_target_names_in_prebuild_sandbox(prebuild_sandbox) + names = self.possible_target_names + names.select do |name| + path = prebuild_sandbox.framework_folder_path_for_target_name(name) + path.exist? + end + end + end +end + +# Target: + +# def pod_name +# root_spec.name +# end + +# def name +# pod_name + #{scope_suffix} +# end + +# def product_module_name +# root_spec.module_name +# end + +# def framework_name +# "#{product_module_name}.framework" +# end + +# def product_name +# if requires_frameworks? +# framework_name +# else +# static_library_name +# end +# end + +# def product_basename +# if requires_frameworks? +# product_module_name +# else +# label +# end +# end + +# def framework_name +# "#{product_module_name}.framework" +# end \ No newline at end of file diff --git a/lib/cocoapods-binary/helper/prebuild_sandbox.rb b/lib/cocoapods-binary/helper/prebuild_sandbox.rb index 8e84170..cb491e7 100644 --- a/lib/cocoapods-binary/helper/prebuild_sandbox.rb +++ b/lib/cocoapods-binary/helper/prebuild_sandbox.rb @@ -19,6 +19,8 @@ def generate_framework_path self.root + "GeneratedFrameworks" end + # @param name [String] pass the target.name (may containing platform suffix) + # @return [Pathname] the folder containing the framework file. def framework_folder_path_for_target_name(name) self.generate_framework_path + name end From 31fdc383abf8f59fd9c5af97393ca9b3ab08cf5e Mon Sep 17 00:00:00 2001 From: leavez Date: Sat, 7 Jul 2018 03:44:01 +0800 Subject: [PATCH 07/25] organize name usages --- lib/cocoapods-binary/Main.rb | 2 +- lib/cocoapods-binary/Prebuild.rb | 13 +++++----- lib/cocoapods-binary/helper/names.rb | 13 ++++++---- .../helper/podfile_options.rb | 24 +++++++++---------- 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/lib/cocoapods-binary/Main.rb b/lib/cocoapods-binary/Main.rb index d45ae85..7d808bd 100644 --- a/lib/cocoapods-binary/Main.rb +++ b/lib/cocoapods-binary/Main.rb @@ -48,7 +48,7 @@ def keep_source_code_for_prebuilt_frameworks! # check user_framework is on podfile = installer_context.podfile podfile.target_definition_list.each do |target_definition| - next if target_definition.prebuild_framework_names.empty? + next if target_definition.prebuild_framework_pod_names.empty? if not target_definition.uses_frameworks? STDERR.puts "[!] Cocoapods-binary requires `use_frameworks!`".red exit diff --git a/lib/cocoapods-binary/Prebuild.rb b/lib/cocoapods-binary/Prebuild.rb index 9bcf412..51bab20 100644 --- a/lib/cocoapods-binary/Prebuild.rb +++ b/lib/cocoapods-binary/Prebuild.rb @@ -43,8 +43,6 @@ def have_exact_prebuild_cache? unchanged = changes.unchanged deleted = changes.deleted - unchange_framework_names = (added + unchanged) - exsited_framework_names = sandbox.exsited_framework_names missing = unchanged.select do |pod_name| not exsited_framework_names.include?(pod_name) @@ -97,9 +95,12 @@ def prebuild_frameworks! sum[target.name] = target sum end - targets = root_names_to_update.map do |root_name| - name_to_target_hash[root_name] - end || [] + targets = root_names_to_update.map do |pod_name| + possible_target_names = Pod.possible_target_names_from_pod_name(pod_name) + possible_target_names.map do |n| + name_to_target_hash[n] + end.compact + end.flatten || [] # add the dendencies dependency_targets = targets.map {|t| t.recursive_dependent_targets }.flatten.uniq || [] @@ -146,7 +147,7 @@ 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 << target.pod_name + Prebuild::Passer.target_names_to_skip_integration_framework << target.name FileUtils.cp_r(root_path, target_folder, :remove_destination => true) next end diff --git a/lib/cocoapods-binary/helper/names.rb b/lib/cocoapods-binary/helper/names.rb index b5a2698..4dfcdd5 100644 --- a/lib/cocoapods-binary/helper/names.rb +++ b/lib/cocoapods-binary/helper/names.rb @@ -1,15 +1,19 @@ module Pod + def self.possible_target_names_from_pod_name(root_pod_name) + suffixes = ["", "-iOS", "-watchOS", "-macOS"] + paths = suffixes.map do |s| + root_pod_name + s + end + end + class Specification # Target name is different to spec name. One spec may map to multiple targets due to # included by multiple platforms. This method return the possible names for targets. # These name may not be existed actually, It's just a theorical combination. def possible_target_names - suffixes = ["", "-iOS", "-watchOS", "-macOS"] - paths = suffixes.map do |s| - self.name + s - end + Pod.possible_target_names_from_pod_name self.name end # return the real targets names generated in prebuild sandbox @@ -21,6 +25,7 @@ def prebuild_target_names_in_prebuild_sandbox(prebuild_sandbox) end end end + end # Target: diff --git a/lib/cocoapods-binary/helper/podfile_options.rb b/lib/cocoapods-binary/helper/podfile_options.rb index 432f2d4..9a4abde 100644 --- a/lib/cocoapods-binary/helper/podfile_options.rb +++ b/lib/cocoapods-binary/helper/podfile_options.rb @@ -23,25 +23,25 @@ def parse_prebuild_framework(name, requirements) def set_prebuild_for_pod(pod_name, should_prebuild) if should_prebuild == true - @prebuild_framework_names ||= [] - @prebuild_framework_names.push pod_name + @prebuild_framework_pod_names ||= [] + @prebuild_framework_pod_names.push pod_name else - @should_not_prebuild_framework_names ||= [] - @should_not_prebuild_framework_names.push pod_name + @should_not_prebuild_framework_pod_names ||= [] + @should_not_prebuild_framework_pod_names.push pod_name end end - def prebuild_framework_names - names = @prebuild_framework_names || [] + def prebuild_framework_pod_names + names = @prebuild_framework_pod_names || [] if parent != nil and parent.kind_of? TargetDefinition - names += parent.prebuild_framework_names + names += parent.prebuild_framework_pod_names end names end - def should_not_prebuild_framework_names - names = @should_not_prebuild_framework_names || [] + def should_not_prebuild_framework_pod_names + names = @should_not_prebuild_framework_pod_names || [] if parent != nil and parent.kind_of? TargetDefinition - names += parent.should_not_prebuild_framework_names + names += parent.should_not_prebuild_framework_pod_names end names end @@ -74,7 +74,7 @@ def prebuild_pod_targets targets = aggregate_target.pod_targets || [] # filter prebuild - prebuild_names = target_definition.prebuild_framework_names + prebuild_names = target_definition.prebuild_framework_pod_names if not Podfile::DSL.prebuild_all targets = targets.select { |pod_target| prebuild_names.include?(pod_target.pod_name) } end @@ -82,7 +82,7 @@ def prebuild_pod_targets targets = (targets + dependency_targets).uniq # filter should not prebuild - explict_should_not_names = target_definition.should_not_prebuild_framework_names + explict_should_not_names = target_definition.should_not_prebuild_framework_pod_names targets = targets.reject { |pod_target| explict_should_not_names.include?(pod_target.pod_name) } all += targets From 4c2a3ad06b6c19b3fba76706d179fbd261063638 Mon Sep 17 00:00:00 2001 From: leavez Date: Sat, 7 Jul 2018 03:53:32 +0800 Subject: [PATCH 08/25] add comments for names --- lib/cocoapods-binary/helper/names.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/cocoapods-binary/helper/names.rb b/lib/cocoapods-binary/helper/names.rb index 4dfcdd5..ac37df6 100644 --- a/lib/cocoapods-binary/helper/names.rb +++ b/lib/cocoapods-binary/helper/names.rb @@ -1,3 +1,15 @@ +# +# There are many kinds of name in cocoapods. Two main names are widely used in this plugin. +# - root_spec.name (spec.root_name, targe.pod_name): +# the name we use in podfile. the concept. +# +# - target.name: +# the name of the final target in xcode project. the final real thing. +# +# One pod may have multiple targets in xcode project, due to one pod can be used in mutiple +# platform simultaneously. So one `root_spec.name` may have multiple coresponding `target.name`s. +# Therefore, map a spec to/from targets is a little complecated. It's one to many. +# module Pod def self.possible_target_names_from_pod_name(root_pod_name) From c80d9ba6992d7249594c9c30da8aa13dea1b8ff2 Mon Sep 17 00:00:00 2001 From: leavez Date: Sat, 7 Jul 2018 15:54:35 +0800 Subject: [PATCH 09/25] fix name usage 2 --- lib/cocoapods-binary/Integration.rb | 2 +- lib/cocoapods-binary/Prebuild.rb | 12 ++++----- lib/cocoapods-binary/helper/names.rb | 12 +++++++++ .../helper/prebuild_sandbox.rb | 25 +++++++------------ 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/lib/cocoapods-binary/Integration.rb b/lib/cocoapods-binary/Integration.rb index 7c7cad7..bfcdd7c 100644 --- a/lib/cocoapods-binary/Integration.rb +++ b/lib/cocoapods-binary/Integration.rb @@ -114,7 +114,7 @@ def remove_target_files_if_needed changes = Pod::Prebuild::Passer.prebuild_pods_changes updated_names = [] if changes == nil - updated_names = PrebuildSandbox.from_standard_sandbox(self.sandbox).exsited_framework_names + updated_names = PrebuildSandbox.from_standard_sandbox(self.sandbox).exsited_framework_pod_names else added = changes.added changed = changes.changed diff --git a/lib/cocoapods-binary/Prebuild.rb b/lib/cocoapods-binary/Prebuild.rb index 51bab20..b934dc3 100644 --- a/lib/cocoapods-binary/Prebuild.rb +++ b/lib/cocoapods-binary/Prebuild.rb @@ -43,9 +43,9 @@ def have_exact_prebuild_cache? unchanged = changes.unchanged deleted = changes.deleted - exsited_framework_names = sandbox.exsited_framework_names + exsited_framework_pod_names = sandbox.exsited_framework_pod_names missing = unchanged.select do |pod_name| - not exsited_framework_names.include?(pod_name) + not exsited_framework_pod_names.include?(pod_name) end needed = (added + changed + deleted + missing) @@ -56,7 +56,7 @@ def have_exact_prebuild_cache? # The install method when have completed cache def install_when_cache_hit! # just print log - self.sandbox.exsited_framework_names.each do |name| + self.sandbox.exsited_framework_pod_names.each do |name| UI.puts "Using #{name}" end end @@ -80,11 +80,11 @@ def prebuild_frameworks! deleted = changes.deleted existed_framework_folder.mkdir unless existed_framework_folder.exist? - exsited_framework_names = sandbox.exsited_framework_names + exsited_framework_pod_names = sandbox.exsited_framework_pod_names # additions missing = unchanged.select do |pod_name| - not exsited_framework_names.include?(pod_name) + not exsited_framework_pod_names.include?(pod_name) end @@ -169,7 +169,7 @@ def prebuild_frameworks! # Remove useless files # remove useless pods all_needed_names = self.pod_targets.map(&:name).uniq - useless_names = sandbox.exsited_framework_names.reject do |name| + useless_names = sandbox.exsited_framework_pod_names.reject do |name| all_needed_names.include? name end useless_names.each do |name| diff --git a/lib/cocoapods-binary/helper/names.rb b/lib/cocoapods-binary/helper/names.rb index ac37df6..dc320de 100644 --- a/lib/cocoapods-binary/helper/names.rb +++ b/lib/cocoapods-binary/helper/names.rb @@ -1,9 +1,11 @@ # # There are many kinds of name in cocoapods. Two main names are widely used in this plugin. # - root_spec.name (spec.root_name, targe.pod_name): +# aka "pod_name" # the name we use in podfile. the concept. # # - target.name: +# aka "target_name" # the name of the final target in xcode project. the final real thing. # # One pod may have multiple targets in xcode project, due to one pod can be used in mutiple @@ -19,6 +21,16 @@ def self.possible_target_names_from_pod_name(root_pod_name) end end + def self.pod_name_from_target_name(target_name) + suffixes = ["-iOS", "-watchOS", "-macOS"] + for s in suffixes + if target_name.end_with? s + return target_name.chomp s + end + end + return target_name + end + class Specification # Target name is different to spec name. One spec may map to multiple targets due to diff --git a/lib/cocoapods-binary/helper/prebuild_sandbox.rb b/lib/cocoapods-binary/helper/prebuild_sandbox.rb index cb491e7..ef1d77d 100644 --- a/lib/cocoapods-binary/helper/prebuild_sandbox.rb +++ b/lib/cocoapods-binary/helper/prebuild_sandbox.rb @@ -1,3 +1,5 @@ +require_relative "names" + module Pod class PrebuildSandbox < Sandbox @@ -25,26 +27,17 @@ def framework_folder_path_for_target_name(name) self.generate_framework_path + name end - def exsited_framework_names + + def exsited_framework_pod_names return [] unless generate_framework_path.exist? - generate_framework_path.children().map do |framework_name| - if framework_name.directory? - if not framework_name.children.empty? - File.basename(framework_name) - else - nil - end + generate_framework_path.children().map do |framework_path| + if framework_path.directory? && (not framework_path.children.empty?) + target_name = framework_path.basename + Pod.pod_name_from_target_name(target_name) else nil end - end.reject(&:nil?) - end - - def framework_existed?(root_name) - return false unless generate_framework_path.exist? - generate_framework_path.children().any? do |child| - child.basename.to_s == root_name - end + end.reject(&:nil?).uniq end end From 58eeb3f4c514da7ede2df5f7b477809c88e6a3a1 Mon Sep 17 00:00:00 2001 From: leavez Date: Sat, 7 Jul 2018 15:57:41 +0800 Subject: [PATCH 10/25] fix name usage 2.1 --- lib/cocoapods-binary/helper/prebuild_sandbox.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cocoapods-binary/helper/prebuild_sandbox.rb b/lib/cocoapods-binary/helper/prebuild_sandbox.rb index ef1d77d..060128f 100644 --- a/lib/cocoapods-binary/helper/prebuild_sandbox.rb +++ b/lib/cocoapods-binary/helper/prebuild_sandbox.rb @@ -33,7 +33,7 @@ def exsited_framework_pod_names generate_framework_path.children().map do |framework_path| if framework_path.directory? && (not framework_path.children.empty?) target_name = framework_path.basename - Pod.pod_name_from_target_name(target_name) + Pod.pod_name_from_target_name(target_name.to_s) else nil end From c1e876e62a89768045d59ae32d56dbfa2e5b7d6a Mon Sep 17 00:00:00 2001 From: leavez Date: Sat, 7 Jul 2018 16:14:18 +0800 Subject: [PATCH 11/25] fix name usages 2.2 --- lib/cocoapods-binary/Prebuild.rb | 27 ++++++++++--------- .../helper/prebuild_sandbox.rb | 13 ++++++--- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/lib/cocoapods-binary/Prebuild.rb b/lib/cocoapods-binary/Prebuild.rb index b934dc3..483fbd3 100644 --- a/lib/cocoapods-binary/Prebuild.rb +++ b/lib/cocoapods-binary/Prebuild.rb @@ -56,7 +56,7 @@ def have_exact_prebuild_cache? # The install method when have completed cache def install_when_cache_hit! # just print log - self.sandbox.exsited_framework_pod_names.each do |name| + self.sandbox.exsited_framework_target_names.each do |name| UI.puts "Using #{name}" end end @@ -91,16 +91,19 @@ def prebuild_frameworks! root_names_to_update = (added + changed + missing) # transform names to targets - name_to_target_hash = self.pod_targets.reduce({}) do |sum, target| - sum[target.name] = target - sum + def targets_for_pod_names(root_pod_names) + name_to_target_hash = self.pod_targets.reduce({}) do |sum, target| + sum[target.name] = target + sum + end + root_pod_names.map do |pod_name| + possible_target_names = Pod.possible_target_names_from_pod_name(pod_name) + possible_target_names.map do |n| + name_to_target_hash[n] + end.compact + end.flatten || [] end - targets = root_names_to_update.map do |pod_name| - possible_target_names = Pod.possible_target_names_from_pod_name(pod_name) - possible_target_names.map do |n| - name_to_target_hash[n] - end.compact - end.flatten || [] + targets = targets_for_pod_names(root_names_to_update) # add the dendencies dependency_targets = targets.map {|t| t.recursive_dependent_targets }.flatten.uniq || [] @@ -169,10 +172,10 @@ def prebuild_frameworks! # Remove useless files # remove useless pods all_needed_names = self.pod_targets.map(&:name).uniq - useless_names = sandbox.exsited_framework_pod_names.reject do |name| + useless_target_names = sandbox.exsited_framework_target_names.reject do |name| all_needed_names.include? name end - useless_names.each do |name| + useless_target_names.each do |name| path = sandbox.framework_folder_path_for_target_name(name) path.rmtree if path.exist? end diff --git a/lib/cocoapods-binary/helper/prebuild_sandbox.rb b/lib/cocoapods-binary/helper/prebuild_sandbox.rb index 060128f..c43961b 100644 --- a/lib/cocoapods-binary/helper/prebuild_sandbox.rb +++ b/lib/cocoapods-binary/helper/prebuild_sandbox.rb @@ -28,17 +28,24 @@ def framework_folder_path_for_target_name(name) end - def exsited_framework_pod_names + + def exsited_framework_target_names return [] unless generate_framework_path.exist? generate_framework_path.children().map do |framework_path| if framework_path.directory? && (not framework_path.children.empty?) - target_name = framework_path.basename - Pod.pod_name_from_target_name(target_name.to_s) + framework_path.basename.to_s else nil end end.reject(&:nil?).uniq end + def exsited_framework_pod_names + target_names = exsited_framework_target_names + target_names.map do |target_name| + Pod.pod_name_from_target_name(target_name.to_s) + end.uniq + end + end end From 411965ed2e7fc63b79e5598370335fa2f792bf76 Mon Sep 17 00:00:00 2001 From: leavez Date: Sat, 7 Jul 2018 19:18:27 +0800 Subject: [PATCH 12/25] refactor pod_name and target_name tranfrom --- lib/cocoapods-binary/Integration.rb | 3 +- lib/cocoapods-binary/Prebuild.rb | 14 +++---- lib/cocoapods-binary/helper/names.rb | 34 --------------- .../helper/prebuild_sandbox.rb | 41 ++++++++++++++----- 4 files changed, 36 insertions(+), 56 deletions(-) diff --git a/lib/cocoapods-binary/Integration.rb b/lib/cocoapods-binary/Integration.rb index bfcdd7c..986741c 100644 --- a/lib/cocoapods-binary/Integration.rb +++ b/lib/cocoapods-binary/Integration.rb @@ -27,8 +27,7 @@ def install_for_prebuild!(standard_sanbox) # make a symlink to target folder prebuild_sandbox = Pod::PrebuildSandbox.from_standard_sandbox(standard_sanbox) # if spec used in multiple platforms, it may return multiple paths - target_names = root_spec.prebuild_target_names_in_prebuild_sandbox(prebuild_sandbox) - + target_names = prebuild_sandbox.existed_target_names_for_pod_name(self.name) def walk(path, &action) path.children.each do |child| diff --git a/lib/cocoapods-binary/Prebuild.rb b/lib/cocoapods-binary/Prebuild.rb index 483fbd3..cf09c50 100644 --- a/lib/cocoapods-binary/Prebuild.rb +++ b/lib/cocoapods-binary/Prebuild.rb @@ -92,16 +92,9 @@ def prebuild_frameworks! # transform names to targets def targets_for_pod_names(root_pod_names) - name_to_target_hash = self.pod_targets.reduce({}) do |sum, target| - sum[target.name] = target - sum + self.pod_targets.select do |target| + target.pod_name == root_pod_names end - root_pod_names.map do |pod_name| - possible_target_names = Pod.possible_target_names_from_pod_name(pod_name) - possible_target_names.map do |n| - name_to_target_hash[n] - end.compact - end.flatten || [] end targets = targets_for_pod_names(root_names_to_update) @@ -138,6 +131,9 @@ def targets_for_pod_names(root_pod_names) end Prebuild::Passer.resources_to_copy_for_static_framework[target.name] = path_objects end + + # save the pod_name for prebuild framwork in sandbox + sandbox.save_pod_name_for_target target end Pod::Prebuild.remove_build_dir(sandbox_path) diff --git a/lib/cocoapods-binary/helper/names.rb b/lib/cocoapods-binary/helper/names.rb index dc320de..3c54cf0 100644 --- a/lib/cocoapods-binary/helper/names.rb +++ b/lib/cocoapods-binary/helper/names.rb @@ -12,45 +12,11 @@ # platform simultaneously. So one `root_spec.name` may have multiple coresponding `target.name`s. # Therefore, map a spec to/from targets is a little complecated. It's one to many. # -module Pod - def self.possible_target_names_from_pod_name(root_pod_name) - suffixes = ["", "-iOS", "-watchOS", "-macOS"] - paths = suffixes.map do |s| - root_pod_name + s - end - end - def self.pod_name_from_target_name(target_name) - suffixes = ["-iOS", "-watchOS", "-macOS"] - for s in suffixes - if target_name.end_with? s - return target_name.chomp s - end - end - return target_name - end - class Specification - # Target name is different to spec name. One spec may map to multiple targets due to - # included by multiple platforms. This method return the possible names for targets. - # These name may not be existed actually, It's just a theorical combination. - def possible_target_names - Pod.possible_target_names_from_pod_name self.name - end - # return the real targets names generated in prebuild sandbox - def prebuild_target_names_in_prebuild_sandbox(prebuild_sandbox) - names = self.possible_target_names - names.select do |name| - path = prebuild_sandbox.framework_folder_path_for_target_name(name) - path.exist? - end - end - end - -end # Target: diff --git a/lib/cocoapods-binary/helper/prebuild_sandbox.rb b/lib/cocoapods-binary/helper/prebuild_sandbox.rb index c43961b..c26480b 100644 --- a/lib/cocoapods-binary/helper/prebuild_sandbox.rb +++ b/lib/cocoapods-binary/helper/prebuild_sandbox.rb @@ -27,25 +27,44 @@ def framework_folder_path_for_target_name(name) self.generate_framework_path + name end - - + def exsited_framework_target_names + exsited_framework_name_pairs.map {|pair| pair[0]}.uniq + end + def exsited_framework_pod_names + exsited_framework_name_pairs.map {|pair| pair[1]}.uniq + end + def existed_target_names_for_pod_name(pod_name) + exsited_framework_name_pairs.select {|pair| pair[1] == pod_name }.map { |pair| pair[0]} + end + + + + def save_pod_name_for_target(target) + folder = framework_folder_path_for_target_name(target.name) + flag_file_path = folder + "#{target.pod_name}.pod_name" + File.write(flag_file_path.to_s, "") + end + + + private + + def pod_name_for_target_folder(target_folder_path) + Pathname.new(target_folder_path).children.first do |child| + child.to_s.end_with? ".pod_name" + end.basename(".pod_name").to_s + end + + # Array<[target_name, pod_name]> + def exsited_framework_name_pairs return [] unless generate_framework_path.exist? generate_framework_path.children().map do |framework_path| if framework_path.directory? && (not framework_path.children.empty?) - framework_path.basename.to_s + [framework_path.basename.to_s, pod_name_for_target_folder(framework_path)] else nil end end.reject(&:nil?).uniq end - - def exsited_framework_pod_names - target_names = exsited_framework_target_names - target_names.map do |target_name| - Pod.pod_name_from_target_name(target_name.to_s) - end.uniq - end - end end From c5efe4350cb6cb7950618333e0e03fe6a6193ad8 Mon Sep 17 00:00:00 2001 From: leavez Date: Sat, 7 Jul 2018 19:21:40 +0800 Subject: [PATCH 13/25] refactor patch integration to support multiple platfroms --- lib/cocoapods-binary/Integration.rb | 74 ++++++++++++++++++----------- 1 file changed, 46 insertions(+), 28 deletions(-) diff --git a/lib/cocoapods-binary/Integration.rb b/lib/cocoapods-binary/Integration.rb index 986741c..52781b2 100644 --- a/lib/cocoapods-binary/Integration.rb +++ b/lib/cocoapods-binary/Integration.rb @@ -145,45 +145,63 @@ def remove_target_files_if_needed # call original old_method2.bind(self).() + # ... + # ... + # ... + # after finishing the very complex orginal function - - # check the prebuilt targets - targets = self.prebuild_pod_targets - targets_have_different_platforms = targets.select {|t| t.pod_name != t.name } - - if targets_have_different_platforms.count > 0 - names = targets_have_different_platforms.map(&:pod_name) - STDERR.puts "[!] Binary doesn't support pods who integrate in 2 or more platforms simultaneously: #{names}".red - exit + + # prepare + # make sturcture to fast get target by name + pod_name_to_targets_hash = self.pod_targets.reduce({}) do |sum, target| + array = sum[target.pod_name] || [] + array << target + sum[target.pod_name] = array + sum + end + def get_corresponding_targets(spec, pod_name_to_targets_hash) + corresponding_targets = pod_name_to_targets_hash[spec.root.name] || [] + corresponding_targets = corresponding_targets.reject do |target| + Prebuild::Passer.target_names_to_skip_integration_framework.include? target.name + end + corresponding_targets + end + def add_vendered_framework(spec, platform, added_framework_file_path) + if spec.attributes_hash[platform] == nil + spec.attributes_hash[platform] = {} + end + vendored_frameworks = spec.attributes_hash[platform]["vendored_frameworks"] || [] + puts "vendored_frameworks --- #{vendored_frameworks}" + vendored_frameworks = [vendored_frameworks] if vendored_frameworks.kind_of?(String) + vendored_frameworks += [added_framework_file_path] + spec.attributes_hash[platform]["vendored_frameworks"] = vendored_frameworks + end + def empty_source_files(spec) + spec.attributes_hash["source_files"] = [] + ["ios", "watchos", "tvos", "osx"].each do |plat| + if spec.attributes_hash[plat] != nil + spec.attributes_hash[plat]["source_files"] = [] + end + end end - specs = self.analysis_result.specifications prebuilt_specs = (specs.select do |spec| self.prebuild_pod_names.include? spec.root.name end) - - # make sturcture to fast get target by name - name_to_target_hash = self.pod_targets.reduce({}) do |sum, target| - sum[target.name] = target - sum - end 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 - original_vendored_frameworks = spec.attributes_hash["vendored_frameworks"] || [] - if original_vendored_frameworks.kind_of?(String) - original_vendored_frameworks = [original_vendored_frameworks] + # use the prebuild framworks as vendered frameworks + targets = get_corresponding_targets(spec, pod_name_to_targets_hash) + puts "************ targets: #{targets}" + targets.each do |target| + framework_file_path = target.framework_name + framework_file_path = target.name + "/" + framework_file_path if targets.count > 1 + puts "target ---- #{target.name}}" + add_vendered_framework(spec, target.platform.name.to_s, framework_file_path) end - original_vendored_frameworks += [target.framework_name] - spec.attributes_hash["vendored_frameworks"] = original_vendored_frameworks - spec.attributes_hash["source_files"] = [] + empty_source_files(spec) # to avoid the warning of missing license spec.attributes_hash["license"] = {} From d78acb3b574b0e98ac565894327581ecc3d45a4b Mon Sep 17 00:00:00 2001 From: leavez Date: Sat, 7 Jul 2018 19:29:10 +0800 Subject: [PATCH 14/25] add comments --- lib/cocoapods-binary/Integration.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/cocoapods-binary/Integration.rb b/lib/cocoapods-binary/Integration.rb index 52781b2..a744d22 100644 --- a/lib/cocoapods-binary/Integration.rb +++ b/lib/cocoapods-binary/Integration.rb @@ -171,7 +171,6 @@ def add_vendered_framework(spec, platform, added_framework_file_path) spec.attributes_hash[platform] = {} end vendored_frameworks = spec.attributes_hash[platform]["vendored_frameworks"] || [] - puts "vendored_frameworks --- #{vendored_frameworks}" vendored_frameworks = [vendored_frameworks] if vendored_frameworks.kind_of?(String) vendored_frameworks += [added_framework_file_path] spec.attributes_hash[platform]["vendored_frameworks"] = vendored_frameworks @@ -192,15 +191,19 @@ def empty_source_files(spec) prebuilt_specs.each do |spec| - # use the prebuild framworks as vendered frameworks + # Use the prebuild framworks as vendered frameworks targets = get_corresponding_targets(spec, pod_name_to_targets_hash) - puts "************ targets: #{targets}" targets.each do |target| + # the framework_file_path rule is decided when `install_for_prebuild`, + # as to compitable with older version and be less wordy. framework_file_path = target.framework_name framework_file_path = target.name + "/" + framework_file_path if targets.count > 1 - puts "target ---- #{target.name}}" add_vendered_framework(spec, target.platform.name.to_s, framework_file_path) end + # Clean the source files + # we just add the prebuilt framework to specific platform and set no source files + # for all platform, so it doesn't support the sence that 'a pod perbuild for one + # platform and not for another platform.' empty_source_files(spec) # to avoid the warning of missing license From ad15231e7cfe76b0347c1559e6bbbf3fe48f04d3 Mon Sep 17 00:00:00 2001 From: leavez Date: Sat, 7 Jul 2018 19:39:55 +0800 Subject: [PATCH 15/25] add compatibility with older version --- lib/cocoapods-binary/helper/prebuild_sandbox.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/cocoapods-binary/helper/prebuild_sandbox.rb b/lib/cocoapods-binary/helper/prebuild_sandbox.rb index c26480b..81d4615 100644 --- a/lib/cocoapods-binary/helper/prebuild_sandbox.rb +++ b/lib/cocoapods-binary/helper/prebuild_sandbox.rb @@ -50,9 +50,10 @@ def save_pod_name_for_target(target) private def pod_name_for_target_folder(target_folder_path) - Pathname.new(target_folder_path).children.first do |child| + name = Pathname.new(target_folder_path).children.first do |child| child.to_s.end_with? ".pod_name" - end.basename(".pod_name").to_s + end.basename(".pod_name").to_s + name ||= Pathname.new(target_folder_path).basename.to_s # for compatibility with older version end # Array<[target_name, pod_name]> From 99f90d8e5a06fe5e82b58053090153c3d45c8246 Mon Sep 17 00:00:00 2001 From: leavez Date: Sat, 7 Jul 2018 20:30:11 +0800 Subject: [PATCH 16/25] fix the pod_name_target finding --- lib/cocoapods-binary/Integration.rb | 19 ++++--------------- lib/cocoapods-binary/Prebuild.rb | 10 ++++------ lib/cocoapods-binary/helper/names.rb | 21 +++++++++++++++++++++ 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/lib/cocoapods-binary/Integration.rb b/lib/cocoapods-binary/Integration.rb index a744d22..0dc9d74 100644 --- a/lib/cocoapods-binary/Integration.rb +++ b/lib/cocoapods-binary/Integration.rb @@ -152,20 +152,8 @@ def remove_target_files_if_needed # prepare - # make sturcture to fast get target by name - pod_name_to_targets_hash = self.pod_targets.reduce({}) do |sum, target| - array = sum[target.pod_name] || [] - array << target - sum[target.pod_name] = array - sum - end - def get_corresponding_targets(spec, pod_name_to_targets_hash) - corresponding_targets = pod_name_to_targets_hash[spec.root.name] || [] - corresponding_targets = corresponding_targets.reject do |target| - Prebuild::Passer.target_names_to_skip_integration_framework.include? target.name - end - corresponding_targets - end + cache = [] + def add_vendered_framework(spec, platform, added_framework_file_path) if spec.attributes_hash[platform] == nil spec.attributes_hash[platform] = {} @@ -192,7 +180,8 @@ def empty_source_files(spec) prebuilt_specs.each do |spec| # Use the prebuild framworks as vendered frameworks - targets = get_corresponding_targets(spec, pod_name_to_targets_hash) + # get_corresponding_targets + targets = Pod.fast_get_targets_for_pod_name(spec.root.name, self.pod_targets, cache) targets.each do |target| # the framework_file_path rule is decided when `install_for_prebuild`, # as to compitable with older version and be less wordy. diff --git a/lib/cocoapods-binary/Prebuild.rb b/lib/cocoapods-binary/Prebuild.rb index cf09c50..7cc9960 100644 --- a/lib/cocoapods-binary/Prebuild.rb +++ b/lib/cocoapods-binary/Prebuild.rb @@ -91,12 +91,10 @@ def prebuild_frameworks! root_names_to_update = (added + changed + missing) # transform names to targets - def targets_for_pod_names(root_pod_names) - self.pod_targets.select do |target| - target.pod_name == root_pod_names - end - end - targets = targets_for_pod_names(root_names_to_update) + cache = [] + targets = root_names_to_update.map do |pod_name| + Pod.fast_get_targets_for_pod_name(pod_name, self.pod_targets, cache) + end.flatten # add the dendencies dependency_targets = targets.map {|t| t.recursive_dependent_targets }.flatten.uniq || [] diff --git a/lib/cocoapods-binary/helper/names.rb b/lib/cocoapods-binary/helper/names.rb index 3c54cf0..e6ec3ea 100644 --- a/lib/cocoapods-binary/helper/names.rb +++ b/lib/cocoapods-binary/helper/names.rb @@ -1,3 +1,4 @@ +# ABOUT NAMES # # There are many kinds of name in cocoapods. Two main names are widely used in this plugin. # - root_spec.name (spec.root_name, targe.pod_name): @@ -13,6 +14,26 @@ # Therefore, map a spec to/from targets is a little complecated. It's one to many. # +# Tool to transform Pod_name to target efficiently +module Pod + def self.fast_get_targets_for_pod_name(pod_name, targets, cache) + pod_name_to_targets_hash = nil + if cache.empty? + pod_name_to_targets_hash = targets.reduce({}) do |sum, target| + array = sum[target.pod_name] || [] + array << target + sum[target.pod_name] = array + sum + end + cache << pod_name_to_targets_hash + else + pod_name_to_targets_hash = cache.first + end + + pod_name_to_targets_hash[pod_name] || [] + end +end + From 01430ed68cb3178132d75efefce6f52d744e3489 Mon Sep 17 00:00:00 2001 From: leavez Date: Sat, 7 Jul 2018 20:46:20 +0800 Subject: [PATCH 17/25] fix pod_name_for_target_folder --- lib/cocoapods-binary/helper/prebuild_sandbox.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cocoapods-binary/helper/prebuild_sandbox.rb b/lib/cocoapods-binary/helper/prebuild_sandbox.rb index 81d4615..3030570 100644 --- a/lib/cocoapods-binary/helper/prebuild_sandbox.rb +++ b/lib/cocoapods-binary/helper/prebuild_sandbox.rb @@ -50,7 +50,7 @@ def save_pod_name_for_target(target) private def pod_name_for_target_folder(target_folder_path) - name = Pathname.new(target_folder_path).children.first do |child| + name = Pathname.new(target_folder_path).children.find do |child| child.to_s.end_with? ".pod_name" end.basename(".pod_name").to_s name ||= Pathname.new(target_folder_path).basename.to_s # for compatibility with older version From 702f5020bcb2f25682dbf125235c78735e43b23c Mon Sep 17 00:00:00 2001 From: leavez Date: Sat, 7 Jul 2018 21:06:59 +0800 Subject: [PATCH 18/25] fix save_pod_name_for_target --- lib/cocoapods-binary/Prebuild.rb | 7 +++++-- lib/cocoapods-binary/helper/prebuild_sandbox.rb | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/cocoapods-binary/Prebuild.rb b/lib/cocoapods-binary/Prebuild.rb index 7cc9960..c939f80 100644 --- a/lib/cocoapods-binary/Prebuild.rb +++ b/lib/cocoapods-binary/Prebuild.rb @@ -130,8 +130,6 @@ def prebuild_frameworks! Prebuild::Passer.resources_to_copy_for_static_framework[target.name] = path_objects end - # save the pod_name for prebuild framwork in sandbox - sandbox.save_pod_name_for_target target end Pod::Prebuild.remove_build_dir(sandbox_path) @@ -162,6 +160,11 @@ def prebuild_frameworks! end end end + + # save the pod_name for prebuild framwork in sandbox + targets.each do |target| + sandbox.save_pod_name_for_target target + end # Remove useless files # remove useless pods diff --git a/lib/cocoapods-binary/helper/prebuild_sandbox.rb b/lib/cocoapods-binary/helper/prebuild_sandbox.rb index 3030570..c0b044c 100644 --- a/lib/cocoapods-binary/helper/prebuild_sandbox.rb +++ b/lib/cocoapods-binary/helper/prebuild_sandbox.rb @@ -42,6 +42,7 @@ def existed_target_names_for_pod_name(pod_name) def save_pod_name_for_target(target) folder = framework_folder_path_for_target_name(target.name) + return unless folder.exist? flag_file_path = folder + "#{target.pod_name}.pod_name" File.write(flag_file_path.to_s, "") end From 4f0d0c87cba084d4690530079ee3ce5c011afa59 Mon Sep 17 00:00:00 2001 From: leavez Date: Sat, 7 Jul 2018 22:23:29 +0800 Subject: [PATCH 19/25] add check for different forms --- lib/cocoapods-binary/Integration.rb | 4 ++++ lib/cocoapods-binary/helper/podfile_options.rb | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/cocoapods-binary/Integration.rb b/lib/cocoapods-binary/Integration.rb index 0dc9d74..7d7bad7 100644 --- a/lib/cocoapods-binary/Integration.rb +++ b/lib/cocoapods-binary/Integration.rb @@ -150,6 +150,10 @@ def remove_target_files_if_needed # ... # after finishing the very complex orginal function + + # check + self.validate_every_pod_only_have_one_form + # prepare cache = [] diff --git a/lib/cocoapods-binary/helper/podfile_options.rb b/lib/cocoapods-binary/helper/podfile_options.rb index 9a4abde..82e30bc 100644 --- a/lib/cocoapods-binary/helper/podfile_options.rb +++ b/lib/cocoapods-binary/helper/podfile_options.rb @@ -97,6 +97,23 @@ def prebuild_pod_names @prebuild_pod_names ||= self.prebuild_pod_targets.map(&:pod_name) end + + def validate_every_pod_only_have_one_form + prebuit = [] + not_prebuilt = [] + aggregate_targets = self.aggregate_targets + aggregate_targets.each do |aggregate_target| + target_definition = aggregate_target.target_definition + prebuit += target_definition.prebuild_framework_pod_names + not_prebuilt += target_definition.should_not_prebuild_framework_pod_names + end + + intersection = prebuit & not_prebuilt + if not intersection.empty? + raise Informative, "One pod can only be prebuilt or not prebuilt. These pod have different forms in multiple targets: #{intersection.to_a}. Please fix that." + end + end + end end From 250ee365e4463f9b5759c0e889853a7c887b826b Mon Sep 17 00:00:00 2001 From: leavez Date: Sat, 7 Jul 2018 22:31:37 +0800 Subject: [PATCH 20/25] add target for test --- test/Binary.xcodeproj/project.pbxproj | 298 +++++++++++++++++- .../Circular.imageset/Contents.json | 18 ++ .../Contents.json | 28 ++ .../Extra Large.imageset/Contents.json | 18 ++ .../Modular.imageset/Contents.json | 18 ++ .../Utilitarian.imageset/Contents.json | 18 ++ .../Assets.xcassets/Contents.json | 6 + .../ExtensionDelegate.swift | 56 ++++ test/BinaryWatch Extension/Info.plist | 36 +++ .../InterfaceController.swift | 31 ++ test/BinaryWatch Extension/import.swift | 1 + .../AppIcon.appiconset/Contents.json | 67 ++++ .../BinaryWatch/Assets.xcassets/Contents.json | 6 + .../Base.lproj/Interface.storyboard | 15 + test/BinaryWatch/Info.plist | 33 ++ 15 files changed, 646 insertions(+), 3 deletions(-) create mode 100644 test/BinaryWatch Extension/Assets.xcassets/Complication.complicationset/Circular.imageset/Contents.json create mode 100644 test/BinaryWatch Extension/Assets.xcassets/Complication.complicationset/Contents.json create mode 100644 test/BinaryWatch Extension/Assets.xcassets/Complication.complicationset/Extra Large.imageset/Contents.json create mode 100644 test/BinaryWatch Extension/Assets.xcassets/Complication.complicationset/Modular.imageset/Contents.json create mode 100644 test/BinaryWatch Extension/Assets.xcassets/Complication.complicationset/Utilitarian.imageset/Contents.json create mode 100644 test/BinaryWatch Extension/Assets.xcassets/Contents.json create mode 100644 test/BinaryWatch Extension/ExtensionDelegate.swift create mode 100644 test/BinaryWatch Extension/Info.plist create mode 100644 test/BinaryWatch Extension/InterfaceController.swift create mode 100644 test/BinaryWatch Extension/import.swift create mode 100644 test/BinaryWatch/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 test/BinaryWatch/Assets.xcassets/Contents.json create mode 100644 test/BinaryWatch/Base.lproj/Interface.storyboard create mode 100644 test/BinaryWatch/Info.plist diff --git a/test/Binary.xcodeproj/project.pbxproj b/test/Binary.xcodeproj/project.pbxproj index 500ac27..291e5da 100644 --- a/test/Binary.xcodeproj/project.pbxproj +++ b/test/Binary.xcodeproj/project.pbxproj @@ -10,9 +10,59 @@ 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 */; }; + 3EEAFD8720F1056D009A9D22 /* Interface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3EEAFD8520F1056D009A9D22 /* Interface.storyboard */; }; + 3EEAFD8920F1056D009A9D22 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3EEAFD8820F1056D009A9D22 /* Assets.xcassets */; }; + 3EEAFD9020F1056E009A9D22 /* BinaryWatch Extension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 3EEAFD8F20F1056E009A9D22 /* BinaryWatch Extension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; + 3EEAFD9520F1056E009A9D22 /* InterfaceController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EEAFD9420F1056E009A9D22 /* InterfaceController.swift */; }; + 3EEAFD9720F1056E009A9D22 /* ExtensionDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EEAFD9620F1056E009A9D22 /* ExtensionDelegate.swift */; }; + 3EEAFD9920F1056E009A9D22 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3EEAFD9820F1056E009A9D22 /* Assets.xcassets */; }; + 3EEAFD9D20F1056E009A9D22 /* BinaryWatch.app in Embed Watch Content */ = {isa = PBXBuildFile; fileRef = 3EEAFD8320F1056D009A9D22 /* BinaryWatch.app */; }; + 3EEAFDA720F10610009A9D22 /* import.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EEAFDA620F10610009A9D22 /* import.swift */; }; AEBC61E3160A9AC38C3A210D /* Pods_Binary.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5687B1A81F152DBEF5CD4432 /* Pods_Binary.framework */; }; /* End PBXBuildFile section */ +/* Begin PBXContainerItemProxy section */ + 3EEAFD9120F1056E009A9D22 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 3E83E31A207BC00E0057855A /* Project object */; + proxyType = 1; + remoteGlobalIDString = 3EEAFD8E20F1056E009A9D22; + remoteInfo = "BinaryWatch Extension"; + }; + 3EEAFD9B20F1056E009A9D22 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 3E83E31A207BC00E0057855A /* Project object */; + proxyType = 1; + remoteGlobalIDString = 3EEAFD8220F1056D009A9D22; + remoteInfo = BinaryWatch; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 3EEAFDA320F1056E009A9D22 /* Embed App Extensions */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 13; + files = ( + 3EEAFD9020F1056E009A9D22 /* BinaryWatch Extension.appex in Embed App Extensions */, + ); + name = "Embed App Extensions"; + runOnlyForDeploymentPostprocessing = 0; + }; + 3EEAFDA520F1056E009A9D22 /* Embed Watch Content */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = "$(CONTENTS_FOLDER_PATH)/Watch"; + dstSubfolderSpec = 16; + files = ( + 3EEAFD9D20F1056E009A9D22 /* BinaryWatch.app in Embed Watch Content */, + ); + name = "Embed Watch Content"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase 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 = ""; }; @@ -20,6 +70,16 @@ 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 = ""; }; + 3EEAFD8320F1056D009A9D22 /* BinaryWatch.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = BinaryWatch.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 3EEAFD8620F1056D009A9D22 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Interface.storyboard; sourceTree = ""; }; + 3EEAFD8820F1056D009A9D22 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 3EEAFD8A20F1056E009A9D22 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 3EEAFD8F20F1056E009A9D22 /* BinaryWatch Extension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = "BinaryWatch Extension.appex"; sourceTree = BUILT_PRODUCTS_DIR; }; + 3EEAFD9420F1056E009A9D22 /* InterfaceController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InterfaceController.swift; sourceTree = ""; }; + 3EEAFD9620F1056E009A9D22 /* ExtensionDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExtensionDelegate.swift; sourceTree = ""; }; + 3EEAFD9820F1056E009A9D22 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 3EEAFD9A20F1056E009A9D22 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 3EEAFDA620F10610009A9D22 /* import.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = import.swift; 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 */ @@ -33,6 +93,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 3EEAFD8C20F1056E009A9D22 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ @@ -40,6 +107,8 @@ isa = PBXGroup; children = ( 3E83E324207BC00E0057855A /* Binary */, + 3EEAFD8420F1056D009A9D22 /* BinaryWatch */, + 3EEAFD9320F1056E009A9D22 /* BinaryWatch Extension */, 3E83E323207BC00E0057855A /* Products */, E8117D681BF19C1B3D847824 /* Pods */, 8E13F0A6AED19C681C2CD7D5 /* Frameworks */, @@ -50,6 +119,8 @@ isa = PBXGroup; children = ( 3E83E322207BC00E0057855A /* Binary.app */, + 3EEAFD8320F1056D009A9D22 /* BinaryWatch.app */, + 3EEAFD8F20F1056E009A9D22 /* BinaryWatch Extension.appex */, ); name = Products; sourceTree = ""; @@ -65,6 +136,28 @@ path = Binary; sourceTree = ""; }; + 3EEAFD8420F1056D009A9D22 /* BinaryWatch */ = { + isa = PBXGroup; + children = ( + 3EEAFD8520F1056D009A9D22 /* Interface.storyboard */, + 3EEAFD8820F1056D009A9D22 /* Assets.xcassets */, + 3EEAFD8A20F1056E009A9D22 /* Info.plist */, + ); + path = BinaryWatch; + sourceTree = ""; + }; + 3EEAFD9320F1056E009A9D22 /* BinaryWatch Extension */ = { + isa = PBXGroup; + children = ( + 3EEAFD9420F1056E009A9D22 /* InterfaceController.swift */, + 3EEAFD9620F1056E009A9D22 /* ExtensionDelegate.swift */, + 3EEAFDA620F10610009A9D22 /* import.swift */, + 3EEAFD9820F1056E009A9D22 /* Assets.xcassets */, + 3EEAFD9A20F1056E009A9D22 /* Info.plist */, + ); + path = "BinaryWatch Extension"; + sourceTree = ""; + }; 8E13F0A6AED19C681C2CD7D5 /* Frameworks */ = { isa = PBXGroup; children = ( @@ -94,29 +187,71 @@ 3E83E31F207BC00E0057855A /* Frameworks */, 3E83E320207BC00E0057855A /* Resources */, 9937F6A880D56826534273F0 /* [CP] Embed Pods Frameworks */, + 3EEAFDA520F1056E009A9D22 /* Embed Watch Content */, ); buildRules = ( ); dependencies = ( + 3EEAFD9C20F1056E009A9D22 /* PBXTargetDependency */, ); name = Binary; productName = Binary; productReference = 3E83E322207BC00E0057855A /* Binary.app */; productType = "com.apple.product-type.application"; }; + 3EEAFD8220F1056D009A9D22 /* BinaryWatch */ = { + isa = PBXNativeTarget; + buildConfigurationList = 3EEAFDA420F1056E009A9D22 /* Build configuration list for PBXNativeTarget "BinaryWatch" */; + buildPhases = ( + 3EEAFD8120F1056D009A9D22 /* Resources */, + 3EEAFDA320F1056E009A9D22 /* Embed App Extensions */, + ); + buildRules = ( + ); + dependencies = ( + 3EEAFD9220F1056E009A9D22 /* PBXTargetDependency */, + ); + name = BinaryWatch; + productName = BinaryWatch; + productReference = 3EEAFD8320F1056D009A9D22 /* BinaryWatch.app */; + productType = "com.apple.product-type.application.watchapp2"; + }; + 3EEAFD8E20F1056E009A9D22 /* BinaryWatch Extension */ = { + isa = PBXNativeTarget; + buildConfigurationList = 3EEAFDA220F1056E009A9D22 /* Build configuration list for PBXNativeTarget "BinaryWatch Extension" */; + buildPhases = ( + 3EEAFD8B20F1056E009A9D22 /* Sources */, + 3EEAFD8C20F1056E009A9D22 /* Frameworks */, + 3EEAFD8D20F1056E009A9D22 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "BinaryWatch Extension"; + productName = "BinaryWatch Extension"; + productReference = 3EEAFD8F20F1056E009A9D22 /* BinaryWatch Extension.appex */; + productType = "com.apple.product-type.watchkit2-extension"; + }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ 3E83E31A207BC00E0057855A /* Project object */ = { isa = PBXProject; attributes = { - LastSwiftUpdateCheck = 0930; + LastSwiftUpdateCheck = 1000; LastUpgradeCheck = 0930; ORGANIZATIONNAME = me.leavez; TargetAttributes = { 3E83E321207BC00E0057855A = { CreatedOnToolsVersion = 9.3; }; + 3EEAFD8220F1056D009A9D22 = { + CreatedOnToolsVersion = 10.0; + }; + 3EEAFD8E20F1056E009A9D22 = { + CreatedOnToolsVersion = 10.0; + }; }; }; buildConfigurationList = 3E83E31D207BC00E0057855A /* Build configuration list for PBXProject "Binary" */; @@ -133,6 +268,8 @@ projectRoot = ""; targets = ( 3E83E321207BC00E0057855A /* Binary */, + 3EEAFD8220F1056D009A9D22 /* BinaryWatch */, + 3EEAFD8E20F1056E009A9D22 /* BinaryWatch Extension */, ); }; /* End PBXProject section */ @@ -145,6 +282,23 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 3EEAFD8120F1056D009A9D22 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 3EEAFD8920F1056D009A9D22 /* Assets.xcassets in Resources */, + 3EEAFD8720F1056D009A9D22 /* Interface.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 3EEAFD8D20F1056E009A9D22 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 3EEAFD9920F1056E009A9D22 /* Assets.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ @@ -199,8 +353,42 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 3EEAFD8B20F1056E009A9D22 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 3EEAFD9720F1056E009A9D22 /* ExtensionDelegate.swift in Sources */, + 3EEAFDA720F10610009A9D22 /* import.swift in Sources */, + 3EEAFD9520F1056E009A9D22 /* InterfaceController.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXSourcesBuildPhase section */ +/* Begin PBXTargetDependency section */ + 3EEAFD9220F1056E009A9D22 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 3EEAFD8E20F1056E009A9D22 /* BinaryWatch Extension */; + targetProxy = 3EEAFD9120F1056E009A9D22 /* PBXContainerItemProxy */; + }; + 3EEAFD9C20F1056E009A9D22 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 3EEAFD8220F1056D009A9D22 /* BinaryWatch */; + targetProxy = 3EEAFD9B20F1056E009A9D22 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + 3EEAFD8520F1056D009A9D22 /* Interface.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 3EEAFD8620F1056D009A9D22 /* Base */, + ); + name = Interface.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + /* Begin XCBuildConfiguration section */ 3E83E332207BC0120057855A /* Debug */ = { isa = XCBuildConfiguration; @@ -322,7 +510,10 @@ 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; @@ -336,7 +527,10 @@ 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; @@ -344,6 +538,86 @@ }; name = Release; }; + 3EEAFD9E20F1056E009A9D22 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + IBSC_MODULE = BinaryWatch_Extension; + INFOPLIST_FILE = BinaryWatch/Info.plist; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + PRODUCT_BUNDLE_IDENTIFIER = me.leavez.Binary.watchkitapp; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = watchos; + SKIP_INSTALL = YES; + SWIFT_VERSION = 4.2; + TARGETED_DEVICE_FAMILY = 4; + WATCHOS_DEPLOYMENT_TARGET = 5.0; + }; + name = Debug; + }; + 3EEAFD9F20F1056E009A9D22 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + IBSC_MODULE = BinaryWatch_Extension; + INFOPLIST_FILE = BinaryWatch/Info.plist; + PRODUCT_BUNDLE_IDENTIFIER = me.leavez.Binary.watchkitapp; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = watchos; + SKIP_INSTALL = YES; + SWIFT_VERSION = 4.2; + TARGETED_DEVICE_FAMILY = 4; + WATCHOS_DEPLOYMENT_TARGET = 5.0; + }; + name = Release; + }; + 3EEAFDA020F1056E009A9D22 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_COMPLICATION_NAME = Complication; + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = "BinaryWatch Extension/Info.plist"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@executable_path/../../Frameworks", + ); + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + PRODUCT_BUNDLE_IDENTIFIER = me.leavez.Binary.watchkitapp.watchkitextension; + PRODUCT_NAME = "${TARGET_NAME}"; + SDKROOT = watchos; + SKIP_INSTALL = YES; + SWIFT_VERSION = 4.2; + TARGETED_DEVICE_FAMILY = 4; + WATCHOS_DEPLOYMENT_TARGET = 5.0; + }; + name = Debug; + }; + 3EEAFDA120F1056E009A9D22 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_COMPLICATION_NAME = Complication; + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = "BinaryWatch Extension/Info.plist"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@executable_path/../../Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = me.leavez.Binary.watchkitapp.watchkitextension; + PRODUCT_NAME = "${TARGET_NAME}"; + SDKROOT = watchos; + SKIP_INSTALL = YES; + SWIFT_VERSION = 4.2; + TARGETED_DEVICE_FAMILY = 4; + WATCHOS_DEPLOYMENT_TARGET = 5.0; + }; + name = Release; + }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ @@ -365,6 +639,24 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + 3EEAFDA220F1056E009A9D22 /* Build configuration list for PBXNativeTarget "BinaryWatch Extension" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 3EEAFDA020F1056E009A9D22 /* Debug */, + 3EEAFDA120F1056E009A9D22 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 3EEAFDA420F1056E009A9D22 /* Build configuration list for PBXNativeTarget "BinaryWatch" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 3EEAFD9E20F1056E009A9D22 /* Debug */, + 3EEAFD9F20F1056E009A9D22 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; /* End XCConfigurationList section */ }; rootObject = 3E83E31A207BC00E0057855A /* Project object */; diff --git a/test/BinaryWatch Extension/Assets.xcassets/Complication.complicationset/Circular.imageset/Contents.json b/test/BinaryWatch Extension/Assets.xcassets/Complication.complicationset/Circular.imageset/Contents.json new file mode 100644 index 0000000..f84499b --- /dev/null +++ b/test/BinaryWatch Extension/Assets.xcassets/Complication.complicationset/Circular.imageset/Contents.json @@ -0,0 +1,18 @@ +{ + "images" : [ + { + "idiom" : "watch", + "scale" : "2x", + "screen-width" : "<=145" + }, + { + "idiom" : "watch", + "scale" : "2x", + "screen-width" : ">145" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/test/BinaryWatch Extension/Assets.xcassets/Complication.complicationset/Contents.json b/test/BinaryWatch Extension/Assets.xcassets/Complication.complicationset/Contents.json new file mode 100644 index 0000000..c8ebf06 --- /dev/null +++ b/test/BinaryWatch Extension/Assets.xcassets/Complication.complicationset/Contents.json @@ -0,0 +1,28 @@ +{ + "assets" : [ + { + "idiom" : "watch", + "filename" : "Circular.imageset", + "role" : "circular" + }, + { + "idiom" : "watch", + "filename" : "Extra Large.imageset", + "role" : "extra-large" + }, + { + "idiom" : "watch", + "filename" : "Modular.imageset", + "role" : "modular" + }, + { + "idiom" : "watch", + "filename" : "Utilitarian.imageset", + "role" : "utilitarian" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/test/BinaryWatch Extension/Assets.xcassets/Complication.complicationset/Extra Large.imageset/Contents.json b/test/BinaryWatch Extension/Assets.xcassets/Complication.complicationset/Extra Large.imageset/Contents.json new file mode 100644 index 0000000..f84499b --- /dev/null +++ b/test/BinaryWatch Extension/Assets.xcassets/Complication.complicationset/Extra Large.imageset/Contents.json @@ -0,0 +1,18 @@ +{ + "images" : [ + { + "idiom" : "watch", + "scale" : "2x", + "screen-width" : "<=145" + }, + { + "idiom" : "watch", + "scale" : "2x", + "screen-width" : ">145" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/test/BinaryWatch Extension/Assets.xcassets/Complication.complicationset/Modular.imageset/Contents.json b/test/BinaryWatch Extension/Assets.xcassets/Complication.complicationset/Modular.imageset/Contents.json new file mode 100644 index 0000000..f84499b --- /dev/null +++ b/test/BinaryWatch Extension/Assets.xcassets/Complication.complicationset/Modular.imageset/Contents.json @@ -0,0 +1,18 @@ +{ + "images" : [ + { + "idiom" : "watch", + "scale" : "2x", + "screen-width" : "<=145" + }, + { + "idiom" : "watch", + "scale" : "2x", + "screen-width" : ">145" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/test/BinaryWatch Extension/Assets.xcassets/Complication.complicationset/Utilitarian.imageset/Contents.json b/test/BinaryWatch Extension/Assets.xcassets/Complication.complicationset/Utilitarian.imageset/Contents.json new file mode 100644 index 0000000..f84499b --- /dev/null +++ b/test/BinaryWatch Extension/Assets.xcassets/Complication.complicationset/Utilitarian.imageset/Contents.json @@ -0,0 +1,18 @@ +{ + "images" : [ + { + "idiom" : "watch", + "scale" : "2x", + "screen-width" : "<=145" + }, + { + "idiom" : "watch", + "scale" : "2x", + "screen-width" : ">145" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/test/BinaryWatch Extension/Assets.xcassets/Contents.json b/test/BinaryWatch Extension/Assets.xcassets/Contents.json new file mode 100644 index 0000000..da4a164 --- /dev/null +++ b/test/BinaryWatch Extension/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/test/BinaryWatch Extension/ExtensionDelegate.swift b/test/BinaryWatch Extension/ExtensionDelegate.swift new file mode 100644 index 0000000..3b5c130 --- /dev/null +++ b/test/BinaryWatch Extension/ExtensionDelegate.swift @@ -0,0 +1,56 @@ +// +// ExtensionDelegate.swift +// BinaryWatch Extension +// +// Created by Gao on 2018/7/7. +// Copyright © 2018 me.leavez. All rights reserved. +// + +import WatchKit + +class ExtensionDelegate: NSObject, WKExtensionDelegate { + + func applicationDidFinishLaunching() { + // Perform any final initialization of your application. + } + + func applicationDidBecomeActive() { + // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. + } + + func applicationWillResignActive() { + // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + // Use this method to pause ongoing tasks, disable timers, etc. + } + + func handle(_ backgroundTasks: Set) { + // Sent when the system needs to launch the application in the background to process tasks. Tasks arrive in a set, so loop through and process each one. + for task in backgroundTasks { + // Use a switch statement to check the task type + switch task { + case let backgroundTask as WKApplicationRefreshBackgroundTask: + // Be sure to complete the background task once you’re done. + backgroundTask.setTaskCompletedWithSnapshot(false) + case let snapshotTask as WKSnapshotRefreshBackgroundTask: + // Snapshot tasks have a unique completion call, make sure to set your expiration date + snapshotTask.setTaskCompleted(restoredDefaultState: true, estimatedSnapshotExpiration: Date.distantFuture, userInfo: nil) + case let connectivityTask as WKWatchConnectivityRefreshBackgroundTask: + // Be sure to complete the connectivity task once you’re done. + connectivityTask.setTaskCompletedWithSnapshot(false) + case let urlSessionTask as WKURLSessionRefreshBackgroundTask: + // Be sure to complete the URL session task once you’re done. + urlSessionTask.setTaskCompletedWithSnapshot(false) + case let relevantShortcutTask as WKRelevantShortcutRefreshBackgroundTask: + // Be sure to complete the relevant-shortcut task once you're done. + relevantShortcutTask.setTaskCompletedWithSnapshot(false) + case let intentDidRunTask as WKIntentDidRunRefreshBackgroundTask: + // Be sure to complete the intent-did-run task once you're done. + intentDidRunTask.setTaskCompletedWithSnapshot(false) + default: + // make sure to complete unhandled task types + task.setTaskCompletedWithSnapshot(false) + } + } + } + +} diff --git a/test/BinaryWatch Extension/Info.plist b/test/BinaryWatch Extension/Info.plist new file mode 100644 index 0000000..7919078 --- /dev/null +++ b/test/BinaryWatch Extension/Info.plist @@ -0,0 +1,36 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleDisplayName + BinaryWatch Extension + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + XPC! + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + NSExtension + + NSExtensionAttributes + + WKAppBundleIdentifier + me.leavez.Binary.watchkitapp + + NSExtensionPointIdentifier + com.apple.watchkit + + WKExtensionDelegateClassName + $(PRODUCT_MODULE_NAME).ExtensionDelegate + + diff --git a/test/BinaryWatch Extension/InterfaceController.swift b/test/BinaryWatch Extension/InterfaceController.swift new file mode 100644 index 0000000..8216054 --- /dev/null +++ b/test/BinaryWatch Extension/InterfaceController.swift @@ -0,0 +1,31 @@ +// +// InterfaceController.swift +// BinaryWatch Extension +// +// Created by Gao on 2018/7/7. +// Copyright © 2018 me.leavez. All rights reserved. +// + +import WatchKit +import Foundation + + +class InterfaceController: WKInterfaceController { + + override func awake(withContext context: Any?) { + super.awake(withContext: context) + + // Configure interface objects here. + } + + override func willActivate() { + // This method is called when watch view controller is about to be visible to user + super.willActivate() + } + + override func didDeactivate() { + // This method is called when watch view controller is no longer visible + super.didDeactivate() + } + +} diff --git a/test/BinaryWatch Extension/import.swift b/test/BinaryWatch Extension/import.swift new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/test/BinaryWatch Extension/import.swift @@ -0,0 +1 @@ + diff --git a/test/BinaryWatch/Assets.xcassets/AppIcon.appiconset/Contents.json b/test/BinaryWatch/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..47bda83 --- /dev/null +++ b/test/BinaryWatch/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,67 @@ +{ + "images" : [ + { + "size" : "24x24", + "idiom" : "watch", + "scale" : "2x", + "role" : "notificationCenter", + "subtype" : "38mm" + }, + { + "size" : "27.5x27.5", + "idiom" : "watch", + "scale" : "2x", + "role" : "notificationCenter", + "subtype" : "42mm" + }, + { + "size" : "29x29", + "idiom" : "watch", + "role" : "companionSettings", + "scale" : "2x" + }, + { + "size" : "29x29", + "idiom" : "watch", + "role" : "companionSettings", + "scale" : "3x" + }, + { + "size" : "40x40", + "idiom" : "watch", + "scale" : "2x", + "role" : "appLauncher", + "subtype" : "38mm" + }, + { + "size" : "44x44", + "idiom" : "watch", + "scale" : "2x", + "role" : "longLook", + "subtype" : "42mm" + }, + { + "size" : "86x86", + "idiom" : "watch", + "scale" : "2x", + "role" : "quickLook", + "subtype" : "38mm" + }, + { + "size" : "98x98", + "idiom" : "watch", + "scale" : "2x", + "role" : "quickLook", + "subtype" : "42mm" + }, + { + "idiom" : "watch-marketing", + "size" : "1024x1024", + "scale" : "1x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/test/BinaryWatch/Assets.xcassets/Contents.json b/test/BinaryWatch/Assets.xcassets/Contents.json new file mode 100644 index 0000000..da4a164 --- /dev/null +++ b/test/BinaryWatch/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/test/BinaryWatch/Base.lproj/Interface.storyboard b/test/BinaryWatch/Base.lproj/Interface.storyboard new file mode 100644 index 0000000..cf05d24 --- /dev/null +++ b/test/BinaryWatch/Base.lproj/Interface.storyboard @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/test/BinaryWatch/Info.plist b/test/BinaryWatch/Info.plist new file mode 100644 index 0000000..565bd7e --- /dev/null +++ b/test/BinaryWatch/Info.plist @@ -0,0 +1,33 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleDisplayName + Binary + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + + WKCompanionAppBundleIdentifier + me.leavez.Binary + WKWatchKitApp + + + From 6586f404f167a3046eed1f41550fb6975f135214 Mon Sep 17 00:00:00 2001 From: leavez Date: Sat, 7 Jul 2018 22:40:55 +0800 Subject: [PATCH 21/25] add test for multiplePlatforms --- .../ExtensionDelegate.swift | 35 ------------------- test/change_podfile.py | 24 +++++++++++++ test/test.sh | 5 +++ 3 files changed, 29 insertions(+), 35 deletions(-) diff --git a/test/BinaryWatch Extension/ExtensionDelegate.swift b/test/BinaryWatch Extension/ExtensionDelegate.swift index 3b5c130..3b03918 100644 --- a/test/BinaryWatch Extension/ExtensionDelegate.swift +++ b/test/BinaryWatch Extension/ExtensionDelegate.swift @@ -18,39 +18,4 @@ class ExtensionDelegate: NSObject, WKExtensionDelegate { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } - func applicationWillResignActive() { - // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. - // Use this method to pause ongoing tasks, disable timers, etc. - } - - func handle(_ backgroundTasks: Set) { - // Sent when the system needs to launch the application in the background to process tasks. Tasks arrive in a set, so loop through and process each one. - for task in backgroundTasks { - // Use a switch statement to check the task type - switch task { - case let backgroundTask as WKApplicationRefreshBackgroundTask: - // Be sure to complete the background task once you’re done. - backgroundTask.setTaskCompletedWithSnapshot(false) - case let snapshotTask as WKSnapshotRefreshBackgroundTask: - // Snapshot tasks have a unique completion call, make sure to set your expiration date - snapshotTask.setTaskCompleted(restoredDefaultState: true, estimatedSnapshotExpiration: Date.distantFuture, userInfo: nil) - case let connectivityTask as WKWatchConnectivityRefreshBackgroundTask: - // Be sure to complete the connectivity task once you’re done. - connectivityTask.setTaskCompletedWithSnapshot(false) - case let urlSessionTask as WKURLSessionRefreshBackgroundTask: - // Be sure to complete the URL session task once you’re done. - urlSessionTask.setTaskCompletedWithSnapshot(false) - case let relevantShortcutTask as WKRelevantShortcutRefreshBackgroundTask: - // Be sure to complete the relevant-shortcut task once you're done. - relevantShortcutTask.setTaskCompletedWithSnapshot(false) - case let intentDidRunTask as WKIntentDidRunRefreshBackgroundTask: - // Be sure to complete the intent-did-run task once you're done. - intentDidRunTask.setTaskCompletedWithSnapshot(false) - default: - // make sure to complete unhandled task types - task.setTaskCompletedWithSnapshot(false) - } - } - } - } diff --git a/test/change_podfile.py b/test/change_podfile.py index 25d5c36..08d2284 100644 --- a/test/change_podfile.py +++ b/test/change_podfile.py @@ -25,6 +25,12 @@ def save_to_podfile(text): file.write(text[1]) file.close() + path = os.path.dirname(os.path.abspath(__file__)) + path += "/BinaryWatch Extension/import.swift" + file = open(path, "w+") + file.write( "" if len(text) <= 2 else text[2]) + file.close() + def initial(): @@ -133,6 +139,24 @@ def universalFlag(): import AFNetworking """) +def multiplePlatforms(): + return (wrapper( +""" +pod "Literal", :binary => true +pod "AFNetworking/Reachability", :binary => true +end + +target 'BinaryWatch Extension' do +pod ""Literal"" +""") , +""" +import Literal +import AFNetworking +""", +""" +import Literal +""" +) diff --git a/test/test.sh b/test/test.sh index 2faf763..9cd29d5 100644 --- a/test/test.sh +++ b/test/test.sh @@ -41,6 +41,11 @@ python change_podfile.py "addVendoredLibPod" pod install build +# +python change_podfile.py "multiplePlatforms" +pod install +build + # python change_podfile.py "universalFlag" pod install From cdc913a5a304dbc57e7ec17b88a91d1aca2e9949 Mon Sep 17 00:00:00 2001 From: leavez Date: Sat, 7 Jul 2018 22:53:37 +0800 Subject: [PATCH 22/25] fix test --- test/change_podfile.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/change_podfile.py b/test/change_podfile.py index 08d2284..8acc575 100644 --- a/test/change_podfile.py +++ b/test/change_podfile.py @@ -143,18 +143,18 @@ def multiplePlatforms(): return (wrapper( """ pod "Literal", :binary => true -pod "AFNetworking/Reachability", :binary => true +pod "AFNetworking/Serialization", :binary => true end target 'BinaryWatch Extension' do -pod ""Literal"" +pod "AFNetworking/Serialization" """) , """ import Literal import AFNetworking """, """ -import Literal +import AFNetworking """ ) From d23483354685148c845114225333d5248d41b637 Mon Sep 17 00:00:00 2001 From: leavez Date: Sun, 8 Jul 2018 00:58:07 +0800 Subject: [PATCH 23/25] fix validate_every_pod_only_have_one_form --- lib/cocoapods-binary/helper/podfile_options.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/cocoapods-binary/helper/podfile_options.rb b/lib/cocoapods-binary/helper/podfile_options.rb index 82e30bc..532155a 100644 --- a/lib/cocoapods-binary/helper/podfile_options.rb +++ b/lib/cocoapods-binary/helper/podfile_options.rb @@ -11,13 +11,17 @@ class TargetDefinition ## --- option for setting using prebuild framework --- def parse_prebuild_framework(name, requirements) + + should_prebuild = Pod::Podfile::DSL.prebuild_all + options = requirements.last - return requirements unless options.is_a?(Hash) + if options.is_a?(Hash) && options[Pod::Prebuild.keyword] != nil + should_prebuild = options.delete(Pod::Prebuild.keyword) + requirements.pop if options.empty? + end - should_prebuild_framework = options.delete(Pod::Prebuild.keyword) pod_name = Specification.root_name(name) - set_prebuild_for_pod(pod_name, should_prebuild_framework) - requirements.pop if options.empty? + set_prebuild_for_pod(pod_name, should_prebuild) end def set_prebuild_for_pod(pod_name, should_prebuild) @@ -105,7 +109,9 @@ def validate_every_pod_only_have_one_form aggregate_targets.each do |aggregate_target| target_definition = aggregate_target.target_definition prebuit += target_definition.prebuild_framework_pod_names - not_prebuilt += target_definition.should_not_prebuild_framework_pod_names + not_prebuilt += aggregate_target.pod_targets.reject do |target| + target_definition.prebuild_framework_pod_names.include? target.pod_name + end.map(&:pod_name) end intersection = prebuit & not_prebuilt From 3333385db6619208efcd430fcb2ef70740894dd6 Mon Sep 17 00:00:00 2001 From: leavez Date: Sun, 8 Jul 2018 01:28:38 +0800 Subject: [PATCH 24/25] fix test --- test/change_podfile.py | 38 +++++++++++++++++++++++++++++++++++++- test/test.sh | 7 ++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/test/change_podfile.py b/test/change_podfile.py index 8acc575..58ba00e 100644 --- a/test/change_podfile.py +++ b/test/change_podfile.py @@ -147,17 +147,53 @@ def multiplePlatforms(): end target 'BinaryWatch Extension' do -pod "AFNetworking/Serialization" + platform :watchos + pod "AFNetworking/Serialization", :binary => true """) , """ import Literal import AFNetworking +class A { + let a: CGRect = [1,2,3,4] + func dd() { _ = AFURLRequestSerializationErrorDomain } +} """, """ import AFNetworking +class A { + func dd() { _ = AFURLRequestSerializationErrorDomain } +} """ ) +def multiplePlatformsWithALLFlag(): + return (wrapper( +""" +all_binary! + +pod "Literal" +pod "AFNetworking/Serialization" +end + +target 'BinaryWatch Extension' do + platform :watchos + pod "AFNetworking/Serialization" +""") , +""" +import Literal +import AFNetworking +class A { + let a: CGRect = [1,2,3,4] + func dd() { _ = AFURLRequestSerializationErrorDomain } +} +""", +""" +import AFNetworking +class A { + func dd() { _ = AFURLRequestSerializationErrorDomain } +} +""" +) if __name__ == "__main__": diff --git a/test/test.sh b/test/test.sh index 9cd29d5..95a0bcf 100644 --- a/test/test.sh +++ b/test/test.sh @@ -41,13 +41,18 @@ python change_podfile.py "addVendoredLibPod" pod install build +# +python change_podfile.py "universalFlag" +pod install +build + # python change_podfile.py "multiplePlatforms" pod install build # -python change_podfile.py "universalFlag" +python change_podfile.py "multiplePlatformsWithALLFlag" pod install build From 589bc2257410d475971bd80440faac7c6201390a Mon Sep 17 00:00:00 2001 From: leavez Date: Sun, 8 Jul 2018 01:44:58 +0800 Subject: [PATCH 25/25] add content in test --- test/change_podfile.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/test/change_podfile.py b/test/change_podfile.py index 58ba00e..512dd1b 100644 --- a/test/change_podfile.py +++ b/test/change_podfile.py @@ -42,6 +42,9 @@ def initial(): """), """ import Masonry +class A { + let d = UIView().mas_top +} """) def addSwiftPod(): @@ -55,6 +58,10 @@ def addSwiftPod(): """ import RxCocoa import Literal +class A { + let a: CGRect = [1,2,3,4] + func dd() { NSObject().rx.observe(CGRect.self, "frame") } +} """) def revertToSourceCode(): @@ -67,7 +74,13 @@ def revertToSourceCode(): """), """ import RxCocoa +import RxSwift import Literal +class A { + let a: CGRect = [1,2,3,4] + let b = Observable.just(1) + func dd() { NSObject().rx.observe(CGRect.self, "frame") } +} """) def addDifferentNamePod(): @@ -83,6 +96,11 @@ def addDifferentNamePod(): import Masonry import Literal import Lottie +class A { + let a: CGRect = [1,2,3,4] + let a2 = LOTAnimationView.self + let d = UIView().mas_top +} """) @@ -99,6 +117,12 @@ def addSubPod(): import Literal import Lottie import AFNetworking +class A { + let a: CGRect = [1,2,3,4] + let a2 = LOTAnimationView.self + let b = AFNetworkReachabilityManager() + let d = UIView().mas_top +} """) def addVendoredLibPod(): @@ -113,6 +137,11 @@ def addVendoredLibPod(): import Literal import AFNetworking import Instabug +class A { + let a: CGRect = [1,2,3,4] + let b = AFNetworkReachabilityManager() + let c = Instabug.self +} """) def deleteAPod(): @@ -124,6 +153,10 @@ def deleteAPod(): """ import Literal import AFNetworking +class A { + let a: CGRect = [1,2,3,4] + let b = AFNetworkReachabilityManager() +} """) def universalFlag(): @@ -137,6 +170,10 @@ def universalFlag(): """ import Literal import AFNetworking +class A { + let a: CGRect = [1,2,3,4] + let b = AFNetworkReachabilityManager() +} """) def multiplePlatforms():