2 // ManagedCompiler.cs: Task for compilers
5 // Marek Sieradzki (marek.sieradzki@gmail.com)
7 // (C) 2005 Marek Sieradzki
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Collections;
34 using Microsoft.Build.Framework;
36 namespace Microsoft.Build.Tasks {
37 public abstract class ManagedCompiler : ToolTaskExtension {
39 protected ManagedCompiler ()
44 protected internal override void AddCommandLineCommands (
45 CommandLineBuilderExtension commandLine)
50 protected internal override void AddResponseFileCommands (
51 CommandLineBuilderExtension commandLine)
53 commandLine.AppendSwitchIfNotNull ("/lib:", AdditionalLibPaths, ",");
54 commandLine.AppendSwitchIfNotNull ("/addmodule:", AddModules, ",");
55 //commandLine.AppendSwitchIfNotNull ("/codepage:", CodePage.ToString ());
57 commandLine.AppendSwitchIfNotNull ("/define:", DefineConstants);
59 if (EmitDebugInformation)
60 commandLine.AppendSwitch ("/debug");
62 commandLine.AppendSwitchIfNotNull ("/keycontainer:", KeyContainer);
63 commandLine.AppendSwitchIfNotNull ("/keyfile:", KeyFile);
64 // FIXME: add ids from metadata
65 if (LinkResources != null) {
66 foreach (ITaskItem item in LinkResources) {
67 commandLine.AppendSwitchIfNotNull ("/linkresource:", item.ItemSpec);
70 commandLine.AppendSwitchIfNotNull ("/main:", MainEntryPoint);
72 commandLine.AppendSwitch ("/noconfig");
74 commandLine.AppendSwitch ("/optimize");
75 if (OutputAssembly != null)
76 commandLine.AppendSwitchIfNotNull ("/out:", OutputAssembly.ItemSpec);
77 if (References != null) {
78 foreach (ITaskItem item in References) {
79 commandLine.AppendSwitchIfNotNull ("/reference:", item.ItemSpec);
82 if (Resources != null) {
83 foreach (ITaskItem item in Resources) {
84 commandLine.AppendSwitchIfNotNull ("/resource:", item.ItemSpec);
87 if (ResponseFiles != null) {
88 foreach (ITaskItem item in ResponseFiles) {
89 commandLine.AppendFileNameIfNotNull (String.Format ("@{0}",item.ItemSpec));
92 if (Sources != null) {
93 foreach (ITaskItem item in Sources) {
94 commandLine.AppendFileNameIfNotNull (item.ItemSpec);
97 if (TargetType != null)
98 commandLine.AppendSwitchIfNotNull ("/target:", TargetType);
99 if (TreatWarningsAsErrors)
100 commandLine.AppendSwitch ("/warnaserror");
101 commandLine.AppendSwitchIfNotNull ("/win32icon:", Win32Icon);
102 commandLine.AppendSwitchIfNotNull ("/win32res:", Win32Resource);
106 protected bool CheckAllReferencesExistOnDisk ()
108 foreach (ITaskItem item in (ITaskItem[])Bag ["References"])
109 if (File.Exists (item.GetMetadata ("FullPath")) == false)
115 protected void CheckHostObjectSupport (string parameterName,
116 bool resultFromHostObjectSetOperation)
121 protected override bool HandleTaskExecutionErrors ()
127 protected bool ListHasNoDuplicateItems (ITaskItem[] itemList,
128 string parameterName)
130 Hashtable items = new Hashtable ();
132 foreach (ITaskItem item in itemList) {
133 if (items.Contains (item.ItemSpec))
134 items.Add (item.ItemSpec, null);
143 protected override bool ValidateParameters ()
148 public string[] AdditionalLibPaths {
149 get { return (string[]) Bag ["AdditionalLibPaths"]; }
150 set { Bag ["AdditionalLibPaths"] = value; }
153 public string[] AddModules {
154 get { return (string[]) Bag ["AddModules"]; }
155 set { Bag ["AddModules"] = value; }
158 public int CodePage {
159 get { return GetIntParameterWithDefault ("CodePage", 0); }
160 set { Bag ["CodePage"] = value; }
163 public string DebugType {
164 get { return (string) Bag ["DebugType"]; }
165 set { Bag ["DebugType"] = value; }
168 public string DefineConstants {
169 get { return (string) Bag ["DefineConstants"]; }
170 set { Bag ["DefineConstants"] = value; }
173 public bool DelaySign {
174 get { return GetBoolParameterWithDefault ("DelaySign", false); }
175 set { Bag ["DelaySign"] = value; }
178 public bool EmitDebugInformation {
179 get { return GetBoolParameterWithDefault ("EmitDebugInformation", false); }
180 set { Bag ["EmitDebugInformation"] = value; }
183 public int FileAlignment {
184 get { return GetIntParameterWithDefault ("FileAlignment", 0); }
185 set { Bag ["FileAlignment"] = value; }
188 protected bool HostCompilerSupportsAllParameters {
190 set { Bag ["HostCompilerSupportsAllParameters"] = value; }
193 public string KeyContainer {
194 get { return (string) Bag ["KeyContainer"]; }
195 set { Bag ["KeyContainer"] = value; }
198 public string KeyFile {
199 get { return (string) Bag ["KeyFile"]; }
200 set { Bag ["KeyFile"] = value; }
203 public ITaskItem[] LinkResources {
204 get { return (ITaskItem[]) Bag ["LinkResources"]; }
205 set { Bag ["LinkResources"] = value; }
208 public string MainEntryPoint {
209 get { return (string) Bag ["MainEntryPoint"]; }
210 set { Bag ["MainEntryPoint"] = value; }
213 public bool NoConfig {
214 get { return GetBoolParameterWithDefault ("NoConfig", false); }
215 set { Bag ["NoConfig"] = value; }
219 get { return GetBoolParameterWithDefault ("NoLogo", false); }
220 set { Bag ["NoLogo"] = value; }
223 public bool Optimize {
224 get { return GetBoolParameterWithDefault ("Optimize", false); }
225 set { Bag ["Optimize"] = value; }
229 public ITaskItem OutputAssembly {
230 get { return (ITaskItem) Bag ["OutputAssembly"]; }
231 set { Bag ["OutputAssembly"] = value; }
234 public ITaskItem[] References {
235 get { return (ITaskItem[]) Bag ["References"]; }
236 set { Bag ["References"] = value; }
239 public ITaskItem[] Resources {
240 get { return (ITaskItem[]) Bag ["Resources"]; }
241 set { Bag ["Resources"] = value; }
244 public ITaskItem[] ResponseFiles {
245 get { return (ITaskItem[]) Bag ["ResponseFiles"]; }
246 set { Bag ["ResponseFiles"] = value; }
249 public ITaskItem[] Sources {
250 get { return (ITaskItem[]) Bag ["Sources"]; }
251 set { Bag ["Sources"] = value; }
254 protected override Encoding StandardOutputEncoding {
255 get { return Console.Error.Encoding; }
258 // FIXME: hack to get build of hello world working
259 public string TargetType {
261 return (Bag.Contains ("TargetType")) ? (((string) Bag ["TargetType"]).ToLower ()) : null;
263 set { Bag ["TargetType"] = value; }
266 public bool TreatWarningsAsErrors {
267 get { return GetBoolParameterWithDefault ("TreatWarningsAsErrors", false); }
268 set { Bag ["TreatWarningsAsErrors"] = value; }
271 public bool Utf8Output {
272 get { return GetBoolParameterWithDefault ("Utf8Output", false); }
273 set { Bag ["Utf8Output"] = value; }
276 public string Win32Icon {
277 get { return (string) Bag ["Win32Icon"]; }
278 set { Bag ["Win32Icon"] = value; }
281 public string Win32Resource {
282 get { return (string) Bag ["Win32Resource"]; }
283 set { Bag ["Win32Resource"] = value; }