From 6d97976719d4aefae595ee919b942da452e97e57 Mon Sep 17 00:00:00 2001 From: Mariana Dematte Date: Fri, 19 Jan 2024 17:05:21 +0100 Subject: [PATCH] ToolTask process start separated to another function (#9649) Fix for #9404 Context We currently do not send the cancelation event to tasks being run by ToolTask, as such, many children task take a long time to cancel, and sometimes they finish executing before said cancelation. This change makes it possible for inherited classes to access the process and check the cancelation event during execution. Changes Made Separated the start of the process to another function that is overridable, as well as exposing the process information. Notes Issue will only be closed once C++ team has incorporated this change into the CustomBuild task. --- src/Utilities/ToolTask.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Utilities/ToolTask.cs b/src/Utilities/ToolTask.cs index 3a8ff43f237..a4be487c4ee 100644 --- a/src/Utilities/ToolTask.cs +++ b/src/Utilities/ToolTask.cs @@ -658,6 +658,19 @@ protected virtual ProcessStartInfo GetProcessStartInfo( return startInfo; } + /// + /// We expect tasks to override this method if they need information about the tool process or its process events during task execution. + /// Implementation should make sure that the task is started in this method. + /// Starts the process during task execution. + /// + /// Fully populated instance representing the tool process to be started. + /// A started process. This could be or another instance. + protected virtual Process StartToolProcess(Process proc) + { + proc.Start(); + return proc; + } + /// /// Writes out a temporary response file and shell-executes the tool requested. Enables concurrent /// logging of the output of the tool. @@ -714,7 +727,7 @@ protected virtual int ExecuteTool( ExitCode = -1; // Start the process - proc.Start(); + proc = StartToolProcess(proc); // Close the input stream. This is done to prevent commands from // blocking the build waiting for input from the user.