Skip to content
This repository has been archived by the owner on Jan 18, 2022. It is now read-only.

Commit

Permalink
Fix xcode paths (#1040)
Browse files Browse the repository at this point in the history
* Postprocess xcode project to file search paths for different sdks

* changelog

* Everything is now reflection
  • Loading branch information
zeroZshadow authored Jul 17, 2019
1 parent e108330 commit ca92bb5
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
- Use the `buildTargetFilter` command line argument to pass in a comma delimited list of build targets to filter for. For example, `+buildTargetFilter win,macos`.
- Added two new GDK packages: `io.improbable.worker.sdk` and `io.improbable.worker.sdk.mobile` which contain the underlying Worker SDK packages for Windows/MacOS/Linux and Android/iOS respectively. [#894](https://github.com/spatialos/gdk-for-unity/pull/894)
- You may now `[Require]` a `WorkerId` in MonoBehaviours. For example: `[Require] private WorkerId workerId;`. [#1016](https://github.com/spatialos/gdk-for-unity/pull/1016)

- iOS builds now perform a post processing step on the XCode project to ensure x86_64 and arm libraries from the SpatialOS Worker SDK are separated. [#1040](https://github.com/spatialos/gdk-for-unity/pull/1040)

### Changed

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Callbacks;

namespace Improbable.Gdk.Mobile
{
public static class BuildPostProcessXCode
{
private static Type pbxType;

[PostProcessBuild]
public static void OnPostProcessBuild(BuildTarget buildTarget, string path)
{
if (buildTarget != BuildTarget.iOS)
{
return;
}

var assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (var assembly in assemblies)
{
var type = assembly.GetTypes().FirstOrDefault(t => t.FullName == "UnityEditor.iOS.Xcode.PBXProject");
if (type != null)
{
pbxType = type;
break;
}
}

// Safety check again API changes
if (pbxType == null)
{
throw new BuildFailedException("Unable to find type UnityEditor.iOS.Xcode.PBXProject");
}

var xcodeObject = Activator.CreateInstance(pbxType);

// Instantiate PBXProject and read from xcode project file.
var projPath = InvokeStaticMethod<string>("GetPBXProjectPath", path);
var xcodeText = File.ReadAllText(projPath);
InvokeMethod(xcodeObject, "ReadFromString", xcodeText);

// Get Target GUIDs
var unityTargetName = InvokeStaticMethod<string>("GetUnityTargetName");
var unityTestTargetName = InvokeStaticMethod<string>("GetUnityTestTargetName");
var targetGUID = InvokeMethod<string>(xcodeObject, "TargetGuidByName", unityTargetName);
var targetTestingGUID = InvokeMethod<string>(xcodeObject, "TargetGuidByName", unityTestTargetName);

// Enumerate configGUIDs that need library path patching
var configNames = InvokeMethod<IEnumerable<string>>(xcodeObject, "BuildConfigNames");
var configGUIDs = configNames
.Select(configName => InvokeMethod<string>(xcodeObject, "BuildConfigByName", targetGUID, configName))
.Concat(configNames.Select(configName =>
InvokeMethod<string>(xcodeObject, "BuildConfigByName", targetTestingGUID, configName)));

// Update library paths for each config
foreach (var configGUID in configGUIDs)
{
InvokeMethod<string>(xcodeObject, "UpdateBuildPropertyForConfig", configGUID, "LIBRARY_SEARCH_PATHS",
null, new[]
{
"$(SRCROOT)/Libraries/io.improbable.worker.sdk.mobile/Plugins/Improbable/Core/iOS/arm",
"$(SRCROOT)/Libraries/io.improbable.worker.sdk.mobile/Plugins/Improbable/Core/iOS/x86_64"
});

// Add platform specific paths
InvokeMethod<string>(xcodeObject, "UpdateBuildPropertyForConfig", configGUID,
"LIBRARY_SEARCH_PATHS[sdk=iphoneos*]", new[]
{
"$(inherited)",
"$(SRCROOT)/Libraries/io.improbable.worker.sdk.mobile/Plugins/Improbable/Core/iOS/arm"
}, null);

InvokeMethod<string>(xcodeObject, "UpdateBuildPropertyForConfig", configGUID,
"LIBRARY_SEARCH_PATHS[sdk=iphonesimulator*]",
new[]
{
"$(inherited)",
"$(SRCROOT)/Libraries/io.improbable.worker.sdk.mobile/Plugins/Improbable/Core/iOS/x86_64"
}, null);
}

// Save changes to xcode project file
InvokeMethod(xcodeObject, "WriteToFile", projPath);
}

private static T InvokeStaticMethod<T>(string methodName, params object[] parameters)
{
return (T) pbxType.InvokeMember(methodName,
BindingFlags.Public | BindingFlags.Static | BindingFlags.InvokeMethod, null, null, parameters);
}

private static void InvokeStaticMethod(string methodName, params object[] parameters)
{
pbxType.InvokeMember(methodName, BindingFlags.Public | BindingFlags.Static | BindingFlags.InvokeMethod,
null, null, parameters);
}

private static T InvokeMethod<T>(object target, string methodName, params object[] parameters)
{
return (T) pbxType.InvokeMember(methodName,
BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod, null, target, parameters);
}

private static void InvokeMethod(object target, string methodName, params object[] parameters)
{
pbxType.InvokeMember(methodName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod,
null, target, parameters);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "Improbable.Worker.Sdk.Mobile",
"references": [],
"optionalUnityReferences": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": false,
"defineConstraints": [],
"versionDefines": []
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ca92bb5

Please sign in to comment.