Imported Upstream version 3.8.0

Former-commit-id: 6a76a29bd07d86e57c6c8da45c65ed5447d38a61
This commit is contained in:
Jo Shields
2014-09-04 09:07:35 +01:00
parent a575963da9
commit fe777c5c82
1062 changed files with 12460 additions and 5983 deletions

View File

@@ -533,6 +533,8 @@ namespace Microsoft.Build.Construction
var item = CreateItemGroupElement ();
AppendChild (item);
return item;
case "ImportGroup":
return AddImportGroup ();
case "Import":
return AddImport (null);
case "Target":

View File

@@ -494,6 +494,11 @@ namespace Microsoft.Build.Evaluation
});
yield return create ("MSBuildToolsPath", () => toolset.ToolsPath);
yield return create ("MSBuildToolsVersion", () => toolset.ToolsVersion);
// This is an implementation specific special property for this Microsoft.Build.dll to differentiate
// the build from Microsoft.Build.Engine.dll. It is significantly used in some *.targets file we share
// between old and new build engine.
yield return create ("MonoUseMicrosoftBuildDll", () => "True");
}
// These are required for reserved property, represents dynamically changing property values.

View File

@@ -164,7 +164,7 @@ namespace Microsoft.Build.Execution
// FIXME: this is kind of workaround for unavoidable issue that PLATFORM=* is actually given
// on some platforms and that prevents setting default "PLATFORM=AnyCPU" property.
if (!string.Equals ("PLATFORM", (string) p.Key, StringComparison.OrdinalIgnoreCase))
this.properties [(string) p.Key] = new ProjectPropertyInstance ((string) p.Key, false, (string) p.Value);
this.properties [(string) p.Key] = new ProjectPropertyInstance ((string) p.Key, true, (string) p.Value);
foreach (var p in global_properties)
this.properties [p.Key] = new ProjectPropertyInstance (p.Key, false, p.Value);
var tools = projects.GetToolset (tools_version) ?? projects.GetToolset (projects.DefaultToolsVersion);
@@ -256,7 +256,7 @@ namespace Microsoft.Build.Execution
void EvaluateItems (ProjectRootElement xml, IEnumerable<ProjectElement> elements)
{
foreach (var child in elements) {
foreach (var child in elements.Reverse ()) {
var ige = child as ProjectItemGroupElement;
if (ige != null) {
foreach (var p in ige.Items) {
@@ -435,6 +435,7 @@ namespace Microsoft.Build.Execution
var parameters = new BuildParameters (projects) {
ForwardingLoggers = remoteLoggers,
Loggers = loggers,
DefaultToolsVersion = projects.DefaultToolsVersion,
};
var requestData = new BuildRequestData (this, targets ?? DefaultTargets.ToArray ());
var result = manager.Build (parameters, requestData);

View File

@@ -37,6 +37,7 @@ using Microsoft.Build.Exceptions;
using System.Globalization;
using Microsoft.Build.Construction;
using Microsoft.Build.Internal.Expressions;
using System.Xml;
namespace Microsoft.Build.Internal
{
@@ -121,17 +122,23 @@ namespace Microsoft.Build.Internal
try {
var initialPropertiesFormatted = "Initial Properties:\n" + string.Join (Environment.NewLine, project.Properties.OrderBy (p => p.Name).Select (p => string.Format ("{0} = {1}", p.Name, p.EvaluatedValue)).ToArray ());
LogMessageEvent (new BuildMessageEventArgs (initialPropertiesFormatted, null, null, MessageImportance.Low));
var initialGlobalPropertiesFormatted = "Initial Global Properties:\n" + string.Join (Environment.NewLine, project.Properties.OrderBy (p => p.Name).Where (p => p.IsImmutable).Select (p => string.Format ("{0} = {1}", p.Name, p.EvaluatedValue)).ToArray ());
LogMessageEvent (new BuildMessageEventArgs (initialGlobalPropertiesFormatted, null, null, MessageImportance.Low));
var initialProjectPropertiesFormatted = "Initial Project Properties:\n" + string.Join (Environment.NewLine, project.Properties.OrderBy (p => p.Name).Where (p => !p.IsImmutable).Select (p => string.Format ("{0} = {1}", p.Name, p.EvaluatedValue)).ToArray ());
LogMessageEvent (new BuildMessageEventArgs (initialProjectPropertiesFormatted, null, null, MessageImportance.Low));
var initialItemsFormatted = "Initial Items:\n" + string.Join (Environment.NewLine, project.Items.OrderBy (i => i.ItemType).Select (i => string.Format ("{0} : {1}", i.ItemType, i.EvaluatedInclude)).ToArray ());
LogMessageEvent (new BuildMessageEventArgs (initialItemsFormatted, null, null, MessageImportance.Low));
// null targets -> success. empty targets -> success(!)
foreach (var targetName in (request.ProjectInstance.InitialTargets).Where (t => t != null))
BuildTargetByName (targetName, args);
if (request.TargetNames == null)
args.Result.OverallResult = BuildResultCode.Success;
args.Result.OverallResult = args.CheckCancel () ? BuildResultCode.Failure : args.Result.ResultsByTarget.Any (p => p.Value.ResultCode == TargetResultCode.Failure) ? BuildResultCode.Failure : BuildResultCode.Success;
else {
foreach (var targetName in (args.TargetNames ?? request.TargetNames).Where (t => t != null))
BuildTargetByName (targetName, args);
foreach (var targetName in (args.TargetNames ?? request.TargetNames).Where (t => t != null)) {
if (!BuildTargetByName (targetName, args))
break;
}
// FIXME: check .NET behavior, whether cancellation always results in failure.
args.Result.OverallResult = args.CheckCancel () ? BuildResultCode.Failure : args.Result.ResultsByTarget.Any (p => p.Value.ResultCode == TargetResultCode.Failure) ? BuildResultCode.Failure : BuildResultCode.Success;
@@ -253,6 +260,7 @@ namespace Microsoft.Build.Internal
var value = args.Project.ExpandString (p.Value);
project.SetProperty (p.Name, value);
}
continue;
}
var ii = child as ProjectItemGroupTaskInstance;
@@ -264,6 +272,7 @@ namespace Microsoft.Build.Internal
continue;
project.AddItem (item.ItemType, project.ExpandString (item.Include));
}
continue;
}
var task = child as ProjectTaskInstance;
@@ -275,7 +284,14 @@ namespace Microsoft.Build.Internal
}
if (!RunBuildTask (target, task, targetResult, args))
return false;
continue;
}
var onError = child as ProjectOnErrorInstance;
if (onError != null)
continue; // evaluated under catch clause.
throw new NotSupportedException (string.Format ("Unexpected Target element children \"{0}\"", child.GetType ()));
}
} catch (Exception ex) {
// fallback task specified by OnError element
@@ -452,7 +468,7 @@ namespace Microsoft.Build.Internal
}
public void SetMetadataValueLiteral (string metadataName, string metadataValue)
{
metadata [metadataName] = ProjectCollection.Unescape (metadataValue);
metadata [metadataName] = WindowsCompatibilityExtensions.NormalizeFilePath (ProjectCollection.Unescape (metadataValue));
}
public IDictionary CloneCustomMetadataEscaped ()
{
@@ -490,7 +506,7 @@ namespace Microsoft.Build.Internal
}
public void SetMetadata (string metadataName, string metadataValue)
{
metadata [metadataName] = metadataValue;
metadata [metadataName] = WindowsCompatibilityExtensions.NormalizeFilePath (metadataValue);
}
public string ItemSpec { get; set; }
public int MetadataCount {
@@ -574,13 +590,16 @@ namespace Microsoft.Build.Internal
// To NOT reuse this IBuildEngine instance for different build, we create another BuildManager and BuildSubmisson and then run it.
public bool BuildProjectFile (string projectFileName, string[] targetNames, IDictionary globalProperties, IDictionary targetOutputs, string toolsVersion)
{
toolsVersion = string.IsNullOrEmpty (toolsVersion) ? project.ToolsVersion : toolsVersion;
var globalPropertiesThatMakeSense = new Dictionary<string,string> ();
foreach (DictionaryEntry p in globalProperties)
globalPropertiesThatMakeSense [(string) p.Key] = (string) p.Value;
var result = new BuildManager ().Build (this.submission.BuildManager.OngoingBuildParameters.Clone (), new BuildRequestData (projectFileName, globalPropertiesThatMakeSense, toolsVersion, targetNames, null));
foreach (var p in result.ResultsByTarget)
targetOutputs [p.Key] = p.Value.Items;
return result.OverallResult == BuildResultCode.Success;
var projectToBuild = new ProjectInstance (ProjectRootElement.Create (XmlReader.Create (projectFileName)), globalPropertiesThatMakeSense, toolsVersion, Projects);
IDictionary<string,TargetResult> outs;
var ret = projectToBuild.Build (targetNames ?? new string [] {"Build"}, Projects.Loggers, out outs);
foreach (var p in outs)
targetOutputs [p.Key] = p.Value.Items ?? new ITaskItem [0];
return ret;
}
public bool BuildProjectFilesInParallel (string[] projectFileNames, string[] targetNames, IDictionary[] globalProperties, IDictionary[] targetOutputsPerProject, string[] toolsVersion, bool useResultsCache, bool unloadProjectsOnCompletion)

View File

@@ -212,6 +212,16 @@ namespace Microsoft.Build.Internal.Expressions
get { return string.Format ("%([{0}].[{1}])", ItemType, Metadata); }
}
}
partial class QuotedExpression : Expression
{
public char QuoteChar { get; set; }
public ExpressionList Contents { get; set; }
public override string ExpressionString {
get { return QuoteChar + string.Concat (Contents.Select (e => e.ExpressionString)).Replace (QuoteChar.ToString (), "\\" + QuoteChar) + QuoteChar; }
}
}
partial class StringLiteral : Expression
{

View File

@@ -346,12 +346,12 @@ namespace Microsoft.Build.Internal.Expressions
var args = Access.Arguments.Select (e => e.EvaluateAsObject (context)).ToArray ();
var method = FindMethod (type, Access.Name.Name, args);
if (method == null)
throw new InvalidProjectFileException (Location, string.Format ("access to undefined static method '{0}' of '{1}' at {2}", Access.Name.Name, Access.Target.EvaluateAsString (context), Location));
throw new InvalidProjectFileException (Location, string.Format ("access to undefined static method '{0}' of '{1}' at {2}", Access.Name.Name, type, Location));
return method.Invoke (null, AdjustArgsForCall (method, args));
} else {
var prop = type.GetProperty (Access.Name.Name);
if (prop == null)
throw new InvalidProjectFileException (Location, string.Format ("access to undefined static property '{0}' of '{1}' at {2}", Access.Name.Name, Access.Target.EvaluateAsString (context), Location));
throw new InvalidProjectFileException (Location, string.Format ("access to undefined static property '{0}' of '{1}' at {2}", Access.Name.Name, type, Location));
return prop.GetValue (null, null);
}
}
@@ -491,6 +491,30 @@ namespace Microsoft.Build.Internal.Expressions
return EvaluateAsString (context);
}
}
partial class QuotedExpression : Expression
{
public override string EvaluateAsString (EvaluationContext context)
{
return QuoteChar + EvaluateAsStringWithoutQuote (context) + QuoteChar;
}
public string EvaluateAsStringWithoutQuote (EvaluationContext context)
{
return string.Concat (Contents.Select (e => e.EvaluateAsString (context)));
}
public override bool EvaluateAsBoolean (EvaluationContext context)
{
var ret = EvaluateAsStringWithoutQuote (context);
return EvaluateStringAsBoolean (context, ret);
}
public override object EvaluateAsObject (EvaluationContext context)
{
return EvaluateAsStringWithoutQuote (context);
}
}
partial class FunctionCallExpression : Expression
{

View File

@@ -60,14 +60,13 @@ namespace Microsoft.Build.Internal.Expressions
while (start < end) {
int bak = start;
ret.Add (ParseSingle (ref start, end));
SkipSpaces (ref start);
if (bak == start)
throw new Exception ("Parser failed to progress token position: " + source);
}
return ret;
}
static readonly char [] token_starters = "$@%(),".ToCharArray ();
static readonly char [] token_starters = "$@%(),'\"".ToCharArray ();
Expression ParseSingle (ref int start, int end)
{
@@ -101,7 +100,23 @@ namespace Microsoft.Build.Internal.Expressions
ret = EvaluateItemExpression (start, last);
start = last + 1;
return ret;
case '\'':
case '"':
var quoteChar = source [start];
start++;
last = FindMatchingCloseQuote (quoteChar, start, end);
if (last < 0) {
if (validation_type == ExpressionValidationType.StrictBoolean)
throw new InvalidProjectFileException (string.Format ("expression did not have matching ')' since index {0} in \"{1}\"", start, source));
else {
start--;
goto default; // treat as raw literal to the section end
}
}
ret = new QuotedExpression () { QuoteChar = quoteChar, Contents = Parse (start, last) };
start = last + 1;
return ret;
// Below (until default) are important only for Condition evaluation
case '(':
if (validation_type == ExpressionValidationType.LaxString)
@@ -134,7 +149,7 @@ namespace Microsoft.Build.Internal.Expressions
return ret;
}
}
int FindMatchingCloseParen (int start, int end)
{
int n = 0;
@@ -148,7 +163,21 @@ namespace Microsoft.Build.Internal.Expressions
}
return -1; // invalid
}
int FindMatchingCloseQuote (char quote, int start, int end)
{
int n = 0;
for (int i = start; i < end; i++) {
if (i < end + 1 && source [i] == '\\' && (source [i + 1] == quote || source [i + 1] == '\\'))
n += 2;
else if (source [i] == quote) {
if (n-- == 0)
return i;
}
}
return -1; // invalid
}
static readonly string spaces = " \t\r\n";
void SkipSpaces (ref int start)
@@ -166,6 +195,7 @@ namespace Microsoft.Build.Internal.Expressions
// property access without member specification
int parenAt = source.IndexOf ('(', start, end - start);
string name = parenAt < 0 ? source.Substring (start, end - start) : source.Substring (start, parenAt - start);
name = name.Trim ();
var access = new PropertyAccess () {
Name = new NameToken () { Name = name },
TargetType = PropertyTargetType.Object
@@ -181,6 +211,7 @@ namespace Microsoft.Build.Internal.Expressions
int mstart = dotAt + 1;
int parenAt = source.IndexOf ('(', mstart, end - mstart);
string name = parenAt < 0 ? source.Substring (mstart, end - mstart) : source.Substring (mstart, parenAt - mstart);
name = name.Trim ();
var access = new PropertyAccess () {
Name = new NameToken () { Name = name },
TargetType = PropertyTargetType.Object,
@@ -196,10 +227,11 @@ namespace Microsoft.Build.Internal.Expressions
string type = source.Substring (start, colonsAt - start);
if (type.Length < 2 || type [0] != '[' || type [type.Length - 1] != ']')
throw new InvalidProjectFileException (string.Format ("Static function call misses appropriate type name surrounded by '[' and ']' at {0} in \"{1}\"", start, source));
type = type.Substring (1, type.Length - 2);
type = type.Substring (1, type.Length - 2).Trim ();
start = colonsAt + 2;
int parenAt = source.IndexOf ('(', start, end - start);
string member = parenAt < 0 ? source.Substring (start, end - start) : source.Substring (start, parenAt - start);
member = member.Trim ();
if (member.Length == 0)
throw new InvalidProjectFileException ("Static member name is missing");
var access = new PropertyAccess () {
@@ -228,6 +260,7 @@ namespace Microsoft.Build.Internal.Expressions
if (source [start] != ',')
throw new InvalidProjectFileException (string.Format ("invalid function call arguments specification. ',' is expected, got '{0}'", source [start]));
start++;
SkipSpaces (ref start);
}
args.Add (ParseSingle (ref start, end));
} while (true);

View File

@@ -40,6 +40,10 @@ namespace MonoTests.Microsoft.Build.Evaluation
public class ProjectCollectionTest
{
[Test]
#if NET_4_0
// BXC #20961
[Category ("NotWorking")]
#endif
public void GlobalProperties ()
{
var g = ProjectCollection.GlobalProjectCollection;

View File

@@ -173,6 +173,10 @@ namespace MonoTests.Microsoft.Build.Evaluation
}
[Test]
#if NET_4_0
// BXC #20961
[Category ("NotWorking")]
#endif
public void BuildCSharpTargetBuild ()
{
string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
@@ -254,6 +258,10 @@ namespace MonoTests.Microsoft.Build.Evaluation
}
[Test]
#if NET_4_0
// BXC #20961
[Category ("NotWorking")]
#endif
public void CreateProjectInstance ()
{
string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
@@ -270,6 +278,10 @@ namespace MonoTests.Microsoft.Build.Evaluation
}
[Test]
#if NET_4_0
// BXC #20961
[Category ("NotWorking")]
#endif
public void LoadCaseInsensitive ()
{
string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>

View File

@@ -291,6 +291,56 @@ namespace MonoTests.Microsoft.Build.Execution
Assert.IsNotNull (p, "#1");
Assert.AreEqual ("False", p.EvaluatedValue, "#2");
}
[Test]
public void ConditionalExpression ()
{
string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<PropertyGroup>
<NoCompilerStandardLib>true</NoCompilerStandardLib>
<ResolveAssemblyReferencesDependsOn>$(ResolveAssemblyReferencesDependsOn);_AddCorlibReference</ResolveAssemblyReferencesDependsOn>
</PropertyGroup>
</Project>";
var xml = XmlReader.Create (new StringReader (project_xml));
var root = ProjectRootElement.Create (xml);
root.FullPath = "ProjectInstanceTest.ConditionalExpression.proj";
var proj = new ProjectInstance (root);
var p = proj.GetProperty ("ResolveAssemblyReferencesDependsOn");
Assert.IsNotNull (p, "#1");
Assert.AreEqual (";_AddCorlibReference", p.EvaluatedValue, "#2");
}
[Test]
[Category ("NotWorking")] // until we figure out why it fails on wrench.
public void ItemsInTargets ()
{
string project_xml = @"<Project DefaultTargets='Default' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<Target Name='Default'>
<PropertyGroup>
<_ExplicitMSCorlibPath>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetPathToStandardLibraries ('$(TargetFrameworkIdentifier)', '$(TargetFrameworkVersion)', '$(TargetFrameworkProfile)'))\mscorlib.dll</_ExplicitMSCorlibPath>
</PropertyGroup>
<ItemGroup>
<_ExplicitReference
Include='$(_ExplicitMSCorlibPath)'
Condition='Exists($(_ExplicitMSCorlibPath))'>
<Private>false</Private>
</_ExplicitReference>
</ItemGroup>
</Target>
<Import Project='$(MSBuildBinPath)\\Microsoft.CSharp.targets' />
</Project>";
var xml = XmlReader.Create (new StringReader (project_xml));
var root = ProjectRootElement.Create (xml);
root.FullPath = "ProjectInstanceTest.ConditionalExpression.proj";
var proj = new ProjectInstance (root, null, "4.0", ProjectCollection.GlobalProjectCollection);
proj.Build ();
// make sure the property value expansion is done successfully.
Assert.IsTrue (!string.IsNullOrEmpty (proj.GetPropertyValue ("_ExplicitMSCorlibPath")), "premise: propertyValue by ToolLocationHelper func call");
var items = proj.GetItems ("_ExplicitReference");
// make sure items are stored after build.
Assert.IsTrue (items.Any (), "items.Any");
Assert.IsTrue (!string.IsNullOrEmpty (items.First ().EvaluatedInclude), "item.EvaluatedInclude");
}
}
namespace SubNamespace

View File

@@ -335,6 +335,22 @@ namespace MonoTests.Microsoft.Build.Internal
var result = p.Build (new ILogger [] { new ConsoleLogger (LoggerVerbosity.Minimal, sw.WriteLine, null, null)});
Assert.IsTrue (result, "#1: " + sw);
}
[Test]
public void FunctionCall ()
{
string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<Target Name='Foo'>
<Warning Text=""$([Microsoft.Build.Utilities.ToolLocationHelper]::GetPathToStandardLibraries ('$(TargetFrameworkIdentifier)', '$(TargetFrameworkVersion)', '$(TargetFrameworkProfile)'))\mscorlib.dll'"" />
</Target>
</Project>";
var xml = XmlReader.Create (new StringReader (project_xml));
var root = ProjectRootElement.Create (xml);
var p = new ProjectInstance (root, null, "4.0", ProjectCollection.GlobalProjectCollection);
var sw = new StringWriter ();
var result = p.Build (new ILogger [] { new ConsoleLogger (LoggerVerbosity.Minimal, sw.WriteLine, null, null)});
Assert.IsTrue (result, "#1: " + sw);
}
}
}