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 {
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);
- }
- }
+
if (TargetType != null)
commandLine.AppendSwitchIfNotNull ("/target:", TargetType);
- if (TreatWarningsAsErrors)
- commandLine.AppendSwitch ("/warnaserror");
+ 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 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;
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 {
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; }
}