This repository has been archived by the owner on Jan 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Postprocess xcode project to file search paths for different sdks * changelog * Everything is now reflection
- Loading branch information
1 parent
e108330
commit ca92bb5
Showing
5 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
workers/unity/Packages/io.improbable.worker.sdk.mobile/BuildPostProcessXCode.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
workers/unity/Packages/io.improbable.worker.sdk.mobile/BuildPostProcessXCode.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
workers/unity/Packages/io.improbable.worker.sdk.mobile/Improbable.Worker.Sdk.Mobile.asmdef
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": [] | ||
} |
7 changes: 7 additions & 0 deletions
7
...s/unity/Packages/io.improbable.worker.sdk.mobile/Improbable.Worker.Sdk.Mobile.asmdef.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.