Fix unity build for osx

This commit is contained in:
Chris Marsh 2017-12-01 08:50:41 -08:00 committed by Chris Marsh
parent 82439911c6
commit 50ea4e61c6

View file

@ -5,52 +5,97 @@ using System.IO;
[InitializeOnLoad] [InitializeOnLoad]
public class ScriptBatch public class ScriptBatch
{ {
static ScriptBatch() static ScriptBatch()
{ {
EnsureDLL(); EnsureDLL();
} }
public static bool FileExists(string filename) public static bool FileExists(string filename)
{ {
return new FileInfo(filename).Exists; return new FileInfo(filename).Exists;
} }
public static void EnsureDLL()
{
UnityEngine.Debug.Log("Make sure Discord dll exists");
string dstDll32 = "Assets/Plugins/x86/discord-rpc.dll"; public static bool RunRpcBuildScript()
string dstDll64 = "Assets/Plugins/x86_64/discord-rpc.dll"; {
UnityEngine.Debug.Log("Try to run build script");
if (!FileExists(dstDll32) || !FileExists(dstDll64)) Process proc = new Process();
{ #if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
string srcDll32 = "../../builds/install/win64-dynamic/bin/discord-rpc.dll"; proc.StartInfo.UseShellExecute = false;
string srcDll64 = "../../builds/install/win64-dynamic/bin/discord-rpc.dll"; // brew installs cmake in /usr/local/bin, which Unity seems to strip from PATH?
string newPath = proc.StartInfo.EnvironmentVariables["PATH"] + ":/usr/local/bin";
proc.StartInfo.EnvironmentVariables["PATH"] = newPath;
#endif
proc.StartInfo.FileName = "python";
proc.StartInfo.Arguments = "build.py";
proc.StartInfo.WorkingDirectory = "../..";
proc.Start();
proc.WaitForExit();
return proc.ExitCode == 0;
}
if (!FileExists(srcDll32) || !FileExists(srcDll64)) public static void EnsureDLL()
{ {
UnityEngine.Debug.Log("Try to run build script"); #if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
Process proc = new Process(); string[] dstDirs = { "Assets/Plugins", "Assets/Plugins/x86", "Assets/Plugins/x86_64" };
proc.StartInfo.FileName = "python"; string[] dstDlls = { "Assets/Plugins/x86/discord-rpc.dll", "Assets/Plugins/x86_64/discord-rpc.dll" };
proc.StartInfo.Arguments = "build.py"; string[] srcDlls = { "../../builds/install/win64-dynamic/bin/discord-rpc.dll", "../../builds/install/win64-dynamic/bin/discord-rpc.dll" };
proc.StartInfo.WorkingDirectory = "../.."; #elif UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
proc.Start(); string[] dstDirs = { "Assets/Plugins" };
proc.WaitForExit(); string[] dstDlls = { "Assets/Plugins/discord-rpc.bundle" };
if (proc.ExitCode != 0) string[] srcDlls = { "../../builds/install/osx-dynamic/lib/libdiscord-rpc.dylib" };
{ #else
UnityEngine.Debug.LogError("Build failed"); string[] dstDirs = { "Assets/Plugins", "Assets/Plugins/x86", "Assets/Plugins/x86_64" };
return; string[] dstDlls = { "Assets/Plugins/x86/discord-rpc.so", "Assets/Plugins/x86_64/discord-rpc.so" };
} string[] srcDlls = { "../../builds/install/linux-dynamic/bin/discord-rpc.dll", "../../builds/install/win64-dynamic/bin/discord-rpc.dll" };
} #endif
// make sure the dirs exist Debug.Assert(dstDlls.Length == srcDlls.Length);
Directory.CreateDirectory("Assets/Plugins");
Directory.CreateDirectory("Assets/Plugins/x86");
Directory.CreateDirectory("Assets/Plugins/x86_64");
// Copy dlls bool exists = true;
FileUtil.CopyFileOrDirectory("../../builds/install/win64-dynamic/bin/discord-rpc.dll", dstDll64); foreach (string fname in dstDlls)
FileUtil.CopyFileOrDirectory("../../builds/install/win32-dynamic/bin/discord-rpc.dll", dstDll32); {
} if (!FileExists(fname))
} {
exists = false;
break;
}
}
if (exists)
{
return;
}
exists = true;
foreach (string fname in srcDlls)
{
if (!FileExists(fname))
{
exists = false;
break;
}
}
if (!exists)
{
if (!RunRpcBuildScript())
{
UnityEngine.Debug.LogError("Build failed");
return;
}
}
// make sure the dirs exist
foreach (string dirname in dstDirs)
{
Directory.CreateDirectory(dirname);
}
// Copy dlls
for (int i = 0; i < dstDlls.Length; ++i)
{
FileUtil.CopyFileOrDirectory(srcDlls[i], dstDlls[i]);
}
}
} }