2007-02-02 Marek Sieradzki <marek.sieradzki@gmail.com>
[mono.git] / mcs / class / Microsoft.Build.Tasks / Microsoft.Build.Tasks / ManagedCompiler.cs
index a454de71646b131bab50d2c3c6ad346143f214d1..1bea8570300003a61811bb8d8f0468384ea7c3b6 100644 (file)
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
+#if NET_2_0
+
 using System;
+using System.Collections;
+using System.Collections.Generic;
 using System.IO;
 using System.Text;
 using Microsoft.Build.Framework;
+using Microsoft.Build.Utilities;
 
 namespace Microsoft.Build.Tasks {
        public abstract class ManagedCompiler : ToolTaskExtension {
@@ -37,35 +42,111 @@ namespace Microsoft.Build.Tasks {
                {
                }
 
+               [MonoTODO]
                protected internal override void AddCommandLineCommands (
                                                 CommandLineBuilderExtension commandLine)
                {
+                       if (NoConfig)
+                               commandLine.AppendSwitch ("/noconfig");
                }
 
+               [MonoTODO]
                protected internal override void AddResponseFileCommands (
                                                 CommandLineBuilderExtension commandLine)
                {
-               }
-
+                       commandLine.AppendSwitchIfNotNull ("/addmodule:", AddModules, ",");
+                       if (Bag ["CodePage"] != null)
+                               commandLine.AppendSwitchIfNotNull ("/codepage:", CodePage.ToString ());
+
+                       commandLine.AppendSwitchIfNotNull ("/debug:", DebugType);
+
+                       if (Bag ["DelaySign"] != null)
+                               if (DelaySign)
+                                       commandLine.AppendSwitch ("/delaysign+");
+                               else
+                                       commandLine.AppendSwitch ("/delaysign-");
+                       if (Bag ["EmitDebugInformation"] != null)
+                               if (EmitDebugInformation)
+                                       commandLine.AppendSwitch ("/debug+");
+                               else
+                                       commandLine.AppendSwitch ("/debug-");
+                       //fileAlignment
+                       commandLine.AppendSwitchIfNotNull ("/keycontainer:", KeyContainer);
+                       commandLine.AppendSwitchIfNotNull ("/keyfile:", KeyFile);
+                       // FIXME: add ids from metadata
+                       if (LinkResources != null)
+                               foreach (ITaskItem item in LinkResources)
+                                               commandLine.AppendSwitchIfNotNull ("/linkresource:", item.ItemSpec);
+                       
+                       if (NoLogo)
+                               commandLine.AppendSwitch ("/nologo");
+
+                       if (Bag ["Optimize"] != null)
+                               if (Optimize)
+                                       commandLine.AppendSwitch ("/optimize+");
+                               else
+                                       commandLine.AppendSwitch ("/optimize-");
+
+                       if (OutputAssembly != null)
+                               commandLine.AppendSwitchIfNotNull ("/out:", OutputAssembly.ItemSpec);
+                       
+                       if (Resources != null)
+                               foreach (ITaskItem item in Resources)
+                                               commandLine.AppendSwitchIfNotNull ("/resource:", item.ItemSpec);
+
+                       if (Sources != null)
+                               foreach (ITaskItem item in Sources)
+                                               commandLine.AppendFileNameIfNotNull (item.ItemSpec);
+                       
+                       if (TargetType != null)
+                               commandLine.AppendSwitchIfNotNull ("/target:", TargetType);
+                       if (Bag ["TreatWarningsAsErrors"] != null)
+                               if (TreatWarningsAsErrors)
+                                       commandLine.AppendSwitch ("/warnaserror+");
+                               else
+                                       commandLine.AppendSwitch ("/warnaserror-");
+                       commandLine.AppendSwitchIfNotNull ("/win32icon:", Win32Icon);
+               }
+
+               [MonoTODO]
                protected bool CheckAllReferencesExistOnDisk ()
                {
-                       foreach (ITaskItem item in (ITaskItem[])Bag ["References"]) 
-                               if (File.Exists (item.GetMetadata ("FullPath")) == false)
-                                       return false;
+                       if (Bag ["References"] != null)
+                               foreach (ITaskItem item in (ITaskItem[]) Bag ["References"])
+                                       if (!File.Exists (item.GetMetadata ("FullPath")))
+                                               return false;
                        return true;
                }
 
+               [MonoTODO]
                protected void CheckHostObjectSupport (string parameterName,
                                                       bool resultFromHostObjectSetOperation)
                {
                }
                
-               protected override bool HandleTaskExecutionErrors (int exitCode,
-                                                                  bool taskLoggedErrors)
+               [MonoTODO]
+               protected override bool HandleTaskExecutionErrors ()
+               {
+                       return true;
+               }
+               
+               [MonoTODO]
+               protected bool ListHasNoDuplicateItems (ITaskItem [] itemList,
+                                                       string parameterName)
                {
+                       Dictionary <string, object> items = new Dictionary <string, object> ();
+                       
+                       foreach (ITaskItem item in itemList) {
+                               if (!items.ContainsKey (item.ItemSpec))
+                                       items.Add (item.ItemSpec, null);
+                               else
+                                       return false;
+                       }
+                       
                        return true;
                }
 
+               [MonoTODO]
                protected override bool ValidateParameters ()
                {
                        return true;
@@ -151,6 +232,7 @@ namespace Microsoft.Build.Tasks {
                        set { Bag ["Optimize"] = value; }
                }
 
+               [Output]
                public ITaskItem OutputAssembly {
                        get { return (ITaskItem) Bag ["OutputAssembly"]; }
                        set { Bag ["OutputAssembly"] = value; }
@@ -173,7 +255,11 @@ namespace Microsoft.Build.Tasks {
 
                public ITaskItem[] Sources {
                        get { return (ITaskItem[]) Bag ["Sources"]; }
-                       set { Bag ["Sources"] = value; }
+                       set {
+                               Bag ["Sources"] = value;
+                               if (Bag ["OutputAssembly"] == null && value != null && value.Length >= 1)
+                                       Bag ["OutputAssembly"] = new TaskItem (String.Format ("{0}.exe", value [0].ItemSpec));
+                       }
                }
 
                protected override Encoding StandardOutputEncoding {
@@ -181,7 +267,13 @@ namespace Microsoft.Build.Tasks {
                }
 
                public string TargetType {
-                       get { return (string) Bag ["TargetType"]; }
+                       get {
+                               if (Bag.Contains ("TargetType")) {
+                                       string s = (string) Bag ["TargetType"];
+                                       return s.ToLower ();
+                               } else
+                                       return null;
+                       }
                        set { Bag ["TargetType"] = value; }
                }
 
@@ -206,3 +298,5 @@ namespace Microsoft.Build.Tasks {
                }
        }
 }
+
+#endif