2017-10-22 23:25:13 +00:00
|
|
|
using System;
|
|
|
|
using P = System.IO.Path;
|
2017-11-11 18:11:44 +00:00
|
|
|
using F = System.IO.File;
|
2017-10-22 23:25:13 +00:00
|
|
|
|
|
|
|
public class GAssembly
|
|
|
|
{
|
2017-10-25 23:42:57 +00:00
|
|
|
private ICakeContext Cake;
|
2017-10-22 23:25:13 +00:00
|
|
|
|
|
|
|
public bool Init { get; private set; }
|
|
|
|
public string Name { get; private set; }
|
|
|
|
public string Dir { get; private set; }
|
|
|
|
public string GDir { get; private set; }
|
|
|
|
public string Csproj { get; private set; }
|
|
|
|
public string RawApi { get; private set; }
|
|
|
|
public string Metadata { get; private set; }
|
|
|
|
|
2017-10-25 23:42:57 +00:00
|
|
|
public string[] Deps { get; set; }
|
2017-10-26 16:30:48 +00:00
|
|
|
public string[] NativeDeps { get; set; }
|
2017-10-22 23:25:13 +00:00
|
|
|
public string ExtraArgs { get; set; }
|
|
|
|
|
|
|
|
public GAssembly(string name)
|
|
|
|
{
|
2017-10-25 23:42:57 +00:00
|
|
|
Cake = Settings.Cake;
|
|
|
|
Deps = new string[0];
|
2017-10-22 23:25:13 +00:00
|
|
|
|
|
|
|
Name = name;
|
|
|
|
Dir = P.Combine("Source", "Libs", name);
|
|
|
|
GDir = P.Combine(Dir, "Generated");
|
|
|
|
|
|
|
|
var temppath = P.Combine(Dir, name);
|
|
|
|
Csproj = temppath + ".csproj";
|
|
|
|
RawApi = temppath + "-api.raw";
|
|
|
|
Metadata = temppath + ".metadata";
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Prepare()
|
|
|
|
{
|
2017-10-25 23:42:57 +00:00
|
|
|
Cake.CreateDirectory(GDir);
|
|
|
|
|
2017-10-22 23:25:13 +00:00
|
|
|
// Raw API file found, time to generate some stuff!!!
|
|
|
|
if (Cake.FileExists(RawApi))
|
|
|
|
{
|
|
|
|
// Fixup API file
|
|
|
|
var tempapi = P.Combine(GDir, Name + "-api.xml");
|
|
|
|
var symfile = P.Combine(Dir, Name + "-symbols.xml");
|
|
|
|
Cake.CopyFile(RawApi, tempapi);
|
2017-10-26 16:30:48 +00:00
|
|
|
Cake.DotNetCoreExecute("BuildOutput/Tools/GapiFixup.dll",
|
|
|
|
"--metadata=" + Metadata + " " + "--api=" + tempapi +
|
|
|
|
(Cake.FileExists(symfile) ? " --symbols=" + symfile : string.Empty)
|
|
|
|
);
|
2017-10-22 23:25:13 +00:00
|
|
|
|
2017-10-25 23:42:57 +00:00
|
|
|
var extraargs = ExtraArgs + " ";
|
|
|
|
|
2017-10-22 23:25:13 +00:00
|
|
|
// Locate APIs to include
|
2017-10-25 23:42:57 +00:00
|
|
|
foreach(var dep in Deps)
|
2017-10-22 23:25:13 +00:00
|
|
|
{
|
|
|
|
var ipath = P.Combine("Source", "Libs", dep, dep + "-api.xml");
|
|
|
|
|
|
|
|
if (!Cake.FileExists(ipath))
|
|
|
|
ipath = P.Combine("Source", "Libs", dep, "Generated", dep + "-api.xml");
|
|
|
|
|
|
|
|
if (Cake.FileExists(ipath))
|
2017-10-25 23:42:57 +00:00
|
|
|
extraargs += " --include=" + ipath + " ";
|
2017-10-22 23:25:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Generate code
|
2017-10-26 16:30:48 +00:00
|
|
|
Cake.DotNetCoreExecute("BuildOutput/Tools/GapiCodegen.dll",
|
2017-10-22 23:25:13 +00:00
|
|
|
"--outdir=" + GDir + " " +
|
2017-10-25 23:42:57 +00:00
|
|
|
"--schema=Source/Libs/Gapi.xsd " +
|
|
|
|
extraargs + " " +
|
2017-10-22 23:25:13 +00:00
|
|
|
"--assembly-name=" + Name + " " +
|
|
|
|
"--generate=" + tempapi
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Init = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Clean()
|
|
|
|
{
|
2017-10-25 23:42:57 +00:00
|
|
|
if (Cake.DirectoryExists(GDir))
|
|
|
|
Cake.DeleteDirectory(GDir, new DeleteDirectorySettings { Recursive = true, Force = true });
|
2017-10-22 23:25:13 +00:00
|
|
|
}
|
2017-10-26 16:30:48 +00:00
|
|
|
|
|
|
|
public void GenerateLinuxStubs()
|
|
|
|
{
|
2017-10-29 23:23:56 +00:00
|
|
|
var basedir = P.Combine("..", "..", Dir);
|
2017-11-11 18:11:44 +00:00
|
|
|
var lines = new List<string>();
|
2017-10-29 23:23:56 +00:00
|
|
|
|
2017-11-09 21:22:51 +00:00
|
|
|
if (Cake.DirectoryExists(P.Combine(basedir, "linux-x86")))
|
|
|
|
Cake.DeleteDirectory(P.Combine(basedir, "linux-x86"), new DeleteDirectorySettings { Recursive = true, Force = true });
|
|
|
|
Cake.CreateDirectory(P.Combine(basedir, "linux-x86"));
|
|
|
|
|
|
|
|
if (Cake.DirectoryExists(P.Combine(basedir, "linux-x64")))
|
|
|
|
Cake.DeleteDirectory(P.Combine(basedir, "linux-x64"), new DeleteDirectorySettings { Recursive = true, Force = true });
|
|
|
|
Cake.CreateDirectory(P.Combine(basedir, "linux-x64"));
|
|
|
|
|
|
|
|
if (Cake.DirectoryExists(P.Combine(basedir, "linux-arm")))
|
|
|
|
Cake.DeleteDirectory(P.Combine(basedir, "linux-arm"), new DeleteDirectorySettings { Recursive = true, Force = true });
|
|
|
|
Cake.CreateDirectory(P.Combine(basedir, "linux-arm"));
|
|
|
|
|
2017-11-11 18:11:44 +00:00
|
|
|
lines.Add("<configuration>");
|
2017-10-26 16:30:48 +00:00
|
|
|
for (int i = 0; i < NativeDeps.Length; i += 2)
|
|
|
|
{
|
2017-11-11 18:11:44 +00:00
|
|
|
lines.Add(" <dllmap dll=\"" + NativeDeps[i + 1] +"\" target=\"" + NativeDeps[i] + "\"/>");
|
|
|
|
|
2017-10-29 15:46:34 +00:00
|
|
|
// Generate x86 stubs
|
2017-10-29 23:23:56 +00:00
|
|
|
Cake.CreateDirectory(P.Combine(basedir, "linux-x86"));
|
|
|
|
Cake.StartProcess("gcc", "-m32 -shared -o " + NativeDeps[i] + " empty.c");
|
|
|
|
Cake.StartProcess("gcc", "-m32 -Wl,--no-as-needed -shared -o " + P.Combine(basedir, "linux-x86", NativeDeps[i + 1] + ".so") + " -fPIC -L. -l:" + NativeDeps[i] + "");
|
|
|
|
|
|
|
|
// Generate x64 stubs
|
|
|
|
Cake.CreateDirectory(P.Combine(basedir, "linux-x64"));
|
|
|
|
Cake.StartProcess("gcc", "-shared -o " + NativeDeps[i] + " empty.c");
|
|
|
|
Cake.StartProcess("gcc", "-Wl,--no-as-needed -shared -o " + P.Combine(basedir, "linux-x64", NativeDeps[i + 1] + ".so") + " -fPIC -L. -l:" + NativeDeps[i] + "");
|
2017-10-29 15:46:34 +00:00
|
|
|
|
|
|
|
// Generate arm stubs
|
2017-10-29 23:23:56 +00:00
|
|
|
Cake.CreateDirectory(P.Combine(basedir, "linux-arm"));
|
|
|
|
Cake.StartProcess("arm-none-eabi-gcc", "-shared -o " + NativeDeps[i] + " empty.c");
|
|
|
|
Cake.StartProcess("arm-none-eabi-gcc", "-Wl,--no-as-needed -shared -o " + P.Combine(basedir, "linux-arm", NativeDeps[i + 1] + ".so") + " -fPIC -L. -l:" + NativeDeps[i] + "");
|
2017-10-26 16:30:48 +00:00
|
|
|
}
|
2017-11-11 18:11:44 +00:00
|
|
|
lines.Add("</configuration>");
|
|
|
|
|
|
|
|
F.WriteAllLines(P.Combine(basedir, Name + ".dll.config"), lines.ToArray());
|
2017-10-26 16:30:48 +00:00
|
|
|
}
|
2017-10-22 23:25:13 +00:00
|
|
|
}
|