Skip to content

Enlighten GenerateTrustInfo for multithreaded mode#13622

Open
jankratochvilcz wants to merge 2 commits intomainfrom
jankratochvilcz/multithreaded/generate-trust-info
Open

Enlighten GenerateTrustInfo for multithreaded mode#13622
jankratochvilcz wants to merge 2 commits intomainfrom
jankratochvilcz/multithreaded/generate-trust-info

Conversation

@jankratochvilcz
Copy link
Copy Markdown
Contributor

Adds [MSBuildMultiThreadableTask] to both conditional compilation variants of GenerateTrustInfo. The NETFRAMEWORK version implements IMultiThreadableTask and absolutizes BaseManifest/TrustInfoFile paths. The non-Framework stub is attribute-only.

Fixes #13619
Parent epic: #11834

Add [MSBuildMultiThreadableTask] to both conditional compilation variants.
NETFRAMEWORK version: implement IMultiThreadableTask and absolutize
BaseManifest and TrustInfoFile paths before file I/O.
Non-Framework version: attribute-only (stub that returns false).

Fixes #13619

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jankratochvilcz jankratochvilcz marked this pull request as ready for review April 27, 2026 19:18
Copilot AI review requested due to automatic review settings April 27, 2026 19:18
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

This PR updates the built-in GenerateTrustInfo task to participate in MSBuild’s multithreaded task execution model by marking both conditional-compilation implementations as multithread-safe and ensuring NETFRAMEWORK file I/O uses task-isolated absolute paths.

Changes:

  • Added [MSBuildMultiThreadableTask] to both NETFRAMEWORK and non-NETFRAMEWORK GenerateTrustInfo implementations.
  • Implemented IMultiThreadableTask for the NETFRAMEWORK implementation and routed BaseManifest/TrustInfoFile file access through TaskEnvironment.GetAbsolutePath(...).

Comment thread src/Tasks/GenerateTrustInfo.cs Outdated
Comment on lines 56 to 60
if (BaseManifest != null)
{
try
{
trustInfo.ReadManifest(BaseManifest.ItemSpec);
}
catch (Exception ex)
AbsolutePath baseManifestPath = TaskEnvironment.GetAbsolutePath(BaseManifest.ItemSpec);
if (FileSystems.Default.FileExists(baseManifestPath))
{
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

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

TaskEnvironment.GetAbsolutePath(BaseManifest.ItemSpec) will throw ArgumentException when BaseManifest.ItemSpec is null/empty, whereas the previous File.Exists check would simply treat it as non-existent. To avoid a behavior regression/crash, guard with !string.IsNullOrEmpty(BaseManifest.ItemSpec) (or handle the exception and log an error) before calling GetAbsolutePath.

Copilot uses AI. Check for mistakes.
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.

Good catch — that's Sin 6 (exception type change). Fixed in the latest commit by adding a string.IsNullOrEmpty guard before GetAbsolutePath, preserving the old silent no-op semantics for empty BaseManifest.ItemSpec.

Comment on lines 108 to +110
// Write trust-info back to a stand-alone trust file
trustInfo.Write(TrustInfoFile.ItemSpec);
AbsolutePath trustInfoFilePath = TaskEnvironment.GetAbsolutePath(TrustInfoFile.ItemSpec);
trustInfo.Write(trustInfoFilePath);
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

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

This change is specifically meant to make BaseManifest/TrustInfoFile path handling deterministic under multithreaded task isolation. There don’t appear to be unit tests covering GenerateTrustInfo with a non-default TaskEnvironment (e.g., project directory different from process CWD); adding one would help prevent regressions in relative-path resolution.

Copilot uses AI. Check for mistakes.
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.

The relative-path correctness here flows through the same TaskEnvironment.GetAbsolutePath path that's exercised by the engine-level multithreaded driver tests and by other migrations of similar shape (~10+ tasks now using the same pattern for relative path resolution). Adding a per-task multithreaded fixture would duplicate that infrastructure.

The behavior under the multithreaded driver is: GetAbsolutePath resolves against the task's project directory rather than process CWD — the resolution itself is the contract validated by TaskEnvironment unit tests. The functional path-resolution behavior here is identical to other migrated tasks (SignFile, ResolveKeySource in the same series), all relying on the same code path.

Happy to add coverage if reviewers feel strongly, but my read is the regression risk is low and the test cost is high.

…temSpec

The previous code path treated a null-or-empty BaseManifest.ItemSpec as
'no file' via File.Exists returning false. Calling TaskEnvironment.GetAbsolutePath
on an empty ItemSpec now throws ArgumentException (Sin 6), regressing that
behavior. Add an explicit string.IsNullOrEmpty guard to preserve the old
silent no-op semantics.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

Enlighten GenerateTrustInfo task for multithreaded mode

2 participants