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;
38 using Mono.XBuild.Utilities;
40 namespace Microsoft.Build.Tasks {
42 public class Vbc : ManagedCompiler {
49 protected internal override void AddResponseFileCommands (
50 CommandLineBuilderExtension commandLine )
52 base.AddResponseFileCommands (commandLine);
54 commandLine.AppendSwitchIfNotNull ("/libpath:", AdditionalLibPaths, ",");
56 commandLine.AppendSwitchIfNotNull ("/baseaddress:", BaseAddress);
58 if (DefineConstants != null)
59 commandLine.AppendSwitchUnquotedIfNotNull ("/define:",
60 String.Format ("\"{0}\"", EscapeDoubleQuotes (DefineConstants)));
64 commandLine.AppendSwitchIfNotNull ("/doc:", DocumentationFile);
68 // GenerateDocumentation
71 foreach (ITaskItem item in Imports)
72 commandLine.AppendSwitchIfNotNull ("/imports:", item.ItemSpec);
74 commandLine.AppendSwitchIfNotNull ("/main:", MainEntryPoint);
79 commandLine.AppendSwitch ("/nowarn");
81 commandLine.AppendSwitchIfNotNull ("/optioncompare:", OptionCompare);
83 if (Bag ["OptionExplicit"] != null)
85 commandLine.AppendSwitch ("/optionexplicit+");
87 commandLine.AppendSwitch ("/optionexplicit-");
89 if (Bag ["OptionStrict"] != null)
91 commandLine.AppendSwitch ("/optionstrict+");
93 commandLine.AppendSwitch ("/optionstrict-");
99 if (References != null)
100 foreach (ITaskItem item in References)
101 commandLine.AppendSwitchIfNotNull ("/reference:", item.ItemSpec);
103 if (Bag ["RemoveIntegerChecks"] != null)
104 if (RemoveIntegerChecks)
105 commandLine.AppendSwitch ("/removeintchecks+");
107 commandLine.AppendSwitch ("/removeintchecks-");
109 if (ResponseFiles != null)
110 foreach (ITaskItem item in ResponseFiles)
111 commandLine.AppendFileNameIfNotNull (String.Format ("@{0}", item.ItemSpec));
113 commandLine.AppendSwitchIfNotNull ("/rootnamespace:", RootNamespace);
115 commandLine.AppendSwitchIfNotNull ("/sdkpath:", SdkPath);
117 // TargetCompactFramework
123 // WarningsNotAsErrors
127 string EscapeDoubleQuotes (string text)
132 return text.Replace ("\"", "\\\"");
136 protected override bool CallHostObjectToExecute ()
138 throw new NotImplementedException ();
142 protected override string GenerateFullPathToTool ()
144 return Path.Combine (ToolPath, ToolExe);
148 protected override HostObjectInitializationStatus InitializeHostObject ()
150 throw new NotImplementedException ();
154 protected override bool ValidateParameters ()
159 protected override void LogEventsFromTextOutput (string singleLine, MessageImportance importance)
161 singleLine = singleLine.Trim ();
162 if (singleLine.Length == 0)
165 // When IncludeDebugInformation is true, prevents the debug symbols stats from braeking this.
166 if (singleLine.StartsWith ("WROTE SYMFILE") ||
167 singleLine.StartsWith ("OffsetTable") ||
168 singleLine.StartsWith ("Compilation succeeded") ||
169 singleLine.StartsWith ("Compilation failed"))
172 Match match = ErrorRegex.Match (singleLine);
173 if (!match.Success) {
174 Log.LogMessage (importance, singleLine);
178 string filename = match.Result ("${file}") ?? "";
180 string line = match.Result ("${line}");
181 int lineNumber = !string.IsNullOrEmpty (line) ? Int32.Parse (line) : 0;
183 string col = match.Result ("${column}");
184 int columnNumber = 0;
185 if (!string.IsNullOrEmpty (col))
186 columnNumber = col == "255+" ? -1 : Int32.Parse (col);
188 string category = match.Result ("${level}");
189 string code = match.Result ("${number}");
190 string text = match.Result ("${message}");
192 if (String.Compare (category, "warning", StringComparison.OrdinalIgnoreCase) == 0) {
193 Log.LogWarning (null, code, null, filename, lineNumber, columnNumber, -1,
195 } else if (String.Compare (category, "error", StringComparison.OrdinalIgnoreCase) == 0) {
196 Log.LogError (null, code, null, filename, lineNumber, columnNumber, -1,
199 Log.LogMessage (importance, singleLine);
204 public string BaseAddress {
205 get { return (string) Bag ["BaseAddress"]; }
206 set { Bag ["BaseAddress"] = value; }
210 public string DisabledWarnings {
211 get { return (string) Bag ["DisabledWarnings"]; }
212 set { Bag ["DisabledWarnings"] = value; }
216 public string DocumentationFile {
217 get { return (string) Bag ["DocumentationFile"]; }
218 set { Bag ["DocumentationFile"] = value; }
222 public string ErrorReport {
223 get { return (string) Bag ["ErrorReport"]; }
224 set { Bag ["ErrorReport"] = value; }
228 public bool GenerateDocumentation {
229 get { return GetBoolParameterWithDefault ("GenerateDocumentation", false); }
230 set { Bag ["GenerateDocumentation"] = value; }
234 public ITaskItem [] Imports {
235 get { return (ITaskItem []) Bag ["Imports"]; }
236 set { Bag ["Imports"] = value; }
240 public bool NoStandardLib {
241 get { return GetBoolParameterWithDefault ("NoStandardLib", false); }
242 set { Bag ["NoStandardLib"] = value; }
246 public bool NoWarnings {
247 get { return GetBoolParameterWithDefault ("NoWarnings", false); }
248 set { Bag ["NoWarnings"] = value; }
252 public string OptionCompare {
253 get { return (string) Bag ["OptionCompare"]; }
254 set { Bag ["OptionCompare"] = value; }
258 public bool OptionExplicit {
259 get { return GetBoolParameterWithDefault ("OptionExplicit", false); }
260 set { Bag ["OpExplicit"] = value; }
264 public bool OptionStrict {
265 get { return GetBoolParameterWithDefault ("OptionStrict", false); }
266 set { Bag ["OptionStrict"] = value; }
270 public string OptionStrictType {
271 get { return (string) Bag ["OptionStrictType"]; }
272 set { Bag ["OptionStrictType"] = value; }
276 public string Platform {
277 get { return (string) Bag ["Platfrom"]; }
278 set { Bag ["Platform"] = value; }
282 public bool RemoveIntegerChecks {
283 get { return GetBoolParameterWithDefault ("RemoveIntegerChecks", false); }
284 set { Bag ["RemoveIntegerChecks"] = value; }
288 public string RootNamespace {
289 get { return (string) Bag ["RootNamespace"]; }
290 set { Bag ["RootNamespace"] = value; }
294 public string SdkPath {
295 get { return (string) Bag ["SdkPath"]; }
296 set { Bag ["SdkPath"] = value; }
300 public bool TargetCompactFramework {
301 get { return (bool) Bag ["TargetCompactFramework"]; }
302 set { Bag ["TargetCompactFramework"] = value; }
306 protected override string ToolName {
307 get { return MSBuildUtils.RunningOnWindows ? "vbnc.bat" : "vbnc"; }
311 public bool UseHostCompilerIfAvailable {
312 get { return (bool) Bag ["UseHostCompilerIfAvailable"]; }
313 set { Bag ["UseHostCompilerIfAvailable"] = value; }
317 public string Verbosity {
318 get { return (string) Bag ["Verbosity"]; }
319 set { Bag ["Verbosity"] = value; }
323 public string WarningsAsErrors {
324 get { return (string) Bag ["WarningsAsErrors"]; }
325 set { Bag ["WarningsAsErrors"] = value; }
329 public string WarningsNotAsErrors {
330 get { return (string) Bag ["WarningsNotAsErrors"]; }
331 set { Bag ["WarningsNotAsErrors"] = value; }
334 // from md's VBBindingCompilerServices.cs
335 //matches "/home/path/Default.aspx.vb (40,31) : Error VBNC30205: Expected end of statement."
336 //and "Error : VBNC99999: vbnc crashed nearby this location in the source code."
337 //and "Error : VBNC99999: Unexpected error: Object reference not set to an instance of an object"
338 static Regex errorRegex;
339 static Regex ErrorRegex {
341 if (errorRegex == null)
342 errorRegex = new Regex (@"^\s*((?<file>.*)\s?\((?<line>\d*)(,(?<column>\d*))?\) : )?(?<level>\w+) :? ?(?<number>[^:]*): (?<message>.*)$", RegexOptions.Compiled | RegexOptions.ExplicitCapture);