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
16 changes: 16 additions & 0 deletions src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class Logger

public bool IsVerbose { get; }

public bool HasLoggedErrors { get; private set; }

public Logger(
ILogWriter writer,
ILProvider ilProvider,
Expand Down Expand Up @@ -93,14 +95,22 @@ public void LogWarning(string text, int code, MessageOrigin origin, string subca
{
MessageContainer? warning = MessageContainer.CreateWarningMessage(this, text, code, origin, subcategory);
if (warning.HasValue)
{
if (warning.Value.Category == MessageCategory.WarningAsError)
HasLoggedErrors = true;
_logWriter.WriteWarning(warning.Value);
}
}

public void LogWarning(MessageOrigin origin, DiagnosticId id, params string[] args)
{
MessageContainer? warning = MessageContainer.CreateWarningMessage(this, origin, id, args);
if (warning.HasValue)
{
if (warning.Value.Category == MessageCategory.WarningAsError)
HasLoggedErrors = true;
_logWriter.WriteWarning(warning.Value);
}
}

public void LogWarning(string text, int code, TypeSystemEntity origin, string subcategory = MessageSubCategory.None) =>
Expand Down Expand Up @@ -137,14 +147,20 @@ public void LogError(string text, int code, string subcategory = MessageSubCateg
{
MessageContainer? error = MessageContainer.CreateErrorMessage(text, code, subcategory, origin);
if (error.HasValue)
{
HasLoggedErrors = true;
_logWriter.WriteError(error.Value);
}
}

public void LogError(MessageOrigin? origin, DiagnosticId id, params string[] args)
{
MessageContainer? error = MessageContainer.CreateErrorMessage(origin, id, args);
if (error.HasValue)
{
HasLoggedErrors = true;
_logWriter.WriteError(error.Value);
}
}

public void LogError(string text, int code, TypeSystemEntity origin, string subcategory = MessageSubCategory.None) =>
Expand Down
24 changes: 23 additions & 1 deletion src/coreclr/tools/aot/ILCompiler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,9 @@ void RunScanner()
if (sourceLinkFileName != null)
dumpers.Add(new SourceLinkWriter(sourceLinkFileName));

CompilationResults compilationResults = compilation.Compile(outputFilePath, ObjectDumper.Compose(dumpers));
// Write to a temporary file and rename on success to avoid leaving partial files on failure
string tempOutputFilePath = outputFilePath + ".tmp";
CompilationResults compilationResults = compilation.Compile(tempOutputFilePath, ObjectDumper.Compose(dumpers));
string exportsFile = Get(_command.ExportsFile);
if (exportsFile != null)
{
Expand Down Expand Up @@ -713,6 +715,26 @@ static bool IsRelatedToInvalidInput(MethodDesc method)

preinitManager.LogStatistics(logger);

// If errors were produced (including warnings treated as errors), delete the temporary file
// and return error code to avoid misleading build systems into thinking the compilation succeeded.
if (logger.HasLoggedErrors)
{
try
{
File.Delete(tempOutputFilePath);
}
catch
{
// If we can't delete the temp file, there's not much we can do.
// The compilation will still fail due to logged errors.
}

return 1;
}

// Rename the temporary file to the final output file
File.Move(tempOutputFilePath, outputFilePath, overwrite: true);

return 0;
}

Expand Down
Loading