Merge pull request #4152 from BrzVlad/misc-gc-altstack
[mono.git] / mcs / class / Microsoft.Build.Tasks / Microsoft.Build.Tasks / ManagedCompiler.cs
index 8f92f0bc4b9d026c04a5fc014ed9c1ab13256f26..19eec8686542011b04d2515874b9a86450136161 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 {
@@ -52,12 +53,17 @@ namespace Microsoft.Build.Tasks {
                protected internal override void AddResponseFileCommands (
                                                 CommandLineBuilderExtension commandLine)
                {
-                       commandLine.AppendSwitchIfNotNull ("/lib:", AdditionalLibPaths, ",");
-                       commandLine.AppendSwitchIfNotNull ("/addmodule:", AddModules, ",");
+                       if (AddModules != null && AddModules.Length > 0)
+                               commandLine.AppendSwitchIfNotNull ("/addmodule:", AddModules, ",");
                        if (Bag ["CodePage"] != null)
                                commandLine.AppendSwitchIfNotNull ("/codepage:", CodePage.ToString ());
-                       commandLine.AppendSwitchIfNotNull ("/debug:", DebugType);
-                       commandLine.AppendSwitchIfNotNull ("/define:", DefineConstants);
+
+                       var dtype = DebugType;
+                       if (string.Equals (dtype, "full", StringComparison.OrdinalIgnoreCase) || string.Equals (dtype, "pdbonly", StringComparison.OrdinalIgnoreCase))
+                               dtype = "portable";
+
+                       commandLine.AppendSwitchIfNotNull ("/debug:", dtype);
+
                        if (Bag ["DelaySign"] != null)
                                if (DelaySign)
                                        commandLine.AppendSwitch ("/delaysign+");
@@ -65,48 +71,46 @@ namespace Microsoft.Build.Tasks {
                                        commandLine.AppendSwitch ("/delaysign-");
                        if (Bag ["EmitDebugInformation"] != null)
                                if (EmitDebugInformation)
-                                       commandLine.AppendSwitch ("/debug+");
+                                       commandLine.AppendSwitch ("/debug:portable");
                                else
                                        commandLine.AppendSwitch ("/debug-");
                        //fileAlignment
                        commandLine.AppendSwitchIfNotNull ("/keycontainer:", KeyContainer);
                        commandLine.AppendSwitchIfNotNull ("/keyfile:", KeyFile);
+                       if (KeyFile != null && !DelaySign)
+                               commandLine.AppendSwitch("/publicsign");
+
                        // 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 (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);
-                               }
-                       }
+                       
                        if (TargetType != null)
                                commandLine.AppendSwitchIfNotNull ("/target:", TargetType);
                        if (Bag ["TreatWarningsAsErrors"] != null)
@@ -115,7 +119,6 @@ namespace Microsoft.Build.Tasks {
                                else
                                        commandLine.AppendSwitch ("/warnaserror-");
                        commandLine.AppendSwitchIfNotNull ("/win32icon:", Win32Icon);
-                       commandLine.AppendSwitchIfNotNull ("/win32res:", Win32Resource);
                }
 
                [MonoTODO]
@@ -137,17 +140,20 @@ namespace Microsoft.Build.Tasks {
                [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)
                {
-                       Hashtable items = new Hashtable ();
+                       Dictionary <string, object> items = new Dictionary <string, object> ();
                        
                        foreach (ITaskItem item in itemList) {
-                               if (items.Contains (item.ItemSpec))
+                               if (!items.ContainsKey (item.ItemSpec))
                                        items.Add (item.ItemSpec, null);
                                else
                                        return false;
@@ -156,6 +162,15 @@ namespace Microsoft.Build.Tasks {
                        return true;
                }
 
+               protected internal virtual bool UseAlternateCommandLineToolToExecute ()
+               {
+                       //
+                       // If an alternate tool name or tool path was specified in the project file, then that tool is used 
+                       // rather than the host compiler for integrated development environment (IDE) builds.
+                       //
+                       return !string.IsNullOrEmpty (ToolPath) || ToolName != ToolExe;
+               }
+
                [MonoTODO]
                protected override bool ValidateParameters ()
                {
@@ -265,18 +280,24 @@ namespace Microsoft.Build.Tasks {
 
                public ITaskItem[] Sources {
                        get { return (ITaskItem[]) Bag ["Sources"]; }
-                       // FIXME: setting sources changes OutputAssembly
-                       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 {
                        get { return Console.Error.Encoding; }
                }
 
-               // FIXME: hack to get build of hello world working
                public string TargetType {
                        get {
-                               return  (Bag.Contains ("TargetType")) ? (((string) Bag ["TargetType"]).ToLower ()) : null;
+                               if (Bag.Contains ("TargetType")) {
+                                       string s = (string) Bag ["TargetType"];
+                                       return s.ToLowerInvariant ();
+                               } else
+                                       return null;
                        }
                        set { Bag ["TargetType"] = value; }
                }
@@ -303,4 +324,3 @@ namespace Microsoft.Build.Tasks {
        }
 }
 
-#endif