Skip to content

Commit df59a82

Browse files
committed
Revert "Add ability to set the desired target from Dependencies file"
This reverts commit 16ce8d0. This is causing issues in Unity 2019. 1. GetXcodeTargetGuids() throws exception due to "Unity-iPhone" target being deprecated. 2. Generating "Unity-iPhone" target in Podfile with no pod by default. Bug: 152165846 Change-Id: I188ebf01020380bc962ffb28aebf31a56ca7c397
1 parent 5caaff3 commit df59a82

File tree

2 files changed

+15
-80
lines changed

2 files changed

+15
-80
lines changed

sample/Assets/ExternalDependencyManager/Editor/SampleDependencies.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@
6262
Cocoapod version specification for the named pod.
6363
If this is not specified the latest version is used.
6464
NOTE: This can't be used when "path" is set.
65-
* "target" (optional)
66-
The Xcode target to which to add the pod to.
6765
* "bitcodeEnabled" (optional)
6866
Whether this Cocoapod requires bitcode to be enabled in Unity's
6967
generated Xcode project. This is "true" by default.

source/IOSResolver/src/IOSResolver.cs

Lines changed: 15 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,6 @@ private class Pod {
5151
/// </summary>
5252
public string version = null;
5353

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-
6154
/// <summary>
6255
/// Properties applied to the pod declaration.
6356
///
@@ -165,7 +158,6 @@ public string PodFilePodLine {
165158
/// </summary>
166159
/// <param name="name">Name of the pod.</param>
167160
/// <param name="version">Version of the pod.</param>
168-
/// <param name="target">The App's target to which to add the pod.</param>
169161
/// <param name="bitcodeEnabled">Whether this pod was compiled with
170162
/// bitcode.</param>
171163
/// <param name="minTargetSdk">Minimum target SDK revision required by
@@ -176,12 +168,10 @@ public string PodFilePodLine {
176168
/// a source.</param>
177169
/// <param name="propertiesByName">Dictionary of additional properties for the pod
178170
/// reference.</param>
179-
public Pod(string name, string version, string target, bool bitcodeEnabled,
180-
string minTargetSdk, IEnumerable<string> sources,
181-
Dictionary<string, string> propertiesByName) {
171+
public Pod(string name, string version, bool bitcodeEnabled, string minTargetSdk,
172+
IEnumerable<string> sources, Dictionary<string, string> propertiesByName) {
182173
this.name = name;
183174
this.version = version;
184-
this.target = target;
185175
if (propertiesByName != null) {
186176
this.propertiesByName = new Dictionary<string, string>(propertiesByName);
187177
}
@@ -219,7 +209,6 @@ public override bool Equals(System.Object obj) {
219209
return pod != null &&
220210
name == pod.name &&
221211
version == pod.version &&
222-
target == pod.target &&
223212
propertiesByName.Count == pod.propertiesByName.Count &&
224213
propertiesByName.Keys.All(key =>
225214
pod.propertiesByName.ContainsKey(key) &&
@@ -314,7 +303,6 @@ protected override bool Read(string filename, Logger logger) {
314303
var falseStrings = new HashSet<string> { "false", "0" };
315304
string podName = null;
316305
string versionSpec = null;
317-
string target = null;
318306
bool bitcodeEnabled = true;
319307
string minTargetSdk = null;
320308
var propertiesByName = new Dictionary<string, string>();
@@ -339,20 +327,6 @@ protected override bool Read(string filename, Logger logger) {
339327
}
340328
}
341329
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-
}
356330
var bitcodeEnabledString =
357331
(reader.GetAttribute("bitcode") ?? "").ToLower();
358332
bitcodeEnabled |= trueStrings.Contains(bitcodeEnabledString);
@@ -367,9 +341,7 @@ protected override bool Read(string filename, Logger logger) {
367341
return false;
368342
}
369343
} else {
370-
AddPodInternal(podName,
371-
target,
372-
preformattedVersion: versionSpec,
344+
AddPodInternal(podName, preformattedVersion: versionSpec,
373345
bitcodeEnabled: bitcodeEnabled,
374346
minTargetSdk: minTargetSdk,
375347
sources: sources,
@@ -562,9 +534,6 @@ protected override bool Read(string filename, Logger logger) {
562534
// Parses a source URL from a Podfile.
563535
private static Regex PODFILE_SOURCE_REGEX = new Regex(@"^\s*source\s+'([^']*)'");
564536

565-
// Regex that matches the start of a target line in a pod file.
566-
private static Regex PODFILE_TARGET_START_LINE_REGEX = new Regex("^target '([^']+)' do");
567-
568537
// Parses dependencies from XML dependency files.
569538
private static IOSXmlDependencies xmlDependencies = new IOSXmlDependencies();
570539

@@ -1113,7 +1082,6 @@ public static void AddPod(string podName, string version = null,
11131082
string minTargetSdk = null,
11141083
IEnumerable<string> sources = null) {
11151084
AddPodInternal(podName,
1116-
DefaultXcodeTarget,
11171085
preformattedVersion: PodVersionExpressionFromVersionDep(version),
11181086
bitcodeEnabled: bitcodeEnabled, minTargetSdk: minTargetSdk,
11191087
sources: sources);
@@ -1142,7 +1110,6 @@ public static void AddPod(string podName, string version = null,
11421110
/// <param name="propertiesByName">Dictionary of additional properties for the pod
11431111
/// reference.</param>
11441112
private static void AddPodInternal(string podName,
1145-
string target,
11461113
string preformattedVersion = null,
11471114
bool bitcodeEnabled = true,
11481115
string minTargetSdk = null,
@@ -1151,7 +1118,7 @@ private static void AddPodInternal(string podName,
11511118
string createdBy = null,
11521119
bool fromXmlFile = false,
11531120
Dictionary<string, string> propertiesByName = null) {
1154-
var pod = new Pod(podName, preformattedVersion, target, bitcodeEnabled, minTargetSdk,
1121+
var pod = new Pod(podName, preformattedVersion, bitcodeEnabled, minTargetSdk,
11551122
sources, propertiesByName);
11561123
pod.createdBy = createdBy ?? pod.createdBy;
11571124
pod.fromXmlFile = fromXmlFile;
@@ -1683,21 +1650,10 @@ public static IEnumerable<string> XcodeTargetNames {
16831650
get {
16841651
// Return hard coded names in the UnityEditor.iOS.Xcode.PBXProject DLL.
16851652
return MultipleXcodeTargetsSupported ?
1686-
new List<string>() { "Unity-iPhone", "UnityFramework" } :
1653+
new List<string>() { "UnityFramework" } :
16871654
new List<string>() { InitializeTargetName() };
16881655
}
16891656
}
1690-
1691-
/// <summary>
1692-
/// Get the default Xcode target name to which to add pods.
1693-
/// </summary>
1694-
/// <returns>The Xcode target to which to add the pods to by default.</returns>
1695-
public static string DefaultXcodeTarget {
1696-
get {
1697-
return MultipleXcodeTargetsSupported ? "UnityFramework" : InitializeTargetName();
1698-
}
1699-
}
1700-
17011657
/// <summary>
17021658
/// Get Xcode target GUIDs using a method that works across all Unity versions.
17031659
/// </summary>
@@ -1733,6 +1689,7 @@ public static IEnumerable<string> GetXcodeTargetGuids(object xcodeProject) {
17331689
}
17341690
return targets;
17351691
}
1692+
17361693
// Implementation of OnPostProcessPatchProject().
17371694
// NOTE: This is separate from the post-processing method to prevent the
17381695
// Mono runtime from loading the Xcode API before calling the post
@@ -1810,11 +1767,10 @@ private static void ParseUnityDeps(string unityPodfilePath) {
18101767
string line;
18111768

18121769
// We are only interested in capturing the dependencies "Pod depName, depVersion", inside
1813-
// of the targets in XcodeTargetNames. However there can be nested targets such as for
1814-
// testing, so we're counting the depth to determine when to capture the pods. Also we only
1815-
// ever enter the first depth if we're in the exact right target.
1770+
// of the specific target. However there can be nested targets such as for testing, so we're
1771+
// counting the depth to determine when to capture the pods. Also we only ever enter the
1772+
// first depth if we're in the exact right target.
18161773
int capturingPodsDepth = 0;
1817-
string currentTarget = null;
18181774
var sources = new List<string>();
18191775
while ((line = unityPodfile.ReadLine()) != null) {
18201776
line = line.Trim();
@@ -1823,24 +1779,14 @@ private static void ParseUnityDeps(string unityPodfilePath) {
18231779
sources.Add(sourceLineMatch.Groups[1].Value);
18241780
continue;
18251781
}
1826-
1827-
var podFileTargetMatch = PODFILE_TARGET_START_LINE_REGEX.Match(line);
1828-
if (podFileTargetMatch.Success) {
1829-
var target = podFileTargetMatch.Groups[1].Value;
1830-
if (XcodeTargetNames.Contains(target))
1831-
{
1832-
capturingPodsDepth++;
1833-
currentTarget = target;
1834-
continue;
1835-
}
1836-
}
1837-
1838-
if (capturingPodsDepth == 0) {
1839-
currentTarget = null;
1782+
if (line.StartsWith("target 'Unity-iPhone' do")) {
1783+
capturingPodsDepth++;
18401784
continue;
18411785
}
18421786

1843-
// Handle other scopes roughly
1787+
if (capturingPodsDepth == 0) continue;
1788+
1789+
// handle other scopes roughly
18441790
if (line.EndsWith(" do")) {
18451791
capturingPodsDepth++; // Ignore nested targets like tests
18461792
} else if (line == "end") {
@@ -1849,16 +1795,9 @@ private static void ParseUnityDeps(string unityPodfilePath) {
18491795

18501796
if (capturingPodsDepth != 1) continue;
18511797

1852-
if (currentTarget == null) {
1853-
Log(string.Format("Couldn't find a valid target for pod {0}, skipping...", line),
1854-
verbose: true);
1855-
continue;
1856-
}
1857-
18581798
// Parse "pod" lines from the default target in the file.
18591799
var podLineMatch = PODFILE_POD_REGEX.Match(line);
18601800
var podGroups = podLineMatch.Groups;
1861-
18621801
if (podGroups.Count > 1) {
18631802
var podName = podGroups["podname"].ToString();
18641803
var podVersion = podGroups["podversion"].ToString();
@@ -1872,7 +1811,6 @@ private static void ParseUnityDeps(string unityPodfilePath) {
18721811
}
18731812
AddPodInternal(
18741813
podName,
1875-
currentTarget,
18761814
preformattedVersion: String.IsNullOrEmpty(podVersion) ? null : podVersion,
18771815
sources: sources, createdBy: unityPodfilePath, overwriteExistingPod: false,
18781816
propertiesByName: propertiesByName);
@@ -1953,9 +1891,8 @@ public static void GenPodfile(BuildTarget buildTarget,
19531891
file.WriteLine(GeneratePodfileSourcesSection() +
19541892
String.Format("platform :ios, '{0}'\n", TargetSdk));
19551893
foreach (var target in XcodeTargetNames) {
1956-
var podsToAddToThisTarget = pods.Values.Where(pod => pod.target.Equals(target));
19571894
file.WriteLine(String.Format("target '{0}' do", target));
1958-
foreach(var pod in podsToAddToThisTarget) {
1895+
foreach(var pod in pods.Values) {
19591896
file.WriteLine(String.Format(" {0}", pod.PodFilePodLine));
19601897
}
19611898
file.WriteLine("end");

0 commit comments

Comments
 (0)