* TaskLoggingHelperExtensios.cs (.ctor): Mark internal.
[mono.git] / mcs / class / Microsoft.Build.Tasks / Microsoft.Build.Tasks / ManagedCompiler.cs
1 //
2 // ManagedCompiler.cs: Task for compilers
3 //
4 // Author:
5 //   Marek Sieradzki (marek.sieradzki@gmail.com)
6 // 
7 // (C) 2005 Marek Sieradzki
8 //
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:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
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.
27
28 #if NET_2_0
29
30 using System;
31 using System.Collections;
32 using System.Collections.Generic;
33 using System.IO;
34 using System.Text;
35 using Microsoft.Build.Framework;
36 using Microsoft.Build.Utilities;
37
38 namespace Microsoft.Build.Tasks {
39         public abstract class ManagedCompiler : ToolTaskExtension {
40         
41                 protected ManagedCompiler ()
42                 {
43                 }
44
45                 [MonoTODO]
46                 protected internal override void AddCommandLineCommands (
47                                                  CommandLineBuilderExtension commandLine)
48                 {
49                         if (NoConfig)
50                                 commandLine.AppendSwitch ("/noconfig");
51                 }
52
53                 [MonoTODO]
54                 protected internal override void AddResponseFileCommands (
55                                                  CommandLineBuilderExtension commandLine)
56                 {
57                         if (AddModules != null && AddModules.Length > 0)
58                                 commandLine.AppendSwitchIfNotNull ("/addmodule:", AddModules, ",");
59                         if (Bag ["CodePage"] != null)
60                                 commandLine.AppendSwitchIfNotNull ("/codepage:", CodePage.ToString ());
61
62                         commandLine.AppendSwitchIfNotNull ("/debug:", DebugType);
63
64                         if (Bag ["DelaySign"] != null)
65                                 if (DelaySign)
66                                         commandLine.AppendSwitch ("/delaysign+");
67                                 else
68                                         commandLine.AppendSwitch ("/delaysign-");
69                         if (Bag ["EmitDebugInformation"] != null)
70                                 if (EmitDebugInformation)
71                                         commandLine.AppendSwitch ("/debug+");
72                                 else
73                                         commandLine.AppendSwitch ("/debug-");
74                         //fileAlignment
75                         commandLine.AppendSwitchIfNotNull ("/keycontainer:", KeyContainer);
76                         commandLine.AppendSwitchIfNotNull ("/keyfile:", KeyFile);
77                         // FIXME: add ids from metadata
78                         if (LinkResources != null)
79                                 foreach (ITaskItem item in LinkResources)
80                                                 commandLine.AppendSwitchIfNotNull ("/linkresource:", item.ItemSpec);
81                         
82                         if (NoLogo)
83                                 commandLine.AppendSwitch ("/nologo");
84
85                         if (Bag ["Optimize"] != null)
86                                 if (Optimize)
87                                         commandLine.AppendSwitch ("/optimize+");
88                                 else
89                                         commandLine.AppendSwitch ("/optimize-");
90
91                         if (OutputAssembly != null)
92                                 commandLine.AppendSwitchIfNotNull ("/out:", OutputAssembly.ItemSpec);
93                         
94                         if (Resources != null)
95                                 foreach (ITaskItem item in Resources) {
96                                         string logical_name = item.GetMetadata ("LogicalName");
97                                         if (logical_name.Length > 0)
98                                                 commandLine.AppendSwitchIfNotNull ("/resource:",
99                                                                 String.Format ("{0},{1}", item.ItemSpec, logical_name));
100                                         else
101                                                 commandLine.AppendSwitchIfNotNull ("/resource:", item.ItemSpec);
102                                 }
103
104                         if (Sources != null)
105                                 foreach (ITaskItem item in Sources)
106                                                 commandLine.AppendFileNameIfNotNull (item.ItemSpec);
107                         
108                         if (TargetType != null)
109                                 commandLine.AppendSwitchIfNotNull ("/target:", TargetType);
110                         if (Bag ["TreatWarningsAsErrors"] != null)
111                                 if (TreatWarningsAsErrors)
112                                         commandLine.AppendSwitch ("/warnaserror+");
113                                 else
114                                         commandLine.AppendSwitch ("/warnaserror-");
115                         commandLine.AppendSwitchIfNotNull ("/win32icon:", Win32Icon);
116                 }
117
118                 [MonoTODO]
119                 protected bool CheckAllReferencesExistOnDisk ()
120                 {
121                         if (Bag ["References"] != null)
122                                 foreach (ITaskItem item in (ITaskItem[]) Bag ["References"])
123                                         if (!File.Exists (item.GetMetadata ("FullPath")))
124                                                 return false;
125                         return true;
126                 }
127
128                 [MonoTODO]
129                 protected void CheckHostObjectSupport (string parameterName,
130                                                        bool resultFromHostObjectSetOperation)
131                 {
132                 }
133                 
134                 [MonoTODO]
135                 protected override bool HandleTaskExecutionErrors ()
136                 {
137                         return ExitCode == 0 && !Log.HasLoggedErrors;
138                 }
139                 
140                 [MonoTODO]
141                 protected bool ListHasNoDuplicateItems (ITaskItem [] itemList,
142                                                         string parameterName)
143                 {
144                         Dictionary <string, object> items = new Dictionary <string, object> ();
145                         
146                         foreach (ITaskItem item in itemList) {
147                                 if (!items.ContainsKey (item.ItemSpec))
148                                         items.Add (item.ItemSpec, null);
149                                 else
150                                         return false;
151                         }
152                         
153                         return true;
154                 }
155
156                 [MonoTODO]
157                 protected override bool ValidateParameters ()
158                 {
159                         return true;
160                 }
161
162                 public string[] AdditionalLibPaths {
163                         get { return (string[]) Bag ["AdditionalLibPaths"]; }
164                         set { Bag ["AdditionalLibPaths"] = value; }
165                 }
166
167                 public string[] AddModules {
168                         get { return (string[]) Bag ["AddModules"]; }
169                         set { Bag ["AddModules"] = value; }
170                 }
171
172                 public int CodePage {
173                         get { return GetIntParameterWithDefault ("CodePage", 0); }
174                         set { Bag ["CodePage"] = value; }
175                 }
176
177                 public string DebugType {
178                         get { return (string) Bag ["DebugType"]; }
179                         set { Bag ["DebugType"] = value; }
180                 }
181
182                 public string DefineConstants {
183                         get { return (string) Bag ["DefineConstants"]; }
184                         set { Bag ["DefineConstants"] = value; }
185                 }
186
187                 public bool DelaySign {
188                         get { return GetBoolParameterWithDefault ("DelaySign", false); }
189                         set { Bag ["DelaySign"] = value; }
190                 }
191
192                 public bool EmitDebugInformation {
193                         get { return GetBoolParameterWithDefault ("EmitDebugInformation", false); }
194                         set { Bag ["EmitDebugInformation"] = value; }
195                 }
196
197                 public int FileAlignment {
198                         get { return GetIntParameterWithDefault ("FileAlignment", 0); }
199                         set { Bag ["FileAlignment"] = value; }
200                 }
201
202                 protected bool HostCompilerSupportsAllParameters {
203                         get { return true; }
204                         set { Bag ["HostCompilerSupportsAllParameters"] = value; }
205                 }
206
207                 public string KeyContainer {
208                         get { return (string) Bag ["KeyContainer"]; }
209                         set { Bag ["KeyContainer"] = value; }
210                 }
211
212                 public string KeyFile {
213                         get { return (string) Bag ["KeyFile"]; }
214                         set { Bag ["KeyFile"] = value; }
215                 }
216
217                 public ITaskItem[] LinkResources {
218                         get { return (ITaskItem[]) Bag ["LinkResources"]; }
219                         set { Bag ["LinkResources"] = value; }
220                 }
221
222                 public string MainEntryPoint {
223                         get { return (string) Bag ["MainEntryPoint"]; }
224                         set { Bag ["MainEntryPoint"] = value; }
225                 }
226
227                 public bool NoConfig {
228                         get { return GetBoolParameterWithDefault ("NoConfig", false); }
229                         set { Bag ["NoConfig"] = value; }
230                 }
231
232                 public bool NoLogo {
233                         get { return GetBoolParameterWithDefault ("NoLogo", false); }
234                         set { Bag ["NoLogo"] = value; }
235                 }
236
237                 public bool Optimize {
238                         get { return GetBoolParameterWithDefault ("Optimize", false); }
239                         set { Bag ["Optimize"] = value; }
240                 }
241
242                 [Output]
243                 public ITaskItem OutputAssembly {
244                         get { return (ITaskItem) Bag ["OutputAssembly"]; }
245                         set { Bag ["OutputAssembly"] = value; }
246                 }
247
248                 public ITaskItem[] References {
249                         get { return (ITaskItem[]) Bag ["References"]; }
250                         set { Bag ["References"] = value; }
251                 }
252
253                 public ITaskItem[] Resources {
254                         get { return (ITaskItem[]) Bag ["Resources"]; }
255                         set { Bag ["Resources"] = value; }
256                 }
257
258                 public ITaskItem[] ResponseFiles {
259                         get { return (ITaskItem[]) Bag ["ResponseFiles"]; }
260                         set { Bag ["ResponseFiles"] = value; }
261                 }
262
263                 public ITaskItem[] Sources {
264                         get { return (ITaskItem[]) Bag ["Sources"]; }
265                         set {
266                                 Bag ["Sources"] = value;
267                                 if (Bag ["OutputAssembly"] == null && value != null && value.Length >= 1)
268                                         Bag ["OutputAssembly"] = new TaskItem (String.Format ("{0}.exe", value [0].ItemSpec));
269                         }
270                 }
271
272                 protected override Encoding StandardOutputEncoding {
273                         get { return Console.Error.Encoding; }
274                 }
275
276                 public string TargetType {
277                         get {
278                                 if (Bag.Contains ("TargetType")) {
279                                         string s = (string) Bag ["TargetType"];
280                                         return s.ToLower ();
281                                 } else
282                                         return null;
283                         }
284                         set { Bag ["TargetType"] = value; }
285                 }
286
287                 public bool TreatWarningsAsErrors {
288                         get { return GetBoolParameterWithDefault ("TreatWarningsAsErrors", false); }
289                         set { Bag ["TreatWarningsAsErrors"] = value; }
290                 }
291
292                 public bool Utf8Output {
293                         get { return GetBoolParameterWithDefault ("Utf8Output", false); }
294                         set { Bag ["Utf8Output"] = value; }
295                 }
296
297                 public string Win32Icon {
298                         get { return (string) Bag ["Win32Icon"]; }
299                         set { Bag ["Win32Icon"] = value; }
300                 }
301
302                 public string Win32Resource {
303                         get { return (string) Bag ["Win32Resource"]; }
304                         set { Bag ["Win32Resource"] = value; }
305                 }
306         }
307 }
308
309 #endif