@@ -86,6 +86,11 @@ private class Pod {
8686        /// </summary> 
8787        public  string  minTargetSdk  =  null ; 
8888
89+         /// <summary> 
90+         /// Whether to add this pod to all targets when multiple 
91+         /// </summary> 
92+         public  bool  addToAllTargets  =  false ; 
93+ 
8994        /// <summary> 
9095        /// Tag that indicates where this was created. 
9196        /// </summary> 
@@ -162,21 +167,25 @@ public string PodFilePodLine {
162167        /// bitcode.</param> 
163168        /// <param name="minTargetSdk">Minimum target SDK revision required by 
164169        /// this pod.</param> 
170+         /// <param name="addToAllTargets">Whether to add this pod to all targets when multiple 
171+         /// target is supported.</param> 
165172        /// <param name="sources">List of sources to search for all pods. 
166173        /// Each source is a URL that is injected in the source section of a Podfile 
167174        /// See https://guides.cocoapods.org/syntax/podfile.html#source for the description of 
168175        /// a source.</param> 
169176        /// <param name="propertiesByName">Dictionary of additional properties for the pod 
170177        /// reference.</param> 
171178        public  Pod ( string  name ,  string  version ,  bool  bitcodeEnabled ,  string  minTargetSdk , 
172-                    IEnumerable < string >  sources ,  Dictionary < string ,  string >  propertiesByName )  { 
179+                    bool  addToAllTargets ,  IEnumerable < string >  sources , 
180+                    Dictionary < string ,  string >  propertiesByName )  { 
173181            this . name  =  name ; 
174182            this . version  =  version ; 
175183            if  ( propertiesByName  !=  null )  { 
176184                this . propertiesByName  =  new  Dictionary < string ,  string > ( propertiesByName ) ; 
177185            } 
178186            this . bitcodeEnabled  =  bitcodeEnabled ; 
179187            this . minTargetSdk  =  minTargetSdk ; 
188+             this . addToAllTargets  =  addToAllTargets ; 
180189            if  ( sources  !=  null )  { 
181190                var  allSources  =  new  List < string > ( sources ) ; 
182191                allSources . AddRange ( this . sources ) ; 
@@ -305,6 +314,7 @@ protected override bool Read(string filename, Logger logger) {
305314            string  versionSpec  =  null ; 
306315            bool  bitcodeEnabled  =  true ; 
307316            string  minTargetSdk  =  null ; 
317+             bool  addToAllTargets  =  false ; 
308318            var  propertiesByName  =  new  Dictionary < string ,  string > ( ) ; 
309319            if  ( ! XmlUtilities . ParseXmlTextFileElements ( 
310320                filename ,  logger , 
@@ -331,7 +341,12 @@ protected override bool Read(string filename, Logger logger) {
331341                                ( reader . GetAttribute ( "bitcodeEnabled" )  ??  "" ) . ToLower ( ) ; 
332342                            bitcodeEnabled  |=  trueStrings . Contains ( bitcodeEnabledString ) ; 
333343                            bitcodeEnabled  &=  ! falseStrings . Contains ( bitcodeEnabledString ) ; 
344+                             var  addToAllTargetsString  = 
345+                                 ( reader . GetAttribute ( "addToAllTargets" )  ??  "" ) . ToLower ( ) ; 
346+                             addToAllTargets  |=  trueStrings . Contains ( addToAllTargetsString ) ; 
347+                             addToAllTargets  &=  ! falseStrings . Contains ( addToAllTargetsString ) ; 
334348                            minTargetSdk  =  reader . GetAttribute ( "minTargetSdk" ) ; 
349+ 
335350                            sources  =  new  List < string > ( ) ; 
336351                            if  ( podName  ==  null )  { 
337352                                logger . Log ( 
@@ -344,6 +359,7 @@ protected override bool Read(string filename, Logger logger) {
344359                            AddPodInternal ( podName ,  preformattedVersion :  versionSpec , 
345360                                           bitcodeEnabled :  bitcodeEnabled , 
346361                                           minTargetSdk :  minTargetSdk , 
362+                                            addToAllTargets :  addToAllTargets , 
347363                                           sources :  sources , 
348364                                           overwriteExistingPod :  false , 
349365                                           createdBy :  String . Format ( "{0}:{1}" , 
@@ -464,6 +480,10 @@ protected override bool Read(string filename, Logger logger) {
464480    // Whether to add an main target to Podfile for Unity 2019.3+. 
465481    private  const  string  PREFERENCE_PODFILE_ALWAYS_ADD_MAIN_TARGET  = 
466482        PREFERENCE_NAMESPACE  +  "PodfileAlwaysAddMainTarget" ; 
483+     // Whether to allow the same pods to be in multiple targets, if specified in Dependecies.xml. 
484+     private  const  string  PREFERENCE_PODFILE_ALLOW_PODS_IN_MULTIPLE_TARGETS  = 
485+         PREFERENCE_NAMESPACE  +  "PodfileAllowPodsInMultipleTargets" ; 
486+ 
467487    // List of preference keys, used to restore default settings. 
468488    private  static string [ ]  PREFERENCE_KEYS  =  new  [ ]  { 
469489        PREFERENCE_COCOAPODS_INSTALL_ENABLED , 
@@ -476,7 +496,8 @@ protected override bool Read(string filename, Logger logger) {
476496        PREFERENCE_SKIP_POD_INSTALL_WHEN_USING_WORKSPACE_INTEGRATION , 
477497        PREFERENCE_PODFILE_ADD_USE_FRAMEWORKS , 
478498        PREFERENCE_PODFILE_STATIC_LINK_FRAMEWORKS , 
479-         PREFERENCE_PODFILE_ALWAYS_ADD_MAIN_TARGET 
499+         PREFERENCE_PODFILE_ALWAYS_ADD_MAIN_TARGET , 
500+         PREFERENCE_PODFILE_ALLOW_PODS_IN_MULTIPLE_TARGETS 
480501    } ; 
481502
482503    // Whether the xcode extension was successfully loaded. 
@@ -546,6 +567,9 @@ protected override bool Read(string filename, Logger logger) {
546567    // Parses a source URL from a Podfile. 
547568    private  static Regex  PODFILE_SOURCE_REGEX  =  new  Regex ( @"^\s*source\s+'([^']*)'" ) ; 
548569
570+     // Parses comments from a Podfile 
571+     private  static Regex  PODFILE_COMMENT_REGEX  =  new  Regex ( @"^\s*\#" ) ; 
572+ 
549573    // Parses dependencies from XML dependency files. 
550574    private  static IOSXmlDependencies  xmlDependencies  =  new  IOSXmlDependencies ( ) ; 
551575
@@ -987,6 +1011,18 @@ public static bool PodfileAlwaysAddMainTarget {
9871011        } 
9881012    } 
9891013
1014+     /// <summary> 
1015+     /// Whether to allow the same pods to be in multiple targets, if specified in Dependecies.xml. 
1016+     /// </summary> 
1017+     public  static bool  PodfileAllowPodsInMultipleTargets  { 
1018+         get  {  return  settings . GetBool ( PREFERENCE_PODFILE_ALLOW_PODS_IN_MULTIPLE_TARGETS , 
1019+                                     defaultValue :  true ) ;  } 
1020+         set  { 
1021+             settings . SetBool ( PREFERENCE_PODFILE_ALLOW_PODS_IN_MULTIPLE_TARGETS ,  value ) ; 
1022+         } 
1023+     } 
1024+ 
1025+ 
9901026    /// <summary> 
9911027    /// Whether to use project level settings. 
9921028    /// </summary> 
@@ -1166,7 +1202,38 @@ public static void AddPod(string podName, string version = null,
11661202        AddPodInternal ( podName , 
11671203                       preformattedVersion :  PodVersionExpressionFromVersionDep ( version ) , 
11681204                       bitcodeEnabled :  bitcodeEnabled ,  minTargetSdk :  minTargetSdk , 
1169-                        sources :  sources ) ; 
1205+                        addToAllTargets :  false ,  sources :  sources ) ; 
1206+     } 
1207+ 
1208+     /// <summary> 
1209+     /// Tells the app what pod dependencies are needed. 
1210+     /// This is called from a deps file in each API to aggregate all of the 
1211+     /// dependencies to automate the Podfile generation. 
1212+     /// </summary> 
1213+     /// <param name="podName">pod path, for example "Google-Mobile-Ads-SDK" to 
1214+     /// be included</param> 
1215+     /// <param name="version">Version specification. 
1216+     /// See PodVersionExpressionFromVersionDep for how the version string is processed.</param> 
1217+     /// <param name="bitcodeEnabled">Whether the pod was compiled with bitcode 
1218+     /// enabled.  If this is set to false on a pod, the entire project will 
1219+     /// be configured with bitcode disabled.</param> 
1220+     /// <param name="minTargetSdk">Minimum SDK revision required by this 
1221+     /// pod.</param> 
1222+     /// <param name="addToAllTargets">Whether to add this pod to all targets when multiple 
1223+     /// target is supported.</param> 
1224+     /// <param name="sources">List of sources to search for all pods. 
1225+     /// Each source is a URL that is injected in the source section of a Podfile 
1226+     /// See https://guides.cocoapods.org/syntax/podfile.html#source for the description of 
1227+     /// a source.</param> 
1228+     public  static void  AddPod ( string  podName ,  string  version  =  null , 
1229+                               bool  bitcodeEnabled  =  true , 
1230+                               string  minTargetSdk  =  null , 
1231+                               bool  addToAllTargets  =  false , 
1232+                               IEnumerable < string >  sources  =  null )  { 
1233+         AddPodInternal ( podName , 
1234+                        preformattedVersion :  PodVersionExpressionFromVersionDep ( version ) , 
1235+                        bitcodeEnabled :  bitcodeEnabled ,  minTargetSdk :  minTargetSdk , 
1236+                        addToAllTargets :  addToAllTargets ,  sources :  sources ) ; 
11701237    } 
11711238
11721239    /// <summary> 
@@ -1182,6 +1249,8 @@ public static void AddPod(string podName, string version = null,
11821249    /// be configured with bitcode disabled.</param> 
11831250    /// <param name="minTargetSdk">Minimum SDK revision required by this 
11841251    /// pod.</param> 
1252+     /// <param name="addToAllTargets">Whether to add this pod to all targets when multiple 
1253+     /// target is supported.</param> 
11851254    /// <param name="sources">List of sources to search for all pods. 
11861255    /// Each source is a URL that is injected in the source section of a Podfile 
11871256    /// See https://guides.cocoapods.org/syntax/podfile.html#source for the description of 
@@ -1195,22 +1264,24 @@ private static void AddPodInternal(string podName,
11951264                                       string  preformattedVersion  =  null , 
11961265                                       bool  bitcodeEnabled  =  true , 
11971266                                       string  minTargetSdk  =  null , 
1267+                                        bool  addToAllTargets  =  false , 
11981268                                       IEnumerable < string >  sources  =  null , 
11991269                                       bool  overwriteExistingPod  =  true , 
12001270                                       string  createdBy  =  null , 
12011271                                       bool  fromXmlFile  =  false , 
12021272                                       Dictionary < string ,  string >  propertiesByName  =  null )  { 
12031273        var  pod  =  new  Pod ( podName ,  preformattedVersion ,  bitcodeEnabled ,  minTargetSdk , 
1204-                           sources ,  propertiesByName ) ; 
1274+                           addToAllTargets ,   sources ,  propertiesByName ) ; 
12051275        pod . createdBy  =  createdBy  ??  pod . createdBy ; 
12061276        pod . fromXmlFile  =  fromXmlFile ; 
12071277
12081278        Log ( String . Format ( 
1209-             "AddPod - name: {0} version: {1} bitcode: {2} sdk: {3} sources : {4},  "  + 
1210-             "properties : {5}\n "  + 
1211-             "createdBy: {6 }\n \n " , 
1279+             "AddPod - name: {0} version: {1} bitcode: {2} sdk: {3} alltarget : {4} "  + 
1280+             "sources : {5} properties: {6 }\n "  + 
1281+             "createdBy: {7 }\n \n " , 
12121282            podName ,  preformattedVersion  ??  "null" ,  bitcodeEnabled . ToString ( ) , 
12131283            minTargetSdk  ??  "null" , 
1284+             addToAllTargets . ToString ( ) , 
12141285            sources  !=  null  ?  String . Join ( ", " ,  ( new  List < string > ( sources ) ) . ToArray ( ) )  :  "(null)" , 
12151286            Pod . PropertyDictionaryToString ( pod . propertiesByName ) , 
12161287            createdBy  ??  pod . createdBy ) , 
@@ -1874,11 +1945,15 @@ private static void ParseUnityDeps(string unityPodfilePath) {
18741945        var  sources  =  new  List < string > ( ) ; 
18751946        while  ( ( line  =  unityPodfile . ReadLine ( ) )  !=  null )  { 
18761947            line  =  line . Trim ( ) ; 
1948+             if  ( PODFILE_COMMENT_REGEX . IsMatch ( line ) )  { 
1949+                 continue ; 
1950+             } 
18771951            var  sourceLineMatch  =  PODFILE_SOURCE_REGEX . Match ( line ) ; 
18781952            if  ( sourceLineMatch . Groups . Count  >  1 )  { 
18791953                sources . Add ( sourceLineMatch . Groups [ 1 ] . Value ) ; 
18801954                continue ; 
18811955            } 
1956+             // TODO: Properly support multiple targets. 
18821957            if  ( line . StartsWith ( "target 'Unity-iPhone' do" ) )  { 
18831958                capturingPodsDepth ++ ; 
18841959                continue ; 
@@ -2000,6 +2075,20 @@ public static void GenPodfile(BuildTarget buildTarget,
20002075
20012076            if  ( MultipleXcodeTargetsSupported  &&  PodfileAlwaysAddMainTarget )  { 
20022077                file . WriteLine ( String . Format ( "target '{0}' do" ,  "Unity-iPhone" ) ) ; 
2078+                 bool  allowPodsInMultipleTargets  =  PodfileAllowPodsInMultipleTargets ; 
2079+                 int  podAdded  =  0 ; 
2080+                 foreach ( var  pod  in  pods . Values )  { 
2081+                     if  ( pod . addToAllTargets )  { 
2082+                         file . WriteLine ( String . Format ( "  {0}{1}" , 
2083+                                 allowPodsInMultipleTargets  ?  ""  :  "# " , 
2084+                                 pod . PodFilePodLine ) ) ; 
2085+                         podAdded ++ ; 
2086+                     } 
2087+                 } 
2088+                 if  ( ! allowPodsInMultipleTargets  &&  podAdded  >  0 )  { 
2089+                     file . WriteLine ( String . Format ( 
2090+                         "  # Commented due to iOS Resolver settings." ) ) ; 
2091+                 } 
20032092                file . WriteLine ( "end" ) ; 
20042093            } 
20052094            if  ( PodfileAddUseFrameworks )  { 
0 commit comments