Skip to content

Commit

Permalink
Bugfix and some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
MNGoldenEagle committed Apr 24, 2019
1 parent 39958c6 commit 4403f64
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
39 changes: 37 additions & 2 deletions Commands/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public Build()

HasRequiredOption<string>("o|output=", "Specifies the name of the generated actor file", value => OutputFile = value);

HasOption<string>("t|target:", "Indicates which version of the ROM to link against.", value => {
HasOption<string>("t|target=", "Indicates which version of the ROM to link against.", value => {
var target = Target.PAL_MQ_DEBUG;
if (!Target.TryParse(value, out target))
{
Expand Down Expand Up @@ -67,6 +67,7 @@ public override int Run(string[] remainingArguments)
if (resultCode != 0)
{
Console.Error.WriteLine("Error occurred on Compile step. Exiting...");
CleanupArtifacts();
return resultCode;
}

Expand All @@ -76,9 +77,11 @@ public override int Run(string[] remainingArguments)
OutputFile = Path.GetTempFileName()
};
resultCode = assembleStep.Run(null);
CleanupCompilerArtifacts();
if (resultCode != 0)
{
Console.Error.WriteLine("Error occurred on Assemble step. Exiting...");
CleanupArtifacts();
return resultCode;
}

Expand All @@ -89,26 +92,58 @@ public override int Run(string[] remainingArguments)
LinkTarget = Target
};
resultCode = linkStep.Run(null);
CleanupAssemblerArtifacts();
if (resultCode != 0)
{
Console.Error.WriteLine("Error occurred on Link step. Exiting...");
CleanupArtifacts();
return resultCode;
}

Overlay overlayStep = new Overlay
{
InputFiles = new string[] { Pipeline.LinkedArtifact },
OverlayPath = OutputFile,
ShowInitAddress = true
ShowInitAddress = true,
InitializationVariable = "INIT"
};
resultCode = overlayStep.Run(null);
CleanupLinkerArtifacts();
if (resultCode != 0)
{
Console.Error.WriteLine("Error occurred on Overlay step. Exiting...");
CleanupArtifacts();
return resultCode;
}

return 0;
}

private void CleanupArtifacts()
{
CleanupCompilerArtifacts();
CleanupAssemblerArtifacts();
CleanupLinkerArtifacts();
}

private void CleanupCompilerArtifacts()
{
foreach (string path in Pipeline.CompiledArtifacts)
{
File.Delete(path);
}
}

private void CleanupAssemblerArtifacts()
{
if (Pipeline.AssembledArtifact == null) { return; }
File.Delete(Pipeline.AssembledArtifact);
}

private void CleanupLinkerArtifacts()
{
if (Pipeline.LinkedArtifact == null) { return; }
File.Delete(Pipeline.LinkedArtifact);
}
}
}
1 change: 1 addition & 0 deletions CoreToolchain/CoreToolchain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

<ItemGroup>
<PackageReference Include="ELFSharp" Version="2.1.1" />
<PackageReference Include="Microsoft.Packaging.Tools.Trimming" Version="1.1.0-preview1-26619-01" />
<PackageReference Include="Mono.Options" Version="5.3.0.1" />
</ItemGroup>

Expand Down

0 comments on commit 4403f64

Please sign in to comment.