814d3e5cd6442f67d8a443740e3b8b7381c79468
[mono.git] / mcs / class / Microsoft.Build.Tasks / Microsoft.Build.Tasks / Csc.cs
1 //
2 // Csc.cs: Task that runs C# compiler
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 Microsoft.Build.Framework;
33 using Microsoft.Build.Tasks.Hosting;
34 using Microsoft.Build.Utilities;
35
36 namespace Microsoft.Build.Tasks {
37         public class Csc : ManagedCompiler {
38         
39                 public Csc ()
40                 {
41                 }
42
43                 protected internal override void AddResponseFileCommands (CommandLineBuilderExtension commandLine)
44                 {
45                         base.AddResponseFileCommands (commandLine);
46
47                         if (AdditionalLibPaths != null && AdditionalLibPaths.Length > 0)
48                                 commandLine.AppendSwitchIfNotNull ("/lib:", AdditionalLibPaths, ",");
49
50                         if (Bag ["AllowUnsafeBlocks"] != null)
51                                 if (AllowUnsafeBlocks)
52                                         commandLine.AppendSwitch ("/unsafe+");
53                                 else
54                                         commandLine.AppendSwitch ("/unsafe-");
55
56                         //baseAddress
57                         
58                         if (Bag ["CheckForOverflowUnderflow"] != null)
59                                 if (CheckForOverflowUnderflow)
60                                         commandLine.AppendSwitch ("/checked+");
61                                 else
62                                         commandLine.AppendSwitch ("/checked-");
63
64                         if (!String.IsNullOrEmpty (DefineConstants)) {
65                                 string [] defines = DefineConstants.Split (new char [] {';', ' '},
66                                                 StringSplitOptions.RemoveEmptyEntries);
67                                 if (defines.Length > 0)
68                                         commandLine.AppendSwitchIfNotNull ("/define:",
69                                                         String.Join (";", defines));
70                         }
71
72                         commandLine.AppendSwitchIfNotNull ("/nowarn:", DisabledWarnings);
73
74                         commandLine.AppendSwitchIfNotNull ("/doc:", DocumentationFile);
75
76                         //errorReport
77
78                         if (GenerateFullPaths)
79                                 commandLine.AppendSwitch ("/fullpaths");
80
81                         commandLine.AppendSwitchIfNotNull ("/langversion:", LangVersion);
82
83                         commandLine.AppendSwitchIfNotNull ("/main:", MainEntryPoint);
84
85                         //moduleAssemblyName
86                         
87                         if (NoStandardLib)
88                                 commandLine.AppendSwitch ("/nostdlib");
89
90                         //platform
91                         commandLine.AppendSwitchIfNotNull ("/platform:", Platform);
92                         //
93                         if (References != null)
94                                 foreach (ITaskItem item in References)
95                                         commandLine.AppendSwitchIfNotNull ("/reference:", item.ItemSpec);
96
97                         if (ResponseFiles != null)
98                                 foreach (ITaskItem item in ResponseFiles) 
99                                         commandLine.AppendSwitchIfNotNull ("@", item.ItemSpec);
100
101                         if (Bag ["WarningLevel"] != null)
102                                 commandLine.AppendSwitchIfNotNull ("/warn:", WarningLevel.ToString ());
103
104                         commandLine.AppendSwitchIfNotNull ("/warnaserror+:", WarningsAsErrors);
105
106                         commandLine.AppendSwitchIfNotNull ("/warnaserror-:", WarningsNotAsErrors);
107
108                         if (Win32Resource != null)
109                                 commandLine.AppendSwitchIfNotNull ("/win32res:", Win32Resource);
110                 }
111
112                 [MonoTODO]
113                 protected override bool CallHostObjectToExecute ()
114                 {
115                         throw new NotImplementedException ();
116                 }
117
118                 protected override string GenerateFullPathToTool ()
119                 {
120                         return Path.Combine (ToolPath, ToolExe);
121                 }
122
123                 [MonoTODO]
124                 protected override HostObjectInitializationStatus InitializeHostObject ()
125                 {
126                         return HostObjectInitializationStatus.NoActionReturnSuccess;
127                 }
128
129                 public bool AllowUnsafeBlocks {
130                         get { return GetBoolParameterWithDefault ("AllowUnsafeBlocks", false); }
131                         set { Bag ["AllowUnsafeBlocks"] = value; }
132                 }
133
134                 public string BaseAddress {
135                         get { return (string) Bag ["BaseAddress"]; }
136                         set { Bag ["BaseAddress"] = value; }
137                 }
138
139                 public bool CheckForOverflowUnderflow {
140                         get { return GetBoolParameterWithDefault ("CheckForOverflowUnderflow", false); }
141                         set { Bag ["CheckForOverflowUnderflow"] = value; }
142                 }
143
144                 public string DisabledWarnings {
145                         get { return (string) Bag ["DisabledWarnings"]; }
146                         set { Bag ["DisabledWarnings"] = value; }
147                 }
148
149                 public string DocumentationFile {
150                         get { return (string) Bag ["DocumentationFile"]; }
151                         set { Bag ["DocumentationFile"] = value; }
152                 }
153
154                 public string ErrorReport {
155                         get { return (string) Bag ["ErrorReport"]; }
156                         set { Bag ["ErrorReport"] = value; }
157                 }
158
159                 public bool GenerateFullPaths {
160                         get { return GetBoolParameterWithDefault ("GenerateFullPaths", false); }
161                         set { Bag ["GenerateFullPaths"] = value; }
162                 }
163
164                 public string LangVersion {
165                         get { return (string) Bag ["LangVersion"]; }
166                         set { Bag ["LangVersion"] = value; }
167                 }
168
169                 public string ModuleAssemblyName {
170                         get { return (string) Bag ["ModuleAssemblyName"]; }
171                         set { Bag ["ModuleAssemblyName"] = value; }
172                 }
173
174                 public bool NoStandardLib {
175                         get { return GetBoolParameterWithDefault ("NoStandardLib", false); }
176                         set { Bag ["NoStandardLib"] = value; }
177                 }
178                 
179                 public string PdbFile {
180                         get { return (string) Bag ["PdbFile"]; }
181                         set { Bag ["PdbFile"] = value; }
182                 }
183
184                 public string Platform {
185                         get { return (string) Bag ["Platform"]; }
186                         set { Bag ["Platform"] = value; }
187                 }
188
189                 protected override string ToolName {
190                         get {
191 #if NET_4_0
192                                 return Utilities.RunningOnWindows ? "dmcs.bat" : "dmcs";
193 #else
194                                 return Utilities.RunningOnWindows ? "gmcs.bat" : "gmcs";
195 #endif
196                         }
197                 }
198
199                 public bool UseHostCompilerIfAvailable {
200                         get { return GetBoolParameterWithDefault ("UseHostCompilerIfAvailable", false); }
201                         set { Bag ["UseHostCompilerIfAvailable"] = value; }
202                 }
203
204                 public int WarningLevel {
205                         get { return GetIntParameterWithDefault ("WarningLevel", 4); }
206                         set { Bag ["WarningLevel"] = value; }
207                 }
208
209                 public string WarningsAsErrors {
210                         get { return (string) Bag ["WarningsAsErrors"]; }
211                         set { Bag ["WarningsAsErrors"] = value; }
212                 }
213
214                 public string WarningsNotAsErrors {
215                         get { return (string) Bag ["WarningsNotAsErrors"]; }
216                         set { Bag ["WarningsNotAsErrors"] = value; }
217                 }
218         }
219 }
220
221 #endif