Emit tool's output as it is received, instead of waiting for it to end.
authorAnkit Jain <jankit@novell.com>
Thu, 22 Jul 2010 22:07:23 +0000 (03:37 +0530)
committerAnkit Jain <jankit@novell.com>
Thu, 22 Jul 2010 22:07:23 +0000 (03:37 +0530)
* ToolTask.cs: Don't wait for the process to end, before emitting
it's stdout/stderr, emit as it is received. This helps with time
consuming tools.

mcs/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/ChangeLog
mcs/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/ToolTask.cs

index 9b48a6ebad10dc95751fa9872300bf72c768ced4..aa0a060404171accd93ac3157f2e340b43fbe3ad 100644 (file)
@@ -1,3 +1,9 @@
+2010-04-10  Ankit Jain  <jankit@novell.com>
+
+       * ToolTask.cs: Don't wait for the process to end, before emitting
+       it's stdout/stderr, emit as it is received. This helps with time
+       consuming tools.
+
 2010-04-10  Ankit Jain  <jankit@novell.com>
 
        * ReservedNameUtils.cs (GetReservedMetadata): Handle empty item.
index 1a9247e2d0dc537abe54988218bcb990e695c62c..de05e9c71fddcfde086c376ce694ea4a03e7dcb8 100644 (file)
@@ -143,6 +143,9 @@ namespace Microsoft.Build.Utilities
 
                                try {
                                        ProcessWrapper pw = ProcessService.StartProcess (pinfo, outwr, errwr, null, environmentOverride);
+                                       pw.OutputStreamChanged += delegate (object o, string msg) { ProcessLine (msg, StandardOutputLoggingImportance); };
+                                       pw.ErrorStreamChanged += delegate (object o, string msg) { ProcessLine (msg, StandardErrorLoggingImportance); };
+
                                        pw.WaitForOutput (timeout == Int32.MaxValue ? -1 : timeout);
                                        exitCode = pw.ExitCode;
                                        outwr.Close();
@@ -153,8 +156,8 @@ namespace Microsoft.Build.Utilities
                                        return -1;
                                }
 
-                               ProcessOutputFile (output, StandardOutputLoggingImportance);
-                               ProcessOutputFile (error, StandardErrorLoggingImportance);
+                               if (typeLoadException)
+                                       ProcessTypeLoadException ();
 
                                Log.LogMessage (MessageImportance.Low, "Tool {0} execution finished.", pathToTool);
                                return exitCode;
@@ -170,34 +173,33 @@ namespace Microsoft.Build.Utilities
                        }
                }
 
-               void ProcessOutputFile (string filename, MessageImportance importance)
+               void ProcessTypeLoadException ()
                {
-                       using (StreamReader sr = File.OpenText (filename)) {
-                               string line;
-                               while ((line = sr.ReadLine ()) != null) {
-                                       if (typeLoadException) {
-                                               toolOutput.Append (sr.ReadToEnd ());
-                                               string output_str = toolOutput.ToString ();
-                                               Regex reg  = new Regex (@".*WARNING.*used in (mscorlib|System),.*",
-                                                               RegexOptions.Multiline);
-
-                                               if (reg.Match (output_str).Success)
-                                                       Log.LogError (
-                                                               "Error: A referenced assembly may be built with an incompatible " + 
-                                                               "CLR version. See the compilation output for more details.");
-                                               else
-                                                       Log.LogError (
-                                                               "Error: A dependency of a referenced assembly may be missing, or " +
-                                                               "you may be referencing an assembly created with a newer CLR " +
-                                                               "version. See the compilation output for more details.");
-
-                                               Log.LogError (output_str);
-                                       }
-
-                                       toolOutput.AppendLine (line);
-                                       LogEventsFromTextOutput (line, importance);
-                               }
-                       }
+                       string output_str = toolOutput.ToString ();
+                       Regex reg  = new Regex (@".*WARNING.*used in (mscorlib|System),.*",
+                                       RegexOptions.Multiline);
+
+                       if (reg.Match (output_str).Success)
+                               Log.LogError (
+                                       "Error: A referenced assembly may be built with an incompatible " +
+                                       "CLR version. See the compilation output for more details.");
+                       else
+                               Log.LogError (
+                                       "Error: A dependency of a referenced assembly may be missing, or " +
+                                       "you may be referencing an assembly created with a newer CLR " +
+                                       "version. See the compilation output for more details.");
+
+                       Log.LogError (output_str);
+               }
+
+               void ProcessLine (string line, MessageImportance importance)
+               {
+                       toolOutput.AppendLine (line);
+
+                       // in case of typeLoadException, collect all the output
+                       // and then handle in ProcessTypeLoadException
+                       if (!typeLoadException)
+                               LogEventsFromTextOutput (line, importance);
                }
 
                protected virtual void LogEventsFromTextOutput (string singleLine, MessageImportance importance)