Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

View File

@@ -315,7 +315,7 @@ namespace Microsoft.Build.BuildEngine {
return;
}
}
DirectoryScanner directoryScanner;
Expression includeExpr, excludeExpr;
ITaskItem[] includes, excludes;
@@ -341,8 +341,10 @@ namespace Microsoft.Build.BuildEngine {
directoryScanner.Includes = includes;
directoryScanner.Excludes = excludes;
if (project.FullFileName != String.Empty)
if (project.FullFileName != String.Empty) {
directoryScanner.ProjectFile = project.ThisFileFullPath;
directoryScanner.BaseDirectory = new DirectoryInfo (Path.GetDirectoryName (project.FullFileName));
}
else
directoryScanner.BaseDirectory = new DirectoryInfo (Directory.GetCurrentDirectory ());

View File

@@ -42,16 +42,19 @@ namespace Microsoft.Build.BuildEngine {
if (whenElement == null)
throw new ArgumentNullException ("whenElement");
this.whenElement = whenElement;
foreach (XmlElement xe in whenElement.ChildNodes) {
switch (xe.Name) {
foreach (XmlNode node in whenElement.ChildNodes) {
switch (node.NodeType) {
case XmlNodeType.Element:
var xe = (XmlElement)node;
switch (xe.Name) {
case "ItemGroup":
BuildItemGroup big = new BuildItemGroup (xe, parentProject, null, true);
//big.BindToXml (xe);
//big.BindToXml (xe);
groupingCollection.Add (big);
break;
case "PropertyGroup":
BuildPropertyGroup bpg = new BuildPropertyGroup (xe, parentProject, null, true);
//bpg.BindToXml (xe);
//bpg.BindToXml (xe);
groupingCollection.Add (bpg);
break;
case "Choose":
@@ -59,7 +62,13 @@ namespace Microsoft.Build.BuildEngine {
groupingCollection.Add (bc);
break;
default:
throw new InvalidProjectFileException ( string.Format ("Invalid element '{0}' in When.", xe.Name));
throw new InvalidProjectFileException (string.Format ("Invalid element '{0}' in When.", xe.Name));
}
break;
case XmlNodeType.Comment:
break;
default:
throw new InvalidProjectFileException (string.Format ("Invalid element '{0}' in When Condition.", node.NodeType));
}
}
}

View File

@@ -291,11 +291,7 @@ namespace Microsoft.Build.BuildEngine
// Hence we expect sender as a valid object only if it is IBuildEngine4 -
// only Microsoft.Build.Internal.BuildEngine4 implements it so far.
// (Used IBuildEngine3 because it needs to build for NET_4_0).
#if NET_4_0
var key = sender as IBuildEngine3 ?? dummy_key;
#else
var key = dummy_key;
#endif
if (!build_records.TryGetValue (key, out r)) {
r = new BuildRecord (this);
build_records.Add (key, r);

View File

@@ -38,6 +38,7 @@ namespace Microsoft.Build.BuildEngine {
DirectoryInfo baseDirectory;
ITaskItem[] includes, excludes;
ITaskItem[] matchedItems;
string projectFile;
static bool _runningOnWindows;
@@ -82,8 +83,11 @@ namespace Microsoft.Build.BuildEngine {
string name = include_item.ItemSpec;
if (!HasWildcard (name)) {
if (!excludedItems.ContainsKey (Path.GetFullPath(name)))
if (!excludedItems.ContainsKey (Path.GetFullPath (name))) {
includedItems.Add (include_item);
if (projectFile != null)
include_item.SetMetadata ("DefiningProjectFullPath", projectFile);
}
} else {
if (name.Split (Path.DirectorySeparatorChar).Length > name.Split (Path.AltDirectorySeparatorChar).Length) {
separatedPath = name.Split (new char [] {Path.DirectorySeparatorChar},
@@ -127,6 +131,8 @@ namespace Microsoft.Build.BuildEngine {
rec_dir += Path.DirectorySeparatorChar;
item.SetMetadata ("RecursiveDir", rec_dir);
}
if (projectFile != null)
item.SetMetadata ("DefiningProjectFullPath", projectFile);
includedItems.Add (item);
}
}
@@ -236,6 +242,11 @@ namespace Microsoft.Build.BuildEngine {
set { baseDirectory = value; }
}
public string ProjectFile {
get { return projectFile; }
set { projectFile = value; }
}
public ITaskItem[] Includes {
get { return includes; }
set { includes = value; }

View File

@@ -110,16 +110,12 @@ namespace Microsoft.Build.BuildEngine {
{
Toolsets.Add (new Toolset ("2.0",
ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version20)));
#if NET_3_5
Toolsets.Add (new Toolset ("3.0",
ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version30)));
Toolsets.Add (new Toolset ("3.5",
ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version35)));
#endif
#if NET_4_0
Toolsets.Add (new Toolset ("4.0",
ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version40)));
#endif
#if XBUILD_12
Toolsets.Add (new Toolset ("12.0", ToolLocationHelper.GetPathToBuildTools ("12.0")));
#endif
@@ -560,11 +556,9 @@ namespace Microsoft.Build.BuildEngine {
get {
// This is used as the fall back version if the
// project can't find a version to use
// Hard-coded to 2.0, so it allows even vs2005 projects
// to build correctly, as they won't have a ToolsVersion
// set!
return String.IsNullOrEmpty (defaultToolsVersion)
? "2.0"
?
"4.0"
: defaultToolsVersion;
}
set {

View File

@@ -152,6 +152,15 @@ namespace Microsoft.Build.BuildEngine {
project_attribute.IndexOf ("$(MSBuildExtensionsPath32)") >= 0 ||
project_attribute.IndexOf ("$(MSBuildExtensionsPath64)") >= 0;
bool condn_has_extn_ref = condition_attribute.IndexOf ("$(MSBuildExtensionsPath)") >= 0 ||
condition_attribute.IndexOf ("$(MSBuildExtensionsPath32)") >= 0 ||
condition_attribute.IndexOf ("$(MSBuildExtensionsPath64)") >= 0;
// we can skip the following logic in case the condition doesn't reference any extension paths
// and it evaluates to false since nothing would change anyway
if (!condn_has_extn_ref && !ConditionParser.ParseAndEvaluate (condition_attribute, project))
return;
string importingFile = importingProject != null ? importingProject.FullFileName : project.FullFileName;
DirectoryInfo base_dir_info = null;
if (!String.IsNullOrEmpty (importingFile))
@@ -231,7 +240,6 @@ namespace Microsoft.Build.BuildEngine {
if (String.IsNullOrEmpty (parsed_import))
throw new InvalidProjectFileException ("The required attribute \"Project\" in Import is empty");
#if NET_4_0
if (DirectoryScanner.HasWildcard (parsed_import)) {
var directoryScanner = new DirectoryScanner () {
Includes = new ITaskItem [] { new TaskItem (parsed_import) },
@@ -242,7 +250,6 @@ namespace Microsoft.Build.BuildEngine {
foreach (ITaskItem matchedItem in directoryScanner.MatchedItems)
yield return matchedItem.ItemSpec;
} else
#endif
yield return parsed_import;
}

View File

@@ -27,6 +27,7 @@
//
using System;
using System.IO;
using Mono.XBuild.Utilities;
namespace Microsoft.Build.BuildEngine
@@ -121,7 +122,20 @@ namespace Microsoft.Build.BuildEngine
public static string GetDirectoryNameOfFileAbove (string path, string file)
{
throw new NotImplementedException ("GetDirectoryNameOfFileAbove");
string filePath;
path = Path.GetFullPath (path);
while (true) {
filePath = Path.Combine (path, file);
if (File.Exists (filePath))
return path;
path = Path.GetDirectoryName (path);
if (path == null) // we traversed up until root without a match, return empty string
return "";
}
}
public static object GetRegistryValue (string key, string value)
@@ -136,7 +150,18 @@ namespace Microsoft.Build.BuildEngine
public static string MakeRelative (string basePath, string path)
{
throw new NotImplementedException ("MakeRelative");
if (String.IsNullOrEmpty (basePath))
return path;
// ensure trailing slash for basePath
if (basePath [basePath.Length - 1] != '\\' && basePath [basePath.Length - 1] != '/')
basePath += '/';
var uriBasePath = new Uri (basePath, UriKind.Absolute);
var uriPath = new Uri (path);
var uriRelative = uriBasePath.MakeRelativeUri (uriPath);
return Uri.UnescapeDataString (uriRelative.ToString ()).Replace ('/', '\\'); // msbuild uses backslash paths everywhere
}
public static string ValueOrDefault (string value, string defaultValue)
@@ -144,4 +169,4 @@ namespace Microsoft.Build.BuildEngine
return string.IsNullOrEmpty (value) ? defaultValue : value;
}
}
}
}

View File

@@ -323,9 +323,7 @@ namespace Microsoft.Build.BuildEngine {
Reevaluate ();
}
#if NET_4_0
ProcessBeforeAndAfterTargets ();
#endif
if (targetNames == null || targetNames.Length == 0) {
if (defaultTargets != null && defaultTargets.Length != 0) {
@@ -404,7 +402,6 @@ namespace Microsoft.Build.BuildEngine {
return sb.ToString ();
}
#if NET_4_0
void ProcessBeforeAndAfterTargets ()
{
var beforeTable = Targets.AsIEnumerable ()
@@ -440,7 +437,6 @@ namespace Microsoft.Build.BuildEngine {
expr.Parse (targets, ParseOptions.AllowItemsNoMetadataAndSplit);
return (string []) expr.ConvertTo (this, typeof (string []));
}
#endif
[MonoTODO]
public string [] GetConditionedPropertyValues (string propertyName)
@@ -1429,6 +1425,10 @@ namespace Microsoft.Build.BuildEngine {
return default (T);
}
internal string ThisFileFullPath {
get { return this_file_property_stack.Peek (); }
}
// Used for MSBuild*This* set of properties
internal void PushThisFileProperty (string full_filename)
{

View File

@@ -77,7 +77,6 @@ namespace Microsoft.Build.BuildEngine {
} else if (onErrorFound)
throw new InvalidProjectFileException (
"The element <OnError> must be last under element <Target>. Found element <Error> instead.");
#if NET_3_5
else if (xe.Name == "ItemGroup") {
var group = new BuildTaskItemGroup (xe, this);
buildTasks.AddRange (group.Items);
@@ -86,7 +85,6 @@ namespace Microsoft.Build.BuildEngine {
buildTasks.Add (new BuildTaskPropertyGroup (xe, this));
continue;
}
#endif
else
buildTasks.Add (new BuildTask (xe, this));
}
@@ -176,14 +174,10 @@ namespace Microsoft.Build.BuildEngine {
try {
buildState = BuildState.Started;
#if NET_4_0
result = BuildDependencies (out executeOnErrors) &&
BuildBeforeThisTargets (out executeOnErrors) &&
DoBuild (out executeOnErrors) && // deps & Before targets built fine, do main build
BuildAfterThisTargets (out executeOnErrors);
#else
result = BuildDependencies (out executeOnErrors) && DoBuild (out executeOnErrors);
#endif
buildState = BuildState.Finished;
} catch (Exception e) {
@@ -224,7 +218,6 @@ namespace Microsoft.Build.BuildEngine {
return result;
}
#if NET_4_0
bool BuildBeforeThisTargets (out bool executeOnErrors)
{
executeOnErrors = false;
@@ -246,7 +239,6 @@ namespace Microsoft.Build.BuildEngine {
return result;
}
#endif
bool BuildOtherTargets (IEnumerable<string> targetNames, Action<string> missing_target, out bool executeOnErrors)
{
@@ -379,7 +371,6 @@ namespace Microsoft.Build.BuildEngine {
}
}
#if NET_4_0
internal string BeforeTargets {
get { return targetElement.GetAttribute ("BeforeTargets"); }
}
@@ -390,7 +381,6 @@ namespace Microsoft.Build.BuildEngine {
internal List<string> BeforeThisTargets { get; set; }
internal List<string> AfterThisTargets { get; set; }
#endif
internal List<IBuildTask> BuildTasks {
get { return buildTasks; }

View File

@@ -14,6 +14,7 @@ Microsoft.Build.BuildEngine/ImportTest.cs
Microsoft.Build.BuildEngine/InternalLoggerExceptionTest.cs
Microsoft.Build.BuildEngine/InvalidProjectFileExceptionTest.cs
Microsoft.Build.BuildEngine/ProjectTest.cs
Microsoft.Build.BuildEngine/PredefinedPropertyFunctionsTest.cs
Microsoft.Build.BuildEngine/TargetCollectionTest.cs
Microsoft.Build.BuildEngine/TargetTest.cs
Microsoft.Build.BuildEngine/TestNamespaceManager.cs

View File

@@ -44,9 +44,13 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<Choose>
<When Condition=""'$(Configuration)' == ''"">
<!-- A user comment is allowed here -->
<ItemGroup>
<A Include='a' />
</ItemGroup>
</When>
</Choose>
</Project>

View File

@@ -39,14 +39,14 @@ public static class Consts {
public static string BinPath {
get {
if (RunningOnMono ()) {
#if XBUILD_12
#if XBUILD_14
string profile = "xbuild_14";
#elif XBUILD_12
string profile = "xbuild_12";
#elif NET_4_5
string profile = "net_4_5";
#elif NET_4_0
string profile = "net_4_0";
#elif NET_3_5
string profile = "net_3_5";
#else
string profile = "net_2_0";
#endif
@@ -54,14 +54,14 @@ public static class Consts {
var lib = Path.GetDirectoryName (Path.GetDirectoryName (corlib));
return Path.Combine (lib, profile);
} else {
#if XBUILD_12
#if XBUILD_14
return ToolLocationHelper.GetPathToBuildTools ("14.0");
#elif XBUILD_12
return ToolLocationHelper.GetPathToBuildTools ("12.0");
#elif NET_4_5
return ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version45);
#elif NET_4_0
return ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version40);
#elif NET_3_5
return ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version35);
#else
return ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version20);
#endif
@@ -71,12 +71,12 @@ public static class Consts {
public static string ToolsVersionString {
get {
#if XBUILD_12
#if XBUILD_14
return " ToolsVersion='14.0'";
#elif XBUILD_12
return " ToolsVersion='12.0'";
#elif NET_4_0
return " ToolsVersion='4.0'";
#elif NET_3_5
return " ToolsVersion='3.5'";
#else
return String.Empty;
#endif
@@ -85,12 +85,12 @@ public static class Consts {
public static string GetTasksAsmPath ()
{
#if XBUILD_12
#if XBUILD_14
return Path.Combine (BinPath, "Microsoft.Build.Tasks.Core.dll");
#elif XBUILD_12
return Path.Combine (BinPath, "Microsoft.Build.Tasks.v12.0.dll");
#elif NET_4_0
return Path.Combine (BinPath, "Microsoft.Build.Tasks.v4.0.dll");
#elif NET_3_5
return Path.Combine (BinPath, "Microsoft.Build.Tasks.v3.5.dll");
#else
return Path.Combine (BinPath, "Microsoft.Build.Tasks.dll");
#endif

View File

@@ -209,7 +209,38 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
project.LoadXml (documentString);
}
#if NET_4_0
[Test]
public void TestImportEmptyVariableWithConditionFalse ()
{
string documentString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<Import Project='$(ImportPath)' Condition='false' />
<Target Name='Build' />
</Project>";
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
project.LoadXml (documentString);
Assert.IsTrue (project.Build ("Build"), "Build failed");
}
[Test]
public void TestImportProjectWithConditionReferencingExtensionPath ()
{
string documentString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<Import Project='$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets' Condition=""Exists('$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets')"" />
<Target Name='Build' />
</Project>";
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
project.LoadXml (documentString);
Assert.IsTrue (project.Build ("Build"), "Build failed");
}
[Test]
public void TestImportWildcard ()
{
@@ -264,7 +295,6 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
File.Delete (second_project);
}
}
#endif
}
}

View File

@@ -0,0 +1,78 @@
//
// PredefinedPropertyFunctionsTest.cs
//
// Authors:
// Alexander Köplinger (alex.koeplinger@outlook.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
using System;
using Microsoft.Build.BuildEngine;
using NUnit.Framework;
namespace MonoTests.Microsoft.Build.BuildEngine {
[TestFixture]
public class PredefinedPropertyFunctionsTest {
[Test]
public void TestMakeRelative ()
{
string documentString = @"
<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<PropertyGroup>
<Path1>c:\users\</Path1>
<Path2>c:\users\username\</Path2>
<Path3>/home/user/</Path3>
<Path4>/home/user/username/</Path4>
<Path5>/home/user/</Path5>
<Path6>/tmp/test/file</Path6>
<Path7>/home/user/</Path7>
<Path8>/home/user/username/path with spaces + special? chars (1)/</Path8>
<Path9>c:\users</Path9>
<Path10>c:\users\username\test\</Path10>
<Path11>/home/user</Path11>
<Path12>/home/user/username/test/</Path12>
<MakeRelative1>$([MSBuild]::MakeRelative($(Path1), $(Path2)))</MakeRelative1>
<MakeRelative2>$([MSBuild]::MakeRelative($(Path2), $(Path1)))</MakeRelative2>
<MakeRelative3>$([MSBuild]::MakeRelative($(Path3), $(Path4)))</MakeRelative3>
<MakeRelative4>$([MSBuild]::MakeRelative($(Path4), $(Path3)))</MakeRelative4>
<MakeRelative5>$([MSBuild]::MakeRelative($(Path5), $(Path6)))</MakeRelative5>
<MakeRelative6>$([MSBuild]::MakeRelative($(Path7), $(Path8)))</MakeRelative6>
<MakeRelative7>$([MSBuild]::MakeRelative($(Path9), $(Path10)))</MakeRelative7>
<MakeRelative8>$([MSBuild]::MakeRelative($(Path11), $(Path12)))</MakeRelative8>
</PropertyGroup>
</Project>
";
var engine = new Engine (Consts.BinPath);
var project = engine.CreateNewProject ();
project.LoadXml (documentString);
Assert.AreEqual (@"username\", project.EvaluatedProperties ["MakeRelative1"].FinalValue, "#1");
Assert.AreEqual (@"..\", project.EvaluatedProperties ["MakeRelative2"].FinalValue, "#2");
Assert.AreEqual (@"username\", project.EvaluatedProperties ["MakeRelative3"].FinalValue, "#3");
Assert.AreEqual (@"..\", project.EvaluatedProperties ["MakeRelative4"].FinalValue, "#4");
Assert.AreEqual (@"..\..\tmp\test\file", project.EvaluatedProperties ["MakeRelative5"].FinalValue, "#5");
Assert.AreEqual (@"username\path with spaces + special? chars (1)\", project.EvaluatedProperties ["MakeRelative6"].FinalValue, "#6");
Assert.AreEqual (@"username\test\", project.EvaluatedProperties ["MakeRelative7"].FinalValue, "#7");
Assert.AreEqual (@"username\test\", project.EvaluatedProperties ["MakeRelative8"].FinalValue, "#8");
}
}
}

View File

@@ -180,7 +180,7 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
}
[Test]
[ExpectedException (typeof (ArgumentException))]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void TestCopyTo4 ()
{
string documentString = @"

View File

@@ -349,7 +349,6 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
}
}
#if NET_3_5
bool Build (string projectXml, ILogger logger)
{
if (Environment.OSVersion.Platform == PlatformID.Win32NT) {
@@ -786,7 +785,6 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
3, "COMPILE: input1a;input1b - output1", "COMPILE: input2a;input2b - output2");
}
#endif
[Test]
public void TestTargetOutputsIncludingMetadata ()