Merge pull request #5714 from alexischr/update_bockbuild
[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
30 using System;
31 using System.IO;
32 using System.Text;
33 using System.Text.RegularExpressions;
34
35 using Microsoft.Build.Framework;
36 using Microsoft.Build.Utilities;
37 using Mono.XBuild.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                         if (Bag ["NoStandardLib"] != null && NoStandardLib)
77                                 commandLine.AppendSwitch ("/nostdlib");
78                         
79                         if (NoWarnings)
80                                 commandLine.AppendSwitch ("/nowarn");
81
82                         commandLine.AppendSwitchIfNotNull ("/optioncompare:", OptionCompare);
83
84                         if (Bag ["OptionExplicit"] != null)
85                                 if (OptionExplicit)
86                                         commandLine.AppendSwitch ("/optionexplicit+");
87                                 else
88                                         commandLine.AppendSwitch ("/optionexplicit-");
89
90                         if (Bag ["OptionStrict"] != null)
91                                 if (OptionStrict)
92                                         commandLine.AppendSwitch ("/optionstrict+");
93                                 else
94                                         commandLine.AppendSwitch ("/optionstrict-");
95
96                         if (Bag ["OptionInfer"] != null)
97                                 if (OptionInfer)
98                                         commandLine.AppendSwitch ("/optioninfer+");
99                                 else
100                                         commandLine.AppendSwitch ("/optioninfer-");
101
102                         // OptionStrictType
103                         
104                         // Platform
105                         
106                         if (References != null)
107                                 foreach (ITaskItem item in References)
108                                         commandLine.AppendSwitchIfNotNull ("/reference:", item.ItemSpec);
109         
110                         if (Bag ["RemoveIntegerChecks"] != null)
111                                 if (RemoveIntegerChecks)
112                                         commandLine.AppendSwitch ("/removeintchecks+");
113                                 else
114                                         commandLine.AppendSwitch ("/removeintchecks-");
115
116                         if (ResponseFiles != null)
117                                 foreach (ITaskItem item in ResponseFiles)
118                                         commandLine.AppendFileNameIfNotNull (String.Format ("@{0}", item.ItemSpec));
119
120                         commandLine.AppendSwitchIfNotNull ("/rootnamespace:", RootNamespace);
121
122                         commandLine.AppendSwitchIfNotNull ("/sdkpath:", SdkPath);
123
124                         // TargetCompactFramework
125
126                         if (String.Compare (VBRuntime, "Embed", StringComparison.OrdinalIgnoreCase) == 0) 
127                                 commandLine.AppendSwitch ("/vbruntime*");
128                         
129                         // Verbosity
130
131                         // WarningsAsErrors
132
133                         // WarningsNotAsErrors
134
135                 }
136
137                 string EscapeDoubleQuotes (string text)
138                 {
139                         if (text == null)
140                                 return null;
141
142                         return text.Replace ("\"", "\\\"");
143                 }
144                 
145                 [MonoTODO]
146                 protected override bool CallHostObjectToExecute ()
147                 {
148                         throw new NotImplementedException ();
149                 }
150                 
151                 [MonoTODO]
152                 protected override string GenerateFullPathToTool ()
153                 {
154                         if (!string.IsNullOrEmpty (ToolPath))
155                                 return Path.Combine (ToolPath, ToolExe);
156                         var possibleToolPath = ToolLocationHelper.GetPathToDotNetFrameworkFile (ToolExe, TargetDotNetFrameworkVersion.VersionLatest);
157                         if (!string.IsNullOrEmpty(possibleToolPath))
158                                 return  possibleToolPath;
159                         return ToolLocationHelper.GetPathToDotNetFrameworkBinFile(ToolExe); 
160                 }
161                 
162                 [MonoTODO]
163                 protected override HostObjectInitializationStatus InitializeHostObject ()
164                 {
165                         throw new NotImplementedException ();
166                 }
167
168                 [MonoTODO]
169                 protected override bool ValidateParameters ()
170                 {
171                         return true;
172                 }
173
174                 protected override void LogEventsFromTextOutput (string singleLine, MessageImportance messageImportance)
175                 {
176                         singleLine = singleLine.Trim ();
177                         if (singleLine.Length == 0)
178                                 return;
179
180                         // When IncludeDebugInformation is true, prevents the debug symbols stats from braeking this.
181                         if (singleLine.StartsWith ("WROTE SYMFILE") ||
182                                 singleLine.StartsWith ("OffsetTable") ||
183                                 singleLine.StartsWith ("Compilation succeeded") ||
184                                 singleLine.StartsWith ("Compilation failed"))
185                                 return;
186
187                         Match match = ErrorRegex.Match (singleLine);
188                         if (!match.Success) {
189                                 Log.LogMessage (messageImportance, singleLine);
190                                 return;
191                         }
192
193                         string filename = match.Result ("${file}") ?? "";
194
195                         string line = match.Result ("${line}");
196                         int lineNumber = !string.IsNullOrEmpty (line) ? Int32.Parse (line) : 0;
197
198                         string col = match.Result ("${column}");
199                         int columnNumber = 0;
200                         if (!string.IsNullOrEmpty (col))
201                                 columnNumber = col.IndexOf ("+") >= 0 ? -1 : Int32.Parse (col);
202
203                         string category = match.Result ("${level}");
204                         string code = match.Result ("${number}");
205                         string text = match.Result ("${message}");
206
207                         if (String.Compare (category, "warning", StringComparison.OrdinalIgnoreCase) == 0) {
208                                 Log.LogWarning (null, code, null, filename, lineNumber, columnNumber, -1,
209                                         -1, text, null);
210                         } else if (String.Compare (category, "error", StringComparison.OrdinalIgnoreCase) == 0) {
211                                 Log.LogError (null, code, null, filename, lineNumber, columnNumber, -1,
212                                         -1, text, null);
213                         } else {
214                                 Log.LogMessage (messageImportance, singleLine);
215                         }
216                 }
217
218                 [MonoTODO]
219                 public string BaseAddress {
220                         get { return (string) Bag ["BaseAddress"]; }
221                         set { Bag ["BaseAddress"] = value; }
222                 }
223                 
224                 [MonoTODO]
225                 public string DisabledWarnings  {
226                         get { return (string) Bag ["DisabledWarnings"]; }
227                         set { Bag ["DisabledWarnings"] = value; }
228                 }
229                 
230                 [MonoTODO]
231                 public string DocumentationFile {
232                         get { return (string) Bag ["DocumentationFile"]; }
233                         set { Bag ["DocumentationFile"] = value; }
234                 }
235                 
236                 [MonoTODO]
237                 public string ErrorReport {
238                         get { return (string) Bag ["ErrorReport"]; }
239                         set { Bag ["ErrorReport"] = value; }
240                 }
241                 
242                 [MonoTODO]
243                 public bool GenerateDocumentation {
244                         get { return GetBoolParameterWithDefault ("GenerateDocumentation", false); }
245                         set { Bag ["GenerateDocumentation"] = value; }
246                 }
247                 
248                 [MonoTODO]
249                 public ITaskItem [] Imports {
250                         get { return (ITaskItem []) Bag ["Imports"]; }
251                         set { Bag ["Imports"] = value; }
252                 }
253                 
254                 [MonoTODO]
255                 public bool NoStandardLib {
256                         get { return GetBoolParameterWithDefault ("NoStandardLib", false); }
257                         set { Bag ["NoStandardLib"] = value; }
258                 }
259                 
260                 [MonoTODO]
261                 public bool NoWarnings {
262                         get { return GetBoolParameterWithDefault ("NoWarnings", false); }
263                         set { Bag ["NoWarnings"] = value; }
264                 }
265                 
266                 [MonoTODO]
267                 public string OptionCompare {
268                         get { return (string) Bag ["OptionCompare"]; }
269                         set { Bag ["OptionCompare"] = value; }
270                 }
271                 
272                 [MonoTODO]
273                 public bool OptionExplicit {
274                         get { return GetBoolParameterWithDefault ("OptionExplicit", false); }
275                         set { Bag ["OpExplicit"] = value; }
276                 }
277                 
278                 [MonoTODO]
279                 public bool OptionStrict {
280                         get { return GetBoolParameterWithDefault ("OptionStrict", false); }
281                         set { Bag ["OptionStrict"] = value; }
282                 }
283                 
284                 [MonoTODO]
285                 public string OptionStrictType {
286                         get { return (string) Bag ["OptionStrictType"]; }
287                         set { Bag ["OptionStrictType"] = value; }
288                 }
289
290                 [MonoTODO]
291                 public bool OptionInfer {
292                         get { return GetBoolParameterWithDefault ("OptionInfer", false); }
293                         set { Bag ["OptionInfer"] = value; }
294                 }
295                 
296                 [MonoTODO]
297                 public string Platform {
298                         get { return (string) Bag ["Platfrom"]; }
299                         set { Bag ["Platform"] = value; }
300                 }
301                 
302                 [MonoTODO]
303                 public bool RemoveIntegerChecks {
304                         get { return GetBoolParameterWithDefault ("RemoveIntegerChecks", false); }
305                         set { Bag ["RemoveIntegerChecks"] = value; }
306                 }
307
308                 [MonoTODO]
309                 public string RootNamespace {
310                         get { return (string) Bag ["RootNamespace"]; }
311                         set { Bag ["RootNamespace"] = value; }
312                 }
313
314                 [MonoTODO]
315                 public string SdkPath {
316                         get { return (string) Bag ["SdkPath"]; }
317                         set { Bag ["SdkPath"] = value; }
318                 }
319
320                 [MonoTODO]
321                 public bool TargetCompactFramework {
322                         get { return (bool) Bag ["TargetCompactFramework"]; }
323                         set { Bag ["TargetCompactFramework"] = value; }
324                 }
325
326                 [MonoTODO]
327                 protected override string ToolName {
328                         get {
329                                 return MSBuildUtils.RunningOnWindows ? "vbnc.bat" : "vbnc";
330                         }
331                 }
332
333                 [MonoTODO]
334                 public bool UseHostCompilerIfAvailable {
335                         get { return (bool) Bag ["UseHostCompilerIfAvailable"]; }
336                         set { Bag ["UseHostCompilerIfAvailable"] = value; }
337                 }
338
339                 [MonoTODO]
340                 public string VBRuntime {
341                         get { return (string) Bag ["VBRuntime"]; }
342                         set { Bag ["VBRuntime"] = value; }
343                 }
344
345                 [MonoTODO]
346                 public string Verbosity {
347                         get { return (string) Bag ["Verbosity"]; }
348                         set { Bag ["Verbosity"] = value; }
349                 }
350
351                 [MonoTODO]
352                 public string WarningsAsErrors {
353                         get { return (string) Bag ["WarningsAsErrors"]; }
354                         set { Bag ["WarningsAsErrors"] = value; }
355                 }
356                 
357                 [MonoTODO]
358                 public string WarningsNotAsErrors {
359                         get { return (string) Bag ["WarningsNotAsErrors"]; }
360                         set { Bag ["WarningsNotAsErrors"] = value; }
361                 }
362
363                 // from md's VBBindingCompilerServices.cs
364                 //matches "/home/path/Default.aspx.vb (40,31) : Error VBNC30205: Expected end of statement."
365                 //and "Error : VBNC99999: vbnc crashed nearby this location in the source code."
366                 //and "Error : VBNC99999: Unexpected error: Object reference not set to an instance of an object"
367                 static Regex errorRegex;
368                 static Regex ErrorRegex {
369                         get {
370                                 if (errorRegex == null)
371                                         errorRegex = new Regex (@"^\s*((?<file>.*)\s?\((?<line>\d*)(,(?<column>\d*))?\) : )?(?<level>\w+) :? ?(?<number>[^:]*): (?<message>.*)$", RegexOptions.Compiled | RegexOptions.ExplicitCapture);
372                                 return errorRegex;
373                         }
374                 }
375
376         }
377 }
378