Skip to content

Commit fa84de7

Browse files
committed
Add logic to allow empty Podfiles
1 parent 9e9e311 commit fa84de7

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

source/IOSResolver/src/IOSResolver.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

source/IOSResolver/src/IOSResolverSettingsDialog.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ private class Settings {
4444
internal bool podfileAlwaysAddMainTarget;
4545
internal bool podfileAllowPodsInMultipleTargets;
4646
internal bool swiftPackageManagerEnabled;
47+
internal bool allowEmptyPodfileGeneration;
4748
internal bool useProjectSettings;
4849
internal EditorMeasurement.Settings analyticsSettings;
4950

@@ -66,6 +67,7 @@ internal Settings() {
6667
podfileAlwaysAddMainTarget = IOSResolver.PodfileAlwaysAddMainTarget;
6768
podfileAllowPodsInMultipleTargets = IOSResolver.PodfileAllowPodsInMultipleTargets;
6869
swiftPackageManagerEnabled = IOSResolver.SwiftPackageManagerEnabled;
70+
allowEmptyPodfileGeneration = IOSResolver.AllowEmptyPodfileGeneration;
6971
useProjectSettings = IOSResolver.UseProjectSettings;
7072
analyticsSettings = new EditorMeasurement.Settings(IOSResolver.analytics);
7173
}
@@ -89,6 +91,7 @@ internal void Save() {
8991
IOSResolver.PodfileAlwaysAddMainTarget = podfileAlwaysAddMainTarget;
9092
IOSResolver.PodfileAllowPodsInMultipleTargets = podfileAllowPodsInMultipleTargets;
9193
IOSResolver.SwiftPackageManagerEnabled = swiftPackageManagerEnabled;
94+
IOSResolver.AllowEmptyPodfileGeneration = allowEmptyPodfileGeneration;
9295
IOSResolver.UseProjectSettings = useProjectSettings;
9396
analyticsSettings.Save();
9497
}
@@ -162,6 +165,14 @@ public void OnGUI() {
162165
"fall back to Cocoapods for any dependencies that do not have an " +
163166
"SPM equivalent specified.");
164167

168+
GUILayout.BeginHorizontal();
169+
GUILayout.Label("Allow empty Podfile generation", EditorStyles.boldLabel);
170+
settings.allowEmptyPodfileGeneration =
171+
EditorGUILayout.Toggle(settings.allowEmptyPodfileGeneration);
172+
GUILayout.EndHorizontal();
173+
GUILayout.Label("If enabled, a Podfile will be generated even if there are no Pods " +
174+
"to install.");
175+
165176
GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));
166177

167178
GUILayout.BeginHorizontal();
@@ -378,6 +389,9 @@ public void OnGUI() {
378389
new KeyValuePair<string, string>(
379390
"swiftLanguageVersion",
380391
IOSResolver.SwiftLanguageVersion.ToString()),
392+
new KeyValuePair<string, string>(
393+
"allowEmptyPodfileGeneration",
394+
IOSResolver.AllowEmptyPodfileGeneration.ToString()),
381395
},
382396
"Settings Save");
383397
settings.Save();

0 commit comments

Comments
 (0)