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