2005-09-25 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 using System;
29 using System.IO;
30 using Microsoft.Build.Framework;
31 using Microsoft.Build.Tasks.Hosting;
32 using Microsoft.Build.Utilities;
33
34 namespace Microsoft.Build.Tasks {
35         public class Csc : ManagedCompiler {
36         
37                 public Csc ()
38                 {
39                 }
40
41                 protected internal override void AddResponseFileCommands (CommandLineBuilderExtension commandLine)
42                 {
43                         base.AddResponseFileCommands (commandLine);
44                         
45                         if (AllowUnsafeBlocks == true)
46                                 commandLine.AppendSwitch ("/unsafe");
47                         //baseAddress
48                         //checkForOverflowUnderflow
49                         commandLine.AppendSwitchIfNotNull ("/nowarn:", DisabledWarnings);
50                         commandLine.AppendSwitchIfNotNull ("/doc:", DocumentationFile);
51                         //errorReport
52                         commandLine.AppendSwitchIfNotNull ("/langversion:", LangVersion);
53                         //moduleAssemblyName
54                         if (NoStandardLib)
55                                 commandLine.AppendSwitch ("/nostdlib");
56                         //platform
57                         commandLine.AppendSwitchIfNotNull ("/warn:", WarningLevel.ToString ());
58                         //warningsAsErrors
59                         //warningNotAsErrors
60                 }
61
62                 protected override bool CallHostObjectToExecute ()
63                 {
64                         return true;
65                 }
66
67                 protected override string GenerateFullPathToTool ()
68                 {
69                         return Path.Combine (ToolPath, ToolName);
70                 }
71
72                 protected override bool InitializeHostObject (out bool appropriateHostObjectExists,
73                                                               out bool continueBuild)
74                 {
75                         appropriateHostObjectExists = true;
76                         continueBuild = true;
77                         return true;
78                 }
79
80                 public bool AllowUnsafeBlocks {
81                         get { return GetBoolParameterWithDefault ("AllowUnsafeBlocks", false); }
82                         set { Bag ["AllowUnsafeBlocks"] = value; }
83                 }
84
85                 public string BaseAddress {
86                         get { return (string) Bag ["BaseAddress"]; }
87                         set { Bag ["BaseAddress"] = value; }
88                 }
89
90                 public bool CheckForOverflowUnderFlow {
91                         get { return GetBoolParameterWithDefault ("CheckForOverflowUnderFlow", false); }
92                         set { Bag ["CheckForOverflowUnderFlow"] = value; }
93                 }
94
95                 public string DisabledWarnings {
96                         get { return (string) Bag ["DisabledWarnings"]; }
97                         set { Bag ["DisabledWarnings"] = value; }
98                 }
99
100                 public string DocumentationFile {
101                         get { return (string) Bag ["DocumentationFile"]; }
102                         set { Bag ["DocumentationFile"] = value; }
103                 }
104
105                 public string ErrorReport {
106                         get { return (string) Bag ["ErrorReport"]; }
107                         set { Bag ["ErrorReport"] = value; }
108                 }
109
110                 public bool GenerateFullPaths {
111                         get { return GetBoolParameterWithDefault ("GenerateFullPaths", false); }
112                         set { Bag ["GenerateFullPaths"] = value; }
113                 }
114
115                 public string LangVersion {
116                         get { return (string) Bag ["LangVersion"]; }
117                         set { Bag ["LangVersion"] = value; }
118                 }
119
120                 public string ModuleAssemblyName {
121                         get { return (string) Bag ["ModuleAssemblyName"]; }
122                         set { Bag ["ModuleAssemblyName"] = value; }
123                 }
124
125                 public bool NoStandardLib {
126                         get { return GetBoolParameterWithDefault ("NoStandardLib", false); }
127                         set { Bag ["NoStandardLib"] = value; }
128                 }
129
130                 public string Platform {
131                         get { return (string) Bag ["Platform"]; }
132                         set { Bag ["Platform"] = value; }
133                 }
134
135                 protected override string ToolName {
136                         get { return "mcs"; }
137                 }
138
139                 public bool UseHostCompilerIfAvailable {
140                         get { return GetBoolParameterWithDefault ("UseHostCompilerIfAvailable", false); }
141                         set { Bag ["UseHostCompilerIfAvailable"] = value; }
142                 }
143
144                 public int WarningLevel {
145                         get { return GetIntParameterWithDefault ("WarningLevel", 2); }
146                         set { Bag ["WarningLevel"] = value; }
147                 }
148
149                 public string WarningsAsErrors {
150                         get { return (string) Bag ["WarningsAsErrors"]; }
151                         set { Bag ["WarningsAsErrors"] = value; }
152                 }
153
154                 public string WarningsNotAsErrors {
155                         get { return (string) Bag ["WarningsNotAsErrors"]; }
156                         set { Bag ["WarningsNotAsErrors"] = value; }
157                 }
158         }
159 }