fff7e3fa5cccf93d0e66d288408fc278d061673f
[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                         commandLine.AppendSwitchIfNotNull ("/lib:", AdditionalLibPaths, ",");
48                         if (Bag ["AllowUnsafeBlocks"] != null)
49                                 if (AllowUnsafeBlocks)
50                                         commandLine.AppendSwitch ("/unsafe+");
51                                 else
52                                         commandLine.AppendSwitch ("/unsafe-");
53
54                         //baseAddress
55                         
56                         if (Bag ["CheckForOverflowUnderflow"] != null)
57                                 if (CheckForOverflowUnderflow)
58                                         commandLine.AppendSwitch ("/checked+");
59                                 else
60                                         commandLine.AppendSwitch ("/checked-");
61
62                         commandLine.AppendSwitchIfNotNull ("/define:", DefineConstants);
63
64                         commandLine.AppendSwitchIfNotNull ("/nowarn:", DisabledWarnings);
65
66                         commandLine.AppendSwitchIfNotNull ("/doc:", DocumentationFile);
67
68                         //errorReport
69
70                         if (GenerateFullPaths)
71                                 commandLine.AppendSwitch ("/fullpaths");
72
73                         commandLine.AppendSwitchIfNotNull ("/langversion:", LangVersion);
74
75                         commandLine.AppendSwitchIfNotNull ("/main:", MainEntryPoint);
76
77                         //moduleAssemblyName
78                         
79                         if (NoStandardLib)
80                                 commandLine.AppendSwitch ("/nostdlib");
81
82                         //platform
83                         //
84                         if (References != null)
85                                 foreach (ITaskItem item in References)
86                                         commandLine.AppendSwitchIfNotNull ("/reference:", item.ItemSpec);
87
88                         if (ResponseFiles != null)
89                                 foreach (ITaskItem item in ResponseFiles) 
90                                         commandLine.AppendFileNameIfNotNull (String.Format ("@{0}",item.ItemSpec));
91
92                         if (Bag ["WarningLevel"] != null)
93                                 commandLine.AppendSwitchIfNotNull ("/warn:", WarningLevel.ToString ());
94
95                         commandLine.AppendSwitchIfNotNull ("/warnaserror+:", WarningsAsErrors);
96
97                         commandLine.AppendSwitchIfNotNull ("/warnaserror-:", WarningsNotAsErrors);
98
99                         if (Win32Resource != null)
100                                 commandLine.AppendSwitchIfNotNull ("/win32res:", String.Format ("\"{0}\"", Win32Resource));
101                 }
102
103                 [MonoTODO]
104                 protected override bool CallHostObjectToExecute ()
105                 {
106                         throw new NotImplementedException ();
107                 }
108
109                 protected override string GenerateFullPathToTool ()
110                 {
111                         return Path.Combine (ToolPath, ToolName);
112                 }
113
114                 [MonoTODO]
115                 protected override HostObjectInitializationStatus InitializeHostObject ()
116                 {
117                         return HostObjectInitializationStatus.NoActionReturnSuccess;
118                 }
119
120                 public bool AllowUnsafeBlocks {
121                         get { return GetBoolParameterWithDefault ("AllowUnsafeBlocks", false); }
122                         set { Bag ["AllowUnsafeBlocks"] = value; }
123                 }
124
125                 public string BaseAddress {
126                         get { return (string) Bag ["BaseAddress"]; }
127                         set { Bag ["BaseAddress"] = value; }
128                 }
129
130                 public bool CheckForOverflowUnderflow {
131                         get { return GetBoolParameterWithDefault ("CheckForOverflowUnderflow", false); }
132                         set { Bag ["CheckForOverflowUnderflow"] = value; }
133                 }
134
135                 public string DisabledWarnings {
136                         get { return (string) Bag ["DisabledWarnings"]; }
137                         set { Bag ["DisabledWarnings"] = value; }
138                 }
139
140                 public string DocumentationFile {
141                         get { return (string) Bag ["DocumentationFile"]; }
142                         set { Bag ["DocumentationFile"] = value; }
143                 }
144
145                 public string ErrorReport {
146                         get { return (string) Bag ["ErrorReport"]; }
147                         set { Bag ["ErrorReport"] = value; }
148                 }
149
150                 public bool GenerateFullPaths {
151                         get { return GetBoolParameterWithDefault ("GenerateFullPaths", false); }
152                         set { Bag ["GenerateFullPaths"] = value; }
153                 }
154
155                 public string LangVersion {
156                         get { return (string) Bag ["LangVersion"]; }
157                         set { Bag ["LangVersion"] = value; }
158                 }
159
160                 public string ModuleAssemblyName {
161                         get { return (string) Bag ["ModuleAssemblyName"]; }
162                         set { Bag ["ModuleAssemblyName"] = value; }
163                 }
164
165                 public bool NoStandardLib {
166                         get { return GetBoolParameterWithDefault ("NoStandardLib", false); }
167                         set { Bag ["NoStandardLib"] = value; }
168                 }
169                 
170                 public string PdbFile {
171                         get { return (string) Bag ["PdbFile"]; }
172                         set { Bag ["PdbFile"] = value; }
173                 }
174
175                 public string Platform {
176                         get { return (string) Bag ["Platform"]; }
177                         set { Bag ["Platform"] = value; }
178                 }
179
180                 protected override string ToolName {
181                         get { return "gmcs"; }
182                 }
183
184                 public bool UseHostCompilerIfAvailable {
185                         get { return GetBoolParameterWithDefault ("UseHostCompilerIfAvailable", false); }
186                         set { Bag ["UseHostCompilerIfAvailable"] = value; }
187                 }
188
189                 public int WarningLevel {
190                         get { return GetIntParameterWithDefault ("WarningLevel", 4); }
191                         set { Bag ["WarningLevel"] = value; }
192                 }
193
194                 public string WarningsAsErrors {
195                         get { return (string) Bag ["WarningsAsErrors"]; }
196                         set { Bag ["WarningsAsErrors"] = value; }
197                 }
198
199                 public string WarningsNotAsErrors {
200                         get { return (string) Bag ["WarningsNotAsErrors"]; }
201                         set { Bag ["WarningsNotAsErrors"] = value; }
202                 }
203         }
204 }
205
206 #endif