From 250769a55a7763b22899221e6e24eb376ef5ad68 Mon Sep 17 00:00:00 2001
From: Olivier Halligon <olivier.halligon@babylonhealth.com>
Date: Fri, 17 May 2019 22:31:59 +0200
Subject: [PATCH 1/2] Fix deployment target used to find simulator to compile
 binary

---
 lib/cocoapods-binary/Prebuild.rb              | 11 +++++++++--
 lib/cocoapods-binary/helper/target_checker.rb |  2 +-
 lib/cocoapods-binary/rome/build_framework.rb  | 13 ++++++-------
 3 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/lib/cocoapods-binary/Prebuild.rb b/lib/cocoapods-binary/Prebuild.rb
index 77bc834..b969585 100644
--- a/lib/cocoapods-binary/Prebuild.rb
+++ b/lib/cocoapods-binary/Prebuild.rb
@@ -97,7 +97,7 @@ def prebuild_frameworks!
                 targets = root_names_to_update.map do |pod_name|
                     tars = Pod.fast_get_targets_for_pod_name(pod_name, self.pod_targets, cache)
                     if tars.nil? || tars.empty?
-                        raise "There's no target named (#{pod_name}) in Pod.xcodeproj.\n #{self.pod_targets.map(&:name)}" if t.nil?
+                        raise "There's no target named (#{pod_name}) in Pods.xcodeproj.\n #{self.pod_targets.map(&:name)}" if t.nil?
                     end
                     tars
                 end.flatten
@@ -123,7 +123,14 @@ def prebuild_frameworks!
 
                 output_path = sandbox.framework_folder_path_for_target_name(target.name)
                 output_path.mkpath unless output_path.exist?
-                Pod::Prebuild.build(sandbox_path, target, output_path, bitcode_enabled,  Podfile::DSL.custom_build_options,  Podfile::DSL.custom_build_options_simulator)
+
+                min_deployment_target = aggregate_targets
+                    .select { |t| t.pod_targets.include?(target) }
+                    .map(&:platform)
+                    .map(&:deployment_target)
+                    .max
+
+                Pod::Prebuild.build(sandbox_path, target, min_deployment_target, output_path, bitcode_enabled,  Podfile::DSL.custom_build_options,  Podfile::DSL.custom_build_options_simulator)
 
                 # save the resource paths for later installing
                 if target.static_framework? and !target.resource_paths.empty?
diff --git a/lib/cocoapods-binary/helper/target_checker.rb b/lib/cocoapods-binary/helper/target_checker.rb
index 7d90a1f..ee4dc0f 100644
--- a/lib/cocoapods-binary/helper/target_checker.rb
+++ b/lib/cocoapods-binary/helper/target_checker.rb
@@ -14,7 +14,7 @@ def self.check_one_pod_should_have_only_one_target(prebuilt_targets)
         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 \
+The plugin requires that one pod should have ONLY ONE target in the 'Pods.xcodeproj'. There are mainly 2 situations \
 causing this problem:
 
 1. One pod integrates in 2 or more different platforms' targets. e.g.
diff --git a/lib/cocoapods-binary/rome/build_framework.rb b/lib/cocoapods-binary/rome/build_framework.rb
index 10c8571..9a5846d 100644
--- a/lib/cocoapods-binary/rome/build_framework.rb
+++ b/lib/cocoapods-binary/rome/build_framework.rb
@@ -14,14 +14,13 @@ def build_for_iosish_platform(sandbox,
                               build_dir, 
                               output_path,
                               target, 
+                              deployment_target, 
                               device, 
                               simulator,
                               bitcode_enabled,
                               custom_build_options = [], # Array<String>
                               custom_build_options_simulator = [] # Array<String>
                               )
-
-  deployment_target = target.platform.deployment_target.to_s
   
   target_label = target.label # name with platform if it's used in multiple platforms
   Pod::UI.puts "Prebuilding #{target_label}..."
@@ -51,7 +50,7 @@ def build_for_iosish_platform(sandbox,
   # combine the binaries
   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)
+  Pod::UI.puts lipo_log unless File.exist?(tmp_lipoed_binary_path)
   FileUtils.mv tmp_lipoed_binary_path, device_binary, :force => true
   
   # collect the swiftmodule file for various archs.
@@ -124,10 +123,10 @@ def xcodebuild(sandbox, target, sdk='macosx', deployment_target=nil, other_optio
               printer.pretty_print(line)
             end
         else
-            raise "shouldn't be handle by xcpretty"
+            raise "shouldn't be handled by xcpretty"
         end
     rescue
-        puts log.red
+        Pod::UI.puts log.red
     end
   end
   [is_succeed, log]
@@ -149,7 +148,7 @@ class Prebuild
     #         [Pathname] output_path
     #         output path for generated frameworks
     #
-    def self.build(sandbox_root_path, target, output_path, bitcode_enabled = false, custom_build_options=[], custom_build_options_simulator=[])
+    def self.build(sandbox_root_path, target, min_deployment_target, output_path, bitcode_enabled = false, custom_build_options=[], custom_build_options_simulator=[])
     
       return if target.nil?
     
@@ -159,7 +158,7 @@ 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, custom_build_options, custom_build_options_simulator)
+      when :ios then build_for_iosish_platform(sandbox, build_dir, output_path, target, min_deployment_target, 'iphoneos', 'iphonesimulator', bitcode_enabled, custom_build_options, custom_build_options_simulator)
       when :osx then xcodebuild(sandbox, target.label, 'macosx', nil, custom_build_options)
       # when :tvos then build_for_iosish_platform(sandbox, build_dir, target, 'appletvos', 'appletvsimulator')
       when :watchos then build_for_iosish_platform(sandbox, build_dir, output_path, target, 'watchos', 'watchsimulator', true, custom_build_options, custom_build_options_simulator)

From aabc1a59a9d3dd61b4e7b4d8b36a4db097f98e03 Mon Sep 17 00:00:00 2001
From: Olivier Halligon <olivier.halligon@babylonhealth.com>
Date: Tue, 21 May 2019 17:41:13 +0200
Subject: [PATCH 2/2] Re-Trigger CI