Merge pull request #631 from kebby/master
[mono.git] / mcs / class / Microsoft.Build.Tasks / Microsoft.Build.Tasks / ManagedCompiler.cs
index f8184a6dd42c0cfdd749f6b18a190a3aff3ae3da..461f2f6c648c641961b33bde4cb3fdc0ea8a6d4a 100644 (file)
 #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 {
@@ -39,90 +42,121 @@ 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 ("/lib:", AdditionalLibPaths, ",");
-                       commandLine.AppendSwitchIfNotNull ("/addmodule:", AddModules, ",");
-                       //commandLine.AppendSwitchIfNotNull ("/codepage:", CodePage.ToString ());
-                       //debugType
-                       commandLine.AppendSwitchIfNotNull ("/define:", DefineConstants);
-                       //delaySign
-                       if (EmitDebugInformation)
-                               commandLine.AppendSwitch ("/debug");
+                       if (AddModules != null && AddModules.Length > 0)
+                               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) {
+                       if (LinkResources != null)
+                               foreach (ITaskItem item in LinkResources)
                                                commandLine.AppendSwitchIfNotNull ("/linkresource:", item.ItemSpec);
-                               }
-                       }
-                       commandLine.AppendSwitchIfNotNull ("/main:", MainEntryPoint);
-                       if (NoConfig)
-                               commandLine.AppendSwitch ("/noconfig");
-                       if (Optimize)
-                               commandLine.AppendSwitch ("/optimize");
+                       
+                       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 (References != null) {
-                               foreach (ITaskItem item in References) {
-                                       commandLine.AppendSwitchIfNotNull ("/reference:", item.ItemSpec);
-                               }
-                       }
-                       if (Resources != null) {
+                       
+                       if (Resources != null)
                                foreach (ITaskItem item in Resources) {
+                                       string logical_name = item.GetMetadata ("LogicalName");
+                                       if (logical_name.Length > 0)
+                                               commandLine.AppendSwitchIfNotNull ("/resource:",
+                                                               String.Format ("{0},{1}", item.ItemSpec, logical_name));
+                                       else
                                                commandLine.AppendSwitchIfNotNull ("/resource:", item.ItemSpec);
                                }
-                       }
-                       if (ResponseFiles != null) {
-                               foreach (ITaskItem item in ResponseFiles) {
-                                               commandLine.AppendFileNameIfNotNull (String.Format ("@{0}",item.ItemSpec));
-                               }
-                       }
-                       if (Sources != null) {
-                               foreach (ITaskItem item in Sources) {
+
+                       if (Sources != null)
+                               foreach (ITaskItem item in Sources)
                                                commandLine.AppendFileNameIfNotNull (item.ItemSpec);
-                               }
-                       }
-                       commandLine.AppendSwitchIfNotNull ("/target:", TargetType);
-                       if (TreatWarningsAsErrors)
-                               commandLine.AppendSwitch ("/warnaserror");
+                       
+                       if (TargetType != null)
+                               commandLine.AppendSwitchIfNotNull ("/target:", TargetType);
+                       if (Bag ["TreatWarningsAsErrors"] != null)
+                               if (TreatWarningsAsErrors)
+                                       commandLine.AppendSwitch ("/warnaserror+");
+                               else
+                                       commandLine.AppendSwitch ("/warnaserror-");
                        commandLine.AppendSwitchIfNotNull ("/win32icon:", Win32Icon);
-                       commandLine.AppendSwitchIfNotNull ("/win32res:", Win32Resource);
                }
 
+               [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)
                {
                }
                
+               [MonoTODO]
                protected override bool HandleTaskExecutionErrors ()
                {
-                       return true;
+                       if (!Log.HasLoggedErrors && ExitCode != 0)
+                               Log.LogError ("Compiler crashed with code: {0}.", ExitCode);
+
+                       return ExitCode == 0 && !Log.HasLoggedErrors;
                }
                
                [MonoTODO]
-               protected bool ListHasNoDuplicateItems (ITaskItem[] itemList,
+               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;
@@ -231,7 +265,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 {
@@ -239,7 +277,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.ToLowerInvariant ();
+                               } else
+                                       return null;
+                       }
                        set { Bag ["TargetType"] = value; }
                }