From 8bc16c861c3a97acc243312c5c92a76a780b730f Mon Sep 17 00:00:00 2001 From: ankit Date: Wed, 7 Apr 2010 10:59:01 +0000 Subject: [PATCH] In class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine: * ConsoleLogger.cs: Dump items and properties when a project starts to build. Useful for debugging. * Engine.cs (LogProjectStarted): Set the properties and items also, for the project started event. * Project.cs (EvaluatedPropertiesAsDictionaryEntries): New. (EvaluatedItemsByNameAsDictionaryEntries): New. Required for ProjectStartedEvent . In class/Microsoft.Build.Tasks/Microsoft.Build.Tasks: * MSBuild.cs: Emit global properties, if any. Sort the property list. git-svn-id: svn+ssh://mono-cvs.ximian.com/source/trunk/mcs@154929 e3ebcda4-bce8-0310-ba0a-eca2169e7518 --- .../Microsoft.Build.BuildEngine/ChangeLog | 10 ++++ .../Microsoft.Build.BuildEngine/ConsoleLogger.cs | 58 +++++++++++++++++++++- .../Microsoft.Build.BuildEngine/Engine.cs | 12 +++-- .../Microsoft.Build.BuildEngine/Project.cs | 21 +++++++- .../Microsoft.Build.Tasks/ChangeLog | 5 ++ .../Microsoft.Build.Tasks/MSBuild.cs | 11 ++-- 6 files changed, 107 insertions(+), 10 deletions(-) diff --git a/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ChangeLog b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ChangeLog index 87a8914b39..01a193d5be 100644 --- a/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ChangeLog +++ b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ChangeLog @@ -1,3 +1,13 @@ +2010-04-07 Ankit Jain + + * ConsoleLogger.cs: Dump items and properties when a project starts + to build. Useful for debugging. + * Engine.cs (LogProjectStarted): Set the properties and items also, + for the project started event. + * Project.cs (EvaluatedPropertiesAsDictionaryEntries): New. + (EvaluatedItemsByNameAsDictionaryEntries): New. Required for + ProjectStartedEvent . + 2010-04-03 Ankit Jain * BuildEngine.cs: Implement IBuildEngine2 instead of diff --git a/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ConsoleLogger.cs b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ConsoleLogger.cs index 8114c79c6c..49f3c2a1ed 100644 --- a/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ConsoleLogger.cs +++ b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ConsoleLogger.cs @@ -29,6 +29,7 @@ using System; using System.Runtime.InteropServices; +using System.Collections; using System.Collections.Generic; using System.IO; using System.Security; @@ -283,6 +284,8 @@ namespace Microsoft.Build.BuildEngine { String.IsNullOrEmpty (args.TargetNames) ? "default" : args.TargetNames)); ResetColor (); WriteLine (String.Empty); + DumpProperties (args.Properties); + DumpItems (args.Items); PushEvent (args); } @@ -405,7 +408,7 @@ namespace Microsoft.Build.BuildEngine { public void CustomEventHandler (object sender, CustomBuildEventArgs args) { } - + private void WriteLine (string message) { if (indent > 0) { @@ -572,6 +575,59 @@ namespace Microsoft.Build.BuildEngine { return false; } + void DumpProperties (IEnumerable properties) + { + if (!IsVerbosityGreaterOrEqual (LoggerVerbosity.Diagnostic)) + return; + + SetColor (eventColor); + WriteLine ("\n"); + WriteLine ("Initial Properties:"); + ResetColor (); + + if (properties == null) + return; + + var dict = new SortedDictionary (); + foreach (DictionaryEntry de in properties) + dict [(string)de.Key] = (string)de.Value; + + foreach (KeyValuePair pair in dict) + WriteLine (String.Format ("{0} = {1}", pair.Key, pair.Value)); + WriteLine ("\n"); + } + + void DumpItems (IEnumerable items) + { + if (!IsVerbosityGreaterOrEqual (LoggerVerbosity.Diagnostic) || items == null) + return; + + SetColor (eventColor); + WriteLine ("\n"); + WriteLine ("Initial Items:"); + ResetColor (); + if (items == null) + return; + + var items_table = new SortedDictionary> (); + foreach (DictionaryEntry de in items) { + string key = (string)de.Key; + if (!items_table.ContainsKey (key)) + items_table [key] = new List (); + + items_table [key].Add ((ITaskItem) de.Value); + } + + foreach (string name in items_table.Keys) { + WriteLine (name); + indent ++; + foreach (ITaskItem item in items_table [name]) + WriteLine (item.ItemSpec); + indent--; + } + WriteLine ("\n"); + } + public string Parameters { get { return parameters; diff --git a/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Engine.cs b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Engine.cs index caefd7f9db..b6fe05eb2c 100644 --- a/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Engine.cs +++ b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Engine.cs @@ -384,13 +384,15 @@ namespace Microsoft.Build.BuildEngine { void LogProjectStarted (Project project, string [] target_names) { - ProjectStartedEventArgs psea; + string targets; if (target_names == null || target_names.Length == 0) - psea = new ProjectStartedEventArgs ("Project started.", null, project.FullFileName, - String.Empty, null, null); + targets = String.Empty; else - psea = new ProjectStartedEventArgs ("Project started.", null, project.FullFileName, - String.Join (";", target_names), null, null); + targets = String.Join (";", target_names); + + ProjectStartedEventArgs psea = new ProjectStartedEventArgs ("Project started.", null, project.FullFileName, targets, + project.EvaluatedPropertiesAsDictionaryEntries, project.EvaluatedItemsByNameAsDictionaryEntries); + eventSource.FireProjectStarted (this, psea); } diff --git a/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Project.cs b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Project.cs index a103b762a1..e8b74e8626 100644 --- a/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Project.cs +++ b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Project.cs @@ -1099,7 +1099,19 @@ namespace Microsoft.Build.BuildEngine { return evaluatedItemsByName; } } - + + internal IEnumerable EvaluatedItemsByNameAsDictionaryEntries { + get { + if (EvaluatedItemsByName.Count == 0) + yield break; + + foreach (KeyValuePair pair in EvaluatedItemsByName) { + foreach (BuildItem bi in pair.Value) + yield return new DictionaryEntry (pair.Key, bi.ConvertToITaskItem (null, ExpressionOptions.ExpandItemRefs)); + } + } + } + internal IDictionary EvaluatedItemsByNameIgnoringCondition { get { // FIXME: do we need to do this here? @@ -1260,6 +1272,13 @@ namespace Microsoft.Build.BuildEngine { } } + internal IEnumerable EvaluatedPropertiesAsDictionaryEntries { + get { + foreach (BuildProperty bp in EvaluatedProperties) + yield return new DictionaryEntry (bp.Name, bp.Value); + } + } + public string FullFileName { get { return fullFileName; } set { fullFileName = value; } diff --git a/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/ChangeLog b/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/ChangeLog index 8fc6eb5d9a..23dfd22b9c 100644 --- a/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/ChangeLog +++ b/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/ChangeLog @@ -1,3 +1,8 @@ +2010-04-07 Ankit Jain + + * MSBuild.cs: Emit global properties, if any. Sort the property + list. + 2010-04-03 Ankit Jain * Csc.cs: Use dmcs as the compiler for 4.0 profile. diff --git a/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/MSBuild.cs b/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/MSBuild.cs index 564bbb2830..90c54cd38c 100644 --- a/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/MSBuild.cs +++ b/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/MSBuild.cs @@ -65,9 +65,14 @@ namespace Microsoft.Build.Tasks { string currentDirectory = Environment.CurrentDirectory; Hashtable outputs; - Dictionary global_properties = SplitPropertiesToDictionary (); + var global_properties = SplitPropertiesToDictionary (); Dictionary projectsByFileName = new Dictionary (); + Log.LogMessage (MessageImportance.Low, "Global Properties:"); + if (global_properties != null) + foreach (KeyValuePair pair in global_properties) + Log.LogMessage (MessageImportance.Low, "\t{0} = {1}", pair.Key, pair.Value); + foreach (ITaskItem project in projects) { filename = project.GetMetadata ("FullPath"); if (!File.Exists (filename)) { @@ -187,12 +192,12 @@ namespace Microsoft.Build.Tasks { get; set; } - Dictionary SplitPropertiesToDictionary () + SortedDictionary SplitPropertiesToDictionary () { if (properties == null) return null; - Dictionary global_properties = new Dictionary (); + var global_properties = new SortedDictionary (); foreach (string kvpair in properties) { if (String.IsNullOrEmpty (kvpair)) continue; -- 2.11.4.GIT