[xbuild] Vbc task - make error column check a little non-specific.
[mono.git] / mcs / class / Microsoft.Build.Tasks / Microsoft.Build.Tasks / Vbc.cs
1 //
2 // UpdateManifest.cs
3 //
4 // Author:
5 //      Leszek Ciesielski  <skolima@gmail.com>
6 //      Marek Sieradzki  <marek.sieradzki@gmail.com>
7 //
8 // Copyright (C) 2006 Forcom (http://www.forcom.com.pl/)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
29 #if NET_2_0
30
31 using System;
32 using System.IO;
33 using System.Text;
34 using System.Text.RegularExpressions;
35
36 using Microsoft.Build.Framework;
37 using Microsoft.Build.Utilities;
38 using Mono.XBuild.Utilities;
39
40 namespace Microsoft.Build.Tasks {
41
42         public class Vbc : ManagedCompiler {
43
44                 public Vbc ()
45                 {
46                 }
47
48                 [MonoTODO]
49                 protected internal override void AddResponseFileCommands (
50                                 CommandLineBuilderExtension commandLine )
51                 {
52                         base.AddResponseFileCommands (commandLine);
53
54                         commandLine.AppendSwitchIfNotNull ("/libpath:", AdditionalLibPaths, ",");
55
56                         commandLine.AppendSwitchIfNotNull ("/baseaddress:", BaseAddress);
57
58                         if (DefineConstants != null)
59                                 commandLine.AppendSwitchUnquotedIfNotNull ("/define:",
60                                                 String.Format ("\"{0}\"", EscapeDoubleQuotes (DefineConstants)));
61
62                         // DisabledWarnings
63
64                         commandLine.AppendSwitchIfNotNull ("/doc:", DocumentationFile);
65
66                         // ErrorReport
67                         
68                         // GenerateDocumentation
69                         
70                         if (Imports != null)
71                                 foreach (ITaskItem item in Imports)
72                                         commandLine.AppendSwitchIfNotNull ("/imports:", item.ItemSpec);
73                         
74                         commandLine.AppendSwitchIfNotNull ("/main:", MainEntryPoint);
75
76                         // NoStandardLib
77                         
78                         if (NoWarnings)
79                                 commandLine.AppendSwitch ("/nowarn");
80
81                         commandLine.AppendSwitchIfNotNull ("/optioncompare:", OptionCompare);
82
83                         if (Bag ["OptionExplicit"] != null)
84                                 if (OptionExplicit)
85                                         commandLine.AppendSwitch ("/optionexplicit+");
86                                 else
87                                         commandLine.AppendSwitch ("/optionexplicit-");
88
89                         if (Bag ["OptionStrict"] != null)
90                                 if (OptionStrict)
91                                         commandLine.AppendSwitch ("/optionstrict+");
92                                 else
93                                         commandLine.AppendSwitch ("/optionstrict-");
94
95                         // OptionStrictType
96                         
97                         // Platform
98                         
99                         if (References != null)
100                                 foreach (ITaskItem item in References)
101                                         commandLine.AppendSwitchIfNotNull ("/reference:", item.ItemSpec);
102         
103                         if (Bag ["RemoveIntegerChecks"] != null)
104                                 if (RemoveIntegerChecks)
105                                         commandLine.AppendSwitch ("/removeintchecks+");
106                                 else
107                                         commandLine.AppendSwitch ("/removeintchecks-");
108
109                         if (ResponseFiles != null)
110                                 foreach (ITaskItem item in ResponseFiles)
111                                         commandLine.AppendFileNameIfNotNull (String.Format ("@{0}", item.ItemSpec));
112
113                         commandLine.AppendSwitchIfNotNull ("/rootnamespace:", RootNamespace);
114
115                         commandLine.AppendSwitchIfNotNull ("/sdkpath:", SdkPath);
116
117                         // TargetCompactFramework
118                         
119                         // Verbosity
120
121                         // WarningsAsErrors
122
123                         // WarningsNotAsErrors
124
125                 }
126
127                 string EscapeDoubleQuotes (string text)
128                 {
129                         if (text == null)
130                                 return null;
131
132                         return text.Replace ("\"", "\\\"");
133                 }
134                 
135                 [MonoTODO]
136                 protected override bool CallHostObjectToExecute ()
137                 {
138                         throw new NotImplementedException ();
139                 }
140                 
141                 [MonoTODO]
142                 protected override string GenerateFullPathToTool ()
143                 {
144                         return Path.Combine (ToolPath, ToolExe);
145                 }
146                 
147                 [MonoTODO]
148                 protected override HostObjectInitializationStatus InitializeHostObject ()
149                 {
150                         throw new NotImplementedException ();
151                 }
152
153                 [MonoTODO]
154                 protected override bool ValidateParameters ()
155                 {
156                         return true;
157                 }
158
159                 protected override void LogEventsFromTextOutput (string singleLine, MessageImportance importance)
160                 {
161                         singleLine = singleLine.Trim ();
162                         if (singleLine.Length == 0)
163                                 return;
164
165                         // When IncludeDebugInformation is true, prevents the debug symbols stats from braeking this.
166                         if (singleLine.StartsWith ("WROTE SYMFILE") ||
167                                 singleLine.StartsWith ("OffsetTable") ||
168                                 singleLine.StartsWith ("Compilation succeeded") ||
169                                 singleLine.StartsWith ("Compilation failed"))
170                                 return;
171
172                         Match match = ErrorRegex.Match (singleLine);
173                         if (!match.Success) {
174                                 Log.LogMessage (importance, singleLine);
175                                 return;
176                         }
177
178                         string filename = match.Result ("${file}") ?? "";
179
180                         string line = match.Result ("${line}");
181                         int lineNumber = !string.IsNullOrEmpty (line) ? Int32.Parse (line) : 0;
182
183                         string col = match.Result ("${column}");
184                         int columnNumber = 0;
185                         if (!string.IsNullOrEmpty (col))
186                                 columnNumber = col.IndexOf ("+") >= 0 ? -1 : Int32.Parse (col);
187
188                         string category = match.Result ("${level}");
189                         string code = match.Result ("${number}");
190                         string text = match.Result ("${message}");
191
192                         if (String.Compare (category, "warning", StringComparison.OrdinalIgnoreCase) == 0) {
193                                 Log.LogWarning (null, code, null, filename, lineNumber, columnNumber, -1,
194                                         -1, text, null);
195                         } else if (String.Compare (category, "error", StringComparison.OrdinalIgnoreCase) == 0) {
196                                 Log.LogError (null, code, null, filename, lineNumber, columnNumber, -1,
197                                         -1, text, null);
198                         } else {
199                                 Log.LogMessage (importance, singleLine);
200                         }
201                 }
202
203                 [MonoTODO]
204                 public string BaseAddress {
205                         get { return (string) Bag ["BaseAddress"]; }
206                         set { Bag ["BaseAddress"] = value; }
207                 }
208                 
209                 [MonoTODO]
210                 public string DisabledWarnings  {
211                         get { return (string) Bag ["DisabledWarnings"]; }
212                         set { Bag ["DisabledWarnings"] = value; }
213                 }
214                 
215                 [MonoTODO]
216                 public string DocumentationFile {
217                         get { return (string) Bag ["DocumentationFile"]; }
218                         set { Bag ["DocumentationFile"] = value; }
219                 }
220                 
221                 [MonoTODO]
222                 public string ErrorReport {
223                         get { return (string) Bag ["ErrorReport"]; }
224                         set { Bag ["ErrorReport"] = value; }
225                 }
226                 
227                 [MonoTODO]
228                 public bool GenerateDocumentation {
229                         get { return GetBoolParameterWithDefault ("GenerateDocumentation", false); }
230                         set { Bag ["GenerateDocumentation"] = value; }
231                 }
232                 
233                 [MonoTODO]
234                 public ITaskItem [] Imports {
235                         get { return (ITaskItem []) Bag ["Imports"]; }
236                         set { Bag ["Imports"] = value; }
237                 }
238                 
239                 [MonoTODO]
240                 public bool NoStandardLib {
241                         get { return GetBoolParameterWithDefault ("NoStandardLib", false); }
242                         set { Bag ["NoStandardLib"] = value; }
243                 }
244                 
245                 [MonoTODO]
246                 public bool NoWarnings {
247                         get { return GetBoolParameterWithDefault ("NoWarnings", false); }
248                         set { Bag ["NoWarnings"] = value; }
249                 }
250                 
251                 [MonoTODO]
252                 public string OptionCompare {
253                         get { return (string) Bag ["OptionCompare"]; }
254                         set { Bag ["OptionCompare"] = value; }
255                 }
256                 
257                 [MonoTODO]
258                 public bool OptionExplicit {
259                         get { return GetBoolParameterWithDefault ("OptionExplicit", false); }
260                         set { Bag ["OpExplicit"] = value; }
261                 }
262                 
263                 [MonoTODO]
264                 public bool OptionStrict {
265                         get { return GetBoolParameterWithDefault ("OptionStrict", false); }
266                         set { Bag ["OptionStrict"] = value; }
267                 }
268                 
269                 [MonoTODO]
270                 public string OptionStrictType {
271                         get { return (string) Bag ["OptionStrictType"]; }
272                         set { Bag ["OptionStrictType"] = value; }
273                 }
274                 
275                 [MonoTODO]
276                 public string Platform {
277                         get { return (string) Bag ["Platfrom"]; }
278                         set { Bag ["Platform"] = value; }
279                 }
280                 
281                 [MonoTODO]
282                 public bool RemoveIntegerChecks {
283                         get { return GetBoolParameterWithDefault ("RemoveIntegerChecks", false); }
284                         set { Bag ["RemoveIntegerChecks"] = value; }
285                 }
286
287                 [MonoTODO]
288                 public string RootNamespace {
289                         get { return (string) Bag ["RootNamespace"]; }
290                         set { Bag ["RootNamespace"] = value; }
291                 }
292
293                 [MonoTODO]
294                 public string SdkPath {
295                         get { return (string) Bag ["SdkPath"]; }
296                         set { Bag ["SdkPath"] = value; }
297                 }
298
299                 [MonoTODO]
300                 public bool TargetCompactFramework {
301                         get { return (bool) Bag ["TargetCompactFramework"]; }
302                         set { Bag ["TargetCompactFramework"] = value; }
303                 }
304
305                 [MonoTODO]
306                 protected override string ToolName {
307                         get { return MSBuildUtils.RunningOnWindows ? "vbnc.bat" : "vbnc"; }
308                 }
309
310                 [MonoTODO]
311                 public bool UseHostCompilerIfAvailable {
312                         get { return (bool) Bag ["UseHostCompilerIfAvailable"]; }
313                         set { Bag ["UseHostCompilerIfAvailable"] = value; }
314                 }
315
316                 [MonoTODO]
317                 public string Verbosity {
318                         get { return (string) Bag ["Verbosity"]; }
319                         set { Bag ["Verbosity"] = value; }
320                 }
321
322                 [MonoTODO]
323                 public string WarningsAsErrors {
324                         get { return (string) Bag ["WarningsAsErrors"]; }
325                         set { Bag ["WarningsAsErrors"] = value; }
326                 }
327                 
328                 [MonoTODO]
329                 public string WarningsNotAsErrors {
330                         get { return (string) Bag ["WarningsNotAsErrors"]; }
331                         set { Bag ["WarningsNotAsErrors"] = value; }
332                 }
333
334                 // from md's VBBindingCompilerServices.cs
335                 //matches "/home/path/Default.aspx.vb (40,31) : Error VBNC30205: Expected end of statement."
336                 //and "Error : VBNC99999: vbnc crashed nearby this location in the source code."
337                 //and "Error : VBNC99999: Unexpected error: Object reference not set to an instance of an object"
338                 static Regex errorRegex;
339                 static Regex ErrorRegex {
340                         get {
341                                 if (errorRegex == null)
342                                         errorRegex = new Regex (@"^\s*((?<file>.*)\s?\((?<line>\d*)(,(?<column>\d*))?\) : )?(?<level>\w+) :? ?(?<number>[^:]*): (?<message>.*)$", RegexOptions.Compiled | RegexOptions.ExplicitCapture);
343                                 return errorRegex;
344                         }
345                 }
346
347         }
348 }
349
350 #endif