2006-02-26 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                         if (AllowUnsafeBlocks == true)
48                                 commandLine.AppendSwitch ("/unsafe");
49                         //baseAddress
50                         //checkForOverflowUnderflow
51                         commandLine.AppendSwitchIfNotNull ("/nowarn:", DisabledWarnings);
52                         commandLine.AppendSwitchIfNotNull ("/doc:", DocumentationFile);
53                         //errorReport
54                         commandLine.AppendSwitchIfNotNull ("/langversion:", LangVersion);
55                         //moduleAssemblyName
56                         if (NoStandardLib)
57                                 commandLine.AppendSwitch ("/nostdlib");
58                         //platform
59                         commandLine.AppendSwitchIfNotNull ("/warn:", WarningLevel.ToString ());
60                         //warningsAsErrors
61                         //warningNotAsErrors
62                 }
63
64                 protected override bool CallHostObjectToExecute ()
65                 {
66                         return true;
67                 }
68
69                 protected override string GenerateFullPathToTool ()
70                 {
71                         return Path.Combine (ToolPath, ToolName);
72                 }
73
74                 protected override HostObjectInitializationStatus InitializeHostObject ()
75                 {
76                         return HostObjectInitializationStatus.NoActionReturnSuccess;
77                 }
78
79                 public bool AllowUnsafeBlocks {
80                         get { return GetBoolParameterWithDefault ("AllowUnsafeBlocks", false); }
81                         set { Bag ["AllowUnsafeBlocks"] = value; }
82                 }
83
84                 public string BaseAddress {
85                         get { return (string) Bag ["BaseAddress"]; }
86                         set { Bag ["BaseAddress"] = value; }
87                 }
88
89                 public bool CheckForOverflowUnderflow {
90                         get { return GetBoolParameterWithDefault ("CheckForOverflowUnderflow", false); }
91                         set { Bag ["CheckForOverflowUnderflow"] = value; }
92                 }
93
94                 public string DisabledWarnings {
95                         get { return (string) Bag ["DisabledWarnings"]; }
96                         set { Bag ["DisabledWarnings"] = value; }
97                 }
98
99                 public string DocumentationFile {
100                         get { return (string) Bag ["DocumentationFile"]; }
101                         set { Bag ["DocumentationFile"] = value; }
102                 }
103
104                 public string ErrorReport {
105                         get { return (string) Bag ["ErrorReport"]; }
106                         set { Bag ["ErrorReport"] = value; }
107                 }
108
109                 public bool GenerateFullPaths {
110                         get { return GetBoolParameterWithDefault ("GenerateFullPaths", false); }
111                         set { Bag ["GenerateFullPaths"] = value; }
112                 }
113
114                 public string LangVersion {
115                         get { return (string) Bag ["LangVersion"]; }
116                         set { Bag ["LangVersion"] = value; }
117                 }
118
119                 public string ModuleAssemblyName {
120                         get { return (string) Bag ["ModuleAssemblyName"]; }
121                         set { Bag ["ModuleAssemblyName"] = value; }
122                 }
123
124                 public bool NoStandardLib {
125                         get { return GetBoolParameterWithDefault ("NoStandardLib", false); }
126                         set { Bag ["NoStandardLib"] = value; }
127                 }
128                 
129                 public string PdbFile {
130                         get { return (string) Bag ["PdbFile"]; }
131                         set { Bag ["PdbFile"] = value; }
132                 }
133
134                 public string Platform {
135                         get { return (string) Bag ["Platform"]; }
136                         set { Bag ["Platform"] = value; }
137                 }
138
139                 protected override string ToolName {
140                         get { return "mcs"; }
141                 }
142
143                 public bool UseHostCompilerIfAvailable {
144                         get { return GetBoolParameterWithDefault ("UseHostCompilerIfAvailable", false); }
145                         set { Bag ["UseHostCompilerIfAvailable"] = value; }
146                 }
147
148                 public int WarningLevel {
149                         get { return GetIntParameterWithDefault ("WarningLevel", 2); }
150                         set { Bag ["WarningLevel"] = value; }
151                 }
152
153                 public string WarningsAsErrors {
154                         get { return (string) Bag ["WarningsAsErrors"]; }
155                         set { Bag ["WarningsAsErrors"] = value; }
156                 }
157
158                 public string WarningsNotAsErrors {
159                         get { return (string) Bag ["WarningsNotAsErrors"]; }
160                         set { Bag ["WarningsNotAsErrors"] = value; }
161                 }
162         }
163 }
164
165 #endif