5 // Leszek Ciesielski <skolima@gmail.com>
6 // Marek Sieradzki <marek.sieradzki@gmail.com>
8 // Copyright (C) 2006 Forcom (http://www.forcom.com.pl/)
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
34 using System.Text.RegularExpressions;
36 using Microsoft.Build.Framework;
37 using Microsoft.Build.Utilities;
39 namespace Microsoft.Build.Tasks {
41 public class Vbc : ManagedCompiler {
48 protected internal override void AddResponseFileCommands (
49 CommandLineBuilderExtension commandLine )
51 base.AddResponseFileCommands (commandLine);
53 commandLine.AppendSwitchIfNotNull ("/libpath:", AdditionalLibPaths, ",");
55 commandLine.AppendSwitchIfNotNull ("/baseaddress:", BaseAddress);
57 if (DefineConstants != null)
58 commandLine.AppendSwitchUnquotedIfNotNull ("/define:",
59 String.Format ("\"{0}\"", EscapeDoubleQuotes (DefineConstants)));
63 commandLine.AppendSwitchIfNotNull ("/doc:", DocumentationFile);
67 // GenerateDocumentation
70 foreach (ITaskItem item in Imports)
71 commandLine.AppendSwitchIfNotNull ("/imports:", item.ItemSpec);
73 commandLine.AppendSwitchIfNotNull ("/main:", MainEntryPoint);
78 commandLine.AppendSwitch ("/nowarn");
80 commandLine.AppendSwitchIfNotNull ("/optioncompare:", OptionCompare);
82 if (Bag ["OptionExplicit"] != null)
84 commandLine.AppendSwitch ("/optionexplicit+");
86 commandLine.AppendSwitch ("/optionexplicit-");
88 if (Bag ["OptionStrict"] != null)
90 commandLine.AppendSwitch ("/optionstrict+");
92 commandLine.AppendSwitch ("/optionstrict-");
98 if (References != null)
99 foreach (ITaskItem item in References)
100 commandLine.AppendSwitchIfNotNull ("/reference:", item.ItemSpec);
102 if (Bag ["RemoveIntegerChecks"] != null)
103 if (RemoveIntegerChecks)
104 commandLine.AppendSwitch ("/removeintchecks+");
106 commandLine.AppendSwitch ("/removeintchecks-");
108 if (ResponseFiles != null)
109 foreach (ITaskItem item in ResponseFiles)
110 commandLine.AppendFileNameIfNotNull (String.Format ("@{0}", item.ItemSpec));
112 commandLine.AppendSwitchIfNotNull ("/rootnamespace:", RootNamespace);
114 commandLine.AppendSwitchIfNotNull ("/sdkpath:", SdkPath);
116 // TargetCompactFramework
122 // WarningsNotAsErrors
126 string EscapeDoubleQuotes (string text)
131 return text.Replace ("\"", "\\\"");
135 protected override bool CallHostObjectToExecute ()
137 throw new NotImplementedException ();
141 protected override string GenerateFullPathToTool ()
143 return Path.Combine (ToolPath, ToolExe);
147 protected override HostObjectInitializationStatus InitializeHostObject ()
149 throw new NotImplementedException ();
153 protected override bool ValidateParameters ()
158 protected override void LogEventsFromTextOutput (string singleLine, MessageImportance importance)
160 singleLine = singleLine.Trim ();
161 if (singleLine.Length == 0)
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"))
171 Match match = ErrorRegex.Match (singleLine);
172 if (!match.Success) {
173 Log.LogMessage (importance, singleLine);
177 string filename = match.Result ("${file}") ?? "";
179 string line = match.Result ("${line}");
180 int lineNumber = !string.IsNullOrEmpty (line) ? Int32.Parse (line) : 0;
182 string col = match.Result ("${column}");
183 int columnNumber = 0;
184 if (!string.IsNullOrEmpty (col))
185 columnNumber = col == "255+" ? -1 : Int32.Parse (col);
187 string category = match.Result ("${level}");
188 string code = match.Result ("${number}");
189 string text = match.Result ("${message}");
191 if (String.Compare (category, "warning", StringComparison.OrdinalIgnoreCase) == 0) {
192 Log.LogWarning (null, code, null, filename, lineNumber, columnNumber, -1,
194 } else if (String.Compare (category, "error", StringComparison.OrdinalIgnoreCase) == 0) {
195 Log.LogError (null, code, null, filename, lineNumber, columnNumber, -1,
198 Log.LogMessage (importance, singleLine);
203 public string BaseAddress {
204 get { return (string) Bag ["BaseAddress"]; }
205 set { Bag ["BaseAddress"] = value; }
209 public string DisabledWarnings {
210 get { return (string) Bag ["DisabledWarnings"]; }
211 set { Bag ["DisabledWarnings"] = value; }
215 public string DocumentationFile {
216 get { return (string) Bag ["DocumentationFile"]; }
217 set { Bag ["DocumentationFile"] = value; }
221 public string ErrorReport {
222 get { return (string) Bag ["ErrorReport"]; }
223 set { Bag ["ErrorReport"] = value; }
227 public bool GenerateDocumentation {
228 get { return GetBoolParameterWithDefault ("GenerateDocumentation", false); }
229 set { Bag ["GenerateDocumentation"] = value; }
233 public ITaskItem [] Imports {
234 get { return (ITaskItem []) Bag ["Imports"]; }
235 set { Bag ["Imports"] = value; }
239 public bool NoStandardLib {
240 get { return GetBoolParameterWithDefault ("NoStandardLib", false); }
241 set { Bag ["NoStandardLib"] = value; }
245 public bool NoWarnings {
246 get { return GetBoolParameterWithDefault ("NoWarnings", false); }
247 set { Bag ["NoWarnings"] = value; }
251 public string OptionCompare {
252 get { return (string) Bag ["OptionCompare"]; }
253 set { Bag ["OptionCompare"] = value; }
257 public bool OptionExplicit {
258 get { return GetBoolParameterWithDefault ("OptionExplicit", false); }
259 set { Bag ["OpExplicit"] = value; }
263 public bool OptionStrict {
264 get { return GetBoolParameterWithDefault ("OptionStrict", false); }
265 set { Bag ["OptionStrict"] = value; }
269 public string OptionStrictType {
270 get { return (string) Bag ["OptionStrictType"]; }
271 set { Bag ["OptionStrictType"] = value; }
275 public string Platform {
276 get { return (string) Bag ["Platfrom"]; }
277 set { Bag ["Platform"] = value; }
281 public bool RemoveIntegerChecks {
282 get { return GetBoolParameterWithDefault ("RemoveIntegerChecks", false); }
283 set { Bag ["RemoveIntegerChecks"] = value; }
287 public string RootNamespace {
288 get { return (string) Bag ["RootNamespace"]; }
289 set { Bag ["RootNamespace"] = value; }
293 public string SdkPath {
294 get { return (string) Bag ["SdkPath"]; }
295 set { Bag ["SdkPath"] = value; }
299 public bool TargetCompactFramework {
300 get { return (bool) Bag ["TargetCompactFramework"]; }
301 set { Bag ["TargetCompactFramework"] = value; }
305 protected override string ToolName {
306 get { return Utilities.RunningOnWindows ? "vbnc.bat" : "vbnc"; }
310 public bool UseHostCompilerIfAvailable {
311 get { return (bool) Bag ["UseHostCompilerIfAvailable"]; }
312 set { Bag ["UseHostCompilerIfAvailable"] = value; }
316 public string Verbosity {
317 get { return (string) Bag ["Verbosity"]; }
318 set { Bag ["Verbosity"] = value; }
322 public string WarningsAsErrors {
323 get { return (string) Bag ["WarningsAsErrors"]; }
324 set { Bag ["WarningsAsErrors"] = value; }
328 public string WarningsNotAsErrors {
329 get { return (string) Bag ["WarningsNotAsErrors"]; }
330 set { Bag ["WarningsNotAsErrors"] = value; }
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 {
340 if (errorRegex == null)
341 errorRegex = new Regex (@"^\s*((?<file>.*)\s?\((?<line>\d*)(,(?<column>\d*))?\) : )?(?<level>\w+) :? ?(?<number>[^:]*): (?<message>.*)$", RegexOptions.Compiled | RegexOptions.ExplicitCapture);