EnablAdd auto generation of native lib stubs

This commit is contained in:
cra0zy 2017-10-26 18:30:48 +02:00
parent 46951b3f91
commit ccb48b505c
95 changed files with 389 additions and 425 deletions

View file

@ -14,6 +14,7 @@ public class GAssembly
public string Metadata { get; private set; }
public string[] Deps { get; set; }
public string[] NativeDeps { get; set; }
public string ExtraArgs { get; set; }
public GAssembly(string name)
@ -42,7 +43,10 @@ public class GAssembly
var tempapi = P.Combine(GDir, Name + "-api.xml");
var symfile = P.Combine(Dir, Name + "-symbols.xml");
Cake.CopyFile(RawApi, tempapi);
GapiFixup.Run(tempapi, Metadata, Cake.FileExists(symfile) ? symfile : string.Empty);
Cake.DotNetCoreExecute("BuildOutput/Tools/GapiFixup.dll",
"--metadata=" + Metadata + " " + "--api=" + tempapi +
(Cake.FileExists(symfile) ? " --symbols=" + symfile : string.Empty)
);
var extraargs = ExtraArgs + " ";
@ -59,7 +63,7 @@ public class GAssembly
}
// Generate code
Cake.DotNetCoreExecute("BuildOutput/Generator/GapiCodegen.dll",
Cake.DotNetCoreExecute("BuildOutput/Tools/GapiCodegen.dll",
"--outdir=" + GDir + " " +
"--schema=Source/Libs/Gapi.xsd " +
extraargs + " " +
@ -76,4 +80,21 @@ public class GAssembly
if (Cake.DirectoryExists(GDir))
Cake.DeleteDirectory(GDir, new DeleteDirectorySettings { Recursive = true, Force = true });
}
public void GenerateLinuxStubs()
{
for (int i = 0; i < NativeDeps.Length; i += 2)
{
Cake.CreateDirectory(P.Combine(Dir, "linux-x64"));
Cake.CreateDirectory(P.Combine(Dir, "linux-x86"));
// Generate x64 stub
Cake.StartProcess("gcc", "-shared -o BuildOutput/LinuxStubs/" + NativeDeps[i] + " BuildOutput/LinuxStubs/empty.c");
Cake.StartProcess("gcc", "-Wl,--no-as-needed -shared -o " + P.Combine(Dir, "linux-x64", NativeDeps[i + 1] + ".so") + " -fPIC -L. -l:BuildOutput/LinuxStubs/" + NativeDeps[i] + "");
// GEnerate x86 stub
Cake.StartProcess("gcc", "-m32 -shared -o BuildOutput/LinuxStubs/" + NativeDeps[i] + " BuildOutput/LinuxStubs/empty.c");
Cake.StartProcess("gcc", "-m32 -Wl,--no-as-needed -shared -o " + P.Combine(Dir, "linux-x86", NativeDeps[i + 1] + ".so") + " -fPIC -L. -l:BuildOutput/LinuxStubs/" + NativeDeps[i] + "");
}
}
}

View file

