[xbuild] Fix bug #671700, resource naming in presence of "Link".
authorAnkit Jain <radical@corewars.org>
Tue, 15 Feb 2011 14:38:05 +0000 (20:08 +0530)
committerAnkit Jain <radical@corewars.org>
Tue, 15 Feb 2011 14:46:33 +0000 (20:16 +0530)
AssignTargetPath.cs: If 'Link' metadata is present, then use that
as the target path.

Add relevant test.

mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/AssignTargetPath.cs
mcs/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/AssignTargetPathTest.cs

index 4b71e08ab7a55ae9970a2c6db48c2d9188a98deb..abec0635561bb4bc4d158c4fdf357ce0fcd0f133 100644 (file)
@@ -54,24 +54,30 @@ namespace Microsoft.Build.Tasks {
                        assignedFiles = new ITaskItem [files.Length];
                        for (int i = 0; i < files.Length; i ++) {
                                string file = files [i].ItemSpec;
+                               string link = files [i].GetMetadata ("Link");
                                string afile = null;
-                               //FIXME: Hack!
-                               string normalized_root = Path.GetFullPath (rootFolder);
 
-                               // cur dir should already be set to
-                               // the project dir
-                               file = Path.GetFullPath (file);
+                               if (String.IsNullOrEmpty (link)) {
+                                       //FIXME: Hack!
+                                       string normalized_root = Path.GetFullPath (rootFolder);
 
-                               if (file.StartsWith (normalized_root)) {
-                                       afile = Path.GetFullPath (file).Substring (
-                                                       normalized_root.Length);
-                                       // skip over "root/"
-                                       if (afile [0] == '\\' ||
-                                               afile [0] == '/')
-                                               afile = afile.Substring (1);
+                                       // cur dir should already be set to
+                                       // the project dir
+                                       file = Path.GetFullPath (file);
 
+                                       if (file.StartsWith (normalized_root)) {
+                                               afile = Path.GetFullPath (file).Substring (
+                                                               normalized_root.Length);
+                                               // skip over "root/"
+                                               if (afile [0] == '\\' ||
+                                                       afile [0] == '/')
+                                                       afile = afile.Substring (1);
+
+                                       } else {
+                                               afile = Path.GetFileName (file);
+                                       }
                                } else {
-                                       afile = Path.GetFileName (file);
+                                       afile = link;
                                }
 
                                assignedFiles [i] = new TaskItem (files [i]);
index 959c8991b771a3d91c2573521f068cb5d8093f58..6524e0b1f2ebe77eb550b4d0e59931777c23fa6e 100755 (executable)
@@ -115,6 +115,53 @@ namespace MonoTests.Microsoft.Build.Tasks
                        }
                }
 
+               [Test]
+               public void TestLink ()
+               {
+                       string projectText = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+                               <ItemGroup>
+                                       <FooFiles Include=""xyz.cs"">
+                                               <Child>Cxyz.cs</Child>
+                                               <Link>Test\Link\xyz.cs</Link>
+                                       </FooFiles>
+                                       <FooFiles Include=""rel\bar.resx"">
+                                               <Child>Crel\bar.resx</Child>
+                                               <Link>Test\Link\bar.resx</Link>
+                                       </FooFiles>
+                                        <FooFiles Include=""rel\qwe.txt"">
+                                                <Child>Crel\qwe.txt</Child>
+                                                <Link>..\Test\Link\qwe.txt</Link>
+                                        </FooFiles>
+                               </ItemGroup>
+                               <Target Name=""1"">
+                                       <AssignTargetPath Files=""@(FooFiles)"" RootFolder=""/"">
+                                               <Output TaskParameter=""AssignedFiles"" ItemName=""FooPath"" />
+                                       </AssignTargetPath>
+                               </Target>
+                       </Project>";
+                       Engine engine = new Engine(Consts.BinPath);
+                       Project project = engine.CreateNewProject();
+
+                       project.LoadXml(projectText);
+
+                       string id = "A";
+                       Assert.IsTrue(project.Build("1"), id + "1 : Error in building");
+
+                       string [] files = new string [] { "xyz.cs", "rel/bar.resx", "rel/qwe.txt"};
+                       string [] assignedFiles = new string [] { "Test/Link/xyz.cs", "Test/Link/bar.resx", "../Test/Link/qwe.txt"};
+
+                       BuildItemGroup include = project.GetEvaluatedItemsByName("FooPath");
+                       Assert.AreEqual(files.Length, include.Count, id + "2");
+
+                       for (int i = 0; i < files.Length; i++) {
+                               Assert.AreEqual (files [i], include [i].FinalItemSpec, id + "3, file #" + i);
+                               Assert.IsTrue (include[i].HasMetadata ("TargetPath"), id + "4, file #" + i + ", TargetPath metadata missing");
+                               Assert.AreEqual (assignedFiles [i], include[i].GetMetadata("TargetPath"), id + "5, file #" + i);
+                               Assert.IsTrue (include [i].HasMetadata ("Child"), id + "6, file #" + i + ", Child metadata missing");
+                               Assert.AreEqual ("C" + files [i], include [i].GetMetadata ("Child"), id + "7, file #" + i + ", Child metadata value incorrect");
+                       }
+               }
+
                void CheckTargetPath(string[] files, string[] assignedFiles, string rootFolder, string id)
                {
                        Engine engine = new Engine(Consts.BinPath);