Merge pull request #1156 from felfert/master
[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                         
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                         if (!string.IsNullOrEmpty (ToolPath))
144                                 return Path.Combine (ToolPath, ToolExe);
145                         return ToolLocationHelper.GetPathToDotNetFrameworkFile (ToolExe, TargetDotNetFrameworkVersion.VersionLatest);
146                 }
147                 
148                 [MonoTODO]
149                 protected override HostObjectInitializationStatus InitializeHostObject ()
150                 {
151                         throw new NotImplementedException ();
152                 }
153
154                 [MonoTODO]
155                 protected override bool ValidateParameters ()
156                 {
157                         return true;
158                 }
159
160                 protected override void LogEventsFromTextOutput (string singleLine, MessageImportance messageImportance)
161                 {
162                         singleLine = singleLine.Trim ();
163                         if (singleLine.Length == 0)
164                                 return;
165
166                         // When IncludeDebugInformation is true, prevents the debug symbols stats from braeking this.
167                         if (singleLine.StartsWith ("WROTE SYMFILE") ||
168                                 singleLine.StartsWith ("OffsetTable") ||
169                                 singleLine.StartsWith ("Compilation succeeded") ||
170                                 singleLine.StartsWith ("Compilation failed"))
171                                 return;
172
173                         Match match = ErrorRegex.Match (singleLine);
174                         if (!match.Success) {
175                                 Log.LogMessage (messageImportance, singleLine);
176                                 return;
177                         }
178
179                         string filename = match.Result ("${file}") ?? "";
180
181                         string line = match.Result ("${line}");
182                         int lineNumber = !string.IsNullOrEmpty (line) ? Int32.Parse (line) : 0;
183
184                         string col = match.Result ("${column}");
185                         int columnNumber = 0;
186                         if (!string.IsNullOrEmpty (col))
187                                 columnNumber = col.IndexOf ("+") >= 0 ? -1 : Int32.Parse (col);
188
189                         string category = match.Result ("${level}");
190                         string code = match.Result ("${number}");
191                         string text = match.Result ("${message}");
192
193                         if (String.Compare (category, "warning", StringComparison.OrdinalIgnoreCase) == 0) {
194                                 Log.LogWarning (null, code, null, filename, lineNumber, columnNumber, -1,
195                                         -1, text, null);
196                         } else if (String.Compare (category, "error", StringComparison.OrdinalIgnoreCase) == 0) {
197                                 Log.LogError (null, code, null, filename, lineNumber, columnNumber, -1,
198                                         -1, text, null);
199                         } else {
200                                 Log.LogMessage (messageImportance, singleLine);
201                         }
202                 }
203
204                 [MonoTODO]
205                 public string BaseAddress {
206                         get { return (string) Bag ["BaseAddress"]; }
207                         set { Bag ["BaseAddress"] = value; }
208                 }
209                 
210                 [MonoTODO]
211                 public string DisabledWarnings  {
212                         get { return (string) Bag ["DisabledWarnings"]; }
213                         set { Bag ["DisabledWarnings"] = value; }
214                 }
215                 
216                 [MonoTODO]
217                 public string DocumentationFile {
218                         get { return (string) Bag ["DocumentationFile"]; }
219                         set { Bag ["DocumentationFile"] = value; }
220                 }
221                 
222                 [MonoTODO]
223                 public string ErrorReport {
224                         get { return (string) Bag ["ErrorReport"]; }
225                         set { Bag ["ErrorReport"] = value; }
226                 }
227                 
228                 [MonoTODO]
229                 public bool GenerateDocumentation {
230                         get { return GetBoolParameterWithDefault ("GenerateDocumentation", false); }
231                         set { Bag ["GenerateDocumentation"] = value; }
232                 }
233                 
234                 [MonoTODO]
235                 public ITaskItem [] Imports {
236                         get { return (ITaskItem []) Bag ["Imports"]; }
237                         set { Bag ["Imports"] = value; }
238                 }
239                 
240                 [MonoTODO]
241                 public bool NoStandardLib {
242                         get { return GetBoolParameterWithDefault ("NoStandardLib", false); }
243                         set { Bag ["NoStandardLib"] = value; }
244                 }
245                 
246                 [MonoTODO]
247                 public bool NoWarnings {
248                         get { return GetBoolParameterWithDefault ("NoWarnings", false); }
249                         set { Bag ["NoWarnings"] = value; }
250                 }
251                 
252                 [MonoTODO]
253                 public string OptionCompare {
254                         get { return (string) Bag ["OptionCompare"]; }
255                         set { Bag ["OptionCompare"] = value; }
256                 }
257                 
258                 [MonoTODO]
259                 public bool OptionExplicit {
260                         get { return GetBoolParameterWithDefault ("OptionExplicit", false); }
261                         set { Bag ["OpExplicit"] = value; }
262                 }
263                 
264                 [MonoTODO]
265                 public bool OptionStrict {
266                         get { return GetBoolParameterWithDefault ("OptionStrict", false); }
267                         set { Bag ["OptionStrict"] = value; }
268                 }
269                 
270                 [MonoTODO]
271                 public string OptionStrictType {
272                         get { return (string) Bag ["OptionStrictType"]; }
273                         set { Bag ["OptionStrictType"] = value; }
274                 }
275                 
276                 [MonoTODO]
277                 public string Platform {
278                         get { return (string) Bag ["Platfrom"]; }
279                         set { Bag ["Platform"] = value; }
280                 }
281                 
282                 [MonoTODO]
283                 public bool RemoveIntegerChecks {
284                         get { return GetBoolParameterWithDefault ("RemoveIntegerChecks", false); }
285                         set { Bag ["RemoveIntegerChecks"] = value; }
286                 }
287
288                 [MonoTODO]
289                 public string RootNamespace {
290                         get { return (string) Bag ["RootNamespace"]; }
291                         set { Bag ["RootNamespace"] = value; }
292                 }
293
294                 [MonoTODO]
295                 public string SdkPath {
296                         get { return (string) Bag ["SdkPath"]; }
297                         set { Bag ["SdkPath"] = value; }
298                 }
299
300                 [MonoTODO]
301                 public bool TargetCompactFramework {
302                         get { return (bool) Bag ["TargetCompactFramework"]; }
303                         set { Bag ["TargetCompactFramework"] = value; }
304                 }
305
306                 [MonoTODO]
307                 protected override string ToolName {
308                         get {
309                                 return MSBuildUtils.RunningOnWindows ? "vbnc.bat" : "vbnc";
310                         }
311                 }
312
313                 [MonoTODO]
314                 public bool UseHostCompilerIfAvailable {
315                         get { return (bool) Bag ["UseHostCompilerIfAvailable"]; }
316                         set { Bag ["UseHostCompilerIfAvailable"] = value; }
317                 }
318
319                 [MonoTODO]
320                 public string Verbosity {
321                         get { return (string) Bag ["Verbosity"]; }
322                         set { Bag ["Verbosity"] = value; }
323                 }
324
325                 [MonoTODO]
326                 public string WarningsAsErrors {
327                         get { return (string) Bag ["WarningsAsErrors"]; }
328                         set { Bag ["WarningsAsErrors"] = value; }
329                 }
330                 
331                 [MonoTODO]
332                 public string WarningsNotAsErrors {
333                         get { return (string) Bag ["WarningsNotAsErrors"]; }
334                         set { Bag ["WarningsNotAsErrors"] = value; }
335                 }
336
337                 // from md's VBBindingCompilerServices.cs
338                 //matches "/home/path/Default.aspx.vb (40,31) : Error VBNC30205: Expected end of statement."
339                 //and "Error : VBNC99999: vbnc crashed nearby this location in the source code."
340                 //and "Error : VBNC99999: Unexpected error: Object reference not set to an instance of an object"
341                 static Regex errorRegex;
342                 static Regex ErrorRegex {
343                         get {
344                                 if (errorRegex == null)
345                                         errorRegex = new Regex (@"^\s*((?<file>.*)\s?\((?<line>\d*)(,(?<column>\d*))?\) : )?(?<level>\w+) :? ?(?<number>[^:]*): (?<message>.*)$", RegexOptions.Compiled | RegexOptions.ExplicitCapture);
346                                 return errorRegex;
347                         }
348                 }
349
350         }
351 }
352