merge -r 58060:58217
[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.IO;
32 using System.Text;
33 using Microsoft.Build.Framework;
34
35 namespace Microsoft.Build.Tasks {
36         public abstract class ManagedCompiler : ToolTaskExtension {
37         
38                 protected ManagedCompiler ()
39                 {
40                 }
41
42                 protected internal override void AddCommandLineCommands (
43                                                  CommandLineBuilderExtension commandLine)
44                 {
45                 }
46
47                 protected internal override void AddResponseFileCommands (
48                                                  CommandLineBuilderExtension commandLine)
49                 {
50                         commandLine.AppendSwitchIfNotNull ("/lib:", AdditionalLibPaths, ",");
51                         commandLine.AppendSwitchIfNotNull ("/addmodule:", AddModules, ",");
52                         //commandLine.AppendSwitchIfNotNull ("/codepage:", CodePage.ToString ());
53                         //debugType
54                         commandLine.AppendSwitchIfNotNull ("/define:", DefineConstants);
55                         //delaySign
56                         if (EmitDebugInformation)
57                                 commandLine.AppendSwitch ("/debug");
58                         //fileAlignment
59                         commandLine.AppendSwitchIfNotNull ("/keycontainer:", KeyContainer);
60                         commandLine.AppendSwitchIfNotNull ("/keyfile:", KeyFile);
61                         // FIXME: add ids from metadata
62                         if (LinkResources != null) {
63                                 foreach (ITaskItem item in LinkResources) {
64                                                 commandLine.AppendSwitchIfNotNull ("/linkresource:", item.ItemSpec);
65                                 }
66                         }
67                         commandLine.AppendSwitchIfNotNull ("/main:", MainEntryPoint);
68                         if (NoConfig)
69                                 commandLine.AppendSwitch ("/noconfig");
70                         if (Optimize)
71                                 commandLine.AppendSwitch ("/optimize");
72                         if (OutputAssembly != null)
73                                 commandLine.AppendSwitchIfNotNull ("/out:", OutputAssembly.ItemSpec);
74                         if (References != null) {
75                                 foreach (ITaskItem item in References) {
76                                         commandLine.AppendSwitchIfNotNull ("/reference:", item.ItemSpec);
77                                 }
78                         }
79                         if (Resources != null) {
80                                 foreach (ITaskItem item in Resources) {
81                                                 commandLine.AppendSwitchIfNotNull ("/resource:", item.ItemSpec);
82                                 }
83                         }
84                         if (ResponseFiles != null) {
85                                 foreach (ITaskItem item in ResponseFiles) {
86                                                 commandLine.AppendFileNameIfNotNull (String.Format ("@{0}",item.ItemSpec));
87                                 }
88                         }
89                         if (Sources != null) {
90                                 foreach (ITaskItem item in Sources) {
91                                                 commandLine.AppendFileNameIfNotNull (item.ItemSpec);
92                                 }
93                         }
94                         commandLine.AppendSwitchIfNotNull ("/target:", TargetType);
95                         if (TreatWarningsAsErrors)
96                                 commandLine.AppendSwitch ("/warnaserror");
97                         commandLine.AppendSwitchIfNotNull ("/win32icon:", Win32Icon);
98                         commandLine.AppendSwitchIfNotNull ("/win32res:", Win32Resource);
99                 }
100
101                 protected bool CheckAllReferencesExistOnDisk ()
102                 {
103                         foreach (ITaskItem item in (ITaskItem[])Bag ["References"]) 
104                                 if (File.Exists (item.GetMetadata ("FullPath")) == false)
105                                         return false;
106                         return true;
107                 }
108
109                 protected void CheckHostObjectSupport (string parameterName,
110                                                        bool resultFromHostObjectSetOperation)
111                 {
112                 }
113                 
114                 protected override bool HandleTaskExecutionErrors (int exitCode,
115                                                                    bool taskLoggedErrors)
116                 {
117                         return true;
118                 }
119
120                 protected override bool ValidateParameters ()
121                 {
122                         return true;
123                 }
124
125                 public string[] AdditionalLibPaths {
126                         get { return (string[]) Bag ["AdditionalLibPaths"]; }
127                         set { Bag ["AdditionalLibPaths"] = value; }
128                 }
129
130                 public string[] AddModules {
131                         get { return (string[]) Bag ["AddModules"]; }
132                         set { Bag ["AddModules"] = value; }
133                 }
134
135                 public int CodePage {
136                         get { return GetIntParameterWithDefault ("CodePage", 0); }
137                         set { Bag ["CodePage"] = value; }
138                 }
139
140                 public string DebugType {
141                         get { return (string) Bag ["DebugType"]; }
142                         set { Bag ["DebugType"] = value; }
143                 }
144
145                 public string DefineConstants {
146                         get { return (string) Bag ["DefineConstants"]; }
147                         set { Bag ["DefineConstants"] = value; }
148                 }
149
150                 public bool DelaySign {
151                         get { return GetBoolParameterWithDefault ("DelaySign", false); }
152                         set { Bag ["DelaySign"] = value; }
153                 }
154
155                 public bool EmitDebugInformation {
156                         get { return GetBoolParameterWithDefault ("EmitDebugInformation", false); }
157                         set { Bag ["EmitDebugInformation"] = value; }
158                 }
159
160                 public int FileAlignment {
161                         get { return GetIntParameterWithDefault ("FileAlignment", 0); }
162                         set { Bag ["FileAlignment"] = value; }
163                 }
164
165                 protected bool HostCompilerSupportsAllParameters {
166                         get { return true; }
167                         set { Bag ["HostCompilerSupportsAllParameters"] = value; }
168                 }
169
170                 public string KeyContainer {
171                         get { return (string) Bag ["KeyContainer"]; }
172                         set { Bag ["KeyContainer"] = value; }
173                 }
174
175                 public string KeyFile {
176                         get { return (string) Bag ["KeyFile"]; }
177                         set { Bag ["KeyFile"] = value; }
178                 }
179
180                 public ITaskItem[] LinkResources {
181                         get { return (ITaskItem[]) Bag ["LinkResources"]; }
182                         set { Bag ["LinkResources"] = value; }
183                 }
184
185                 public string MainEntryPoint {
186                         get { return (string) Bag ["MainEntryPoint"]; }
187                         set { Bag ["MainEntryPoint"] = value; }
188                 }
189
190                 public bool NoConfig {
191                         get { return GetBoolParameterWithDefault ("NoConfig", false); }
192                         set { Bag ["NoConfig"] = value; }
193                 }
194
195                 public bool NoLogo {
196                         get { return GetBoolParameterWithDefault ("NoLogo", false); }
197                         set { Bag ["NoLogo"] = value; }
198                 }
199
200                 public bool Optimize {
201                         get { return GetBoolParameterWithDefault ("Optimize", false); }
202                         set { Bag ["Optimize"] = value; }
203                 }
204
205                 public ITaskItem OutputAssembly {
206                         get { return (ITaskItem) Bag ["OutputAssembly"]; }
207                         set { Bag ["OutputAssembly"] = value; }
208                 }
209
210                 public ITaskItem[] References {
211                         get { return (ITaskItem[]) Bag ["References"]; }
212                         set { Bag ["References"] = value; }
213                 }
214
215                 public ITaskItem[] Resources {
216                         get { return (ITaskItem[]) Bag ["Resources"]; }
217                         set { Bag ["Resources"] = value; }
218                 }
219
220                 public ITaskItem[] ResponseFiles {
221                         get { return (ITaskItem[]) Bag ["ResponseFiles"]; }
222                         set { Bag ["ResponseFiles"] = value; }
223                 }
224
225                 public ITaskItem[] Sources {
226                         get { return (ITaskItem[]) Bag ["Sources"]; }
227                         set { Bag ["Sources"] = value; }
228                 }
229
230                 protected override Encoding StandardOutputEncoding {
231                         get { return Console.Error.Encoding; }
232                 }
233
234                 public string TargetType {
235                         get { return (string) Bag ["TargetType"]; }
236                         set { Bag ["TargetType"] = value; }
237                 }
238
239                 public bool TreatWarningsAsErrors {
240                         get { return GetBoolParameterWithDefault ("TreatWarningsAsErrors", false); }
241                         set { Bag ["TreatWarningsAsErrors"] = value; }
242                 }
243
244                 public bool Utf8Output {
245                         get { return GetBoolParameterWithDefault ("Utf8Output", false); }
246                         set { Bag ["Utf8Output"] = value; }
247                 }
248
249                 public string Win32Icon {
250                         get { return (string) Bag ["Win32Icon"]; }
251                         set { Bag ["Win32Icon"] = value; }
252                 }
253
254                 public string Win32Resource {
255                         get { return (string) Bag ["Win32Resource"]; }
256                         set { Bag ["Win32Resource"] = value; }
257                 }
258         }
259 }
260
261 #endif