@@ -516,6 +516,10 @@ protected override bool Read(string filename, Logger logger) {
516516 private const string PREFERENCE_PODFILE_ALLOW_PODS_IN_MULTIPLE_TARGETS =
517517 PREFERENCE_NAMESPACE + "PodfileAllowPodsInMultipleTargets" ;
518518
519+ // Whether to allow empty Podfile generation.
520+ private const string PREFERENCE_ALLOW_EMPTY_PODFILE_GENERATION =
521+ PREFERENCE_NAMESPACE + "AllowEmptyPodfileGeneration" ;
522+
519523 // Whether to use Swift Package Manager for dependency resolution.
520524 private const string PREFERENCE_SWIFT_PACKAGE_MANAGER_ENABLED =
521525 PREFERENCE_NAMESPACE + "SwiftPackageManagerEnabled" ;
@@ -536,6 +540,7 @@ protected override bool Read(string filename, Logger logger) {
536540 PREFERENCE_SWIFT_LANGUAGE_VERSION ,
537541 PREFERENCE_PODFILE_ALWAYS_ADD_MAIN_TARGET ,
538542 PREFERENCE_PODFILE_ALLOW_PODS_IN_MULTIPLE_TARGETS ,
543+ PREFERENCE_ALLOW_EMPTY_PODFILE_GENERATION ,
539544 PREFERENCE_SWIFT_PACKAGE_MANAGER_ENABLED
540545 } ;
541546
@@ -1172,6 +1177,18 @@ public static bool PodfileAllowPodsInMultipleTargets {
11721177 }
11731178 }
11741179
1180+ /// <summary>
1181+ /// Whether to allow empty Podfile generation. True by default.
1182+ /// If true, a Podfile will be generated even if there are no Pods to install.
1183+ /// </summary>
1184+ public static bool AllowEmptyPodfileGeneration {
1185+ get { return settings . GetBool ( PREFERENCE_ALLOW_EMPTY_PODFILE_GENERATION ,
1186+ defaultValue : true ) ; }
1187+ set {
1188+ settings . SetBool ( PREFERENCE_ALLOW_EMPTY_PODFILE_GENERATION , value ) ;
1189+ }
1190+ }
1191+
11751192 /// <summary>
11761193 /// Whether to use Swift Package Manager for dependency resolution.
11771194 /// If enabled, the resolver will attempt to use SPM for packages that define SPM support,
@@ -1315,7 +1332,7 @@ public static bool PodPresent(string pod) {
13151332 private static bool InjectDependencies ( ) {
13161333 return ( EditorUserBuildSettings . activeBuildTarget == BuildTarget . iOS ||
13171334 EditorUserBuildSettings . activeBuildTarget == BuildTarget . tvOS ) &&
1318- Enabled && ( pods . Count > 0 || spmDependencies . SwiftPackages . Count > 0 ) ;
1335+ Enabled && ( pods . Count > 0 || spmDependencies . SwiftPackages . Count > 0 || AllowEmptyPodfileGeneration ) ;
13191336 }
13201337
13211338 /// <summary>
@@ -2193,6 +2210,7 @@ public static void OnPostProcessResolveSwiftPackages(BuildTarget buildTarget,
21932210 public static void OnPostProcessGenPodfile ( BuildTarget buildTarget ,
21942211 string pathToBuiltProject ) {
21952212 if ( ! InjectDependencies ( ) || ! PodfileGenerationEnabled ) return ;
2213+ if ( pods . Count == 0 && ! AllowEmptyPodfileGeneration ) return ;
21962214 GenPodfile ( buildTarget , pathToBuiltProject , podsToIgnore ) ;
21972215 }
21982216
@@ -2363,7 +2381,7 @@ public static void GenPodfile(BuildTarget buildTarget,
23632381 }
23642382 filteredPods . Add ( pod ) ;
23652383 }
2366- if ( filteredPods . Count == 0 ) {
2384+ if ( filteredPods . Count == 0 && ! AllowEmptyPodfileGeneration ) {
23672385 Log ( "Found no pods to add, skipping generation of the Podfile" ) ;
23682386 podfileGenerationSkipped = true ;
23692387 return ;
0 commit comments