New test.
[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.IO;
33 using System.Text;
34 using Microsoft.Build.Framework;
35
36 namespace Microsoft.Build.Tasks {
37         public abstract class ManagedCompiler : ToolTaskExtension {
38         
39                 protected ManagedCompiler ()
40                 {
41                 }
42
43                 [MonoTODO]
44                 protected internal override void AddCommandLineCommands (
45                                                  CommandLineBuilderExtension commandLine)
46                 {
47                 }
48
49                 [MonoTODO]
50                 protected internal override void AddResponseFileCommands (
51                                                  CommandLineBuilderExtension commandLine)
52                 {
53                         commandLine.AppendSwitchIfNotNull ("/lib:", AdditionalLibPaths, ",");
54                         commandLine.AppendSwitchIfNotNull ("/addmodule:", AddModules, ",");
55                         //commandLine.AppendSwitchIfNotNull ("/codepage:", CodePage.ToString ());
56                         //debugType
57                         commandLine.AppendSwitchIfNotNull ("/define:", DefineConstants);
58                         //delaySign
59                         if (EmitDebugInformation)
60                                 commandLine.AppendSwitch ("/debug");
61                         //fileAlignment
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);
68                                 }
69                         }
70                         commandLine.AppendSwitchIfNotNull ("/main:", MainEntryPoint);
71                         if (NoConfig)
72                                 commandLine.AppendSwitch ("/noconfig");
73                         if (Optimize)
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);
80                                 }
81                         }
82                         if (Resources != null) {
83                                 foreach (ITaskItem item in Resources) {
84                                                 commandLine.AppendSwitchIfNotNull ("/resource:", item.ItemSpec);
85                                 }
86                         }
87                         if (ResponseFiles != null) {
88                                 foreach (ITaskItem item in ResponseFiles) {
89                                                 commandLine.AppendFileNameIfNotNull (String.Format ("@{0}",item.ItemSpec));
90                                 }
91                         }
92                         if (Sources != null) {
93                                 foreach (ITaskItem item in Sources) {
94                                                 commandLine.AppendFileNameIfNotNull (item.ItemSpec);
95                                 }
96                         }
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);
103                 }
104
105                 [MonoTODO]
106                 protected bool CheckAllReferencesExistOnDisk ()
107                 {
108                         foreach (ITaskItem item in (ITaskItem[])Bag ["References"]) 
109                                 if (File.Exists (item.GetMetadata ("FullPath")) == false)
110                                         return false;
111                         return true;
112                 }
113
114                 [MonoTODO]
115                 protected void CheckHostObjectSupport (string parameterName,
116                                                        bool resultFromHostObjectSetOperation)
117                 {
118                 }
119                 
120                 [MonoTODO]
121                 protected override bool HandleTaskExecutionErrors ()
122                 {
123                         return true;
124                 }
125                 
126                 [MonoTODO]
127                 protected bool ListHasNoDuplicateItems (ITaskItem[] itemList,
128                                                         string parameterName)
129                 {
130                         Hashtable items = new Hashtable ();
131                         
132                         foreach (ITaskItem item in itemList) {
133                                 if (items.Contains (item.ItemSpec))
134                                         items.Add (item.ItemSpec, null);
135                                 else
136                                         return false;
137                         }
138                         
139                         return true;
140                 }
141
142                 [MonoTODO]
143                 protected override bool ValidateParameters ()
144                 {
145                         return true;
146                 }
147
148                 public string[] AdditionalLibPaths {
149                         get { return (string[]) Bag ["AdditionalLibPaths"]; }
150                         set { Bag ["AdditionalLibPaths"] = value; }
151                 }
152
153                 public string[] AddModules {
154                         get { return (string[]) Bag ["AddModules"]; }
155                         set { Bag ["AddModules"] = value; }
156                 }
157
158                 public int CodePage {
159                         get { return GetIntParameterWithDefault ("CodePage", 0); }
160                         set { Bag ["CodePage"] = value; }
161                 }
162
163                 public string DebugType {
164                         get { return (string) Bag ["DebugType"]; }
165                         set { Bag ["DebugType"] = value; }
166                 }
167
168                 public string DefineConstants {
169                         get { return (string) Bag ["DefineConstants"]; }
170                         set { Bag ["DefineConstants"] = value; }
171                 }
172
173                 public bool DelaySign {
174                         get { return GetBoolParameterWithDefault ("DelaySign", false); }
175                         set { Bag ["DelaySign"] = value; }
176                 }
177
178                 public bool EmitDebugInformation {
179                         get { return GetBoolParameterWithDefault ("EmitDebugInformation", false); }
180                         set { Bag ["EmitDebugInformation"] = value; }
181                 }
182
183                 public int FileAlignment {
184                         get { return GetIntParameterWithDefault ("FileAlignment", 0); }
185                         set { Bag ["FileAlignment"] = value; }
186                 }
187
188                 protected bool HostCompilerSupportsAllParameters {
189                         get { return true; }
190                         set { Bag ["HostCompilerSupportsAllParameters"] = value; }
191                 }
192
193                 public string KeyContainer {
194                         get { return (string) Bag ["KeyContainer"]; }
195                         set { Bag ["KeyContainer"] = value; }
196                 }
197
198                 public string KeyFile {
199                         get { return (string) Bag ["KeyFile"]; }
200                         set { Bag ["KeyFile"] = value; }
201                 }
202
203                 public ITaskItem[] LinkResources {
204                         get { return (ITaskItem[]) Bag ["LinkResources"]; }
205                         set { Bag ["LinkResources"] = value; }
206                 }
207
208                 public string MainEntryPoint {
209                         get { return (string) Bag ["MainEntryPoint"]; }
210                         set { Bag ["MainEntryPoint"] = value; }
211                 }
212
213                 public bool NoConfig {
214                         get { return GetBoolParameterWithDefault ("NoConfig", false); }
215                         set { Bag ["NoConfig"] = value; }
216                 }
217
218                 public bool NoLogo {
219                         get { return GetBoolParameterWithDefault ("NoLogo", false); }
220                         set { Bag ["NoLogo"] = value; }
221                 }
222
223                 public bool Optimize {
224                         get { return GetBoolParameterWithDefault ("Optimize", false); }
225                         set { Bag ["Optimize"] = value; }
226                 }
227
228                 [Output]
229                 public ITaskItem OutputAssembly {
230                         get { return (ITaskItem) Bag ["OutputAssembly"]; }
231                         set { Bag ["OutputAssembly"] = value; }
232                 }
233
234                 public ITaskItem[] References {
235                         get { return (ITaskItem[]) Bag ["References"]; }
236                         set { Bag ["References"] = value; }
237                 }
238
239                 public ITaskItem[] Resources {
240                         get { return (ITaskItem[]) Bag ["Resources"]; }
241                         set { Bag ["Resources"] = value; }
242                 }
243
244                 public ITaskItem[] ResponseFiles {
245                         get { return (ITaskItem[]) Bag ["ResponseFiles"]; }
246                         set { Bag ["ResponseFiles"] = value; }
247                 }
248
249                 public ITaskItem[] Sources {
250                         get { return (ITaskItem[]) Bag ["Sources"]; }
251                         set { Bag ["Sources"] = value; }
252                 }
253
254                 protected override Encoding StandardOutputEncoding {
255                         get { return Console.Error.Encoding; }
256                 }
257
258                 // FIXME: hack to get build of hello world working
259                 public string TargetType {
260                         get {
261                                 return  (Bag.Contains ("TargetType")) ? (((string) Bag ["TargetType"]).ToLower ()) : null;
262                         }
263                         set { Bag ["TargetType"] = value; }
264                 }
265
266                 public bool TreatWarningsAsErrors {
267                         get { return GetBoolParameterWithDefault ("TreatWarningsAsErrors", false); }
268                         set { Bag ["TreatWarningsAsErrors"] = value; }
269                 }
270
271                 public bool Utf8Output {
272                         get { return GetBoolParameterWithDefault ("Utf8Output", false); }
273                         set { Bag ["Utf8Output"] = value; }
274                 }
275
276                 public string Win32Icon {
277                         get { return (string) Bag ["Win32Icon"]; }
278                         set { Bag ["Win32Icon"] = value; }
279                 }
280
281                 public string Win32Resource {
282                         get { return (string) Bag ["Win32Resource"]; }
283                         set { Bag ["Win32Resource"] = value; }
284                 }
285         }
286 }
287
288 #endif