-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add new multithreaded APIs #12625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add new multithreaded APIs #12625
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0857b2a
Add new multithreaded APIs
AR-May c1a9532
Update src/Framework/MSBuildMultiThreadableTaskAttribute.cs
AR-May 3fcbf68
address review comments
AR-May 477edce
Merge branch 'add-mt-apis' of https://github.com/AR-May/msbuild into …
AR-May 38e8138
add more niceities to xmldocs
baronfel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace Microsoft.Build.Framework | ||
| { | ||
| /// <summary> | ||
| /// Interface for tasks that can execute in a thread-safe manner within MSBuild's multithreaded execution model. | ||
| /// Tasks that implement this interface declare their capability to run in multiple threads within one process. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// The task <strong>must</strong>: | ||
| /// <list type="bullet"> | ||
| /// <item>Use the provided <see cref="TaskEnvironment"/> for all modifications to process state such as environment variables, | ||
| /// working directory, or process spawning instead of directly modifying global process state</item> | ||
| /// <item>Not depend on global process state for correct operation, including avoiding relative path | ||
| /// resolution that relies on the current working directory</item> | ||
| /// <item>Use <see cref="TaskEnvironment.GetAbsolutePath(string)"/> instead of <see cref="System.IO.Path.GetFullPath(string)"/> for path resolution</item> | ||
| /// <item>Handle any internal synchronization if the task spawns multiple threads internally</item> | ||
| /// </list> | ||
| /// Tasks implementing this interface can be safely executed in parallel with other tasks or | ||
| /// instances of the same task within a single MSBuild process, enabling better performance | ||
| /// in multithreaded build scenarios. | ||
| /// | ||
| /// See the <see href="https://github.com/dotnet/msbuild/blob/main/documentation/specs/multithreading/thread-safe-tasks.md">Thread-Safe Tasks specification</see> for detailed guidelines on thread-safe task development. | ||
| /// </remarks> | ||
| public interface IMultiThreadableTask : ITask | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the task execution environment, which provides access to project current directory and environment variables in a thread-safe manner. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This property is set on behalf of the Task by the MSBuild engine before the Task is executed. It should <strong>never</strong> be set by a Task itself. | ||
| /// </remarks> | ||
| /// <value>Task environment which provides access to project current directory and environment variables.</value> | ||
| TaskEnvironment TaskEnvironment { get; internal set; } | ||
| } | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| #nullable enable | ||
|
|
||
| using System; | ||
|
|
||
| namespace Microsoft.Build.Framework | ||
| { | ||
| /// <summary> | ||
| /// Attribute that marks a task class as thread-safe for multithreaded execution. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Task classes marked with this attribute indicate they can be safely executed in parallel | ||
| /// in the same process with other tasks. This is a compatibility bridge option for existing tasks | ||
| /// that do not have access to TaskEnvironment APIs. | ||
| /// | ||
| /// Tasks using this attribute must satisfy strict requirements: | ||
|
AR-May marked this conversation as resolved.
|
||
| /// - Must not modify global process state (environment variables, working directory, etc.) | ||
| /// - Must not depend on global process state, including relative path resolution | ||
| /// | ||
| /// MSBuild detects this attribute by its namespace and name only, ignoring the defining assembly. | ||
| /// This allows customers to define the attribute in their own assemblies alongside their tasks. | ||
| /// Since MSBuild does not ship this attribute, task authors can copy this definition into their | ||
| /// own projects and mark their task classes with it. Customers using newer MSBuild versions | ||
| /// should prefer implementing IMultiThreadableTask which provides access to TaskEnvironment | ||
| /// for safe process state operations. | ||
| /// </remarks> | ||
| [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] | ||
| internal class MSBuildMultiThreadableTaskAttribute : Attribute | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the MSBuildMultiThreadableTaskAttribute class. | ||
| /// </summary> | ||
| public MSBuildMultiThreadableTaskAttribute() | ||
| { | ||
| } | ||
| } | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
|
|
||
| namespace Microsoft.Build.Framework | ||
| { | ||
| /// <summary> | ||
| /// Represents an absolute file system path. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This struct ensures that paths are always in absolute form and properly formatted. | ||
| /// </remarks> | ||
| public readonly struct AbsolutePath | ||
| { | ||
| /// <summary> | ||
| /// Gets the string representation of this path. | ||
| /// </summary> | ||
| public string Path { get; } | ||
|
|
||
| /// <summary> | ||
| /// Creates a new instance of AbsolutePath. | ||
| /// </summary> | ||
| /// <param name="path">The absolute path string.</param> | ||
| public AbsolutePath(string path) | ||
| { | ||
| throw new NotImplementedException(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates a new instance of AbsolutePath. | ||
| /// </summary> | ||
| /// <param name="path">The absolute path string.</param> | ||
| /// <param name="ignoreRootedCheck">If true, skips checking whether the path is rooted.</param> | ||
| internal AbsolutePath(string path, bool ignoreRootedCheck) | ||
| { | ||
| throw new NotImplementedException(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates a new absolute path by combining a absolute path with a relative path. | ||
| /// </summary> | ||
| /// <param name="path">The path to combine with the base path.</param> | ||
| /// <param name="basePath">The base path to combine with.</param> | ||
| public AbsolutePath(string path, AbsolutePath basePath) | ||
| { | ||
| throw new NotImplementedException(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Implicitly converts an AbsolutePath to a string. | ||
| /// </summary> | ||
| /// <param name="path">The path to convert.</param> | ||
| public static implicit operator string(AbsolutePath path) => throw new NotImplementedException(); | ||
|
|
||
| /// <summary> | ||
| /// Returns the string representation of this path. | ||
| /// </summary> | ||
| /// <returns>The path as a string.</returns> | ||
| public override string ToString() => throw new NotImplementedException(); | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics; | ||
|
|
||
| namespace Microsoft.Build.Framework | ||
| { | ||
| /// <summary> | ||
| /// Provides an <see cref="IMultiThreadableTask"/> with access to a run-time execution environment including | ||
| /// environment variables, file paths, and process management capabilities. | ||
| /// </summary> | ||
| public sealed class TaskEnvironment | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the project directory for the task execution. | ||
| /// </summary> | ||
| public AbsolutePath ProjectDirectory | ||
| { | ||
| get => throw new NotImplementedException(); | ||
| internal set => throw new NotImplementedException(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Converts a relative or absolute path string to an absolute path. | ||
| /// This function resolves paths relative to ProjectDirectory. | ||
| /// </summary> | ||
| /// <param name="path">The path to convert.</param> | ||
| /// <returns>An absolute path representation.</returns> | ||
| public AbsolutePath GetAbsolutePath(string path) => throw new NotImplementedException(); | ||
|
|
||
| /// <summary> | ||
| /// Gets the value of an environment variable. | ||
| /// </summary> | ||
| /// <param name="name">The name of the environment variable.</param> | ||
| /// <returns>The value of the environment variable, or null if it does not exist.</returns> | ||
| public string? GetEnvironmentVariable(string name) => throw new NotImplementedException(); | ||
|
|
||
| /// <summary> | ||
| /// Gets a dictionary containing all environment variables. | ||
| /// </summary> | ||
| /// <returns>A read-only dictionary of environment variables.</returns> | ||
| public IReadOnlyDictionary<string, string> GetEnvironmentVariables() => throw new NotImplementedException(); | ||
|
|
||
| /// <summary> | ||
| /// Sets the value of an environment variable. | ||
| /// </summary> | ||
| /// <param name="name">The name of the environment variable.</param> | ||
| /// <param name="value">The value to set, or null to remove the environment variable.</param> | ||
| public void SetEnvironmentVariable(string name, string? value) => throw new NotImplementedException(); | ||
|
|
||
| /// <summary> | ||
| /// Creates a new ProcessStartInfo configured for the current task execution environment. | ||
| /// </summary> | ||
| /// <returns>A ProcessStartInfo object configured for the current task execution environment.</returns> | ||
| public ProcessStartInfo GetProcessStartInfo() => throw new NotImplementedException(); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.