@@ -407,6 +407,9 @@ protected override bool Read(string filename, Logger logger) {
407407
408408 // List of pods to ignore because they are replaced by Swift packages.
409409 private static HashSet < string > podsToIgnore = new HashSet < string > ( ) ;
410+ // Flag used to denoted if generating the Podfile was skipped because of no pods.
411+ // Used by subsequent steps to know they should be skipped as well.
412+ private static bool podfileGenerationSkipped = false ;
410413
411414 // Order of post processing operations.
412415 private const int BUILD_ORDER_REFRESH_DEPENDENCIES = 10 ;
@@ -2352,6 +2355,21 @@ public static void GenPodfile(BuildTarget buildTarget,
23522355 }
23532356 }
23542357
2358+ var filteredPods = new List < Pod > ( ) ;
2359+ foreach ( var pod in pods . Values ) {
2360+ if ( podsToIgnore != null && podsToIgnore . Contains ( pod . name ) ) {
2361+ Log ( String . Format ( "Skipping pod {0} because it is replaced by a Swift Package." , pod . name ) , verbose : true ) ;
2362+ continue ;
2363+ }
2364+ filteredPods . Add ( pod ) ;
2365+ }
2366+ if ( filteredPods . Count == 0 ) {
2367+ Log ( "Found no pods to add, skipping generation of the Podfile" ) ;
2368+ podfileGenerationSkipped = true ;
2369+ return ;
2370+ }
2371+ podfileGenerationSkipped = false ;
2372+
23552373 Log ( String . Format ( "Generating Podfile {0} with {1} integration." , podfilePath ,
23562374 ( CocoapodsWorkspaceIntegrationEnabled ? "Xcode workspace" :
23572375 ( CocoapodsProjectIntegrationEnabled ? "Xcode project" : "no target" ) ) ) ,
@@ -2376,11 +2394,7 @@ public static void GenPodfile(BuildTarget buildTarget,
23762394
23772395 foreach ( var target in XcodeTargetNames ) {
23782396 file . WriteLine ( String . Format ( "target '{0}' do" , target ) ) ;
2379- foreach ( var pod in pods . Values ) {
2380- if ( podsToIgnore != null && podsToIgnore . Contains ( pod . name ) ) {
2381- Log ( String . Format ( "Skipping pod {0} because it is replaced by a Swift Package." , pod . name ) , verbose : true ) ;
2382- continue ;
2383- }
2397+ foreach ( var pod in filteredPods ) {
23842398 file . WriteLine ( String . Format ( " {0}" , pod . PodFilePodLine ) ) ;
23852399 }
23862400 file . WriteLine ( "end" ) ;
@@ -2390,10 +2404,7 @@ public static void GenPodfile(BuildTarget buildTarget,
23902404 file . WriteLine ( String . Format ( "target '{0}' do" , XcodeMainTargetName ) ) ;
23912405 bool allowPodsInMultipleTargets = PodfileAllowPodsInMultipleTargets ;
23922406 int podAdded = 0 ;
2393- foreach ( var pod in pods . Values ) {
2394- if ( podsToIgnore != null && podsToIgnore . Contains ( pod . name ) ) {
2395- continue ;
2396- }
2407+ foreach ( var pod in filteredPods ) {
23972408 if ( pod . addToAllTargets ) {
23982409 file . WriteLine ( String . Format ( " {0}{1}" ,
23992410 allowPodsInMultipleTargets ? "" : "# " ,
@@ -2420,7 +2431,7 @@ public static void GenPodfile(BuildTarget buildTarget,
24202431 int maxProperties = 0 ;
24212432 int maxSources = Pod . Sources . Count ;
24222433 int fromXmlFileCount = 0 ;
2423- foreach ( var pod in pods . Values ) {
2434+ foreach ( var pod in filteredPods ) {
24242435 maxProperties = Math . Max ( maxProperties , pod . propertiesByName . Count ) ;
24252436 maxSources = Math . Max ( maxSources , pod . sources . Count ) ;
24262437 if ( ! String . IsNullOrEmpty ( pod . version ) ) versionCount ++ ;
@@ -2430,7 +2441,7 @@ public static void GenPodfile(BuildTarget buildTarget,
24302441 }
24312442 analytics . Report ( "generatepodfile/podinfo" ,
24322443 new KeyValuePair < string , string > [ ] {
2433- new KeyValuePair < string , string > ( "numPods" , pods . Count . ToString ( ) ) ,
2444+ new KeyValuePair < string , string > ( "numPods" , filteredPods . Count . ToString ( ) ) ,
24342445 new KeyValuePair < string , string > ( "numPodsWithVersions" ,
24352446 versionCount . ToString ( ) ) ,
24362447 new KeyValuePair < string , string > ( "numLocalPods" ,
@@ -2779,6 +2790,11 @@ public static void OnPostProcessInstallPods(BuildTarget buildTarget,
27792790 string pathToBuiltProject ) {
27802791 if ( ! InjectDependencies ( ) || ! PodfileGenerationEnabled ) return ;
27812792
2793+ // If the Podfile Generation was skipped because of no pods to install, skip this step.
2794+ if ( podfileGenerationSkipped ) {
2795+ return ;
2796+ }
2797+
27822798 if ( EditorUserBuildSettings . activeBuildTarget == BuildTarget . iOS ) {
27832799 UpdateTargetIosSdkVersion ( true ) ;
27842800 }
@@ -2885,7 +2901,8 @@ public static void OnPostProcessUpdateProjectDeps(
28852901 BuildTarget buildTarget , string pathToBuiltProject ) {
28862902 if ( ! InjectDependencies ( ) || ! PodfileGenerationEnabled ||
28872903 ! CocoapodsProjectIntegrationEnabled || // Early out for Workspace level integration.
2888- ! cocoapodsToolsInstallPresent ) {
2904+ ! cocoapodsToolsInstallPresent ||
2905+ podfileGenerationSkipped ) {
28892906 return ;
28902907 }
28912908
0 commit comments