63 lines
1.9 KiB
C#
Raw Normal View History

2019-06-12 21:56:55 +02:00
using Capnp;
2019-09-10 22:48:25 +02:00
using CapnpC.CSharp.Generator;
2019-06-12 21:56:55 +02:00
using System;
using System.IO;
2019-08-29 01:26:30 -04:00
using System.Runtime.CompilerServices;
2019-09-10 22:48:25 +02:00
using System.Security;
2019-06-12 21:56:55 +02:00
namespace CapnpC
{
internal class Program
2019-06-12 21:56:55 +02:00
{
static void Main(string[] args)
{
Stream input;
if (args.Length > 0)
{
input = new FileStream(args[0], FileMode.Open, FileAccess.Read);
}
else
2019-07-11 21:44:42 +02:00
{
Console.WriteLine("Cap'n Proto C# code generator backend");
Console.WriteLine("expecting binary-encoded code generation request from standard input");
2019-06-12 21:56:55 +02:00
input = Console.OpenStandardInput();
}
2019-09-10 22:48:25 +02:00
var result = CapnpCompilation.GenerateFromStream(input);
if (result.IsSuccess)
2019-07-11 21:44:42 +02:00
{
2019-09-10 22:48:25 +02:00
foreach (var generatedFile in result.GeneratedFiles)
{
if (generatedFile.IsSuccess)
{
string outputFile = generatedFile.CapnpFilePath + ".cs";
try
{
File.WriteAllText(outputFile, generatedFile.GeneratedContent);
}
catch (Exception exception)
{
Console.Error.WriteLine(exception.Message);
Environment.ExitCode = -1;
}
}
else
{
Console.Error.WriteLine($"Error generating {generatedFile.CapnpFilePath}: {generatedFile.Exception.Message}");
Environment.ExitCode = -1;
}
}
2019-07-11 21:44:42 +02:00
}
2019-09-10 22:48:25 +02:00
else
2019-06-12 21:56:55 +02:00
{
2019-09-10 22:48:25 +02:00
Console.Error.WriteLine(result.Exception.Message);
2019-07-11 21:44:42 +02:00
Environment.ExitCode = -1;
2019-06-12 21:56:55 +02:00
}
}
}
}