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 if (!string.IsNullOrEmpty (ToolPath))
145 return Path.Combine (ToolPath, ToolExe);
146 return ToolLocationHelper.GetPathToDotNetFrameworkFile (ToolExe, TargetDotNetFrameworkVersion.VersionLatest);
150 protected override HostObjectInitializationStatus InitializeHostObject ()
152 throw new NotImplementedException ();
156 protected override bool ValidateParameters ()
161 protected override void LogEventsFromTextOutput (string singleLine, MessageImportance importance)
163 singleLine = singleLine.Trim ();
164 if (singleLine.Length == 0)
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"))
174 Match match = ErrorRegex.Match (singleLine);
175 if (!match.Success) {
176 Log.LogMessage (importance, singleLine);
180 string filename = match.Result ("${file}") ?? "";
182 string line = match.Result ("${line}");
183 int lineNumber = !string.IsNullOrEmpty (line) ? Int32.Parse (line) : 0;
185 string col = match.Result ("${column}");
186 int columnNumber = 0;
187 if (!string.IsNullOrEmpty (col))
188 columnNumber = col.IndexOf ("+") >= 0 ? -1 : Int32.Parse (col);
190 string category = match.Result ("${level}");
191 string code = match.Result ("${number}");
192 string text = match.Result ("${message}");
194 if (String.Compare (category, "warning", StringComparison.OrdinalIgnoreCase) == 0) {
195 Log.LogWarning (null, code, null, filename, lineNumber, columnNumber, -1,
197 } else if (String.Compare (category, "error", StringComparison.OrdinalIgnoreCase) == 0) {
198 Log.LogError (null, code, null, filename, lineNumber, columnNumber, -1,
201 Log.LogMessage (importance, singleLine);
206 public string BaseAddress {
207 get { return (string) Bag ["BaseAddress"]; }
208 set { Bag ["BaseAddress"] = value; }
212 public string DisabledWarnings {
213 get { return (string) Bag ["DisabledWarnings"]; }
214 set { Bag ["DisabledWarnings"] = value; }
218 public string DocumentationFile {
219 get { return (string) Bag ["DocumentationFile"]; }
220 set { Bag ["DocumentationFile"] = value; }
224 public string ErrorReport {
225 get { return (string) Bag ["ErrorReport"]; }
226 set { Bag ["ErrorReport"] = value; }
230 public bool GenerateDocumentation {
231 get { return GetBoolParameterWithDefault ("GenerateDocumentation", false); }
232 set { Bag ["GenerateDocumentation"] = value; }
236 public ITaskItem [] Imports {
237 get { return (ITaskItem []) Bag ["Imports"]; }
238 set { Bag ["Imports"] = value; }
242 public bool NoStandardLib {
243 get { return GetBoolParameterWithDefault ("NoStandardLib", false); }
244 set { Bag ["NoStandardLib"] = value; }
248 public bool NoWarnings {
249 get { return GetBoolParameterWithDefault ("NoWarnings", false); }
250 set { Bag ["NoWarnings"] = value; }
254 public string OptionCompare {
255 get { return (string) Bag ["OptionCompare"]; }
256 set { Bag ["OptionCompare"] = value; }
260 public bool OptionExplicit {
261 get { return GetBoolParameterWithDefault ("OptionExplicit", false); }
262 set { Bag ["OpExplicit"] = value; }
266 public bool OptionStrict {
267 get { return GetBoolParameterWithDefault ("OptionStrict", false); }
268 set { Bag ["OptionStrict"] = value; }
272 public string OptionStrictType {
273 get { return (string) Bag ["OptionStrictType"]; }
274 set { Bag ["OptionStrictType"] = value; }
278 public string Platform {
279 get { return (string) Bag ["Platfrom"]; }
280 set { Bag ["Platform"] = value; }
284 public bool RemoveIntegerChecks {
285 get { return GetBoolParameterWithDefault ("RemoveIntegerChecks", false); }
286 set { Bag ["RemoveIntegerChecks"] = value; }
290 public string RootNamespace {
291 get { return (string) Bag ["RootNamespace"]; }
292 set { Bag ["RootNamespace"] = value; }
296 public string SdkPath {
297 get { return (string) Bag ["SdkPath"]; }
298 set { Bag ["SdkPath"] = value; }
302 public bool TargetCompactFramework {
303 get { return (bool) Bag ["TargetCompactFramework"]; }
304 set { Bag ["TargetCompactFramework"] = value; }
308 protected override string ToolName {
311 return MSBuildUtils.RunningOnWindows ? "vbnc.bat" : "vbnc";
313 return MSBuildUtils.RunningOnWindows ? "vbnc2.bat" : "vbnc2";
319 public bool UseHostCompilerIfAvailable {
320 get { return (bool) Bag ["UseHostCompilerIfAvailable"]; }
321 set { Bag ["UseHostCompilerIfAvailable"] = value; }
325 public string Verbosity {
326 get { return (string) Bag ["Verbosity"]; }
327 set { Bag ["Verbosity"] = value; }
331 public string WarningsAsErrors {
332 get { return (string) Bag ["WarningsAsErrors"]; }
333 set { Bag ["WarningsAsErrors"] = value; }
337 public string WarningsNotAsErrors {
338 get { return (string) Bag ["WarningsNotAsErrors"]; }
339 set { Bag ["WarningsNotAsErrors"] = value; }
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 {
349 if (errorRegex == null)
350 errorRegex = new Regex (@"^\s*((?<file>.*)\s?\((?<line>\d*)(,(?<column>\d*))?\) : )?(?<level>\w+) :? ?(?<number>[^:]*): (?<message>.*)$", RegexOptions.Compiled | RegexOptions.ExplicitCapture);