@ -1,262 +0,0 @@
// xml alteration engine.
//
// Authors:
// Mike Kestner <mkestner@speakeasy.net>
// Stephan Sundermann <stephansundermann@gmail.com>
//
// Copyright (c) 2003 Mike Kestner
// Copyright (c) 2013 Stephan Sundermann
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the GNU General Public
// License as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
using System;
using System.IO;
using System.Xml;
using System.Xml.XPath;
public class GapiFixup
{
public static int Run(string api_filename, string meta_filename, string symbol_filename = "")
{
XmlDocument api_doc = new XmlDocument();
XmlDocument meta_doc = new XmlDocument();
XmlDocument symbol_doc = new XmlDocument();
if (!string.IsNullOrEmpty(meta_filename))
{
try
{
Stream stream = System.IO.File.OpenRead(meta_filename);
meta_doc.Load(stream);
stream.Close();
}
catch (XmlException e)
{
Console.WriteLine("Invalid meta file.");
Console.WriteLine(e);
return 1;
}
}
if (!string.IsNullOrEmpty(api_filename))
{
try
{
Stream stream = System.IO.File.OpenRead(api_filename);
api_doc.Load(stream);
stream.Close();
}
catch (XmlException e)
{
Console.WriteLine("Invalid api file.");
Console.WriteLine(e);
return 1;
}
}
if (!string.IsNullOrEmpty(symbol_filename))
{
try
{
Stream stream = System.IO.File.OpenRead(symbol_filename);
symbol_doc.Load(stream);
stream.Close();
}
catch (XmlException e)
{
Console.WriteLine("Invalid api file.");
Console.WriteLine(e);
return 1;
}
}
XPathNavigator meta_nav = meta_doc.CreateNavigator();
XPathNavigator api_nav = api_doc.CreateNavigator();
XPathNodeIterator copy_iter = meta_nav.Select("/metadata/copy-node");
while (copy_iter.MoveNext())
{
string path = copy_iter.Current.GetAttribute("path", String.Empty);
XPathExpression expr = api_nav.Compile(path);
string parent = copy_iter.Current.Value;
XPathNodeIterator parent_iter = api_nav.Select(parent);
bool matched = false;
while (parent_iter.MoveNext())
{
XmlNode parent_node = ((IHasXmlNode)parent_iter.Current).GetNode();
XPathNodeIterator path_iter = parent_iter.Current.Clone().Select(expr);
while (path_iter.MoveNext())
{
XmlNode node = ((IHasXmlNode)path_iter.Current).GetNode();
parent_node.AppendChild(node.Clone());
}
matched = true;
}
if (!matched)
Console.WriteLine("Warning: <copy-node path=\"{0}\"/> matched no nodes", path);
}
XPathNodeIterator rmv_iter = meta_nav.Select("/metadata/remove-node");
while (rmv_iter.MoveNext())
{
string path = rmv_iter.Current.GetAttribute("path", "");
XPathNodeIterator api_iter = api_nav.Select(path);
bool matched = false;
while (api_iter.MoveNext())
{
XmlElement api_node = ((IHasXmlNode)api_iter.Current).GetNode() as XmlElement;
api_node.ParentNode.RemoveChild(api_node);
matched = true;
}
if (!matched)
Console.WriteLine("Warning: <remove-node path=\"{0}\"/> matched no nodes", path);
}
XPathNodeIterator add_iter = meta_nav.Select("/metadata/add-node");
while (add_iter.MoveNext())
{
string path = add_iter.Current.GetAttribute("path", "");
XPathNodeIterator api_iter = api_nav.Select(path);
bool matched = false;
while (api_iter.MoveNext())
{
XmlElement api_node = ((IHasXmlNode)api_iter.Current).GetNode() as XmlElement;
foreach (XmlNode child in ((IHasXmlNode)add_iter.Current).GetNode().ChildNodes)
api_node.AppendChild(api_doc.ImportNode(child, true));
matched = true;
}
if (!matched)
Console.WriteLine("Warning: <add-node path=\"{0}\"/> matched no nodes", path);
}
XPathNodeIterator change_node_type_iter = meta_nav.Select("/metadata/change-node-type");
while (change_node_type_iter.MoveNext())
{
string path = change_node_type_iter.Current.GetAttribute("path", "");
XPathNodeIterator api_iter = api_nav.Select(path);
bool matched = false;
while (api_iter.MoveNext())
{
XmlElement node = ((IHasXmlNode)api_iter.Current).GetNode() as XmlElement;
XmlElement parent = node.ParentNode as XmlElement;
XmlElement new_node = api_doc.CreateElement(change_node_type_iter.Current.Value);
foreach (XmlNode child in node.ChildNodes)
new_node.AppendChild(child.Clone());
foreach (XmlAttribute attribute in node.Attributes)
new_node.Attributes.Append((XmlAttribute)attribute.Clone());
parent.ReplaceChild(new_node, node);
matched = true;
}
if (!matched)
Console.WriteLine("Warning: <change-node-type path=\"{0}\"/> matched no nodes", path);
}
XPathNodeIterator attr_iter = meta_nav.Select("/metadata/attr");
while (attr_iter.MoveNext())
{
string path = attr_iter.Current.GetAttribute("path", "");
string attr_name = attr_iter.Current.GetAttribute("name", "");
int max_matches = -1;
var max_matches_str = attr_iter.Current.GetAttribute("max-matches", "");
if (max_matches_str != "")
max_matches = Convert.ToInt32(max_matches_str);
XPathNodeIterator api_iter = api_nav.Select(path);
var nmatches = 0;
while (api_iter.MoveNext())
{
XmlElement node = ((IHasXmlNode)api_iter.Current).GetNode() as XmlElement;
node.SetAttribute(attr_name, attr_iter.Current.Value);
nmatches++;
if (max_matches > 0 && nmatches == max_matches)
break;
}
if (nmatches == 0)
Console.WriteLine("Warning: <attr path=\"{0}\"/> matched no nodes", path);
}
XPathNodeIterator move_iter = meta_nav.Select("/metadata/move-node");
while (move_iter.MoveNext())
{
string path = move_iter.Current.GetAttribute("path", "");
XPathExpression expr = api_nav.Compile(path);
string parent = move_iter.Current.Value;
XPathNodeIterator parent_iter = api_nav.Select(parent);
bool matched = false;
while (parent_iter.MoveNext())
{
XmlNode parent_node = ((IHasXmlNode)parent_iter.Current).GetNode();
XPathNodeIterator path_iter = parent_iter.Current.Clone().Select(expr);
while (path_iter.MoveNext())
{
XmlNode node = ((IHasXmlNode)path_iter.Current).GetNode();
parent_node.AppendChild(node.Clone());
node.ParentNode.RemoveChild(node);
}
matched = true;
}
if (!matched)
Console.WriteLine("Warning: <move-node path=\"{0}\"/> matched no nodes", path);
}
XPathNodeIterator remove_attr_iter = meta_nav.Select("/metadata/remove-attr");
while (remove_attr_iter.MoveNext())
{
string path = remove_attr_iter.Current.GetAttribute("path", "");
string name = remove_attr_iter.Current.GetAttribute("name", "");
XPathNodeIterator api_iter = api_nav.Select(path);
bool matched = false;
while (api_iter.MoveNext())
{
XmlElement node = ((IHasXmlNode)api_iter.Current).GetNode() as XmlElement;
node.RemoveAttribute(name);
matched = true;
}
if (!matched)
Console.WriteLine("Warning: <remove-attr path=\"{0}\"/> matched no nodes", path);
}
if (symbol_doc != null)
{
XPathNavigator symbol_nav = symbol_doc.CreateNavigator();
XPathNodeIterator iter = symbol_nav.Select("/api/*");
while (iter.MoveNext())
{
XmlNode sym_node = ((IHasXmlNode)iter.Current).GetNode();
XPathNodeIterator parent_iter = api_nav.Select("/api");
if (parent_iter.MoveNext())
{
XmlNode parent_node = ((IHasXmlNode)parent_iter.Current).GetNode();
parent_node.AppendChild(api_doc.ImportNode(sym_node, true));
}
}
}
api_doc.Save(api_filename);
return 0;
}
}

