@@ -51,6 +51,13 @@ private class Pod {
51
51
/// </summary>
52
52
public string version = null ;
53
53
54
+ /// <summary>
55
+ /// The App's target to which to add the pod.
56
+ ///
57
+ /// See: XcodeTargetNames for valid target names.
58
+ /// </summary>
59
+ public string target = null ;
60
+
54
61
/// <summary>
55
62
/// Properties applied to the pod declaration.
56
63
///
@@ -158,6 +165,7 @@ public string PodFilePodLine {
158
165
/// </summary>
159
166
/// <param name="name">Name of the pod.</param>
160
167
/// <param name="version">Version of the pod.</param>
168
+ /// <param name="target">The App's target to which to add the pod.</param>
161
169
/// <param name="bitcodeEnabled">Whether this pod was compiled with
162
170
/// bitcode.</param>
163
171
/// <param name="minTargetSdk">Minimum target SDK revision required by
@@ -168,10 +176,12 @@ public string PodFilePodLine {
168
176
/// a source.</param>
169
177
/// <param name="propertiesByName">Dictionary of additional properties for the pod
170
178
/// reference.</param>
171
- public Pod ( string name , string version , bool bitcodeEnabled , string minTargetSdk ,
172
- IEnumerable < string > sources , Dictionary < string , string > propertiesByName ) {
179
+ public Pod ( string name , string version , string target , bool bitcodeEnabled ,
180
+ string minTargetSdk , IEnumerable < string > sources ,
181
+ Dictionary < string , string > propertiesByName ) {
173
182
this . name = name ;
174
183
this . version = version ;
184
+ this . target = target ;
175
185
if ( propertiesByName != null ) {
176
186
this . propertiesByName = new Dictionary < string , string > ( propertiesByName ) ;
177
187
}
@@ -209,6 +219,7 @@ public override bool Equals(System.Object obj) {
209
219
return pod != null &&
210
220
name == pod . name &&
211
221
version == pod . version &&
222
+ target == pod . target &&
212
223
propertiesByName . Count == pod . propertiesByName . Count &&
213
224
propertiesByName . Keys . All ( key =>
214
225
pod . propertiesByName . ContainsKey ( key ) &&
@@ -303,6 +314,7 @@ protected override bool Read(string filename, Logger logger) {
303
314
var falseStrings = new HashSet < string > { "false" , "0" } ;
304
315
string podName = null ;
305
316
string versionSpec = null ;
317
+ string target = null ;
306
318
bool bitcodeEnabled = true ;
307
319
string minTargetSdk = null ;
308
320
var propertiesByName = new Dictionary < string , string > ( ) ;
@@ -327,6 +339,20 @@ protected override bool Read(string filename, Logger logger) {
327
339
}
328
340
}
329
341
versionSpec = reader . GetAttribute ( "version" ) ;
342
+ target = reader . GetAttribute ( "target" ) ;
343
+ if ( target == null ) {
344
+ target = DefaultXcodeTarget ;
345
+ } else {
346
+ // Make sure that the provided target is supported.
347
+ if ( ! XcodeTargetNames . Contains ( target ) ) {
348
+ logger . Log ( string . Format ( "Incorrect target name passed {0}." +
349
+ "Adding the pod to the default" +
350
+ "target: {1}" ,
351
+ target ,
352
+ DefaultXcodeTarget ) ) ;
353
+ target = DefaultXcodeTarget ;
354
+ }
355
+ }
330
356
var bitcodeEnabledString =
331
357
( reader . GetAttribute ( "bitcode" ) ?? "" ) . ToLower ( ) ;
332
358
bitcodeEnabled |= trueStrings . Contains ( bitcodeEnabledString ) ;
@@ -341,7 +367,9 @@ protected override bool Read(string filename, Logger logger) {
341
367
return false ;
342
368
}
343
369
} else {
344
- AddPodInternal ( podName , preformattedVersion : versionSpec ,
370
+ AddPodInternal ( podName ,
371
+ target ,
372
+ preformattedVersion : versionSpec ,
345
373
bitcodeEnabled : bitcodeEnabled ,
346
374
minTargetSdk : minTargetSdk ,
347
375
sources : sources ,
@@ -532,6 +560,9 @@ protected override bool Read(string filename, Logger logger) {
532
560
// Parses a source URL from a Podfile.
533
561
private static Regex PODFILE_SOURCE_REGEX = new Regex ( @"^\s*source\s+'([^']*)'" ) ;
534
562
563
+ // Regex that matches the start of a target line in a pod file.
564
+ private static Regex PODFILE_TARGET_START_LINE_REGEX = new Regex ( "^target '([^']+)' do" ) ;
565
+
535
566
// Parses dependencies from XML dependency files.
536
567
private static IOSXmlDependencies xmlDependencies = new IOSXmlDependencies ( ) ;
537
568
@@ -1080,6 +1111,7 @@ public static void AddPod(string podName, string version = null,
1080
1111
string minTargetSdk = null ,
1081
1112
IEnumerable < string > sources = null ) {
1082
1113
AddPodInternal ( podName ,
1114
+ DefaultXcodeTarget ,
1083
1115
preformattedVersion : PodVersionExpressionFromVersionDep ( version ) ,
1084
1116
bitcodeEnabled : bitcodeEnabled , minTargetSdk : minTargetSdk ,
1085
1117
sources : sources ) ;
@@ -1108,6 +1140,7 @@ public static void AddPod(string podName, string version = null,
1108
1140
/// <param name="propertiesByName">Dictionary of additional properties for the pod
1109
1141
/// reference.</param>
1110
1142
private static void AddPodInternal ( string podName ,
1143
+ string target ,
1111
1144
string preformattedVersion = null ,
1112
1145
bool bitcodeEnabled = true ,
1113
1146
string minTargetSdk = null ,
@@ -1116,7 +1149,7 @@ private static void AddPodInternal(string podName,
1116
1149
string createdBy = null ,
1117
1150
bool fromXmlFile = false ,
1118
1151
Dictionary < string , string > propertiesByName = null ) {
1119
- var pod = new Pod ( podName , preformattedVersion , bitcodeEnabled , minTargetSdk ,
1152
+ var pod = new Pod ( podName , preformattedVersion , target , bitcodeEnabled , minTargetSdk ,
1120
1153
sources , propertiesByName ) ;
1121
1154
pod . createdBy = createdBy ?? pod . createdBy ;
1122
1155
pod . fromXmlFile = fromXmlFile ;
@@ -1648,10 +1681,21 @@ public static IEnumerable<string> XcodeTargetNames {
1648
1681
get {
1649
1682
// Return hard coded names in the UnityEditor.iOS.Xcode.PBXProject DLL.
1650
1683
return MultipleXcodeTargetsSupported ?
1651
- new List < string > ( ) { "UnityFramework" } :
1684
+ new List < string > ( ) { "Unity-iPhone" , " UnityFramework" } :
1652
1685
new List < string > ( ) { InitializeTargetName ( ) } ;
1653
1686
}
1654
1687
}
1688
+
1689
+ /// <summary>
1690
+ /// Get the default Xcode target name to which to add pods.
1691
+ /// </summary>
1692
+ /// <returns>The Xcode target to which to add the pods to by default.</returns>
1693
+ public static string DefaultXcodeTarget {
1694
+ get {
1695
+ return MultipleXcodeTargetsSupported ? "UnityFramework" : InitializeTargetName ( ) ;
1696
+ }
1697
+ }
1698
+
1655
1699
/// <summary>
1656
1700
/// Get Xcode target GUIDs using a method that works across all Unity versions.
1657
1701
/// </summary>
@@ -1687,7 +1731,6 @@ public static IEnumerable<string> GetXcodeTargetGuids(object xcodeProject) {
1687
1731
}
1688
1732
return targets ;
1689
1733
}
1690
-
1691
1734
// Implementation of OnPostProcessPatchProject().
1692
1735
// NOTE: This is separate from the post-processing method to prevent the
1693
1736
// Mono runtime from loading the Xcode API before calling the post
@@ -1765,10 +1808,11 @@ private static void ParseUnityDeps(string unityPodfilePath) {
1765
1808
string line ;
1766
1809
1767
1810
// We are only interested in capturing the dependencies "Pod depName, depVersion", inside
1768
- // of the specific target . However there can be nested targets such as for testing, so we're
1769
- // counting the depth to determine when to capture the pods. Also we only ever enter the
1770
- // first depth if we're in the exact right target.
1811
+ // of the targets in XcodeTargetNames . However there can be nested targets such as for
1812
+ // testing, so we're counting the depth to determine when to capture the pods. Also we only
1813
+ // ever enter the first depth if we're in the exact right target.
1771
1814
int capturingPodsDepth = 0 ;
1815
+ string currentTarget = null ;
1772
1816
var sources = new List < string > ( ) ;
1773
1817
while ( ( line = unityPodfile . ReadLine ( ) ) != null ) {
1774
1818
line = line . Trim ( ) ;
@@ -1777,14 +1821,24 @@ private static void ParseUnityDeps(string unityPodfilePath) {
1777
1821
sources . Add ( sourceLineMatch . Groups [ 1 ] . Value ) ;
1778
1822
continue ;
1779
1823
}
1780
- if ( line . StartsWith ( "target 'Unity-iPhone' do" ) ) {
1781
- capturingPodsDepth ++ ;
1782
- continue ;
1824
+
1825
+ var podFileTargetMatch = PODFILE_TARGET_START_LINE_REGEX . Match ( line ) ;
1826
+ if ( podFileTargetMatch . Success ) {
1827
+ var target = podFileTargetMatch . Groups [ 1 ] . Value ;
1828
+ if ( XcodeTargetNames . Contains ( target ) )
1829
+ {
1830
+ capturingPodsDepth ++ ;
1831
+ currentTarget = target ;
1832
+ continue ;
1833
+ }
1783
1834
}
1784
1835
1785
- if ( capturingPodsDepth == 0 ) continue ;
1836
+ if ( capturingPodsDepth == 0 ) {
1837
+ currentTarget = null ;
1838
+ continue ;
1839
+ }
1786
1840
1787
- // handle other scopes roughly
1841
+ // Handle other scopes roughly
1788
1842
if ( line . EndsWith ( " do" ) ) {
1789
1843
capturingPodsDepth ++ ; // Ignore nested targets like tests
1790
1844
} else if ( line == "end" ) {
@@ -1793,9 +1847,16 @@ private static void ParseUnityDeps(string unityPodfilePath) {
1793
1847
1794
1848
if ( capturingPodsDepth != 1 ) continue ;
1795
1849
1850
+ if ( currentTarget == null ) {
1851
+ Log ( string . Format ( "Couldn't find a valid target for pod {0}, skipping..." , line ) ,
1852
+ verbose : true ) ;
1853
+ continue ;
1854
+ }
1855
+
1796
1856
// Parse "pod" lines from the default target in the file.
1797
1857
var podLineMatch = PODFILE_POD_REGEX . Match ( line ) ;
1798
1858
var podGroups = podLineMatch . Groups ;
1859
+
1799
1860
if ( podGroups . Count > 1 ) {
1800
1861
var podName = podGroups [ "podname" ] . ToString ( ) ;
1801
1862
var podVersion = podGroups [ "podversion" ] . ToString ( ) ;
@@ -1809,6 +1870,7 @@ private static void ParseUnityDeps(string unityPodfilePath) {
1809
1870
}
1810
1871
AddPodInternal (
1811
1872
podName ,
1873
+ currentTarget ,
1812
1874
preformattedVersion : String . IsNullOrEmpty ( podVersion ) ? null : podVersion ,
1813
1875
sources : sources , createdBy : unityPodfilePath , overwriteExistingPod : false ,
1814
1876
propertiesByName : propertiesByName ) ;
@@ -1889,8 +1951,9 @@ public static void GenPodfile(BuildTarget buildTarget,
1889
1951
file . WriteLine ( GeneratePodfileSourcesSection ( ) +
1890
1952
String . Format ( "platform :ios, '{0}'\n " , TargetSdk ) ) ;
1891
1953
foreach ( var target in XcodeTargetNames ) {
1954
+ var podsToAddToThisTarget = pods . Values . Where ( pod => pod . target . Equals ( target ) ) ;
1892
1955
file . WriteLine ( String . Format ( "target '{0}' do" , target ) ) ;
1893
- foreach ( var pod in pods . Values ) {
1956
+ foreach ( var pod in podsToAddToThisTarget ) {
1894
1957
file . WriteLine ( String . Format ( " {0}" , pod . PodFilePodLine ) ) ;
1895
1958
}
1896
1959
file . WriteLine ( "end" ) ;
0 commit comments