Skip to content

Migrate SGen task to Task environment API#13457

Draft
OvesN wants to merge 30 commits intodotnet:mainfrom
OvesN:dev/veronikao/migrate-SGen-Task-to-TaskEnvironment-API
Draft

Migrate SGen task to Task environment API#13457
OvesN wants to merge 30 commits intodotnet:mainfrom
OvesN:dev/veronikao/migrate-SGen-Task-to-TaskEnvironment-API

Conversation

@OvesN
Copy link
Copy Markdown
Contributor

@OvesN OvesN commented Mar 27, 2026

Fixes #13455

Context

The SGen task was made thread-safe.

Changes Made

SGen.cs

  • Routed file existence checks and path resolution through TaskEnvironment.GetAbsolutePath().

Testing

Unit tests in SGen_Tests.cs

Notes

OvesN and others added 16 commits March 20, 2026 13:56
The test relied on FileAttributes.ReadOnly to force File.Delete to throw,
but this is not cross-platform - Unix read-only attributes don't prevent deletion.
ApplyEnvironmentOverrides  moved inside SetUpProcessStartInfo.
Added override for DeleteTempFile using AbsolutePath.
Made Driver private again, expose only enum value to decided if driver is multitheaded.
Made GetProcessStartInfoMultithreadable private.
add overload for DeleteTempFile with AbsolutePath argument
…nto dev/veronikao/migrate-SGen-Task-to-TaskEnvironment-API
@OvesN OvesN self-assigned this Mar 30, 2026
@OvesN OvesN marked this pull request as draft March 30, 2026 13:09
@OvesN OvesN changed the base branch from dev/veronikao/migrate-Al-task-to-TaskEnvironment-API to main April 8, 2026 06:38
@OvesN OvesN marked this pull request as ready for review April 8, 2026 06:54
Copilot AI review requested due to automatic review settings April 8, 2026 06:54
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 the SGen task to the TaskEnvironment API to support thread-safe/multithreaded execution by routing path resolution, file existence checks, and environment variable access through the task environment.

Changes:

  • Marked SGen as multithreadable and updated it to use TaskEnvironment.GetAbsolutePath() / GetEnvironmentVariable().
  • Switched several internal path computations to use AbsolutePath.
  • Added unit tests covering TaskEnvironment integration for tool path resolution, working directory propagation, and BuildAssemblyPath absolutization.

Reviewed changes

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

File Description
src/Tasks/SGen.cs Uses TaskEnvironment for env/path operations and introduces AbsolutePath usage for key paths.
src/Tasks.UnitTests/SGen_Tests.cs Adds tests validating the multithreaded TaskEnvironment behavior for SGen.

@OvesN OvesN marked this pull request as draft April 8, 2026 07:55
@OvesN OvesN marked this pull request as ready for review April 8, 2026 11:24
@OvesN OvesN requested review from JanProvaznik and SimaTian April 8, 2026 11:27
pathToTool = SdkToolsPathUtility.GeneratePathToTool(
f => !string.IsNullOrEmpty(f)
? SdkToolsPathUtility.FileInfoExists(TaskEnvironment.GetAbsolutePath(f))
: SdkToolsPathUtility.FileInfoExists(f),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

in the else branch, the f is null or empty, right? why do we call the FileInfoExists in such case? won't it be always false?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is to fully preserve the previous behavior. Earlier, the code passed the path directly to
SdkToolsPathUtility.FileInfoExists, and if it was null, it would throw an ArgumentNullException.

@OvesN OvesN marked this pull request as draft April 9, 2026 11:31
@OvesN
Copy link
Copy Markdown
Contributor Author

OvesN commented Apr 9, 2026

Blocked for now, we should fix this first
#13514

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.

Migrate SGen Task to TaskEnvironment API

4 participants