View file

@ -1,4 +0,0 @@
using System.Reflection;
using System.Runtime.CompilerServices;
[assembly:AssemblyVersion("3.22.24.0")]

Binary file not shown.

View file

@ -12,5 +12,6 @@
</PropertyGroup>
<ItemGroup>
<Content Include="linux-x64\libcairo-2.so" PackagePath="runtimes\linux-x64\native" Visible="false" />
<Content Include="linux-x86\libcairo-2.so" PackagePath="runtimes\linux-x86\native" Visible="false" />
</ItemGroup>
</Project>

Binary file not shown.

View file

@ -1,76 +0,0 @@
assembly_name = 'cairo-sharp'
raw_api_fname = join_paths(meson.current_source_dir(), 'cairo-api.raw')
metadata_fname = join_paths(meson.current_source_dir(), 'cairo.metadata')
sources = [
'Antialias.cs',
'Cairo.cs',
'CairoDebug.cs',
'Color.cs',
'Content.cs',
'Context.cs',
'Device.cs',
'DirectFBSurface.cs',
'Distance.cs',
'Extend.cs',
'FillRule.cs',
'Filter.cs',
'FontExtents.cs',
'FontFace.cs',
'FontOptions.cs',
'FontSlant.cs',
'FontType.cs',
'FontWeight.cs',
'Format.cs',
'GlitzSurface.cs',
'Glyph.cs',
'Gradient.cs',
'HintMetrics.cs',
'HintStyle.cs',
'ImageSurface.cs',
'LinearGradient.cs',
'LineCap.cs',
'LineJoin.cs',
'Matrix.cs',
'NativeMethods.cs',
'Operator.cs',
'Path.cs',
'Pattern.cs',
'PatternType.cs',
'PdfSurface.cs',
'Point.cs',
'PointD.cs',
'PSSurface.cs',
'RadialGradient.cs',
'Rectangle.cs',
'Region.cs',
'ScaledFont.cs',
'SolidPattern.cs',
'Status.cs',
'SubpixelOrder.cs',
'Surface.cs',
'SurfacePattern.cs',
'SurfaceType.cs',
'SvgSurface.cs',
'SvgVersion.cs',
'TextExtents.cs',
'Win32Surface.cs',
'XcbSurface.cs',
'XlibSurface.cs',
]
cairo_sharp = library(assembly_name, sources, assemblyinfo,
install: install,
install_dir: lib_install_dir
)
nuget_infos += [['CairoSharp', cairo_sharp, []]]
install_infos += [assembly_name, cairo_sharp.full_path()]
cairo_api_includes = join_paths(meson.current_source_dir(), 'cairo-api.xml')
if install
install_data(cairo_api_includes, install_dir: gapi_xml_installdir)
endif
cairo_sharp_dep = declare_dependency(link_with: cairo_sharp)

Binary file not shown.

View file

