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