@@ -86,6 +86,11 @@ private class Pod {
86
86
/// </summary>
87
87
public string minTargetSdk = null ;
88
88
89
+ /// <summary>
90
+ /// Whether to add this pod to all targets when multiple
91
+ /// </summary>
92
+ public bool addToAllTargets = false ;
93
+
89
94
/// <summary>
90
95
/// Tag that indicates where this was created.
91
96
/// </summary>
@@ -162,21 +167,25 @@ public string PodFilePodLine {
162
167
/// bitcode.</param>
163
168
/// <param name="minTargetSdk">Minimum target SDK revision required by
164
169
/// this pod.</param>
170
+ /// <param name="addToAllTargets">Whether to add this pod to all targets when multiple
171
+ /// target is supported.</param>
165
172
/// <param name="sources">List of sources to search for all pods.
166
173
/// Each source is a URL that is injected in the source section of a Podfile
167
174
/// See https://guides.cocoapods.org/syntax/podfile.html#source for the description of
168
175
/// a source.</param>
169
176
/// <param name="propertiesByName">Dictionary of additional properties for the pod
170
177
/// reference.</param>
171
178
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 ) {
173
181
this . name = name ;
174
182
this . version = version ;
175
183
if ( propertiesByName != null ) {
176
184
this . propertiesByName = new Dictionary < string , string > ( propertiesByName ) ;
177
185
}
178
186
this . bitcodeEnabled = bitcodeEnabled ;
179
187
this . minTargetSdk = minTargetSdk ;
188
+ this . addToAllTargets = addToAllTargets ;
180
189
if ( sources != null ) {
181
190
var allSources = new List < string > ( sources ) ;
182
191
allSources . AddRange ( this . sources ) ;
@@ -305,6 +314,7 @@ protected override bool Read(string filename, Logger logger) {
305
314
string versionSpec = null ;
306
315
bool bitcodeEnabled = true ;
307
316
string minTargetSdk = null ;
317
+ bool addToAllTargets = false ;
308
318
var propertiesByName = new Dictionary < string , string > ( ) ;
309
319
if ( ! XmlUtilities . ParseXmlTextFileElements (
310
320
filename , logger ,
@@ -331,7 +341,12 @@ protected override bool Read(string filename, Logger logger) {
331
341
( reader . GetAttribute ( "bitcodeEnabled" ) ?? "" ) . ToLower ( ) ;
332
342
bitcodeEnabled |= trueStrings . Contains ( bitcodeEnabledString ) ;
333
343
bitcodeEnabled &= ! falseStrings . Contains ( bitcodeEnabledString ) ;
344
+ var addToAllTargetsString =
345
+ ( reader . GetAttribute ( "addToAllTargets" ) ?? "" ) . ToLower ( ) ;
346
+ addToAllTargets |= trueStrings . Contains ( addToAllTargetsString ) ;
347
+ addToAllTargets &= ! falseStrings . Contains ( addToAllTargetsString ) ;
334
348
minTargetSdk = reader . GetAttribute ( "minTargetSdk" ) ;
349
+
335
350
sources = new List < string > ( ) ;
336
351
if ( podName == null ) {
337
352
logger . Log (
@@ -344,6 +359,7 @@ protected override bool Read(string filename, Logger logger) {
344
359
AddPodInternal ( podName , preformattedVersion : versionSpec ,
345
360
bitcodeEnabled : bitcodeEnabled ,
346
361
minTargetSdk : minTargetSdk ,
362
+ addToAllTargets : addToAllTargets ,
347
363
sources : sources ,
348
364
overwriteExistingPod : false ,
349
365
createdBy : String . Format ( "{0}:{1}" ,
@@ -464,6 +480,10 @@ protected override bool Read(string filename, Logger logger) {
464
480
// Whether to add an main target to Podfile for Unity 2019.3+.
465
481
private const string PREFERENCE_PODFILE_ALWAYS_ADD_MAIN_TARGET =
466
482
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
+
467
487
// List of preference keys, used to restore default settings.
468
488
private static string [ ] PREFERENCE_KEYS = new [ ] {
469
489
PREFERENCE_COCOAPODS_INSTALL_ENABLED ,
@@ -476,7 +496,8 @@ protected override bool Read(string filename, Logger logger) {
476
496
PREFERENCE_SKIP_POD_INSTALL_WHEN_USING_WORKSPACE_INTEGRATION ,
477
497
PREFERENCE_PODFILE_ADD_USE_FRAMEWORKS ,
478
498
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
480
501
} ;
481
502
482
503
// Whether the xcode extension was successfully loaded.
@@ -546,6 +567,9 @@ protected override bool Read(string filename, Logger logger) {
546
567
// Parses a source URL from a Podfile.
547
568
private static Regex PODFILE_SOURCE_REGEX = new Regex ( @"^\s*source\s+'([^']*)'" ) ;
548
569
570
+ // Parses comments from a Podfile
571
+ private static Regex PODFILE_COMMENT_REGEX = new Regex ( @"^\s*\#" ) ;
572
+
549
573
// Parses dependencies from XML dependency files.
550
574
private static IOSXmlDependencies xmlDependencies = new IOSXmlDependencies ( ) ;
551
575
@@ -987,6 +1011,18 @@ public static bool PodfileAlwaysAddMainTarget {
987
1011
}
988
1012
}
989
1013
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
+
990
1026
/// <summary>
991
1027
/// Whether to use project level settings.
992
1028
/// </summary>
@@ -1166,7 +1202,38 @@ public static void AddPod(string podName, string version = null,
1166
1202
AddPodInternal ( podName ,
1167
1203
preformattedVersion : PodVersionExpressionFromVersionDep ( version ) ,
1168
1204
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 ) ;
1170
1237
}
1171
1238
1172
1239
/// <summary>
@@ -1182,6 +1249,8 @@ public static void AddPod(string podName, string version = null,
1182
1249
/// be configured with bitcode disabled.</param>
1183
1250
/// <param name="minTargetSdk">Minimum SDK revision required by this
1184
1251
/// pod.</param>
1252
+ /// <param name="addToAllTargets">Whether to add this pod to all targets when multiple
1253
+ /// target is supported.</param>
1185
1254
/// <param name="sources">List of sources to search for all pods.
1186
1255
/// Each source is a URL that is injected in the source section of a Podfile
1187
1256
/// See https://guides.cocoapods.org/syntax/podfile.html#source for the description of
@@ -1195,22 +1264,24 @@ private static void AddPodInternal(string podName,
1195
1264
string preformattedVersion = null ,
1196
1265
bool bitcodeEnabled = true ,
1197
1266
string minTargetSdk = null ,
1267
+ bool addToAllTargets = false ,
1198
1268
IEnumerable < string > sources = null ,
1199
1269
bool overwriteExistingPod = true ,
1200
1270
string createdBy = null ,
1201
1271
bool fromXmlFile = false ,
1202
1272
Dictionary < string , string > propertiesByName = null ) {
1203
1273
var pod = new Pod ( podName , preformattedVersion , bitcodeEnabled , minTargetSdk ,
1204
- sources , propertiesByName ) ;
1274
+ addToAllTargets , sources , propertiesByName ) ;
1205
1275
pod . createdBy = createdBy ?? pod . createdBy ;
1206
1276
pod . fromXmlFile = fromXmlFile ;
1207
1277
1208
1278
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 " ,
1212
1282
podName , preformattedVersion ?? "null" , bitcodeEnabled . ToString ( ) ,
1213
1283
minTargetSdk ?? "null" ,
1284
+ addToAllTargets . ToString ( ) ,
1214
1285
sources != null ? String . Join ( ", " , ( new List < string > ( sources ) ) . ToArray ( ) ) : "(null)" ,
1215
1286
Pod . PropertyDictionaryToString ( pod . propertiesByName ) ,
1216
1287
createdBy ?? pod . createdBy ) ,
@@ -1874,11 +1945,15 @@ private static void ParseUnityDeps(string unityPodfilePath) {
1874
1945
var sources = new List < string > ( ) ;
1875
1946
while ( ( line = unityPodfile . ReadLine ( ) ) != null ) {
1876
1947
line = line . Trim ( ) ;
1948
+ if ( PODFILE_COMMENT_REGEX . IsMatch ( line ) ) {
1949
+ continue ;
1950
+ }
1877
1951
var sourceLineMatch = PODFILE_SOURCE_REGEX . Match ( line ) ;
1878
1952
if ( sourceLineMatch . Groups . Count > 1 ) {
1879
1953
sources . Add ( sourceLineMatch . Groups [ 1 ] . Value ) ;
1880
1954
continue ;
1881
1955
}
1956
+ // TODO: Properly support multiple targets.
1882
1957
if ( line . StartsWith ( "target 'Unity-iPhone' do" ) ) {
1883
1958
capturingPodsDepth ++ ;
1884
1959
continue ;
@@ -2000,6 +2075,20 @@ public static void GenPodfile(BuildTarget buildTarget,
2000
2075
2001
2076
if ( MultipleXcodeTargetsSupported && PodfileAlwaysAddMainTarget ) {
2002
2077
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
+ }
2003
2092
file . WriteLine ( "end" ) ;
2004
2093
}
2005
2094
if ( PodfileAddUseFrameworks ) {
0 commit comments