Skip to content

Commit

Permalink
Miscellaneous logging improvements (#6326)
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillOsenkov committed Apr 20, 2021
1 parent 369631b commit 4920537
Show file tree
Hide file tree
Showing 44 changed files with 1,388 additions and 516 deletions.
16 changes: 16 additions & 0 deletions ref/Microsoft.Build.Framework/net/Microsoft.Build.Framework.cs
Expand Up @@ -38,6 +38,7 @@ public abstract partial class BuildEventArgs : System.EventArgs
public Microsoft.Build.Framework.BuildEventContext BuildEventContext { get { throw null; } set { } }
public string HelpKeyword { get { throw null; } }
public virtual string Message { get { throw null; } protected set { } }
protected internal string RawMessage { get { throw null; } set { } }
protected internal System.DateTime RawTimestamp { get { throw null; } set { } }
public string SenderName { get { throw null; } }
public int ThreadId { get { throw null; } }
Expand Down Expand Up @@ -340,6 +341,8 @@ public partial interface ITaskItem2 : Microsoft.Build.Framework.ITaskItem
}
public partial class LazyFormattedBuildEventArgs : Microsoft.Build.Framework.BuildEventArgs
{
[System.NonSerializedAttribute]
protected object locker;
protected LazyFormattedBuildEventArgs() { }
public LazyFormattedBuildEventArgs(string message, string helpKeyword, string senderName) { }
public LazyFormattedBuildEventArgs(string message, string helpKeyword, string senderName, System.DateTime eventTimestamp, params object[] messageArgs) { }
Expand Down Expand Up @@ -408,6 +411,7 @@ public partial class ProjectFinishedEventArgs : Microsoft.Build.Framework.BuildS
protected ProjectFinishedEventArgs() { }
public ProjectFinishedEventArgs(string message, string helpKeyword, string projectFile, bool succeeded) { }
public ProjectFinishedEventArgs(string message, string helpKeyword, string projectFile, bool succeeded, System.DateTime eventTimestamp) { }
public override string Message { get { throw null; } }
public string ProjectFile { get { throw null; } }
public bool Succeeded { get { throw null; } }
}
Expand All @@ -431,6 +435,7 @@ public partial class ProjectStartedEventArgs : Microsoft.Build.Framework.BuildSt
public ProjectStartedEventArgs(string message, string helpKeyword, string projectFile, string targetNames, System.Collections.IEnumerable properties, System.Collections.IEnumerable items, System.DateTime eventTimestamp) { }
public System.Collections.Generic.IDictionary<string, string> GlobalProperties { get { throw null; } }
public System.Collections.IEnumerable Items { get { throw null; } }
public override string Message { get { throw null; } }
public Microsoft.Build.Framework.BuildEventContext ParentProjectBuildEventContext { get { throw null; } }
public string ProjectFile { get { throw null; } }
public int ProjectId { get { throw null; } }
Expand All @@ -452,6 +457,7 @@ public partial class PropertyReassignmentEventArgs : Microsoft.Build.Framework.B
public PropertyReassignmentEventArgs() { }
public PropertyReassignmentEventArgs(string propertyName, string previousValue, string newValue, string location, string message, string helpKeyword = null, string senderName = null, Microsoft.Build.Framework.MessageImportance importance = Microsoft.Build.Framework.MessageImportance.Low) { }
public string Location { get { throw null; } set { } }
public override string Message { get { throw null; } }
public string NewValue { get { throw null; } set { } }
public string PreviousValue { get { throw null; } set { } }
public string PropertyName { get { throw null; } set { } }
Expand Down Expand Up @@ -558,6 +564,7 @@ public partial class TargetFinishedEventArgs : Microsoft.Build.Framework.BuildSt
public TargetFinishedEventArgs(string message, string helpKeyword, string targetName, string projectFile, string targetFile, bool succeeded) { }
public TargetFinishedEventArgs(string message, string helpKeyword, string targetName, string projectFile, string targetFile, bool succeeded, System.Collections.IEnumerable targetOutputs) { }
public TargetFinishedEventArgs(string message, string helpKeyword, string targetName, string projectFile, string targetFile, bool succeeded, System.DateTime eventTimestamp, System.Collections.IEnumerable targetOutputs) { }
public override string Message { get { throw null; } }
public string ProjectFile { get { throw null; } }
public bool Succeeded { get { throw null; } }
public string TargetFile { get { throw null; } }
Expand All @@ -570,6 +577,10 @@ public partial class TargetSkippedEventArgs : Microsoft.Build.Framework.BuildMes
public TargetSkippedEventArgs() { }
public TargetSkippedEventArgs(string message, params object[] messageArgs) { }
public Microsoft.Build.Framework.TargetBuiltReason BuildReason { get { throw null; } set { } }
public string Condition { get { throw null; } set { } }
public string EvaluatedCondition { get { throw null; } set { } }
public override string Message { get { throw null; } }
public bool OriginallySucceeded { get { throw null; } set { } }
public string ParentTarget { get { throw null; } set { } }
public string TargetFile { get { throw null; } set { } }
public string TargetName { get { throw null; } set { } }
Expand All @@ -581,6 +592,7 @@ public partial class TargetStartedEventArgs : Microsoft.Build.Framework.BuildSta
public TargetStartedEventArgs(string message, string helpKeyword, string targetName, string projectFile, string targetFile, string parentTarget, Microsoft.Build.Framework.TargetBuiltReason buildReason, System.DateTime eventTimestamp) { }
public TargetStartedEventArgs(string message, string helpKeyword, string targetName, string projectFile, string targetFile, string parentTarget, System.DateTime eventTimestamp) { }
public Microsoft.Build.Framework.TargetBuiltReason BuildReason { get { throw null; } }
public override string Message { get { throw null; } }
public string ParentTarget { get { throw null; } }
public string ProjectFile { get { throw null; } }
public string TargetFile { get { throw null; } }
Expand All @@ -600,6 +612,7 @@ public partial class TaskFinishedEventArgs : Microsoft.Build.Framework.BuildStat
protected TaskFinishedEventArgs() { }
public TaskFinishedEventArgs(string message, string helpKeyword, string projectFile, string taskFile, string taskName, bool succeeded) { }
public TaskFinishedEventArgs(string message, string helpKeyword, string projectFile, string taskFile, string taskName, bool succeeded, System.DateTime eventTimestamp) { }
public override string Message { get { throw null; } }
public string ProjectFile { get { throw null; } }
public bool Succeeded { get { throw null; } }
public string TaskFile { get { throw null; } }
Expand All @@ -621,6 +634,8 @@ public enum TaskParameterMessageKind
TaskOutput = 1,
AddItem = 2,
RemoveItem = 3,
SkippedTargetInputs = 4,
SkippedTargetOutputs = 5,
}
public partial class TaskPropertyInfo
{
Expand All @@ -637,6 +652,7 @@ public partial class TaskStartedEventArgs : Microsoft.Build.Framework.BuildStatu
protected TaskStartedEventArgs() { }
public TaskStartedEventArgs(string message, string helpKeyword, string projectFile, string taskFile, string taskName) { }
public TaskStartedEventArgs(string message, string helpKeyword, string projectFile, string taskFile, string taskName, System.DateTime eventTimestamp) { }
public override string Message { get { throw null; } }
public string ProjectFile { get { throw null; } }
public string TaskFile { get { throw null; } }
public string TaskName { get { throw null; } }
Expand Down
Expand Up @@ -38,6 +38,7 @@ public abstract partial class BuildEventArgs : System.EventArgs
public Microsoft.Build.Framework.BuildEventContext BuildEventContext { get { throw null; } set { } }
public string HelpKeyword { get { throw null; } }
public virtual string Message { get { throw null; } protected set { } }
protected internal string RawMessage { get { throw null; } set { } }
protected internal System.DateTime RawTimestamp { get { throw null; } set { } }
public string SenderName { get { throw null; } }
public int ThreadId { get { throw null; } }
Expand Down Expand Up @@ -340,6 +341,8 @@ public partial interface ITaskItem2 : Microsoft.Build.Framework.ITaskItem
}
public partial class LazyFormattedBuildEventArgs : Microsoft.Build.Framework.BuildEventArgs
{
[System.NonSerializedAttribute]
protected object locker;
protected LazyFormattedBuildEventArgs() { }
public LazyFormattedBuildEventArgs(string message, string helpKeyword, string senderName) { }
public LazyFormattedBuildEventArgs(string message, string helpKeyword, string senderName, System.DateTime eventTimestamp, params object[] messageArgs) { }
Expand Down Expand Up @@ -407,6 +410,7 @@ public partial class ProjectFinishedEventArgs : Microsoft.Build.Framework.BuildS
protected ProjectFinishedEventArgs() { }
public ProjectFinishedEventArgs(string message, string helpKeyword, string projectFile, bool succeeded) { }
public ProjectFinishedEventArgs(string message, string helpKeyword, string projectFile, bool succeeded, System.DateTime eventTimestamp) { }
public override string Message { get { throw null; } }
public string ProjectFile { get { throw null; } }
public bool Succeeded { get { throw null; } }
}
Expand All @@ -430,6 +434,7 @@ public partial class ProjectStartedEventArgs : Microsoft.Build.Framework.BuildSt
public ProjectStartedEventArgs(string message, string helpKeyword, string projectFile, string targetNames, System.Collections.IEnumerable properties, System.Collections.IEnumerable items, System.DateTime eventTimestamp) { }
public System.Collections.Generic.IDictionary<string, string> GlobalProperties { get { throw null; } }
public System.Collections.IEnumerable Items { get { throw null; } }
public override string Message { get { throw null; } }
public Microsoft.Build.Framework.BuildEventContext ParentProjectBuildEventContext { get { throw null; } }
public string ProjectFile { get { throw null; } }
public int ProjectId { get { throw null; } }
Expand All @@ -451,6 +456,7 @@ public partial class PropertyReassignmentEventArgs : Microsoft.Build.Framework.B
public PropertyReassignmentEventArgs() { }
public PropertyReassignmentEventArgs(string propertyName, string previousValue, string newValue, string location, string message, string helpKeyword = null, string senderName = null, Microsoft.Build.Framework.MessageImportance importance = Microsoft.Build.Framework.MessageImportance.Low) { }
public string Location { get { throw null; } set { } }
public override string Message { get { throw null; } }
public string NewValue { get { throw null; } set { } }
public string PreviousValue { get { throw null; } set { } }
public string PropertyName { get { throw null; } set { } }
Expand Down Expand Up @@ -557,6 +563,7 @@ public partial class TargetFinishedEventArgs : Microsoft.Build.Framework.BuildSt
public TargetFinishedEventArgs(string message, string helpKeyword, string targetName, string projectFile, string targetFile, bool succeeded) { }
public TargetFinishedEventArgs(string message, string helpKeyword, string targetName, string projectFile, string targetFile, bool succeeded, System.Collections.IEnumerable targetOutputs) { }
public TargetFinishedEventArgs(string message, string helpKeyword, string targetName, string projectFile, string targetFile, bool succeeded, System.DateTime eventTimestamp, System.Collections.IEnumerable targetOutputs) { }
public override string Message { get { throw null; } }
public string ProjectFile { get { throw null; } }
public bool Succeeded { get { throw null; } }
public string TargetFile { get { throw null; } }
Expand All @@ -569,6 +576,10 @@ public partial class TargetSkippedEventArgs : Microsoft.Build.Framework.BuildMes
public TargetSkippedEventArgs() { }
public TargetSkippedEventArgs(string message, params object[] messageArgs) { }
public Microsoft.Build.Framework.TargetBuiltReason BuildReason { get { throw null; } set { } }
public string Condition { get { throw null; } set { } }
public string EvaluatedCondition { get { throw null; } set { } }
public override string Message { get { throw null; } }
public bool OriginallySucceeded { get { throw null; } set { } }
public string ParentTarget { get { throw null; } set { } }
public string TargetFile { get { throw null; } set { } }
public string TargetName { get { throw null; } set { } }
Expand All @@ -580,6 +591,7 @@ public partial class TargetStartedEventArgs : Microsoft.Build.Framework.BuildSta
public TargetStartedEventArgs(string message, string helpKeyword, string targetName, string projectFile, string targetFile, string parentTarget, Microsoft.Build.Framework.TargetBuiltReason buildReason, System.DateTime eventTimestamp) { }
public TargetStartedEventArgs(string message, string helpKeyword, string targetName, string projectFile, string targetFile, string parentTarget, System.DateTime eventTimestamp) { }
public Microsoft.Build.Framework.TargetBuiltReason BuildReason { get { throw null; } }
public override string Message { get { throw null; } }
public string ParentTarget { get { throw null; } }
public string ProjectFile { get { throw null; } }
public string TargetFile { get { throw null; } }
Expand All @@ -599,6 +611,7 @@ public partial class TaskFinishedEventArgs : Microsoft.Build.Framework.BuildStat
protected TaskFinishedEventArgs() { }
public TaskFinishedEventArgs(string message, string helpKeyword, string projectFile, string taskFile, string taskName, bool succeeded) { }
public TaskFinishedEventArgs(string message, string helpKeyword, string projectFile, string taskFile, string taskName, bool succeeded, System.DateTime eventTimestamp) { }
public override string Message { get { throw null; } }
public string ProjectFile { get { throw null; } }
public bool Succeeded { get { throw null; } }
public string TaskFile { get { throw null; } }
Expand All @@ -620,6 +633,8 @@ public enum TaskParameterMessageKind
TaskOutput = 1,
AddItem = 2,
RemoveItem = 3,
SkippedTargetInputs = 4,
SkippedTargetOutputs = 5,
}
public partial class TaskPropertyInfo
{
Expand All @@ -636,6 +651,7 @@ public partial class TaskStartedEventArgs : Microsoft.Build.Framework.BuildStatu
protected TaskStartedEventArgs() { }
public TaskStartedEventArgs(string message, string helpKeyword, string projectFile, string taskFile, string taskName) { }
public TaskStartedEventArgs(string message, string helpKeyword, string projectFile, string taskFile, string taskName, System.DateTime eventTimestamp) { }
public override string Message { get { throw null; } }
public string ProjectFile { get { throw null; } }
public string TaskFile { get { throw null; } }
public string TaskName { get { throw null; } }
Expand Down
11 changes: 11 additions & 0 deletions src/Build.UnitTests/BackEnd/MockLoggingService.cs
Expand Up @@ -300,6 +300,17 @@ public void LogCommentFromText(BuildEventContext buildEventContext, MessageImpor
_writer(message);
}

/// <inheritdoc />
public void LogCommentFromText(BuildEventContext buildEventContext, MessageImportance importance, string message, params object[] messageArgs)
{
if (messageArgs?.Length > 0)
{
message = string.Format(message, messageArgs);
}

_writer(message);
}

/// <summary>
/// Logs a pre-formed build event
/// </summary>
Expand Down
37 changes: 37 additions & 0 deletions src/Build.UnitTests/BackEnd/TargetBuilder_Tests.cs
Expand Up @@ -198,6 +198,43 @@ public void TestDependencyBuildWithError()
Assert.Equal(TargetResultCode.Success, resultsCache.GetResultForRequest(entry.Request)["Baz"].ResultCode);
}

[Fact]
public void TestLoggingForSkippedTargetInputsAndOutputs()
{
string projectContents = @"
<Project>
<Target Name=""Build"" Inputs=""a.txt;b.txt"" Outputs=""c.txt"">
<Message Text=""test"" Importance=""High"" />
</Target>
</Project>";

using (var env = TestEnvironment.Create())
{
var files = env.CreateTestProjectWithFiles(projectContents, new[] { "a.txt", "b.txt", "c.txt" });
var fileA = new FileInfo(files.CreatedFiles[0]);
var fileB = new FileInfo(files.CreatedFiles[1]);
var fileC = new FileInfo(files.CreatedFiles[2]);

var now = DateTime.UtcNow;
fileA.LastWriteTimeUtc = now - TimeSpan.FromSeconds(10);
fileB.LastWriteTimeUtc = now - TimeSpan.FromSeconds(10);
fileC.LastWriteTimeUtc = now;

var logger = files.BuildProjectExpectSuccess();
var logText = logger.FullLog.Replace("\r\n", "\n");

var expected = @"
Skipping target ""Build"" because all output files are up-to-date with respect to the input files.
Input files:
a.txt
b.txt
Output files: c.txt
Done building target ""Build"" in project ""build.proj"".".Replace("\r\n", "\n");

logText.ShouldContainWithoutWhitespace(expected);
}
}

/// <summary>
/// Ensure that skipped targets only infer outputs once
/// </summary>
Expand Down

0 comments on commit 4920537

Please sign in to comment.