diff --git a/lib/cocoapods-binary/Integration.rb b/lib/cocoapods-binary/Integration.rb index 8a9a75b..8778f2b 100644 --- a/lib/cocoapods-binary/Integration.rb +++ b/lib/cocoapods-binary/Integration.rb @@ -2,6 +2,7 @@ require_relative 'helper/feature_switches' require_relative 'helper/prebuild_sandbox' require_relative 'helper/passer' +require_relative 'helper/target_checker' # NOTE: @@ -128,18 +129,12 @@ def remove_target_files_if_needed # call original old_method2.bind(self).() + # check the pods + # Although we have did it in prebuild stage, it's not sufficient. + # Same pod may appear in another target in form of source code. + Prebuild.check_one_pod_should_have_only_one_target(self.prebuild_pod_targets) - # 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 - end - - + # specs = self.analysis_result.specifications prebuilt_specs = (specs.select do |spec| self.prebuild_pod_names.include? spec.root.name diff --git a/lib/cocoapods-binary/Prebuild.rb b/lib/cocoapods-binary/Prebuild.rb index e5a69c5..9123a5f 100644 --- a/lib/cocoapods-binary/Prebuild.rb +++ b/lib/cocoapods-binary/Prebuild.rb @@ -1,5 +1,7 @@ require_relative 'rome/build_framework' require_relative 'helper/passer' +require_relative 'helper/target_checker' + # patch prebuild ability module Pod @@ -67,6 +69,10 @@ def install_when_cache_hit! # Build the needed framework files def prebuild_frameworks! + # check + # give a early warning, instead of after compiling all the pods + Prebuild.check_one_pod_should_have_only_one_target(self.pod_targets) + # build options sandbox_path = sandbox.root existed_framework_folder = sandbox.generate_framework_path @@ -98,7 +104,9 @@ def prebuild_frameworks! sum end targets = root_names_to_update.map do |root_name| - name_to_target_hash[root_name] + t = name_to_target_hash[root_name] + raise "There's no target named (#{root_name}) in Pod.xcodeproj.\n #{name_to_target_hash.keys}" if t.nil? + t end || [] # add the dendencies @@ -111,12 +119,14 @@ def prebuild_frameworks! targets = targets.reject {|pod_target| sandbox.local?(pod_target.pod_name) } - # build! Pod::UI.puts "Prebuild frameworks (total #{targets.count})" Pod::Prebuild.remove_build_dir(sandbox_path) targets.each do |target| - next unless target.should_build? + if !target.should_build? + UI.puts "Prebuilding #{target.label}" + next + end output_path = sandbox.framework_folder_path_for_pod_name(target.name) output_path.mkpath unless output_path.exist? diff --git a/lib/cocoapods-binary/helper/target_checker.rb b/lib/cocoapods-binary/helper/target_checker.rb new file mode 100644 index 0000000..7d90a1f --- /dev/null +++ b/lib/cocoapods-binary/helper/target_checker.rb @@ -0,0 +1,49 @@ + +module Pod + class Prebuild + + # Check the targets, for the current limitation of the plugin + # + # @param [Array] prebuilt_targets + def self.check_one_pod_should_have_only_one_target(prebuilt_targets) + + targets_have_different_platforms = prebuilt_targets.select {|t| t.pod_name != t.name } + + if targets_have_different_platforms.count > 0 + names = targets_have_different_platforms.map(&:pod_name) + raw_names = targets_have_different_platforms.map(&:name) + message = "Oops, you came across a limitation of cocoapods-binary. + +The plugin requires that one pod should have ONLY ONE target in the 'Pod.xcodeproj'. There are mainly 2 situations \ +causing this problem: + +1. One pod integrates in 2 or more different platforms' targets. e.g. + ``` + target 'iphoneApp' do + pod 'A', :binary => true + end + target 'watchApp' do + pod 'A' + end + ``` + +2. Use different subspecs in multiple targets. e.g. + ``` + target 'iphoneApp' do + pod 'A/core' + pod 'A/network' + end + target 'iphoneAppTest' do + pod 'A/core' + end + ``` + +Related pods: #{names}, target names: #{raw_names} + " + raise Informative, message + end + end + + + end +end \ No newline at end of file