Fix ProjectImports.zip regression from shared FileUtilities statics#18
Draft
JanProvaznik wants to merge 2 commits intomainfrom
Draft
Fix ProjectImports.zip regression from shared FileUtilities statics#18JanProvaznik wants to merge 2 commits intomainfrom
JanProvaznik wants to merge 2 commits intomainfrom
Conversation
After FileUtilities moved from Shared to Framework (dotnet#13364), all assemblies share the same cacheDirectory static. ClearCacheDirectory() in XMake.cs now deletes the same directory that ProjectImportsCollector uses for its temporary archive, causing 'Could not find a part of the path' errors during binlog finalization. Fix: Store the temporary ProjectImports archive in TempFileDirectory (the parent) rather than GetCacheDirectory() (the child that gets wiped). Also make DeleteArchive resilient to the archive already being cleaned up. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The previous test simulated ProjectImportsCollector + ClearCacheDirectory in isolation. Replace with a real build through MSBuild CLI (ExecMSBuild with -bl:), which exercises the full XMake.Execute → EndBuild → ClearCacheDirectory code path. Verify the binlog still contains embedded project imports by replaying with ArchiveFileEncountered. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
4e0c79d to
1d02dca
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix
Fixes the scenario test failures reported in dotnet/dotnet#5433 (codeflow for dotnet#13364).
Problem
PR dotnet#13364 moved
FileUtilitiesfromsrc/Shared/(compiled into each assembly with independent statics) tosrc/Framework/(single shared assembly). Before that move,ClearCacheDirectory()inXMake.csused MSBuild.exe's owncacheDirectorystatic — a separate, mostly-empty directory — so the call was effectively a no-op for the real build cache. After the move, all assemblies share onecacheDirectorystatic, soClearCacheDirectory()now deletes the directory thatProjectImportsCollectoruses for its temporaryProjectImports.ziparchive.This causes 9 scenario test failures across all platforms:
\
Unhandled exception: Could not find a part of the path
'.../MSBuildTemp.../MSBuild-1/run-dotnet-run.ProjectImports.zip'
\\
Root Cause
FileUtilitieswith independentcacheDirectory/TempFileDirectorystaticsFileUtilitiesin FrameworkXMake.ClearCacheDirectory()-> MSBuild.exe's cache dir (empty, no-op)XMake.ClearCacheDirectory()-> shared cache dir (contains ProjectImports.zip!)ProjectImportsCollector-> Build.dll's cache dir (untouched by XMake cleanup)ProjectImportsCollector-> same shared cache dir (destroyed by XMake cleanup)Fix
ProjectImportsCollector.cs: Store the temporary archive inTempFileDirectory(the parent) instead ofGetCacheDirectory()(the child subdirectory wiped byClearCacheDirectory()). The archive is still cleaned up byDeleteArchive()after embedding and by theProcessExithandler.ProjectImportsCollector.cs: MakeDeleteArchive()resilient to IO errors (best-effort cleanup).BinaryLogger_Tests.cs: Regression test that verifies the archive remains readable afterClearCacheDirectory().Open question
Before dotnet#13364, the
ClearCacheDirectory()calls inXMake.cswere no-ops for the real result cache. Now they actually delete result cache files. This is probably fine (runs afterEndBuild), but is a behavioral change worth validating -- especially for theDiscardBuildResults=falsecase where callers may expect disk-spilled results to survive.