Skip to content

Commit

Permalink
Revert "Add ability to set the desired target from Dependencies file"
Browse files Browse the repository at this point in the history
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
  • Loading branch information
chkuang-g committed Mar 23, 2020
1 parent 5caaff3 commit df59a82
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@
Cocoapod version specification for the named pod.
If this is not specified the latest version is used.
NOTE: This can't be used when "path" is set.
* "target" (optional)
The Xcode target to which to add the pod to.
* "bitcodeEnabled" (optional)
Whether this Cocoapod requires bitcode to be enabled in Unity's
generated Xcode project. This is "true" by default.
Expand Down
93 changes: 15 additions & 78 deletions source/IOSResolver/src/IOSResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,6 @@ private class Pod {
/// </summary>
public string version = null;

/// <summary>
/// The App's target to which to add the pod.
///
/// See: XcodeTargetNames for valid target names.
/// </summary>
public string target = null;

/// <summary>
/// Properties applied to the pod declaration.
///
Expand Down Expand Up @@ -165,7 +158,6 @@ public string PodFilePodLine {
/// </summary>
/// <param name="name">Name of the pod.</param>
/// <param name="version">Version of the pod.</param>
/// <param name="target">The App's target to which to add the pod.</param>
/// <param name="bitcodeEnabled">Whether this pod was compiled with
/// bitcode.</param>
/// <param name="minTargetSdk">Minimum target SDK revision required by
Expand All @@ -176,12 +168,10 @@ public string PodFilePodLine {
/// a source.</param>
/// <param name="propertiesByName">Dictionary of additional properties for the pod
/// reference.</param>
public Pod(string name, string version, string target, bool bitcodeEnabled,
string minTargetSdk, IEnumerable<string> sources,
Dictionary<string, string> propertiesByName) {
public Pod(string name, string version, bool bitcodeEnabled, string minTargetSdk,
IEnumerable<string> sources, Dictionary<string, string> propertiesByName) {
this.name = name;
this.version = version;
this.target = target;
if (propertiesByName != null) {
this.propertiesByName = new Dictionary<string, string>(propertiesByName);
}
Expand Down Expand Up @@ -219,7 +209,6 @@ public override bool Equals(System.Object obj) {
return pod != null &&
name == pod.name &&
version == pod.version &&
target == pod.target &&
propertiesByName.Count == pod.propertiesByName.Count &&
propertiesByName.Keys.All(key =>
pod.propertiesByName.ContainsKey(key) &&
Expand Down Expand Up @@ -314,7 +303,6 @@ protected override bool Read(string filename, Logger logger) {
var falseStrings = new HashSet<string> { "false", "0" };
string podName = null;
string versionSpec = null;
string target = null;
bool bitcodeEnabled = true;
string minTargetSdk = null;
var propertiesByName = new Dictionary<string, string>();
Expand All @@ -339,20 +327,6 @@ protected override bool Read(string filename, Logger logger) {
}
}
versionSpec = reader.GetAttribute("version");
target = reader.GetAttribute("target");
if (target == null) {
target = DefaultXcodeTarget;
} else {
// Make sure that the provided target is supported.
if (!XcodeTargetNames.Contains(target)) {
logger.Log(string.Format("Incorrect target name passed {0}." +
"Adding the pod to the default" +
"target: {1}",
target,
DefaultXcodeTarget));
target = DefaultXcodeTarget;
}
}
var bitcodeEnabledString =
(reader.GetAttribute("bitcode") ?? "").ToLower();
bitcodeEnabled |= trueStrings.Contains(bitcodeEnabledString);
Expand All @@ -367,9 +341,7 @@ protected override bool Read(string filename, Logger logger) {
return false;
}
} else {
AddPodInternal(podName,
target,
preformattedVersion: versionSpec,
AddPodInternal(podName, preformattedVersion: versionSpec,
bitcodeEnabled: bitcodeEnabled,
minTargetSdk: minTargetSdk,
sources: sources,
Expand Down Expand Up @@ -562,9 +534,6 @@ protected override bool Read(string filename, Logger logger) {
// Parses a source URL from a Podfile.
private static Regex PODFILE_SOURCE_REGEX = new Regex(@"^\s*source\s+'([^']*)'");

// Regex that matches the start of a target line in a pod file.
private static Regex PODFILE_TARGET_START_LINE_REGEX = new Regex("^target '([^']+)' do");

// Parses dependencies from XML dependency files.
private static IOSXmlDependencies xmlDependencies = new IOSXmlDependencies();

Expand Down Expand Up @@ -1113,7 +1082,6 @@ public static void AddPod(string podName, string version = null,
string minTargetSdk = null,
IEnumerable<string> sources = null) {
AddPodInternal(podName,
DefaultXcodeTarget,
preformattedVersion: PodVersionExpressionFromVersionDep(version),
bitcodeEnabled: bitcodeEnabled, minTargetSdk: minTargetSdk,
sources: sources);
Expand Down Expand Up @@ -1142,7 +1110,6 @@ public static void AddPod(string podName, string version = null,
/// <param name="propertiesByName">Dictionary of additional properties for the pod
/// reference.</param>
private static void AddPodInternal(string podName,
string target,
string preformattedVersion = null,
bool bitcodeEnabled = true,
string minTargetSdk = null,
Expand All @@ -1151,7 +1118,7 @@ private static void AddPodInternal(string podName,
string createdBy = null,
bool fromXmlFile = false,
Dictionary<string, string> propertiesByName = null) {
var pod = new Pod(podName, preformattedVersion, target, bitcodeEnabled, minTargetSdk,
var pod = new Pod(podName, preformattedVersion, bitcodeEnabled, minTargetSdk,
sources, propertiesByName);
pod.createdBy = createdBy ?? pod.createdBy;
pod.fromXmlFile = fromXmlFile;
Expand Down Expand Up @@ -1683,21 +1650,10 @@ public static IEnumerable<string> XcodeTargetNames {
get {
// Return hard coded names in the UnityEditor.iOS.Xcode.PBXProject DLL.
return MultipleXcodeTargetsSupported ?
new List<string>() { "Unity-iPhone", "UnityFramework" } :
new List<string>() { "UnityFramework" } :
new List<string>() { InitializeTargetName() };
}
}

/// <summary>
/// Get the default Xcode target name to which to add pods.
/// </summary>
/// <returns>The Xcode target to which to add the pods to by default.</returns>
public static string DefaultXcodeTarget {
get {
return MultipleXcodeTargetsSupported ? "UnityFramework" : InitializeTargetName();
}
}

/// <summary>
/// Get Xcode target GUIDs using a method that works across all Unity versions.
/// </summary>
Expand Down Expand Up @@ -1733,6 +1689,7 @@ public static IEnumerable<string> GetXcodeTargetGuids(object xcodeProject) {
}
return targets;
}

// Implementation of OnPostProcessPatchProject().
// NOTE: This is separate from the post-processing method to prevent the
// Mono runtime from loading the Xcode API before calling the post
Expand Down Expand Up @@ -1810,11 +1767,10 @@ private static void ParseUnityDeps(string unityPodfilePath) {
string line;

// We are only interested in capturing the dependencies "Pod depName, depVersion", inside
// of the targets in XcodeTargetNames. However there can be nested targets such as for
// testing, so we're counting the depth to determine when to capture the pods. Also we only
// ever enter the first depth if we're in the exact right target.
// of the specific target. However there can be nested targets such as for testing, so we're
// counting the depth to determine when to capture the pods. Also we only ever enter the
// first depth if we're in the exact right target.
int capturingPodsDepth = 0;
string currentTarget = null;
var sources = new List<string>();
while ((line = unityPodfile.ReadLine()) != null) {
line = line.Trim();
Expand All @@ -1823,24 +1779,14 @@ private static void ParseUnityDeps(string unityPodfilePath) {
sources.Add(sourceLineMatch.Groups[1].Value);
continue;
}

var podFileTargetMatch = PODFILE_TARGET_START_LINE_REGEX.Match(line);
if (podFileTargetMatch.Success) {
var target = podFileTargetMatch.Groups[1].Value;
if (XcodeTargetNames.Contains(target))
{
capturingPodsDepth++;
currentTarget = target;
continue;
}
}

if (capturingPodsDepth == 0) {
currentTarget = null;
if (line.StartsWith("target 'Unity-iPhone' do")) {
capturingPodsDepth++;
continue;
}

// Handle other scopes roughly
if (capturingPodsDepth == 0) continue;

// handle other scopes roughly
if (line.EndsWith(" do")) {
capturingPodsDepth++; // Ignore nested targets like tests
} else if (line == "end") {
Expand All @@ -1849,16 +1795,9 @@ private static void ParseUnityDeps(string unityPodfilePath) {

if (capturingPodsDepth != 1) continue;

if (currentTarget == null) {
Log(string.Format("Couldn't find a valid target for pod {0}, skipping...", line),
verbose: true);
continue;
}

// Parse "pod" lines from the default target in the file.
var podLineMatch = PODFILE_POD_REGEX.Match(line);
var podGroups = podLineMatch.Groups;

if (podGroups.Count > 1) {
var podName = podGroups["podname"].ToString();
var podVersion = podGroups["podversion"].ToString();
Expand All @@ -1872,7 +1811,6 @@ private static void ParseUnityDeps(string unityPodfilePath) {
}
AddPodInternal(
podName,
currentTarget,
preformattedVersion: String.IsNullOrEmpty(podVersion) ? null : podVersion,
sources: sources, createdBy: unityPodfilePath, overwriteExistingPod: false,
propertiesByName: propertiesByName);
Expand Down Expand Up @@ -1953,9 +1891,8 @@ public static void GenPodfile(BuildTarget buildTarget,
file.WriteLine(GeneratePodfileSourcesSection() +
String.Format("platform :ios, '{0}'\n", TargetSdk));
foreach (var target in XcodeTargetNames) {
var podsToAddToThisTarget = pods.Values.Where(pod => pod.target.Equals(target));
file.WriteLine(String.Format("target '{0}' do", target));
foreach(var pod in podsToAddToThisTarget) {
foreach(var pod in pods.Values) {
file.WriteLine(String.Format(" {0}", pod.PodFilePodLine));
}
file.WriteLine("end");
Expand Down

0 comments on commit df59a82

Please sign in to comment.