Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,10 @@ public static void EmitObject(string objectFilePath, IReadOnlyCollection<Depende
factory.Target.OperatingSystem == TargetOS.Windows ? new CoffObjectWriter(factory, options) :
new ElfObjectWriter(factory, options);

using Stream outputFileStream = new FileStream(objectFilePath, FileMode.Create);
objectWriter.EmitObject(outputFileStream, nodes, dumper, logger);
using (Stream outputFileStream = new FileStream(objectFilePath, FileMode.Create))
{
objectWriter.EmitObject(outputFileStream, nodes, dumper, logger);
}

stopwatch.Stop();
if (logger.IsVerbose)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public interface ILogWriter
void WriteMessage(MessageContainer message);
void WriteWarning(MessageContainer warning);
void WriteError(MessageContainer error);
bool HasLoggedErrors { get; }
}
}
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 => _logWriter.HasLoggedErrors;

public Logger(
ILogWriter writer,
ILProvider ilProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace ILCompiler
public class TextLogWriter : ILogWriter
{
private TextWriter _writer;
private bool _hasLoggedErrors;

public TextLogWriter(TextWriter writer)
{
Expand All @@ -22,12 +23,18 @@ public void WriteMessage(MessageContainer message)

public void WriteWarning(MessageContainer warning)
{
// Warnings treated as errors should also set the error flag
if (warning.Category == MessageCategory.WarningAsError)
_hasLoggedErrors = true;
_writer.WriteLine(warning.ToMSBuildString());
}

public void WriteError(MessageContainer error)
{
_hasLoggedErrors = true;
_writer.WriteLine(error.ToMSBuildString());
}

public bool HasLoggedErrors => _hasLoggedErrors;
}
}
19 changes: 19 additions & 0 deletions src/coreclr/tools/aot/ILCompiler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,25 @@ static bool IsRelatedToInvalidInput(MethodDesc method)

preinitManager.LogStatistics(logger);

// If errors were produced (including warnings treated as errors), delete the output file
// to avoid misleading build systems into thinking the compilation succeeded.
// This catches any errors logged after object writing (e.g., from typeSystemContext.LogWarnings).
if (logger.HasLoggedErrors)
{
try
{
if (File.Exists(outputFilePath))
File.Delete(outputFilePath);
}
catch
{
// If we can't delete the file, there's not much we can do.
// The compilation will still fail due to logged errors.
}

return 1;
}

return 0;
}

Expand Down
Loading