Skip to content

Commit

Permalink
Better error handling for compiling packages; set file name for prepr…
Browse files Browse the repository at this point in the history
…ocessor
  • Loading branch information
Nenkai committed Apr 6, 2023
1 parent 89f8f20 commit bb6d626
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 50 deletions.
5 changes: 3 additions & 2 deletions GTAdhocToolchain.Preprocessor/AdhocScriptPreprocessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public void SetBaseDirectory(string baseDirectory)
public void SetCurrentFileName(string fileName)
{
_currentFileName = fileName;
_scanner?.SetFileName(fileName);
}

public void SetCurrentFileTimestamp(DateTime timestamp)
Expand Down Expand Up @@ -363,7 +364,7 @@ private void DoInclude()
var oldFileName = _currentFileName;
var oldTimestamp = _fileTimeStamp;

_currentFileName = file;
SetCurrentFileName(file);
_fileTimeStamp = new FileInfo(pathToInclude).LastWriteTime;

_writer.WriteLine($"# 1 \"{file}\"");
Expand All @@ -377,7 +378,7 @@ private void DoInclude()
// Restore state
_lookahead = oldToken;
_scanner = oldScanner;
_currentFileName = oldFileName;
SetCurrentFileName(oldFileName);
_fileTimeStamp = oldTimestamp;

_writer.WriteLine($"# {_lookahead.Location.Start.Line} \"{_currentFileName}\"");
Expand Down
95 changes: 48 additions & 47 deletions GTAdhocToolchain.Project/AdhocProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,14 @@ private void BuildPackageFile()
Directory.CreateDirectory(pkgContentPath);

int logPadLen = FilesToCompile.Length.ToString().Length;
for (int i = 0; i < FilesToCompile.Length; i++)
try
{
AdhocProjectFile srcFile = FilesToCompile[i];
Logger.Info($"[{(i + 1).ToString().PadLeft(logPadLen)}/{FilesToCompile.Length}] Compiling: {srcFile.Name}");

try
for (int i = 0; i < FilesToCompile.Length; i++)
{
AdhocProjectFile srcFile = FilesToCompile[i];
Logger.Info($"[{(i + 1).ToString().PadLeft(logPadLen)}/{FilesToCompile.Length}] Compiling: {srcFile.Name}");


string source = File.ReadAllText(srcFile.FullPath);
var time = new FileInfo(srcFile.FullPath).LastWriteTime;

Expand All @@ -267,58 +268,58 @@ private void BuildPackageFile()
AdhocCodeGen codeGen = new AdhocCodeGen(compiler, compiler.SymbolMap);
codeGen.Generate();
codeGen.SaveTo(Path.Combine(pkgContentPath, Path.ChangeExtension(srcFile.Name, ".adc")));
}
catch (PreprocessorException preprocessException)
{
Logger.Error($"{preprocessException.FileName}:{preprocessException.Token.Location.Start.Line}: preprocess error: {preprocessException.Message}");
}
catch (ParserException parseException)
{
Logger.Error($"Syntax error: {parseException.Description} at {parseException.SourceText}:{parseException.LineNumber}");
}
catch (AdhocCompilationException compileException)
{
Logger.Error($"Compilation error: {compileException.Message}");
}
catch (Exception e)
{
Logger.Fatal(e, "Internal error in compilation");
}

if (!srcFile.IsMain)
{
string componentName = Path.ChangeExtension(srcFile.FullPath, ".mwidget");
if (File.Exists(componentName))
if (!srcFile.IsMain)
{
Logger.Info($"Adding linked component '{Path.GetFileName(componentName)}'");
string componentName = Path.ChangeExtension(srcFile.FullPath, ".mwidget");
if (File.Exists(componentName))
{
Logger.Info($"Adding linked component '{Path.GetFileName(componentName)}'");

string outTmpComponentFile = Path.Combine(pkgContentPath, Path.GetFileName(componentName));
File.Copy(componentName, outTmpComponentFile);
string outTmpComponentFile = Path.Combine(pkgContentPath, Path.GetFileName(componentName));
File.Copy(componentName, outTmpComponentFile);

if (SerializeComponents)
{
Logger.Info($"Serializing '{Path.GetFileName(componentName)}' to binary");
MTextIO io = new MTextIO(componentName);
var root = io.Read();
if (SerializeComponents)
{
Logger.Info($"Serializing '{Path.GetFileName(componentName)}' to binary");
MTextIO io = new MTextIO(componentName);
var root = io.Read();

MBinaryWriter writer = new MBinaryWriter(outTmpComponentFile);
writer.Version = SerializeComponentsVersion;
writer.WriteNode(root);
MBinaryWriter writer = new MBinaryWriter(outTmpComponentFile);
writer.Version = SerializeComponentsVersion;
writer.WriteNode(root);
}
}
else
{
Logger.Warn($"File '{srcFile.Name}' does not have a linked UI definition file '{Path.GetFileName(componentName)}' (this warning can be ignored if this is not a root)");
}
}
else
{
Logger.Warn($"File '{srcFile.Name}' does not have a linked UI definition file '{Path.GetFileName(componentName)}' (this warning can be ignored if this is not a root)");
}
}
}

// Create package mproject with external references
CreatePackageMProject(pkgContentPath);
// Create package mproject with external references
CreatePackageMProject(pkgContentPath);

Logger.Info($"Packaging...");
AdhocPackage.PackFromFolder(pkgPath, Path.Combine(ProjectDir, pkgName));
Logger.Info($"Packaging successful -> {pkgName}");
Logger.Info($"Packaging...");
AdhocPackage.PackFromFolder(pkgPath, Path.Combine(ProjectDir, pkgName));
Logger.Info($"Packaging successful -> {pkgName}");
}
catch (PreprocessorException preprocessException)
{
Logger.Error($"{preprocessException.FileName}:{preprocessException.Token.Location.Start.Line}: preprocess error: {preprocessException.Message}");
}
catch (ParserException parseException)
{
Logger.Error($"Syntax error: {parseException.Description} at {parseException.SourceText}:{parseException.LineNumber}");
}
catch (AdhocCompilationException compileException)
{
Logger.Error($"Compilation error: {compileException.Message}");
}
catch (Exception e)
{
Logger.Fatal(e, "Internal error in compilation");
}
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion esprima-dotnet

0 comments on commit bb6d626

Please sign in to comment.