Skip to content

Commit

Permalink
Merge pull request #6397 from dotnet/dev/kirillo/intrinsicTaskLocation
Browse files Browse the repository at this point in the history
Log location of intrinsic tasks
  • Loading branch information
Forgind authored May 28, 2021
2 parents ec23638 + b785165 commit 8861fa0
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/Build.UnitTests/BackEnd/NodePackets_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ private static TaskParameterEventArgs CreateTaskParameter()
items,
logItemMetadata: true,
DateTime.MinValue);
result.LineNumber = 30000;
result.ColumnNumber = 50;

// normalize line endings as we can't rely on the line endings of NodePackets_Tests.cs
Assert.Equal(@"Task Parameter:
Expand Down Expand Up @@ -433,6 +435,8 @@ private void CompareLogMessagePackets(LogMessagePacket left, LogMessagePacket ri
Assert.Equal(leftTaskParameter.Message, rightTaskParameter.Message);
Assert.Equal(leftTaskParameter.BuildEventContext, rightTaskParameter.BuildEventContext);
Assert.Equal(leftTaskParameter.Timestamp, rightTaskParameter.Timestamp);
Assert.Equal(leftTaskParameter.LineNumber, rightTaskParameter.LineNumber);
Assert.Equal(leftTaskParameter.ColumnNumber, rightTaskParameter.ColumnNumber);
break;

case LoggingEventType.TaskFinishedEvent:
Expand Down
4 changes: 4 additions & 0 deletions src/Build.UnitTests/BuildEventArgsSerialization_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,15 @@ public void RoundtripTaskParameterEventArgs()
new TaskItemData("ItemSpec2", Enumerable.Range(1,3).ToDictionary(i => i.ToString(), i => i.ToString() + "value"))
};
var args = new TaskParameterEventArgs(TaskParameterMessageKind.TaskOutput, "ItemName", items, true, DateTime.MinValue);
args.LineNumber = 265;
args.ColumnNumber = 6;

Roundtrip(args,
e => e.Kind.ToString(),
e => e.ItemType,
e => e.LogItemMetadata.ToString(),
e => e.LineNumber.ToString(),
e => e.ColumnNumber.ToString(),
e => TranslationHelpers.GetItemsString(e.Items));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ private void ExecuteAdd(ProjectItemGroupTaskItemInstance child, ItemBucket bucke
TaskParameterMessageKind.AddItem,
child.ItemType,
itemsToAdd,
logItemMetadata: true);
logItemMetadata: true,
child.Location);
}

// Now add the items we created to the lookup.
Expand Down Expand Up @@ -261,7 +262,8 @@ private void ExecuteRemove(ProjectItemGroupTaskItemInstance child, ItemBucket bu
TaskParameterMessageKind.RemoveItem,
child.ItemType,
itemsToRemove,
logItemMetadata: true);
logItemMetadata: true,
child.Location);
}

bucket.Lookup.RemoveItems(itemsToRemove);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,19 @@ internal static void LogTaskParameter(
TaskParameterMessageKind messageKind,
string itemType,
IList items,
bool logItemMetadata)
bool logItemMetadata,
IElementLocation location = null)
{
var args = CreateTaskParameterEventArgs(
loggingContext.BuildEventContext,
messageKind,
itemType,
items,
logItemMetadata,
DateTime.UtcNow);
DateTime.UtcNow,
location?.Line ?? 0,
location?.Column ?? 0);

loggingContext.LogBuildEvent(args);
}

Expand All @@ -270,7 +274,9 @@ internal static TaskParameterEventArgs CreateTaskParameterEventArgs(
string itemType,
IList items,
bool logItemMetadata,
DateTime timestamp)
DateTime timestamp,
int line = 0,
int column = 0)
{
// Only create a snapshot of items if we use AppDomains
#if FEATURE_APPDOMAIN
Expand All @@ -284,6 +290,8 @@ internal static TaskParameterEventArgs CreateTaskParameterEventArgs(
logItemMetadata,
timestamp);
args.BuildEventContext = buildEventContext;
args.LineNumber = line;
args.ColumnNumber = column;
return args;
}

Expand Down
4 changes: 3 additions & 1 deletion src/Build/Logging/BinaryLogger/BuildEventArgsReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,9 @@ private BuildEventArgs ReadTaskParameterEventArgs()
itemType,
items,
logItemMetadata: true,
fields.Timestamp);
fields.Timestamp,
fields.LineNumber,
fields.ColumnNumber);
e.ProjectFile = fields.ProjectFile;
return e;
}
Expand Down
12 changes: 10 additions & 2 deletions src/Framework/BuildMessageEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,20 @@ internal override void CreateFromStream(BinaryReader reader, int version)
/// <summary>
/// Line number of interest in associated file.
/// </summary>
public int LineNumber => lineNumber;
public int LineNumber
{
get => lineNumber;
internal set => lineNumber = value;
}

/// <summary>
/// Column number of interest in associated file.
/// </summary>
public int ColumnNumber => columnNumber;
public int ColumnNumber
{
get => columnNumber;
internal set => columnNumber = value;
}

/// <summary>
/// Ending line number of interest in associated file.
Expand Down
4 changes: 4 additions & 0 deletions src/Framework/TaskParameterEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ internal override void CreateFromStream(BinaryReader reader, int version)
BuildEventContext = reader.ReadOptionalBuildEventContext();
Kind = (TaskParameterMessageKind)reader.Read7BitEncodedInt();
ItemType = reader.ReadOptionalString();
LineNumber = reader.Read7BitEncodedInt();
ColumnNumber = reader.Read7BitEncodedInt();
Items = ReadItems(reader);
}

Expand Down Expand Up @@ -134,6 +136,8 @@ internal override void WriteToStream(BinaryWriter writer)
writer.WriteOptionalBuildEventContext(BuildEventContext);
writer.Write7BitEncodedInt((int)Kind);
writer.WriteOptionalString(ItemType);
writer.Write7BitEncodedInt(LineNumber);
writer.Write7BitEncodedInt(ColumnNumber);
WriteItems(writer, Items);
}

Expand Down

0 comments on commit 8861fa0

Please sign in to comment.