@ -7,7 +7,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GLibSharp", "GLibSharp\GLib
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GioSharp", "GioSharp\GioSharp.csproj", "{25C49839-7DA6-45BA-849A-C6D4B8FAFA31}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CairoSharp", "CairoSharp\CairoSharp.csproj", "{23BB5F1B-2E85-4DF8-AC51-8018DDB8DE0E}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CairSharp", "CairSharp\CairSharp.csproj", "{23BB5F1B-2E85-4DF8-AC51-8018DDB8DE0E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PangoSharp", "PangoSharp\PangoSharp.csproj", "{B7A3467A-DFF6-4089-B78A-E13B3D11FDAD}"
EndProject

View file

@ -14,5 +14,8 @@
<Content Include="linux-x64\libglib-2.0-0.so" PackagePath="runtimes\linux-x64\native" Visible="false" />
<Content Include="linux-x64\libgobject-2.0-0.so" PackagePath="runtimes\linux-x64\native" Visible="false" />
<Content Include="linux-x64\libgthread-2.0-0.so" PackagePath="runtimes\linux-x64\native" Visible="false" />
<Content Include="linux-x86\libglib-2.0-0.so" PackagePath="runtimes\linux-x86\native" Visible="false" />
<Content Include="linux-x86\libgobject-2.0-0.so" PackagePath="runtimes\linux-x86\native" Visible="false" />
<Content Include="linux-x86\libgthread-2.0-0.so" PackagePath="runtimes\linux-x86\native" Visible="false" />
</ItemGroup>
</Project>

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -1,5 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<TargetFramework>netstandard2.0</TargetFramework>
@ -18,8 +17,8 @@
<ProjectReference Include="..\GioSharp\GioSharp.csproj">
<Name>GioSharp</Name>
</ProjectReference>
<ProjectReference Include="..\CairoSharp\CairoSharp.csproj">
<Name>CairoSharp</Name>
<ProjectReference Include="..\CairSharp\CairSharp.csproj">
<Name>CairSharp</Name>
</ProjectReference>
<ProjectReference Include="..\PangoSharp\PangoSharp.csproj">
<Name>PangoSharp</Name>
@ -28,6 +27,7 @@
<ItemGroup>
<Content Include="linux-x64\libgdk_pixbuf-2.0-0.so" PackagePath="runtimes\linux-x64\native" Visible="false" />
<Content Include="linux-x64\libgdk-3-0.so" PackagePath="runtimes\linux-x64\native" Visible="false" />
<Content Include="linux-x86\libgdk_pixbuf-2.0-0.so" PackagePath="runtimes\linux-x86\native" Visible="false" />
<Content Include="linux-x86\libgdk-3-0.so" PackagePath="runtimes\linux-x86\native" Visible="false" />
</ItemGroup>
</Project>

Binary file not shown.

Binary file not shown.

View file

@ -18,6 +18,7 @@
</ItemGroup>
<ItemGroup>
<Content Include="linux-x64\libgio-2.0-0.so" PackagePath="runtimes\linux-x64\native" Visible="false" />
<Content Include="linux-x86\libgio-2.0-0.so" PackagePath="runtimes\linux-x86\native" Visible="false" />
</ItemGroup>
</Project>

Binary file not shown.

View file

@ -24,8 +24,8 @@
<ProjectReference Include="..\GdkSharp\GdkSharp.csproj">
<Name>GdkSharp</Name>
</ProjectReference>
<ProjectReference Include="..\CairoSharp\CairoSharp.csproj">
<Name>CairoSharp</Name>
<ProjectReference Include="..\CairSharp\CairSharp.csproj">
<Name>CairSharp</Name>
</ProjectReference>
<ProjectReference Include="..\PangoSharp\PangoSharp.csproj">
<Name>PangoSharp</Name>
@ -33,5 +33,6 @@
</ItemGroup>
<ItemGroup>
<Content Include="linux-x64\libgtk-3-0.so" PackagePath="runtimes\linux-x64\native" Visible="false" />
<Content Include="linux-x86\libgtk-3-0.so" PackagePath="runtimes\linux-x86\native" Visible="false" />
</ItemGroup>
</Project>

Binary file not shown.

View file

@ -25,7 +25,7 @@ namespace Pango {
public partial class Global {
public static string PangoNativeDll = "libpango-1.0-0";
internal const string PangoNativeDll = "libpango-1.0-0";
[DllImport (PangoNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern bool pango_scan_int(IntPtr pos, out int out_param);

View file

@ -14,11 +14,12 @@
<ProjectReference Include="..\GLibSharp\GLibSharp.csproj">
<Name>GLibSharp</Name>
</ProjectReference>
<ProjectReference Include="..\CairoSharp\CairoSharp.csproj">
<Name>CairoSharp</Name>
<ProjectReference Include="..\CairSharp\CairSharp.csproj">
<Name>CairSharp</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="linux-x64\libpango-1.0-0.so" PackagePath="runtimes\linux-x64\native" Visible="false" />
<Content Include="linux-x86\libpango-1.0-0.so" PackagePath="runtimes\linux-x86\native" Visible="false" />
</ItemGroup>
</Project>

Binary file not shown.

View file

@ -1,31 +0,0 @@
#!/bin/bash
set -e
cd "$(dirname "$0")"
genstub ()
{
DLLNAME=$1
TARGET=$2
rm -f empty.c
touch empty.c
gcc -shared -o ${TARGET} empty.c
gcc -Wl,--no-as-needed -shared -o ${DLLNAME}.so -fPIC -L. -l:${TARGET}
rm -f ${TARGET}
rm -f empty.c
echo "Mapped ${DLLNAME}.dll ==> ${TARGET}"
}
#genstub libglib-2.0-0 libglib-2.0.so.0
#genstub libgobject-2.0-0 libgobject-2.0.so.0
#genstub libgthread-2.0-0 libgthread-2.0.so.0
#genstub libgio-2.0-0 libgio-2.0.so.0
#genstub libatk-1.0-0 libatk-1.0.so.0
#genstub libcairo-2 libcairo.so.2
#genstub libgtk-3-0 libgtk-3.so.0
#genstub libgdk-3-0 libgdk-3.so.0
#genstub libgdk_pixbuf-2.0-0 libgdk_pixbuf-2.0.so.0
#genstub libgtk-3-0 libgtk-3.so.0
genstub libpango-1.0-0 libpango-1.0.so.0

View file

@ -1,10 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<StartupObject>GtkSharp.Generation.CodeGenerator</StartupObject>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<OutputPath>..\..\..\BuildOutput\Generator</OutputPath>
<OutputPath>..\..\..\BuildOutput\Tools</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>

View file

@ -1,12 +0,0 @@
using System;
namespace GapiCodegen
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}

View file

@ -0,0 +1,242 @@
// gapi-fixup.cs - xml alteration engine.
//
// Authors:
// Mike Kestner <mkestner@speakeasy.net>
// Stephan Sundermann <stephansundermann@gmail.com>
//
// Copyright (c) 2003 Mike Kestner
// Copyright (c) 2013 Stephan Sundermann
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the GNU General Public
// License as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
namespace GtkSharp.Parsing {
using System;
using System.IO;
using System.Xml;
using System.Xml.XPath;
public class Fixup {
public static int Main (string[] args)
{
if (args.Length < 2) {
Console.WriteLine ("Usage: gapi-fixup --metadata=<filename> --api=<filename> --symbols=<filename>");
return 0;
}
string api_filename = "";
XmlDocument api_doc = new XmlDocument ();
XmlDocument meta_doc = new XmlDocument ();
XmlDocument symbol_doc = new XmlDocument ();
foreach (string arg in args) {
if (arg.StartsWith("--metadata=")) {
string meta_filename = arg.Substring (11);
try {
Stream stream = File.OpenRead (meta_filename);
meta_doc.Load (stream);
stream.Close ();
} catch (XmlException e) {
Console.WriteLine ("Invalid meta file.");
Console.WriteLine (e);
return 1;
}
} else if (arg.StartsWith ("--api=")) {
api_filename = arg.Substring (6);
try {
Stream stream = File.OpenRead (api_filename);
api_doc.Load (stream);
stream.Close ();
} catch (XmlException e) {
Console.WriteLine ("Invalid api file.");
Console.WriteLine (e);
return 1;
}
} else if (arg.StartsWith ("--symbols=")) {
string symbol_filename = arg.Substring (10);
try {
Stream stream = File.OpenRead (symbol_filename);
symbol_doc.Load (stream);
stream.Close ();
} catch (XmlException e) {
Console.WriteLine ("Invalid api file.");
Console.WriteLine (e);
return 1;
}
} else {
Console.WriteLine ("Usage: gapi-fixup --metadata=<filename> --api=<filename>");
return 1;
}
}
XPathNavigator meta_nav = meta_doc.CreateNavigator ();
XPathNavigator api_nav = api_doc.CreateNavigator ();
XPathNodeIterator copy_iter = meta_nav.Select ("/metadata/copy-node");
while (copy_iter.MoveNext ()) {
string path = copy_iter.Current.GetAttribute ("path", String.Empty);
XPathExpression expr = api_nav.Compile (path);
string parent = copy_iter.Current.Value;
XPathNodeIterator parent_iter = api_nav.Select (parent);
bool matched = false;
while (parent_iter.MoveNext ()) {
XmlNode parent_node = ((IHasXmlNode)parent_iter.Current).GetNode ();
XPathNodeIterator path_iter = parent_iter.Current.Clone ().Select (expr);
while (path_iter.MoveNext ()) {
XmlNode node = ((IHasXmlNode)path_iter.Current).GetNode ();
parent_node.AppendChild (node.Clone ());
}
matched = true;
}
if (!matched)
Console.WriteLine ("Warning: <copy-node path=\"{0}\"/> matched no nodes", path);
}
XPathNodeIterator rmv_iter = meta_nav.Select ("/metadata/remove-node");
while (rmv_iter.MoveNext ()) {
string path = rmv_iter.Current.GetAttribute ("path", "");
XPathNodeIterator api_iter = api_nav.Select (path);
bool matched = false;
while (api_iter.MoveNext ()) {
XmlElement api_node = ((IHasXmlNode)api_iter.Current).GetNode () as XmlElement;
api_node.ParentNode.RemoveChild (api_node);
matched = true;
}
if (!matched)
Console.WriteLine ("Warning: <remove-node path=\"{0}\"/> matched no nodes", path);
}
XPathNodeIterator add_iter = meta_nav.Select ("/metadata/add-node");
while (add_iter.MoveNext ()) {
string path = add_iter.Current.GetAttribute ("path", "");
XPathNodeIterator api_iter = api_nav.Select (path);
bool matched = false;
while (api_iter.MoveNext ()) {
XmlElement api_node = ((IHasXmlNode)api_iter.Current).GetNode () as XmlElement;
foreach (XmlNode child in ((IHasXmlNode)add_iter.Current).GetNode().ChildNodes)
api_node.AppendChild (api_doc.ImportNode (child, true));
matched = true;
}
if (!matched)
Console.WriteLine ("Warning: <add-node path=\"{0}\"/> matched no nodes", path);
}
XPathNodeIterator change_node_type_iter = meta_nav.Select ("/metadata/change-node-type");
while (change_node_type_iter.MoveNext ()) {
string path = change_node_type_iter.Current.GetAttribute ("path", "");
XPathNodeIterator api_iter = api_nav.Select (path);
bool matched = false;
while (api_iter.MoveNext ()) {
XmlElement node = ( (IHasXmlNode) api_iter.Current).GetNode () as XmlElement;
XmlElement parent = node.ParentNode as XmlElement;
XmlElement new_node = api_doc.CreateElement (change_node_type_iter.Current.Value);
foreach (XmlNode child in node.ChildNodes)
new_node.AppendChild (child.Clone ());
foreach (XmlAttribute attribute in node.Attributes)
new_node.Attributes.Append ( (XmlAttribute) attribute.Clone ());
parent.ReplaceChild (new_node, node);
matched = true;
}
if (!matched)
Console.WriteLine ("Warning: <change-node-type path=\"{0}\"/> matched no nodes", path);
}
XPathNodeIterator attr_iter = meta_nav.Select ("/metadata/attr");
while (attr_iter.MoveNext ()) {
string path = attr_iter.Current.GetAttribute ("path", "");
string attr_name = attr_iter.Current.GetAttribute ("name", "");
XPathNodeIterator api_iter = api_nav.Select (path);
bool matched = false;
while (api_iter.MoveNext ()) {
XmlElement node = ((IHasXmlNode)api_iter.Current).GetNode () as XmlElement;
node.SetAttribute (attr_name, attr_iter.Current.Value);
matched = true;
}
if (!matched)
Console.WriteLine ("Warning: <attr path=\"{0}\"/> matched no nodes", path);
}
XPathNodeIterator move_iter = meta_nav.Select ("/metadata/move-node");
while (move_iter.MoveNext ()) {
string path = move_iter.Current.GetAttribute ("path", "");
XPathExpression expr = api_nav.Compile (path);
string parent = move_iter.Current.Value;
XPathNodeIterator parent_iter = api_nav.Select (parent);
bool matched = false;
while (parent_iter.MoveNext ()) {
XmlNode parent_node = ((IHasXmlNode)parent_iter.Current).GetNode ();
XPathNodeIterator path_iter = parent_iter.Current.Clone ().Select (expr);
while (path_iter.MoveNext ()) {
XmlNode node = ((IHasXmlNode)path_iter.Current).GetNode ();
parent_node.AppendChild (node.Clone ());
node.ParentNode.RemoveChild (node);
}
matched = true;
}
if (!matched)
Console.WriteLine ("Warning: <move-node path=\"{0}\"/> matched no nodes", path);
}
XPathNodeIterator remove_attr_iter = meta_nav.Select ("/metadata/remove-attr");
while (remove_attr_iter.MoveNext ()) {
string path = remove_attr_iter.Current.GetAttribute ("path", "");
string name = remove_attr_iter.Current.GetAttribute ("name", "");
XPathNodeIterator api_iter = api_nav.Select (path);
bool matched = false;
while (api_iter.MoveNext ()) {
XmlElement node = ( (IHasXmlNode) api_iter.Current).GetNode () as XmlElement;
node.RemoveAttribute (name);
matched = true;
}
if (!matched)
Console.WriteLine ("Warning: <remove-attr path=\"{0}\"/> matched no nodes", path);
}
if (symbol_doc != null) {
XPathNavigator symbol_nav = symbol_doc.CreateNavigator ();
XPathNodeIterator iter = symbol_nav.Select ("/api/*");
while (iter.MoveNext ()) {
XmlNode sym_node = ((IHasXmlNode)iter.Current).GetNode ();
XPathNodeIterator parent_iter = api_nav.Select ("/api");
if (parent_iter.MoveNext ()) {
XmlNode parent_node = ((IHasXmlNode)parent_iter.Current).GetNode ();
parent_node.AppendChild (api_doc.ImportNode (sym_node, true));
}
}
}
api_doc.Save (api_filename);
return 0;
}
}
}

View file

@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<OutputPath>..\..\..\BuildOutput\Tools</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>
</Project>

48
Source/Tools/Tools.sln Executable file
View file

@ -0,0 +1,48 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GapiCodegen", "GapiCodegen\GapiCodegen.csproj", "{2CA6614A-F064-4136-ABDE-2DFB37E0F12B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GapiFixup", "GapiFixup\GapiFixup.csproj", "{DC7A0B5F-448F-4978-849B-3038D9B9C285}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2CA6614A-F064-4136-ABDE-2DFB37E0F12B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2CA6614A-F064-4136-ABDE-2DFB37E0F12B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2CA6614A-F064-4136-ABDE-2DFB37E0F12B}.Debug|x64.ActiveCfg = Debug|x64
{2CA6614A-F064-4136-ABDE-2DFB37E0F12B}.Debug|x64.Build.0 = Debug|x64
{2CA6614A-F064-4136-ABDE-2DFB37E0F12B}.Debug|x86.ActiveCfg = Debug|x86
{2CA6614A-F064-4136-ABDE-2DFB37E0F12B}.Debug|x86.Build.0 = Debug|x86
{2CA6614A-F064-4136-ABDE-2DFB37E0F12B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2CA6614A-F064-4136-ABDE-2DFB37E0F12B}.Release|Any CPU.Build.0 = Release|Any CPU
{2CA6614A-F064-4136-ABDE-2DFB37E0F12B}.Release|x64.ActiveCfg = Release|x64
{2CA6614A-F064-4136-ABDE-2DFB37E0F12B}.Release|x64.Build.0 = Release|x64
{2CA6614A-F064-4136-ABDE-2DFB37E0F12B}.Release|x86.ActiveCfg = Release|x86
{2CA6614A-F064-4136-ABDE-2DFB37E0F12B}.Release|x86.Build.0 = Release|x86
{DC7A0B5F-448F-4978-849B-3038D9B9C285}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DC7A0B5F-448F-4978-849B-3038D9B9C285}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DC7A0B5F-448F-4978-849B-3038D9B9C285}.Debug|x64.ActiveCfg = Debug|x64
{DC7A0B5F-448F-4978-849B-3038D9B9C285}.Debug|x64.Build.0 = Debug|x64
{DC7A0B5F-448F-4978-849B-3038D9B9C285}.Debug|x86.ActiveCfg = Debug|x86
{DC7A0B5F-448F-4978-849B-3038D9B9C285}.Debug|x86.Build.0 = Debug|x86
{DC7A0B5F-448F-4978-849B-3038D9B9C285}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DC7A0B5F-448F-4978-849B-3038D9B9C285}.Release|Any CPU.Build.0 = Release|Any CPU
{DC7A0B5F-448F-4978-849B-3038D9B9C285}.Release|x64.ActiveCfg = Release|x64
{DC7A0B5F-448F-4978-849B-3038D9B9C285}.Release|x64.Build.0 = Release|x64
{DC7A0B5F-448F-4978-849B-3038D9B9C285}.Release|x86.ActiveCfg = Release|x86
{DC7A0B5F-448F-4978-849B-3038D9B9C285}.Release|x86.Build.0 = Release|x86
EndGlobalSection
EndGlobal

View file

@ -1,5 +1,4 @@
#load CakeScripts\GAssembly.cs
#load CakeScripts\GapiFixup.cs
#load CakeScripts\Settings.cs
#addin "Cake.FileHelpers"
#addin "Cake.Incubator"
@ -10,32 +9,50 @@ Settings.Cake = Context;
Settings.BuildTarget = Argument("BuildTarget", "Default");
Settings.Assembly = Argument("Assembly", "");
var configuration = Argument("Configuration", "Release");
var msbuildsettings = new DotNetCoreMSBuildSettings();
var list = new List<GAssembly>();
var glist = new List<GAssembly>()
{
new GAssembly("GLibSharp"),
new GAssembly("GLibSharp")
{
NativeDeps = new[] {
"libglib-2.0.so.0", "libglib-2.0-0",
"libgobject-2.0.so.0", "libgobject-2.0-0",
"libgthread-2.0.so.0", "libgthread-2.0-0"
}
},
new GAssembly("GioSharp")
{
Deps = new[] { "GLibSharp" }
Deps = new[] { "GLibSharp" },
NativeDeps = new[] { "libgio-2.0.so.0", "libgio-2.0-0" }
},
new GAssembly("AtkSharp")
{
Deps = new[] { "GLibSharp" },
NativeDeps = new[] { "libatk-1.0.so.0", "libatk-1.0-0" },
ExtraArgs = "--abi-cs-usings=Atk,GLib"
},
new GAssembly("CairoSharp"),
new GAssembly("CairSharp")
{
NativeDeps = new[] { "libcairo.so.2", "libcairo-2" }
},
new GAssembly("PangoSharp")
{
Deps = new[] { "GLibSharp", "CairoSharp" }
Deps = new[] { "GLibSharp", "CairSharp" },
NativeDeps = new[] { "libpango-1.0.so.0", "libpango-1.0-0" }
},
new GAssembly("GdkSharp")
{
Deps = new[] { "GLibSharp", "GioSharp", "CairoSharp", "PangoSharp" }
Deps = new[] { "GLibSharp", "GioSharp", "CairSharp", "PangoSharp" },
NativeDeps = new[] {
"libgdk-3.so.0", "libgdk-3-0",
"libgdk_pixbuf-2.0.so.0", "libgdk_pixbuf-2.0-0"
}
},
new GAssembly("GtkSharp")
{
Deps = new[] { "GLibSharp", "GioSharp", "AtkSharp", "CairoSharp", "PangoSharp", "GdkSharp" },
Deps = new[] { "GLibSharp", "GioSharp", "AtkSharp", "CairSharp", "PangoSharp", "GdkSharp" },
NativeDeps = new[] { "libgtk-3.so.0", "libgtk-3-0" },
ExtraArgs = "--abi-cs-usings=Gtk,GLib"
}
};
@ -45,6 +62,10 @@ var glist = new List<GAssembly>()
Task("Init")
.Does(() =>
{
// Assign version
msbuildsettings = msbuildsettings.WithProperty("Version", "3.0.0.0");
msbuildsettings = msbuildsettings.WithProperty("Authors", "'GLibSharp Team'");
// Add stuff to list
foreach(var gassembly in glist)
if(string.IsNullOrEmpty(Settings.Assembly) || Settings.Assembly == gassembly.Name)
@ -55,9 +76,9 @@ Task("Prepare")
.IsDependentOn("Clean")
.Does(() =>
{
// Build Tools
DotNetCoreRestore("Source/Tools/GapiCodegen/GapiCodegen.csproj");
MSBuild("Source/Tools/GapiCodegen/GapiCodegen.csproj", new MSBuildSettings {
// Build tools
DotNetCoreRestore("Source/Tools/Tools.sln");
MSBuild("Source/Tools/Tools.sln", new MSBuildSettings {
Verbosity = Verbosity.Minimal,
Configuration = "Release",
});
@ -68,10 +89,15 @@ Task("Prepare")
DotNetCoreRestore("Source/Libs/GLibSharp.sln");
});
Task("Test")
Task("GenerateLinuxStubs")
.IsDependentOn("Init")
.Does(() =>
{
CreateDirectory("BuildOutput/LinuxStubs");
FileWriteText("BuildOutput/LinuxStubs/empty.c", "");
foreach(var gassembly in list)
gassembly.GenerateLinuxStubs();
DeleteDirectory("BuildOutput/LinuxStubs", new DeleteDirectorySettings { Recursive = true, Force = true });
});
Task("Clean")
@ -93,22 +119,18 @@ Task("Build")
.IsDependentOn("Prepare")
.Does(() =>
{
if (list.Count == glist.Count)
var settings = new DotNetCoreBuildSettings
{
MSBuild("Source/Libs/GLibSharp.sln", new MSBuildSettings {
Verbosity = Verbosity.Minimal,
Configuration = "Release",
});
}
MSBuildSettings = msbuildsettings
};
if (list.Count == glist.Count)
DotNetCoreBuild("Source/Libs/GLibSharp.sln", settings);
else
{
foreach(var gassembly in list)
{
MSBuild(gassembly.Csproj, new MSBuildSettings {
Verbosity = Verbosity.Minimal,
Configuration = "Release",
});
}
DotNetCoreBuild(gassembly.Csproj, settings);
}
});
@ -118,9 +140,11 @@ Task("PackageNuGet")
{
var settings = new DotNetCorePackSettings
{
MSBuildSettings = msbuildsettings,
Configuration = "Release",
OutputDirectory = "BuildOutput/NugetPackages",
NoBuild = true
NoBuild = true,
};
foreach(var gassembly in list)