From 0e5af666b114afbac8cd68c584ebf102ad55052f Mon Sep 17 00:00:00 2001 From: Alan McGovern Date: Thu, 30 Aug 2012 01:22:23 +0100 Subject: [PATCH] [Microsoft.Build.Tasks] Don't throw if duplicate dependencies are found We should use the dictionary setter instead of the Add method so that we do not get an exception if the same Nth order dependency is found multiple times --- .../ResolveAssemblyReference.cs | 2 +- .../ResolveAssemblyReferenceTest.cs | 57 +++++++++++++++--- .../binary/XbuildReferenceBugTest2.exe | Bin 0 -> 4608 bytes 3 files changed, 50 insertions(+), 9 deletions(-) create mode 100755 mcs/class/Microsoft.Build.Tasks/Test/resources/binary/XbuildReferenceBugTest2.exe diff --git a/mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/ResolveAssemblyReference.cs b/mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/ResolveAssemblyReference.cs index 0265415a436..e9a26a444eb 100644 --- a/mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/ResolveAssemblyReference.cs +++ b/mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/ResolveAssemblyReference.cs @@ -338,7 +338,7 @@ namespace Microsoft.Build.Tasks { if (resolved_ref != null && !IsFromGacOrTargetFramework (resolved_ref) && resolved_ref.FoundInSearchPath != SearchPath.PkgConfig) { - tempResolvedDepFiles.Add (resolved_ref.AssemblyName.FullName, resolved_ref.TaskItem); + tempResolvedDepFiles[resolved_ref.AssemblyName.FullName] = resolved_ref.TaskItem; dependencies.Enqueue (resolved_ref.TaskItem.ItemSpec); } } diff --git a/mcs/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/ResolveAssemblyReferenceTest.cs b/mcs/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/ResolveAssemblyReferenceTest.cs index 0cd3e79d6a7..5816d7adf5c 100644 --- a/mcs/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/ResolveAssemblyReferenceTest.cs +++ b/mcs/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/ResolveAssemblyReferenceTest.cs @@ -136,17 +136,58 @@ namespace MonoTests.Microsoft.Build.Tasks { Assert.IsTrue (big.Cast ().Any (item => item.Include.EndsWith ("FancyStuff.dll")), "A6"); Assert.IsTrue (big.Cast ().Any (item => item.Include.EndsWith ("Testing.dll")), "A7"); } - - string ResolveAssembly (string gacAssembly, string hintPath) + + [Test] + public void ResolveBinary_FancyStuffAndXbuild () + { + engine = new Engine (Consts.BinPath); + project = engine.CreateNewProject (); + project.LoadXml (ResolveAssembly (null, @"Test\resources\binary\FancyStuff.dll", @"Test\resources\binary\XbuildReferenceBugTest.exe")); + + Assert.IsTrue (project.Build ("A"), "A1"); + big = project.GetEvaluatedItemsByName ("ResolvedFiles"); + Assert.AreEqual (2, big.Count, "A2"); + Assert.IsTrue (big[0].Include.EndsWith ("FancyStuff.dll"), "A3"); + Assert.IsTrue (big[1].Include.EndsWith ("XbuildReferenceBugTest.exe"), "A3"); + + big = project.GetEvaluatedItemsByName ("ResolvedDependencyFiles"); + Assert.AreEqual (2, big.Count, "A4"); + Assert.IsTrue (big.Cast ().Any (item => item.Include.EndsWith ("SimpleWrite.dll")), "A5"); + Assert.IsTrue (big.Cast ().Any (item => item.Include.EndsWith ("Testing.dll")), "A6"); + } + + [Test] + public void ResolveBinary_SameAssemblyTwice () + { + engine = new Engine (Consts.BinPath); + project = engine.CreateNewProject (); + project.LoadXml (ResolveAssembly (null, @"Test\resources\binary\XbuildReferenceBugTest.exe", @"Test\resources\binary\XbuildReferenceBugTest2.exe")); + + Assert.IsTrue (project.Build ("A"), "A1"); + big = project.GetEvaluatedItemsByName ("ResolvedFiles"); + Assert.AreEqual (2, big.Count, "A2"); + Assert.IsTrue (big[0].Include.EndsWith ("XbuildReferenceBugTest.exe"), "A3"); + Assert.IsTrue (big[1].Include.EndsWith ("XbuildReferenceBugTest2.exe"), "A3b"); + + big = project.GetEvaluatedItemsByName ("ResolvedDependencyFiles"); + Assert.AreEqual (3, big.Count, "A4"); + Assert.IsTrue (big.Cast ().Any (item => item.Include.EndsWith ("SimpleWrite.dll")), "A5"); + Assert.IsTrue (big.Cast ().Any (item => item.Include.EndsWith ("FancyStuff.dll")), "A6"); + Assert.IsTrue (big.Cast ().Any (item => item.Include.EndsWith ("Testing.dll")), "A7"); + } + + string ResolveAssembly (string gacAssembly, params string[] hintPaths) { - string reference; + string reference = ""; if (string.IsNullOrEmpty (gacAssembly)) { - reference = string.Format ( - @" - {1} - ", System.IO.Path.GetFileNameWithoutExtension (hintPath), hintPath); + foreach (var hintPath in hintPaths) { + reference += string.Format ( + @" + {1} + ", System.IO.Path.GetFileNameWithoutExtension (hintPath), hintPath); + } } else { - reference = string.Format ( + reference += string.Format ( @"", gacAssembly); } diff --git a/mcs/class/Microsoft.Build.Tasks/Test/resources/binary/XbuildReferenceBugTest2.exe b/mcs/class/Microsoft.Build.Tasks/Test/resources/binary/XbuildReferenceBugTest2.exe new file mode 100755 index 0000000000000000000000000000000000000000..2f2d1650616c5b40303d9229b63d1198104455c4 GIT binary patch literal 4608 zcmeHKO>A7%6+Ulb=f|l{erOtt7M{lmf>eI~Nl4PfPR2h;n8+r^Gx;SddGqGZ_$BXW zxc5ER(@L$8Xr)RlvOw(uBqBjJED#G2fr_?LyFfxnmAV0mMFcy9#D-NDz<16Y#}mbd zptceVuIHY6?)kglJ@3AEu4gV>rFBHqf&SH3L^m*UD+v8&vIKR{18?`x>zm&1yJ1bg z-&daZjor|3UAv*}xlt4+c177bjch-%r%sjZFs>@6ySr;wEA;F!qG@X#oqX-c?DA?i zDQ9iAHWJ|{9m8KA1hLTz=uB)3xePZr!OtTtp+nAX9Tk30v_*a^V{4k3&^+Rnm@g1D zI$Of_;S$l0F#ljT(NEju-^Sawpo`^3%pYy@aT2wdVE)hbAkfJ^TevZkW)odhc4+QgIp?A}W|1h4o(C#hpJ9EVfQJa^6sOPJ@>oTXXNC5k}*EcA7u{}%e0 z&`yiBw$Q^u%R-l|&>E!Y5NbXB!+ObDPoIExQD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