Skip to content

Commit 8fde874

Browse files
authored
[release/6.0-rc1] MonoAOTCompiler: Check for proxy file's target only when the cache is being used. (#57867)
Backport of #57865 Fixes #57800 .
1 parent faf0c8f commit 8fde874

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

src/tasks/AotCompilerTask/MonoAOTCompiler.cs

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ public override bool Execute()
352352
if (!result.IsCompleted)
353353
{
354354
if (!Log.HasLoggedErrors)
355-
Log.LogError("Unknown failed occured while compiling");
355+
Log.LogError("Unknown failure occured while compiling");
356356

357357
return false;
358358
}
@@ -646,17 +646,14 @@ private bool PrecompileLibrary(ITaskItem assemblyItem, string? monoPaths)
646646
Log.LogError($"Precompiling failed for {assembly}: {ex.Message}");
647647
return false;
648648
}
649-
649+
finally
650+
{
651+
File.Delete(responseFilePath);
652+
}
650653

651654
bool copied = false;
652655
foreach (var proxyFile in proxyFiles)
653656
{
654-
if (!File.Exists(proxyFile.TempFile))
655-
{
656-
Log.LogError($"Precompiling failed for {assembly}. Could not find output file {proxyFile.TempFile}");
657-
return false;
658-
}
659-
660657
copied |= proxyFile.CopyOutputFileIfChanged();
661658
_fileWrites.Add(proxyFile.TargetFile);
662659
}
@@ -668,7 +665,6 @@ private bool PrecompileLibrary(ITaskItem assemblyItem, string? monoPaths)
668665
Log.LogMessage(MessageImportance.High, $"[{count}/{_totalNumAssemblies}] {Path.GetFileName(assembly)} -> {copiedFiles}");
669666
}
670667

671-
File.Delete(responseFilePath);
672668
compiledAssemblies.GetOrAdd(aotAssembly.ItemSpec, aotAssembly);
673669
return true;
674670
}
@@ -677,36 +673,44 @@ private bool PrecompileLibrarySerial(ITaskItem assemblyItem, string? monoPaths)
677673
{
678674
try
679675
{
680-
if (!PrecompileLibrary(assemblyItem, monoPaths))
681-
return !Log.HasLoggedErrors;
682-
return true;
676+
if (PrecompileLibrary(assemblyItem, monoPaths))
677+
return true;
678+
}
679+
catch (LogAsErrorException laee)
680+
{
681+
Log.LogError($"Precompile failed for {assemblyItem}: {laee.Message}");
683682
}
684683
catch (Exception ex)
685684
{
686685
if (Log.HasLoggedErrors)
687686
Log.LogMessage(MessageImportance.Low, $"Precompile failed for {assemblyItem}: {ex}");
688687
else
689688
Log.LogError($"Precompile failed for {assemblyItem}: {ex}");
690-
691-
return false;
692689
}
690+
691+
return false;
693692
}
694693

695694
private void PrecompileLibraryParallel(ITaskItem assemblyItem, string? monoPaths, ParallelLoopState state)
696695
{
697696
try
698697
{
699-
if (!PrecompileLibrary(assemblyItem, monoPaths))
700-
state.Break();
698+
if (PrecompileLibrary(assemblyItem, monoPaths))
699+
return;
700+
}
701+
catch (LogAsErrorException laee)
702+
{
703+
Log.LogError($"Precompile failed for {assemblyItem}: {laee.Message}");
701704
}
702705
catch (Exception ex)
703706
{
704707
if (Log.HasLoggedErrors)
705708
Log.LogMessage(MessageImportance.Low, $"Precompile failed for {assemblyItem}: {ex}");
706709
else
707710
Log.LogError($"Precompile failed for {assemblyItem}: {ex}");
708-
state.Break();
709711
}
712+
713+
state.Break();
710714
}
711715

712716
private bool GenerateAotModulesTable(ITaskItem[] assemblies, string[]? profilers, string outputFile)
@@ -927,6 +931,9 @@ public bool CopyOutputFileIfChanged()
927931
if (!_cache.Enabled)
928932
return true;
929933

934+
if (!File.Exists(TempFile))
935+
throw new LogAsErrorException($"Could not find output file {TempFile}");
936+
930937
if (!_cache.ShouldCopy(this, out string? cause))
931938
{
932939
_cache.Log.LogMessage(MessageImportance.Low, $"Skipping copying over {TargetFile} as the contents are unchanged");

0 commit comments

Comments
 (0)