* ToolTask.cs (RealExecute): Handle TypeLoadExceptions, compiler
authorAnkit Jain <radical@corewars.org>
Fri, 24 Apr 2009 11:21:00 +0000 (11:21 -0000)
committerAnkit Jain <radical@corewars.org>
Fri, 24 Apr 2009 11:21:00 +0000 (11:21 -0000)
crashes and report them. Borrow some tricks from md.
(LogEventsFromTextOutput): Ignore known non-error messages. Don't
log unknown lines, crashes get handled elsewhere.

svn path=/trunk/mcs/; revision=132569

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

index de7d653e8b2c96933479506714b63e00242e67fd..aa83579f8194327d75ef9b7024652dbc731076e5 100644 (file)
@@ -1,3 +1,10 @@
+2009-04-24  Ankit Jain  <jankit@novell.com>
+
+       * ToolTask.cs (RealExecute): Handle TypeLoadExceptions, compiler
+       crashes and report them. Borrow some tricks from md.
+       (LogEventsFromTextOutput): Ignore known non-error messages. Don't
+       log unknown lines, crashes get handled elsewhere.
+
 2009-04-08  Ankit Jain  <jankit@novell.com>
 
        Fix bug #491828.
index 5de62e20fc694769ef812f1a0498b5f86a46ad0d..032b76b3f7c45308de940b888c0bf600fc205518 100644 (file)
@@ -164,14 +164,43 @@ namespace Microsoft.Build.Utilities
                                return false;
                        }
 
+                       bool typeLoadException = false;
+                       StringBuilder compilerOutput = new StringBuilder ();
                        foreach (string s in new string[] { output, error }) {
                                using (StreamReader sr = File.OpenText (s)) {
                                        string line;
                                        while ((line = sr.ReadLine ()) != null) {
+                                               if (typeLoadException) {
+                                                       compilerOutput.Append (sr.ReadToEnd ());
+                                                       break;
+                                               }
+
+                                               compilerOutput.AppendLine (line);
+
+                                               line = line.Trim ();
+                                               if (line.Length == 0)
+                                                       continue;
+
+                                               if (line.StartsWith ("Unhandled Exception: System.TypeLoadException") ||
+                                                   line.StartsWith ("Unhandled Exception: System.IO.FileNotFoundException")) {
+                                                       typeLoadException = true;
+                                               }
                                                LogEventsFromTextOutput (line, MessageImportance.Low);
                                        }
                                }
+                               if (typeLoadException) {
+                                       string output_str = compilerOutput.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);
+                               }
                        }
+
+                       if (!Log.HasLoggedErrors && exitCode != 0)
+                               Log.LogError ("Compiler crashed: " + compilerOutput.ToString ());
                        
                        Log.LogMessage (MessageImportance.Low, String.Format ("Tool {0} execution finished.", pathToTool));
                        
@@ -182,7 +211,11 @@ namespace Microsoft.Build.Utilities
                [MonoTODO]
                protected virtual void LogEventsFromTextOutput (string singleLine, MessageImportance importance)
                {
-                       if (String.IsNullOrEmpty (singleLine))
+                       // When IncludeDebugInformation is true, prevents the debug symbols stats from braeking this.
+                       if (singleLine.StartsWith ("WROTE SYMFILE") ||
+                               singleLine.StartsWith ("OffsetTable") ||
+                               singleLine.StartsWith ("Compilation succeeded") ||
+                               singleLine.StartsWith ("Compilation failed"))
                                return;
 
                        string filename, origin, category, code, subcategory, text;
@@ -196,15 +229,13 @@ namespace Microsoft.Build.Utilities
                        text = m.Groups [regex.GroupNumberFromName ("TEXT")].Value;
                        
                        ParseOrigin (origin, out filename, out lineNumber, out columnNumber, out endLineNumber, out endColumnNumber);
-                       
+
                        if (category == "warning") {
                                Log.LogWarning (subcategory, code, null, filename, lineNumber, columnNumber, endLineNumber,
                                        endColumnNumber, text, null);
                        } else if (category == "error") {
                                Log.LogError (subcategory, code, null, filename, lineNumber, columnNumber, endLineNumber,
                                        endColumnNumber, text, null);
-                       } else {
-                               Log.LogError (singleLine);
                        }
                }