Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/Harp.Toolkit/Generate/GenerateATxmegaFirmwareCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@ public GenerateATxmegaFirmwareCommand()
var generator = new FirmwareGenerator(deviceMetadata, portPinMetadata);
var headers = generator.GenerateHeaders();
var implementation = generateImplementation ? generator.GenerateImplementation() : default;
if (GeneratorHelper.AssertNoGeneratorErrors(generator.Errors))
{
GenerateCommand.WriteFileContents(outputPath.FullName, headers);
if (generateImplementation)
GenerateCommand.WriteFileContents(outputPath.FullName, implementation);
}
GeneratorHelper.AssertNoGeneratorErrors(generator.Errors);
GenerateCommand.WriteFileContents(outputPath.FullName, headers);
if (generateImplementation)
GenerateCommand.WriteFileContents(outputPath.FullName, implementation);
});
}
}
4 changes: 2 additions & 2 deletions src/Harp.Toolkit/Generate/GenerateCSharpInterfaceCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public GenerateCSharpInterfaceCommand()
var deviceMetadata = metadataPathArgument.Load(parseResult);
var generator = new InterfaceGenerator(deviceMetadata, namespaceOption.GetValue(parseResult, deviceMetadata));
var implementation = generator.GenerateImplementation();
if (GeneratorHelper.AssertNoGeneratorErrors(generator.Errors))
GenerateCommand.WriteFileContents(outputPath.FullName, implementation);
GeneratorHelper.AssertNoGeneratorErrors(generator.Errors);
GenerateCommand.WriteFileContents(outputPath.FullName, implementation);
});
}
}
4 changes: 2 additions & 2 deletions src/Harp.Toolkit/Generate/GeneratePythonInterfaceCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public GeneratePythonInterfaceCommand()
var deviceMetadata = metadataPathArgument.Load(parseResult);
var generator = new PythonGenerator(deviceMetadata, package);
var implementation = generator.GenerateImplementation();
if (GeneratorHelper.AssertNoGeneratorErrors(generator.Errors))
GenerateCommand.WriteFileContents(outputPath.FullName, implementation);
GeneratorHelper.AssertNoGeneratorErrors(generator.Errors);
GenerateCommand.WriteFileContents(outputPath.FullName, implementation);
});
}
}
16 changes: 11 additions & 5 deletions src/Harp.Toolkit/Generate/GeneratorHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Harp.Toolkit.Generate;

public static class GeneratorHelper
{
public static bool AssertNoGeneratorErrors(CompilerErrorCollection errors)
public static void AssertNoGeneratorErrors(CompilerErrorCollection errors)
{
if (errors.Count > 0)
{
Expand All @@ -16,10 +16,16 @@ public static bool AssertNoGeneratorErrors(CompilerErrorCollection errors)
var warningString = error.IsWarning ? "warning" : "error";
errorLog.AppendLine($"{error.FileName}: {warningString}: {error.ErrorText}");
}
Console.Error.WriteLine(errorLog.ToString());
return !errors.HasErrors;
}

return true;
var message = errorLog.ToString();
if (errors.HasErrors)
{
var exception = new InvalidOperationException(message);
exception.SetDescription(message);
throw exception;
}

Console.Error.WriteLine(message);
}
}
}
3 changes: 1 addition & 2 deletions src/Harp.Toolkit/Verify/GeneratedInterfaceCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ public static IReadOnlyDictionary<int, Type> Compile(DeviceMetadata deviceOnlyMe
{
var generator = new InterfaceGenerator(deviceOnlyMetadata, @namespace);
var implementation = generator.GenerateImplementation();
if (!GeneratorHelper.AssertNoGeneratorErrors(generator.Errors))
throw new InvalidOperationException("Interface generation from device.yml completed with errors.");
GeneratorHelper.AssertNoGeneratorErrors(generator.Errors);

var syntaxTree = CSharpSyntaxTree.ParseText(implementation.Device);
var compilation = CSharpCompilation.Create(
Expand Down
3 changes: 1 addition & 2 deletions src/Harp.Toolkit/Verify/VerifyCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,9 @@ static async Task<int> RunVerification(string portName, FileInfo? reportFile, bo
string? deviceRawYaml = null;
if (metadataPath is not null)
{
AnsiConsole.Markup($"Loading device metadata from [bold]{metadataPath.FullName}[/]...");
deviceRawYaml = await File.ReadAllTextAsync(metadataPath.FullName, cancellationToken);
deviceMetadata = MetadataPathOption.Parse(metadataPath, deviceRawYaml);
AnsiConsole.MarkupLine($" [green]Done![/] ({deviceMetadata.Registers.Count} registers)");
AnsiConsole.MarkupLine($"Loaded device metadata from [bold]{metadataPath.FullName}[/] ({deviceMetadata.Registers.Count} registers).");
}

using var connection = await VerifyConnection.OpenAsync(portName, cancellationToken);
Expand Down
Loading