Skip to content

Migrate GenerateDepsFile to IMultiThreadableTask#53950

Open
SimaTian wants to merge 1 commit intodotnet:mainfrom
SimaTian:migrate-generate-deps-file
Open

Migrate GenerateDepsFile to IMultiThreadableTask#53950
SimaTian wants to merge 1 commit intodotnet:mainfrom
SimaTian:migrate-generate-deps-file

Conversation

@SimaTian
Copy link
Copy Markdown
Member

Migrates \GenerateDepsFile\ to support \IMultiThreadableTask.

Changes

  • Adds [MSBuildMultiThreadableTask]\ attribute and implements \IMultiThreadableTask.
  • Absolutizes \ProjectPath\ and \DepsFilePath\ in \ExecuteCore; scopes \AssetsFilePath\ / \RuntimeGraphPath\ absolutization inside \WriteDepsFile\ (point-of-use).
  • \DepsFilePath\ is backed by \AbsolutePath\ throughout: \File.Create\ uses .Value; \FilesWritten\ output uses .OriginalValue\ to preserve user-supplied relativity.
  • Adds 6 behavioral tests: output-relativity preservation, ProjectPath absolutization, decoy-CWD resolution, cross-thread env-var isolation, multi-process parity, concurrent execution.

Addresses AR-May findings from #52936

  • ✅ ProjectPath absolutized at task level before passing to \DependencyContextBuilder.
  • ✅ Absolutization moved into \WriteDepsFile\ helper (point-of-use).
  • ✅ \FilesWritten\ uses \AbsolutePath.OriginalValue\ (output fidelity).

Supersedes

Part of the split of stuck merge-group PR #52936. This is the 2-of-5 split for \GenerateDepsFile.

Implements IMultiThreadableTask to enable safe multi-threaded execution:
- Added [MSBuildMultiThreadableTask] attribute
- Added TaskEnvironment property with NETFRAMEWORK polyfill
- Absolutize ProjectPath at task level before passing to DependencyContextBuilder
- Moved AssetsFilePath and RuntimeGraphPath absolutization into WriteDepsFile
- Use AbsolutePath.OriginalValue for FilesWritten output to preserve relativity

Addresses all 3 AR-May findings from PR dotnet#52936:
1. ProjectPath absolutization: Now absolutized at ExecuteCore level via TaskEnvironment.GetAbsolutePath,
   passes .Value (absolute) to DependencyContextBuilder
2. Cleanliness: AssetsFilePath and RuntimeGraphPath absolutization moved into WriteDepsFile where consumed
3. Output fidelity: FilesWritten uses AbsolutePath.OriginalValue to preserve user-supplied relative paths

Added comprehensive behavioral tests in GivenAGenerateDepsFileMultiThreading.cs:
- OutputRelativityIsPreserved: Verifies FilesWritten preserves relative paths
- ProjectPathIsAbsolutized: Ensures ProjectPath is absolutized before use
- DecoyCwdDoesNotAffectPathResolution: Validates CWD independence
- CrossThreadEnvVarIsolation: Tests environment variable isolation
- MultiProcessParity: Confirms identical output with/without TaskEnvironment
- ConcurrentExecutionProducesCorrectResults: Parallel execution test

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Migrates GenerateDepsFile to support MSBuild multithreaded execution by implementing IMultiThreadableTask, using TaskEnvironment for path resolution, and adding unit tests intended to validate correctness under concurrent execution / non-default working directories.

Changes:

  • Add [MSBuildMultiThreadableTask] and implement IMultiThreadableTask on GenerateDepsFile, including TaskEnvironment handling.
  • Absolutize ProjectPath/DepsFilePath before writing and move AssetsFilePath/RuntimeGraphPath absolutization to point-of-use.
  • Add a new multithreading-focused unit test suite for GenerateDepsFile.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/Tasks/Microsoft.NET.Build.Tasks/GenerateDepsFile.cs Adds IMultiThreadableTask support and adjusts path handling for multithread-safe execution and output fidelity.
src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/GivenAGenerateDepsFileMultiThreading.cs Adds behavioral/concurrency tests for GenerateDepsFile in multithreaded / CWD-sensitive scenarios.

Comment on lines +324 to +326
AbsolutePath absoluteProjectPath = TaskEnvironment?.GetAbsolutePath(ProjectPath) ?? new AbsolutePath(Path.GetFullPath(ProjectPath));
AbsolutePath absoluteDepsFilePath = TaskEnvironment?.GetAbsolutePath(DepsFilePath) ?? new AbsolutePath(Path.GetFullPath(DepsFilePath));
WriteDepsFile(absoluteProjectPath, absoluteDepsFilePath, TaskEnvironment);
Comment on lines +10 to +14
using Microsoft.Build.Utilities;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Xunit;
using Task = System.Threading.Tasks.Task;
using Task = System.Threading.Tasks.Task;

namespace Microsoft.NET.Build.Tasks.UnitTests
{
Comment on lines +66 to +74
string projectPath = depsJson.SelectToken("targets..TestApp/1.0.0")?.Parent?.Parent?.Parent?.Parent?
.SelectToken("libraries['TestApp/1.0.0'].path")?.ToString();

// The path stored should be absolute because we absolutized ProjectPath
if (!string.IsNullOrEmpty(projectPath))
{
Path.IsPathRooted(projectPath).Should().BeTrue(
"ProjectPath should be absolutized internally even when passed as relative");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants