Skip to content

Commit b7a90e4

Browse files
author
Stewart Miles
committed
Improved error reporting for Cocoapod installation problems.
* Improved error reporting when "pod repo update" fails. For example, if the user has a custom credential helper configured "pod repo update" will likely fail when run from inside Unity. * Improved error reporting when "pod install" generates an XML format Xcode project that is not readable by Unity's xcodeapi. Bug: 33316250 Change-Id: I55ca7fe8e1ba522e4e955155b612ac69e5a231a0
1 parent b5bdc72 commit b7a90e4

22 files changed

+102
-83
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Version 1.2.9 - Dec 7, 2016
2+
## Bug Fixes
3+
* Improved error reporting when "pod repo update" fails.
4+
* Added detection of xml format xcode projects generated by old Cocoapods
5+
installations.
6+
17
# Version 1.2.8 - Dec 6, 2016
28
## Bug Fixes
39
* Increased speed of JarResolver resolution.

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ project.ext {
138138
buildPath = file('build').absolutePath
139139
exportPath = file('build/plugin.unitypackage').absolutePath
140140
dllDir = 'Assets/PlayServicesResolver/Editor'
141-
pluginVersion = '1.2.8.0'
141+
pluginVersion = '1.2.9.0'
142142
currentPluginPath = file('.').absolutePath
143143
currentPluginBasename = 'play-services-resolver'
144144
currentPluginName = (currentPluginBasename + '-' + pluginVersion +

exploded/Assets/PlayServicesResolver/Editor.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.
Binary file not shown.

exploded/Assets/PlayServicesResolver/Editor/Google.VersionHandler_v1.2.8.0.dll.meta renamed to exploded/Assets/PlayServicesResolver/Editor/Google.IOSResolver_v1.2.9.0.dll.meta

Lines changed: 3 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exploded/Assets/PlayServicesResolver/Editor/Google.IOSResolver_v1.2.8.0.dll.meta renamed to exploded/Assets/PlayServicesResolver/Editor/Google.JarResolver_v1.2.9.0.dll.meta

Lines changed: 2 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exploded/Assets/PlayServicesResolver/Editor/Google.JarResolver_v1.2.8.0.dll.meta renamed to exploded/Assets/PlayServicesResolver/Editor/Google.VersionHandler_v1.2.9.0.dll.meta

Lines changed: 3 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exploded/Assets/PlayServicesResolver/Editor/play-services-resolver_v1.2.8.0.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Assets/PlayServicesResolver/Editor/Google.IOSResolver_v1.2.9.0.dll
2+
Assets/PlayServicesResolver/Editor/Google.JarResolver_v1.2.9.0.dll
3+
Assets/PlayServicesResolver/Editor/Google.VersionHandler_v1.2.9.0.dll

exploded/Assets/PlayServicesResolver/Editor/play-services-resolver_v1.2.8.0.txt.meta renamed to exploded/Assets/PlayServicesResolver/Editor/play-services-resolver_v1.2.9.0.txt.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
-44 KB
Binary file not shown.
44.9 KB
Binary file not shown.

plugin/Assets/PlayServicesResolver.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugin/Assets/PlayServicesResolver/Editor.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugin/Assets/PlayServicesResolver/Editor/Google.IOSResolver.dll.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugin/Assets/PlayServicesResolver/Editor/Google.JarResolver.dll.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugin/Assets/PlayServicesResolver/Editor/Google.VersionHandler.dll.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugin/Assets/PlayServicesResolver/Editor/play-services-resolver.txt.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/IOSResolver/src/IOSResolver.cs

Lines changed: 76 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ public static SortedDictionary<int, List<string>>
205205
// Name of the project within PODS_DIR that references downloaded Cocoapods.
206206
private const string PODS_PROJECT_NAME = "Pods";
207207

208+
// Version of the Cocoapods installation.
209+
private static string podsVersion = "";
210+
208211
// Search for a file up to a maximum search depth stopping the
209212
// depth first search each time the specified file is found.
210213
private static List<string> FindFile(
@@ -755,9 +758,11 @@ public static void OnPostProcessInstallPods(BuildTarget buildTarget,
755758
// Require at least version 1.0.0
756759
CommandLine.Result result;
757760
result = RunPodCommand("--version", pathToBuiltProject);
758-
if (result.exitCode != 0 || result.stdout[0] == '0') {
761+
if (result.exitCode == 0) podsVersion = result.stdout.Trim();
762+
763+
if (result.exitCode != 0 || podsVersion[0] == '0') {
759764
Log("Error running cocoapods. Please ensure you have at least " +
760-
"version 1.0.0. " + COCOAPOD_INSTALL_INSTRUCTIONS + "\n\n" +
765+
"version 1.0.0. " + COCOAPOD_INSTALL_INSTRUCTIONS + "\n\n" +
761766
"'" + POD_EXECUTABLE + " --version' returned status: " +
762767
result.exitCode.ToString() + "\n" +
763768
"output: " + result.stdout, level: LogLevel.Error);
@@ -770,8 +775,9 @@ public static void OnPostProcessInstallPods(BuildTarget buildTarget,
770775
// We'll attempt to resolve the error by updating the pod repo -
771776
// which is a slow operation - and retrying pod installation.
772777
if (result.exitCode != 0) {
773-
bool updateSucceeded =
774-
RunPodCommand("repo update", pathToBuiltProject).exitCode != 0;
778+
CommandLine.Result repoUpdateResult =
779+
RunPodCommand("repo update", pathToBuiltProject);
780+
bool repoUpdateSucceeded = repoUpdateResult.exitCode == 0;
775781

776782
// Second attempt result.
777783
// This is isolated in case it fails, so we can just report the
@@ -786,14 +792,17 @@ public static void OnPostProcessInstallPods(BuildTarget buildTarget,
786792
"result in an non-functional Xcode project.\n\n" +
787793
"After the failure, \"pod repo update\" " +
788794
"was executed and " +
789-
(updateSucceeded ? "succeeded. " : "failed. ") +
795+
(repoUpdateSucceeded ? "succeeded. " : "failed. ") +
790796
"\"pod install\" was then attempted again, and still " +
791797
"failed. This may be due to a broken Cocoapods " +
792798
"installation. See: " +
793799
"https://guides.cocoapods.org/using/troubleshooting.html " +
794800
"for potential solutions.\n\n" +
795-
"See the output below for details.\n\n" + result.stdout +
796-
"\n\n" + result.stderr, level: LogLevel.Error);
801+
"pod install output:\n\n" + result.stdout +
802+
"\n\n" + result.stderr +
803+
"\n\n\n" +
804+
"pod repo update output:\n\n" + repoUpdateResult.stdout +
805+
"\n\n" + repoUpdateResult.stderr, level: LogLevel.Error);
797806
return;
798807
}
799808
}
@@ -968,49 +977,68 @@ public static void UpdateProjectDeps(
968977
// Attempt to read per-file compile / build settings from the Pods
969978
// project.
970979
var podsProjectPath = GetProjectPath(podsDir, PODS_PROJECT_NAME);
971-
var podsProject = new UnityEditor.iOS.Xcode.PBXProject();
972-
podsProject.ReadFromString(File.ReadAllText(podsProjectPath));
973-
foreach (var directory in Directory.GetDirectories(podsDir)) {
974-
// Each pod will have a top level directory under the pods dir
975-
// named after the pod. Also, some pods have build targets in the
976-
// xcode project where each build target has the same name as the
977-
// pod such that pod Foo is in directory Foo with build target Foo.
978-
// Since we can't read the build targets from the generated Xcode
979-
// project using Unity's API, we scan the Xcode project for targets
980-
// to optionally retrieve build settings for each source file
981-
// the settings can be applied in the target project.
982-
var podTargetName = Path.GetFileName(directory);
983-
var podTargetGuid = podsProject.TargetGuidByName(podTargetName);
984-
Log(String.Format("Looking for target: {0} guid: {1}",
985-
podTargetName, podTargetGuid ?? "null"),
986-
verbose: true);
987-
if (podTargetGuid == null) continue;
988-
foreach (var podPathProjectPath in podPathToProjectPaths) {
989-
var podSourceFileGuid = podsProject.FindFileGuidByRealPath(
990-
podPathProjectPath.Key);
991-
if (podSourceFileGuid == null) continue;
992-
var podSourceFileCompileFlags =
993-
podsProject.GetCompileFlagsForFile(podTargetGuid,
994-
podSourceFileGuid);
995-
if (podSourceFileCompileFlags == null) {
996-
continue;
997-
}
998-
var targetSourceFileGuid = project.FindFileGuidByProjectPath(
999-
podPathProjectPath.Value);
1000-
if (targetSourceFileGuid == null) {
1001-
Log("Unable to find " + podPathProjectPath.Value +
1002-
" in generated project", level: LogLevel.Warning);
1003-
continue;
1004-
}
1005-
Log(String.Format(
1006-
"Setting {0} compile flags to ({1})",
1007-
podPathProjectPath.Key,
1008-
String.Join(", ",
1009-
podSourceFileCompileFlags.ToArray())),
980+
if (File.Exists(podsProjectPath)) {
981+
var podsProject = new UnityEditor.iOS.Xcode.PBXProject();
982+
podsProject.ReadFromString(File.ReadAllText(podsProjectPath));
983+
foreach (var directory in Directory.GetDirectories(podsDir)) {
984+
// Each pod will have a top level directory under the pods dir
985+
// named after the pod. Also, some pods have build targets in
986+
// the xcode project where each build target has the same name
987+
// as the pod such that pod Foo is in directory Foo with build
988+
// target Foo. Since we can't read the build targets from the
989+
// generated Xcode project using Unity's API, we scan the Xcode
990+
// project for targets to optionally retrieve build settings
991+
// for each source file the settings can be applied in the
992+
// target project.
993+
var podTargetName = Path.GetFileName(directory);
994+
var podTargetGuid =
995+
podsProject.TargetGuidByName(podTargetName);
996+
Log(String.Format("Looking for target: {0} guid: {1}",
997+
podTargetName, podTargetGuid ?? "null"),
1010998
verbose: true);
1011-
project.SetCompileFlagsForFile(target, targetSourceFileGuid,
1012-
podSourceFileCompileFlags);
999+
if (podTargetGuid == null) continue;
1000+
foreach (var podPathProjectPath in podPathToProjectPaths) {
1001+
var podSourceFileGuid = podsProject.FindFileGuidByRealPath(
1002+
podPathProjectPath.Key);
1003+
if (podSourceFileGuid == null) continue;
1004+
var podSourceFileCompileFlags =
1005+
podsProject.GetCompileFlagsForFile(podTargetGuid,
1006+
podSourceFileGuid);
1007+
if (podSourceFileCompileFlags == null) {
1008+
continue;
1009+
}
1010+
var targetSourceFileGuid =
1011+
project.FindFileGuidByProjectPath(
1012+
podPathProjectPath.Value);
1013+
if (targetSourceFileGuid == null) {
1014+
Log("Unable to find " + podPathProjectPath.Value +
1015+
" in generated project", level: LogLevel.Warning);
1016+
continue;
1017+
}
1018+
Log(String.Format(
1019+
"Setting {0} compile flags to ({1})",
1020+
podPathProjectPath.Key,
1021+
String.Join(", ",
1022+
podSourceFileCompileFlags.ToArray())),
1023+
verbose: true);
1024+
project.SetCompileFlagsForFile(
1025+
target, targetSourceFileGuid,
1026+
podSourceFileCompileFlags);
1027+
}
10131028
}
1029+
} else if (File.Exists(podsProjectPath + ".xml")) {
1030+
// If neither the Pod pbxproj or pbxproj.xml are present pod
1031+
// install failed earlier and an error has already been report.
1032+
Log("Old Cocoapods installation detected (version: " +
1033+
podsVersion + "). Unable to include " +
1034+
"source pods, your project will not build.\n" +
1035+
"\n" +
1036+
"Older versions of the pod tool generate xml format Xcode " +
1037+
"projects which can not be read by Unity's xcodeapi. To " +
1038+
"resolve this issue update Cocoapods to at least version " +
1039+
"1.1.0\n\n" +
1040+
COCOAPOD_INSTALL_INSTRUCTIONS,
1041+
level: LogLevel.Error);
10141042
}
10151043

10161044
File.WriteAllText(pbxprojPath, project.WriteToString());

0 commit comments

Comments
 (0)