From 7c2843dbb9b3b7e1bbf62ba93b25bc92234415f1 Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Wed, 7 Apr 2010 21:24:16 +0000 Subject: [PATCH] * ToolTask.cs: Use regex to parse output. Regex is from monodevelop. svn path=/trunk/mcs/; revision=154992 --- .../Microsoft.Build.Utilities/ChangeLog | 4 + .../Microsoft.Build.Utilities/ToolTask.cs | 121 +++++------------- 2 files changed, 38 insertions(+), 87 deletions(-) diff --git a/mcs/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/ChangeLog b/mcs/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/ChangeLog index 3af2f2a1f3d..da51c4d49ae 100644 --- a/mcs/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/ChangeLog +++ b/mcs/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/ChangeLog @@ -1,3 +1,7 @@ +2010-04-08 Ankit Jain + + * ToolTask.cs: Use regex to parse output. Regex is from monodevelop. + 2010-04-08 Ankit Jain * ToolTask.cs (ExecuteTool): Check that the tool exists. diff --git a/mcs/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/ToolTask.cs b/mcs/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/ToolTask.cs index 226c72cc766..f3c3b676b30 100644 --- a/mcs/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/ToolTask.cs +++ b/mcs/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/ToolTask.cs @@ -56,8 +56,6 @@ namespace Microsoft.Build.Utilities StringBuilder toolOutput; bool typeLoadException; - static Regex regex; - protected ToolTask () : this (null, null) { @@ -81,19 +79,6 @@ namespace Microsoft.Build.Utilities this.environmentOverride = new SCS.ProcessStringDictionary (); } - static ToolTask () - { - regex = new Regex ( - @"^\s*" - + @"(((?(((\d+>)?[a-zA-Z]?:[^:]*)|([^:]*))):)" - + "|())" - + "(?(()|([^:]*? )))" - + "(?(error|warning)) " - + "(?[^:]*):" - + "(?.*)$", - RegexOptions.IgnoreCase); - } - [MonoTODO] protected virtual bool CallHostObjectToExecute () { @@ -238,82 +223,33 @@ namespace Microsoft.Build.Utilities singleLine.StartsWith ("Compilation failed")) return; - string filename, origin, category, code, subcategory, text; - int lineNumber, columnNumber, endLineNumber, endColumnNumber; - - Match m = regex.Match (singleLine); - origin = m.Groups [regex.GroupNumberFromName ("ORIGIN")].Value; - category = m.Groups [regex.GroupNumberFromName ("CATEGORY")].Value; - code = m.Groups [regex.GroupNumberFromName ("CODE")].Value; - subcategory = m.Groups [regex.GroupNumberFromName ("SUBCATEGORY")].Value; - 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); + Match match = CscErrorRegex.Match (singleLine); + if (!match.Success) + return; + + string filename = match.Result ("${file}") ?? ""; + string line = match.Result ("${line}"); + int lineNumber = !string.IsNullOrEmpty (line) ? Int32.Parse (line) : 0; + + string col = match.Result ("${column}"); + int columnNumber = 0; + if (!string.IsNullOrEmpty (col)) + columnNumber = col == "255+" ? -1 : Int32.Parse (col); + + string category = match.Result ("${level}"); + string code = match.Result ("${number}"); + string text = match.Result ("${message}"); + + if (String.Compare (category, "warning", StringComparison.OrdinalIgnoreCase) == 0) { + Log.LogWarning (null, code, null, filename, lineNumber, columnNumber, -1, + -1, text, null); + } else if (String.Compare (category, "error", StringComparison.OrdinalIgnoreCase) == 0) { + Log.LogError (null, code, null, filename, lineNumber, columnNumber, -1, + -1, text, null); } else { Log.LogMessage (importance, singleLine); } } - - private void ParseOrigin (string origin, out string filename, - out int lineNumber, out int columnNumber, - out int endLineNumber, out int endColumnNumber) - { - int lParen; - string[] temp; - string[] left, right; - - if (origin.IndexOf ('(') != -1 ) { - lParen = origin.IndexOf ('('); - filename = origin.Substring (0, lParen); - temp = origin.Substring (lParen + 1, origin.Length - lParen - 2).Split (','); - if (temp.Length == 1) { - left = temp [0].Split ('-'); - if (left.Length == 1) { - lineNumber = Int32.Parse (left [0]); - columnNumber = 0; - endLineNumber = 0; - endColumnNumber = 0; - } else if (left.Length == 2) { - lineNumber = Int32.Parse (left [0]); - columnNumber = 0; - endLineNumber = Int32.Parse (left [1]); - endColumnNumber = 0; - } else - throw new Exception ("Invalid line/column format."); - } else if (temp.Length == 2) { - right = temp [1].Split ('-'); - lineNumber = Int32.Parse (temp [0]); - endLineNumber = 0; - if (right.Length == 1) { - columnNumber = Int32.Parse (right [0]); - endColumnNumber = 0; - } else if (right.Length == 2) { - columnNumber = Int32.Parse (right [0]); - endColumnNumber = Int32.Parse (right [0]); - } else - throw new Exception ("Invalid line/column format."); - } else if (temp.Length == 4) { - lineNumber = Int32.Parse (temp [0]); - endLineNumber = Int32.Parse (temp [2]); - columnNumber = Int32.Parse (temp [1]); - endColumnNumber = Int32.Parse (temp [3]); - } else - throw new Exception ("Invalid line/column format."); - } else { - filename = origin; - lineNumber = 0; - columnNumber = 0; - endLineNumber = 0; - endColumnNumber = 0; - } - } protected virtual string GenerateCommandLineCommands () { @@ -452,6 +388,17 @@ namespace Microsoft.Build.Utilities toolPath = value; } } + + // Snatched from our codedom code, with some changes to make it compatible with csc + // (the line+column group is optional is csc) + static Regex errorRegex; + static Regex CscErrorRegex { + get { + if (errorRegex == null) + errorRegex = new Regex (@"^(\s*(?[^\(]+)(\((?\d*)(,(?\d*[\+]*))?\))?:\s+)*(?\w+)\s+(?.*\d):\s*(?.*)", RegexOptions.Compiled | RegexOptions.ExplicitCapture); + return errorRegex; + } + } } } -- 2.25.1