copied mono-api-diff.cs from mono-2-2 branch so new patch can be applied and history...
[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
39 namespace Microsoft.Build.Tasks {
40
41         public class Vbc : ManagedCompiler {
42
43                 public Vbc ()
44                 {
45                 }
46
47                 [MonoTODO]
48                 protected internal override void AddResponseFileCommands (
49                                 CommandLineBuilderExtension commandLine )
50                 {
51                         base.AddResponseFileCommands (commandLine);
52
53                         commandLine.AppendSwitchIfNotNull ("/libpath:", AdditionalLibPaths, ",");
54
55                         commandLine.AppendSwitchIfNotNull ("/baseaddress:", BaseAddress);
56
57                         if (DefineConstants != null)
58                                 commandLine.AppendSwitchUnquotedIfNotNull ("/define:",
59                                                 String.Format ("\"{0}\"", EscapeDoubleQuotes (DefineConstants)));
60
61                         // DisabledWarnings
62
63                         commandLine.AppendSwitchIfNotNull ("/doc:", DocumentationFile);
64
65                         // ErrorReport
66                         
67                         // GenerateDocumentation
68                         
69                         if (Imports != null)
70                                 foreach (ITaskItem item in Imports)
71                                         commandLine.AppendSwitchIfNotNull ("/imports:", item.ItemSpec);
72                         
73                         commandLine.AppendSwitchIfNotNull ("/main:", MainEntryPoint);
74
75                         // NoStandardLib
76                         
77                         if (NoWarnings)
78                                 commandLine.AppendSwitch ("/nowarn");
79
80                         commandLine.AppendSwitchIfNotNull ("/optioncompare:", OptionCompare);
81
82                         if (Bag ["OptionExplicit"] != null)
83                                 if (OptionExplicit)
84                                         commandLine.AppendSwitch ("/optionexplicit+");
85                                 else
86                                         commandLine.AppendSwitch ("/optionexplicit-");
87
88                         if (Bag ["OptionStrict"] != null)
89                                 if (OptionStrict)
90                                         commandLine.AppendSwitch ("/optionstrict+");
91                                 else
92                                         commandLine.AppendSwitch ("/optionstrict-");
93
94                         // OptionStrictType
95                         
96                         // Platform
97                         
98                         if (References != null)
99                                 foreach (ITaskItem item in References)
100                                         commandLine.AppendSwitchIfNotNull ("/reference:", item.ItemSpec);
101         
102                         if (Bag ["RemoveIntegerChecks"] != null)
103                                 if (RemoveIntegerChecks)
104                                         commandLine.AppendSwitch ("/removeintchecks+");
105                                 else
106                                         commandLine.AppendSwitch ("/removeintchecks-");
107
108                         if (ResponseFiles != null)
109                                 foreach (ITaskItem item in ResponseFiles)
110                                         commandLine.AppendFileNameIfNotNull (String.Format ("@{0}", item.ItemSpec));
111
112                         commandLine.AppendSwitchIfNotNull ("/rootnamespace:", RootNamespace);
113
114                         commandLine.AppendSwitchIfNotNull ("/sdkpath:", SdkPath);
115
116                         // TargetCompactFramework
117                         
118                         // Verbosity
119
120                         // WarningsAsErrors
121
122                         // WarningsNotAsErrors
123
124                 }
125
126                 string EscapeDoubleQuotes (string text)
127                 {
128                         if (text == null)
129                                 return null;
130
131                         return text.Replace ("\"", "\\\"");
132                 }
133                 
134                 [MonoTODO]
135                 protected override bool CallHostObjectToExecute ()
136                 {
137                         throw new NotImplementedException ();
138                 }
139                 
140                 [MonoTODO]
141                 protected override string GenerateFullPathToTool ()
142                 {
143                         return Path.Combine (ToolPath, ToolExe);
144                 }
145                 
146                 [MonoTODO]
147                 protected override HostObjectInitializationStatus InitializeHostObject ()
148                 {
149                         throw new NotImplementedException ();
150                 }
151
152                 [MonoTODO]
153                 protected override bool ValidateParameters ()
154                 {
155                         return true;
156                 }
157
158                 protected override void LogEventsFromTextOutput (string singleLine, MessageImportance importance)
159                 {
160                         singleLine = singleLine.Trim ();
161                         if (singleLine.Length == 0)
162                                 return;
163
164                         // When IncludeDebugInformation is true, prevents the debug symbols stats from braeking this.
165                         if (singleLine.StartsWith ("WROTE SYMFILE") ||
166                                 singleLine.StartsWith ("OffsetTable") ||
167                                 singleLine.StartsWith ("Compilation succeeded") ||
168                                 singleLine.StartsWith ("Compilation failed"))
169                                 return;
170
171                         Match match = ErrorRegex.Match (singleLine);
172                         if (!match.Success) {
173                                 Log.LogMessage (importance, singleLine);
174                                 return;
175                         }
176
177                         string filename = match.Result ("${file}") ?? "";
178
179                         string line = match.Result ("${line}");
180                         int lineNumber = !string.IsNullOrEmpty (line) ? Int32.Parse (line) : 0;
181
182                         string col = match.Result ("${column}");
183                         int columnNumber = 0;
184                         if (!string.IsNullOrEmpty (col))
185                                 columnNumber = col == "255+" ? -1 : Int32.Parse (col);
186
187                         string category = match.Result ("${level}");
188                         string code = match.Result ("${number}");
189                         string text = match.Result ("${message}");
190
191                         if (String.Compare (category, "warning", StringComparison.OrdinalIgnoreCase) == 0) {
192                                 Log.LogWarning (null, code, null, filename, lineNumber, columnNumber, -1,
193                                         -1, text, null);
194                         } else if (String.Compare (category, "error", StringComparison.OrdinalIgnoreCase) == 0) {
195                                 Log.LogError (null, code, null, filename, lineNumber, columnNumber, -1,
196                                         -1, text, null);
197                         } else {
198                                 Log.LogMessage (importance, singleLine);
199                         }
200                 }
201
202                 [MonoTODO]
203                 public string BaseAddress {
204                         get { return (string) Bag ["BaseAddress"]; }
205                         set { Bag ["BaseAddress"] = value; }
206                 }
207                 
208                 [MonoTODO]
209                 public string DisabledWarnings  {
210                         get { return (string) Bag ["DisabledWarnings"]; }
211                         set { Bag ["DisabledWarnings"] = value; }
212                 }
213                 
214                 [MonoTODO]
215                 public string DocumentationFile {
216                         get { return (string) Bag ["DocumentationFile"]; }
217                         set { Bag ["DocumentationFile"] = value; }
218                 }
219                 
220                 [MonoTODO]
221                 public string ErrorReport {
222                         get { return (string) Bag ["ErrorReport"]; }
223                         set { Bag ["ErrorReport"] = value; }
224                 }
225                 
226                 [MonoTODO]
227                 public bool GenerateDocumentation {
228                         get { return GetBoolParameterWithDefault ("GenerateDocumentation", false); }
229                         set { Bag ["GenerateDocumentation"] = value; }
230                 }
231                 
232                 [MonoTODO]
233                 public ITaskItem [] Imports {
234                         get { return (ITaskItem []) Bag ["Imports"]; }
235                         set { Bag ["Imports"] = value; }
236                 }
237                 
238                 [MonoTODO]
239                 public bool NoStandardLib {
240                         get { return GetBoolParameterWithDefault ("NoStandardLib", false); }
241                         set { Bag ["NoStandardLib"] = value; }
242                 }
243                 
244                 [MonoTODO]
245                 public bool NoWarnings {
246                         get { return GetBoolParameterWithDefault ("NoWarnings", false); }
247                         set { Bag ["NoWarnings"] = value; }
248                 }
249                 
250                 [MonoTODO]
251                 public string OptionCompare {
252                         get { return (string) Bag ["OptionCompare"]; }
253                         set { Bag ["OptionCompare"] = value; }
254                 }
255                 
256                 [MonoTODO]
257                 public bool OptionExplicit {
258                         get { return GetBoolParameterWithDefault ("OptionExplicit", false); }
259                         set { Bag ["OpExplicit"] = value; }
260                 }
261                 
262                 [MonoTODO]
263                 public bool OptionStrict {
264                         get { return GetBoolParameterWithDefault ("OptionStrict", false); }
265                         set { Bag ["OptionStrict"] = value; }
266                 }
267                 
268                 [MonoTODO]
269                 public string OptionStrictType {
270                         get { return (string) Bag ["OptionStrictType"]; }
271                         set { Bag ["OptionStrictType"] = value; }
272                 }
273                 
274                 [MonoTODO]
275                 public string Platform {
276                         get { return (string) Bag ["Platfrom"]; }
277                         set { Bag ["Platform"] = value; }
278                 }
279                 
280                 [MonoTODO]
281                 public bool RemoveIntegerChecks {
282                         get { return GetBoolParameterWithDefault ("RemoveIntegerChecks", false); }
283                         set { Bag ["RemoveIntegerChecks"] = value; }
284                 }
285
286                 [MonoTODO]
287                 public string RootNamespace {
288                         get { return (string) Bag ["RootNamespace"]; }
289                         set { Bag ["RootNamespace"] = value; }
290                 }
291
292                 [MonoTODO]
293                 public string SdkPath {
294                         get { return (string) Bag ["SdkPath"]; }
295                         set { Bag ["SdkPath"] = value; }
296                 }
297
298                 [MonoTODO]
299                 public bool TargetCompactFramework {
300                         get { return (bool) Bag ["TargetCompactFramework"]; }
301                         set { Bag ["TargetCompactFramework"] = value; }
302                 }
303
304                 [MonoTODO]
305                 protected override string ToolName {
306                         get { return Utilities.RunningOnWindows ? "vbnc.bat" : "vbnc"; }
307                 }
308
309                 [MonoTODO]
310                 public bool UseHostCompilerIfAvailable {
311                         get { return (bool) Bag ["UseHostCompilerIfAvailable"]; }
312                         set { Bag ["UseHostCompilerIfAvailable"] = value; }
313                 }
314
315                 [MonoTODO]
316                 public string Verbosity {
317                         get { return (string) Bag ["Verbosity"]; }
318                         set { Bag ["Verbosity"] = value; }
319                 }
320
321                 [MonoTODO]
322                 public string WarningsAsErrors {
323                         get { return (string) Bag ["WarningsAsErrors"]; }
324                         set { Bag ["WarningsAsErrors"] = value; }
325                 }
326                 
327                 [MonoTODO]
328                 public string WarningsNotAsErrors {
329                         get { return (string) Bag ["WarningsNotAsErrors"]; }
330                         set { Bag ["WarningsNotAsErrors"] = value; }
331                 }
332
333                 // from md's VBBindingCompilerServices.cs
334                 //matches "/home/path/Default.aspx.vb (40,31) : Error VBNC30205: Expected end of statement."
335                 //and "Error : VBNC99999: vbnc crashed nearby this location in the source code."
336                 //and "Error : VBNC99999: Unexpected error: Object reference not set to an instance of an object"
337                 static Regex errorRegex;
338                 static Regex ErrorRegex {
339                         get {
340                                 if (errorRegex == null)
341                                         errorRegex = new Regex (@"^\s*((?<file>.*)\s?\((?<line>\d*)(,(?<column>\d*))?\) : )?(?<level>\w+) :? ?(?<number>[^:]*): (?<message>.*)$", RegexOptions.Compiled | RegexOptions.ExplicitCapture);
342                                 return errorRegex;
343                         }
344                 }
345
346         }
347 }
348
349 #endif