Add code generation on compiling to premake scripts using custom build commands

This commit is contained in:
Jan
2019-10-25 02:13:37 +02:00
parent d93b4f5fac
commit 034de70bbc
27 changed files with 345 additions and 325 deletions

View File

@ -31,7 +31,7 @@ namespace ZoneCodeGenerator.Generating
"ZoneWrite", new GeneratorPreset("$asset/$asset_write_db", "ZoneWrite.stg")
},
{
"AssetStructTests", new GeneratorPreset("$asset_struct_test", "AssetStructTests.stg")
"AssetStructTests", new GeneratorPreset("$asset/$asset_struct_test", "AssetStructTests.stg")
}
};
@ -40,7 +40,10 @@ namespace ZoneCodeGenerator.Generating
public static bool GenerateCodeForPreset(string presetName, StructureInformation asset, CUISession session)
{
if (!presets.ContainsKey(presetName))
{
Console.WriteLine($"Unknown preset '{presetName}'");
return false;
}
var preset = presets[presetName];
@ -67,12 +70,19 @@ namespace ZoneCodeGenerator.Generating
var renderingContext = RenderingContext.BuildContext(session, asset);
if (renderingContext == null)
{
Console.WriteLine("Building rendering context failed");
return false;
}
if (!codeTemplate.HasHeaderTemplate && !codeTemplate.HasSourceTemplate)
{
Console.WriteLine($"Preset '{presetName}' does not have a header or a source! This is weird.");
return false;
}
var generatedCode = false;
if (codeTemplate.HasHeaderTemplate)
{
generatedCode = true;
using (var fileStream = new FileStream(fullPath + ".h", FileMode.Create))
{
codeTemplate.RenderHeaderFile(fileStream, renderingContext);
@ -82,7 +92,6 @@ namespace ZoneCodeGenerator.Generating
if (codeTemplate.HasSourceTemplate)
{
generatedCode = true;
using (var fileStream = new FileStream(fullPath + ".cpp", FileMode.Create))
{
codeTemplate.RenderSourceFile(fileStream, renderingContext);
@ -90,10 +99,13 @@ namespace ZoneCodeGenerator.Generating
}
}
return generatedCode;
return true;
}
catch (Exception)
catch (Exception e)
{
Console.WriteLine("An exception occured while trying to generate code");
Console.WriteLine(e.GetType().Name);
Console.WriteLine(e.Message);
return false;
}
}

View File

@ -82,8 +82,8 @@ namespace ZoneCodeGenerator.Generating
{
if (resourceStream == null)
{
if (Verbose)
Console.WriteLine($"Resource '{fileName}' doesn't exist");
Console.WriteLine($"Resource '{fileName}' doesn't exist");
Console.WriteLine("The following files do exist: " + string.Join(", ", Assembly.GetExecutingAssembly().GetManifestResourceNames()));
return;
}

View File

@ -56,8 +56,10 @@ namespace ZoneCodeGenerator.Parsing.C_Header
return dataRepository;
}
}
catch (IOException)
catch (IOException e)
{
Console.WriteLine("An exception occured while trying to read header file");
Console.WriteLine(e.Message);
return null;
}
}