From 693176c27f9cc574f69dacdf661c521c4ed28276 Mon Sep 17 00:00:00 2001 From: Michael Hutchinson Date: Tue, 11 Feb 2014 16:46:28 -0500 Subject: [PATCH] [xbuild] Fix Tooltask.ToolPath behaviour to match .NET --- .../Microsoft.Build.Tasks/AL.cs | 8 ++--- .../Microsoft.Build.Tasks/Csc.cs | 10 ++++--- .../Microsoft.Build.Tasks/GenerateResource.cs | 6 ++-- .../Microsoft.Build.Tasks/LC.cs | 4 ++- .../Microsoft.Build.Tasks/Vbc.cs | 4 ++- .../Microsoft.Build.Utilities/ToolTask.cs | 13 ++------- .../Microsoft.Build.Utilities/ToolTaskTest.cs | 29 +++++++++++++++++++ .../xbuild/data/2.0/Microsoft.CSharp.targets | 5 ---- .../xbuild/data/3.5/Microsoft.CSharp.targets | 5 ---- 9 files changed, 52 insertions(+), 32 deletions(-) diff --git a/mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/AL.cs b/mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/AL.cs index 6b91a2e2554..1fc961b72dc 100644 --- a/mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/AL.cs +++ b/mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/AL.cs @@ -98,7 +98,9 @@ namespace Microsoft.Build.Tasks { protected override string GenerateFullPathToTool () { - return Path.Combine (ToolPath, ToolExe); + if (!string.IsNullOrEmpty (ToolPath)) + return Path.Combine (ToolPath, ToolExe); + return ToolLocationHelper.GetPathToDotNetFrameworkFile (ToolExe, TargetDotNetFrameworkVersion.VersionLatest); } public string AlgorithmId { @@ -234,9 +236,7 @@ namespace Microsoft.Build.Tasks { } protected override string ToolName { - get { - return MSBuildUtils.RunningOnWindows ? "al.bat" : "al"; - } + get { return "al.exe"; } } public string Trademark { diff --git a/mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/Csc.cs b/mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/Csc.cs index 20ad611efd3..142e73eddeb 100644 --- a/mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/Csc.cs +++ b/mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/Csc.cs @@ -43,6 +43,10 @@ namespace Microsoft.Build.Tasks { protected internal override void AddResponseFileCommands (CommandLineBuilderExtension commandLine) { +#if !NET_4_0 + //pre-MSBuild 2 targets don't support multi-targeting, so tell compiler to use 2.0 corlib + commandLine.AppendSwitch ("/sdk:2"); +#endif base.AddResponseFileCommands (commandLine); if (AdditionalLibPaths != null && AdditionalLibPaths.Length > 0) @@ -129,11 +133,9 @@ namespace Microsoft.Build.Tasks { protected override string GenerateFullPathToTool () { - string exe = !string.IsNullOrEmpty (ToolExe)? ToolExe : ToolName; - string path = ToolPath; if (!string.IsNullOrEmpty (ToolPath)) - return Path.Combine (path, exe); - return ToolLocationHelper.GetPathToDotNetFrameworkFile (exe, TargetDotNetFrameworkVersion.VersionLatest); + return Path.Combine (ToolPath, ToolExe); + return ToolLocationHelper.GetPathToDotNetFrameworkFile (ToolExe, TargetDotNetFrameworkVersion.VersionLatest); } [MonoTODO] diff --git a/mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/GenerateResource.cs b/mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/GenerateResource.cs index 60dd7a68c4b..8abdad3b7f7 100644 --- a/mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/GenerateResource.cs +++ b/mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/GenerateResource.cs @@ -376,7 +376,9 @@ namespace Microsoft.Build.Tasks { protected override string GenerateFullPathToTool () { - return Path.Combine (ToolPath, ToolExe); + if (!string.IsNullOrEmpty (ToolPath)) + return Path.Combine (ToolPath, ToolExe); + return ToolLocationHelper.GetPathToDotNetFrameworkFile (ToolExe, TargetDotNetFrameworkVersion.VersionLatest); } protected override MessageImportance StandardOutputLoggingImportance { @@ -384,7 +386,7 @@ namespace Microsoft.Build.Tasks { } protected override string ToolName { - get { return MSBuildUtils.RunningOnWindows ? "resgen2.bat" : "resgen2"; } + get { return "resgen.exe"; } } public string SourceFile { get; set; } diff --git a/mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/LC.cs b/mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/LC.cs index 3d91d826dab..d26974c6ab7 100644 --- a/mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/LC.cs +++ b/mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/LC.cs @@ -72,7 +72,9 @@ namespace Microsoft.Build.Tasks { protected override string GenerateFullPathToTool () { - return Path.Combine (ToolPath, ToolExe); + if (!string.IsNullOrEmpty (ToolPath)) + return Path.Combine (ToolPath, ToolExe); + return ToolLocationHelper.GetPathToDotNetFrameworkFile (ToolExe, TargetDotNetFrameworkVersion.VersionLatest); } protected override bool ValidateParameters() diff --git a/mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/Vbc.cs b/mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/Vbc.cs index 80d500c16c7..107f9eb2896 100644 --- a/mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/Vbc.cs +++ b/mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/Vbc.cs @@ -141,7 +141,9 @@ namespace Microsoft.Build.Tasks { [MonoTODO] protected override string GenerateFullPathToTool () { - return Path.Combine (ToolPath, ToolExe); + if (!string.IsNullOrEmpty (ToolPath)) + return Path.Combine (ToolPath, ToolExe); + return ToolLocationHelper.GetPathToDotNetFrameworkFile (ToolExe, TargetDotNetFrameworkVersion.VersionLatest); } [MonoTODO] diff --git a/mcs/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/ToolTask.cs b/mcs/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/ToolTask.cs index 01a7c453aec..ee7c37a3691 100644 --- a/mcs/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/ToolTask.cs +++ b/mcs/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/ToolTask.cs @@ -72,7 +72,6 @@ namespace Microsoft.Build.Utilities { this.TaskResources = taskResources; this.HelpKeywordPrefix = helpKeywordPrefix; - this.toolPath = MonoLocationHelper.GetBinDir (); this.responseFileEncoding = Encoding.UTF8; this.timeout = Int32.MaxValue; } @@ -440,15 +439,12 @@ namespace Microsoft.Build.Utilities public virtual string ToolExe { get { - if (toolExe == null) + if (string.IsNullOrEmpty (toolExe)) return ToolName; else return toolExe; } - set { - if (!String.IsNullOrEmpty (value)) - toolExe = value; - } + set { toolExe = value; } } protected abstract string ToolName @@ -459,10 +455,7 @@ namespace Microsoft.Build.Utilities public string ToolPath { get { return toolPath; } - set { - if (!String.IsNullOrEmpty (value)) - toolPath = value; - } + set { toolPath = value; } } // Keep in sync with mcs/class/System/Microsoft.CSharp/CSharpCodeCompiler.cs diff --git a/mcs/class/Microsoft.Build.Utilities/Test/Microsoft.Build.Utilities/ToolTaskTest.cs b/mcs/class/Microsoft.Build.Utilities/Test/Microsoft.Build.Utilities/ToolTaskTest.cs index 8b3ae6e69c4..a76e13f1be6 100644 --- a/mcs/class/Microsoft.Build.Utilities/Test/Microsoft.Build.Utilities/ToolTaskTest.cs +++ b/mcs/class/Microsoft.Build.Utilities/Test/Microsoft.Build.Utilities/ToolTaskTest.cs @@ -56,6 +56,23 @@ namespace MonoTests.Microsoft.Build.Utilities { task.Codes.Clear (); } } + + [Test] + public void ToolExeAndPath () + { + TestToolTask a = new TestToolTask (); + Assert.AreEqual (a.ToolExe, "TestTool.exe", "#1"); + a.ToolExe = "Foo"; + Assert.AreEqual (a.ToolExe, "Foo", "#2"); + a.ToolExe = ""; + Assert.AreEqual (a.ToolExe, "TestTool.exe", "#3"); + + Assert.AreEqual (a.ToolPath, null, "#4"); + a.ToolPath = "Bar"; + Assert.AreEqual (a.ToolPath, "Bar", "#5"); + a.ToolPath = ""; + Assert.AreEqual (a.ToolPath, "", "#6"); + } } class LogEventsFromTextOutputToolTask : ToolTask { @@ -137,5 +154,17 @@ namespace MonoTests.Microsoft.Build.Utilities { Codes.Add (e.Code); } } + + class TestToolTask : ToolTask { + + protected override string ToolName { + get { return "TestTool.exe"; } + } + + protected override string GenerateFullPathToTool () + { + throw new NotImplementedException (); + } + } } diff --git a/mcs/tools/xbuild/data/2.0/Microsoft.CSharp.targets b/mcs/tools/xbuild/data/2.0/Microsoft.CSharp.targets index 66e00b8f930..114e862c88c 100644 --- a/mcs/tools/xbuild/data/2.0/Microsoft.CSharp.targets +++ b/mcs/tools/xbuild/data/2.0/Microsoft.CSharp.targets @@ -96,9 +96,4 @@ - - - gmcs - gmcs.bat - diff --git a/mcs/tools/xbuild/data/3.5/Microsoft.CSharp.targets b/mcs/tools/xbuild/data/3.5/Microsoft.CSharp.targets index 66e00b8f930..114e862c88c 100644 --- a/mcs/tools/xbuild/data/3.5/Microsoft.CSharp.targets +++ b/mcs/tools/xbuild/data/3.5/Microsoft.CSharp.targets @@ -96,9 +96,4 @@ - - - gmcs - gmcs.bat - -- 2.25.1