Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Сhange ProperyReassignment logged message type #9494

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 58 additions & 7 deletions src/Build.UnitTests/Evaluation/Evaluator_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4597,7 +4597,7 @@ public void VerifyMSBuildLogsAMessageWhenLocalPropertyCannotOverrideValueOfGloba
public void VerifyPropertyTrackingLoggingDefault()
{
// Having just environment variables defined should default to nothing being logged except one environment variable read.
this.VerifyPropertyTrackingLoggingScenario(
VerifyPropertyTrackingLoggingScenario(
null,
logger =>
{
Expand All @@ -4616,7 +4616,8 @@ public void VerifyPropertyTrackingLoggingDefault()
logger
.AllBuildEvents
.OfType<PropertyReassignmentEventArgs>()
.ShouldBeEmpty();
.Count()
.ShouldBe(2);

logger
.AllBuildEvents
Expand All @@ -4628,7 +4629,7 @@ public void VerifyPropertyTrackingLoggingDefault()
[Fact]
public void VerifyPropertyTrackingLoggingPropertyReassignment()
{
this.VerifyPropertyTrackingLoggingScenario(
VerifyPropertyTrackingLoggingScenario(
"1",
logger =>
{
Expand Down Expand Up @@ -4677,13 +4678,14 @@ public void VerifyPropertyTrackingLoggingNone()

logger
.AllBuildEvents
.OfType<PropertyReassignmentEventArgs>()
.OfType<PropertyInitialValueSetEventArgs>()
.ShouldBeEmpty();

logger
.AllBuildEvents
.OfType<PropertyInitialValueSetEventArgs>()
.ShouldBeEmpty();
.AllBuildEvents
.OfType<PropertyReassignmentEventArgs>()
.Count()
.ShouldBe(2);
});
}

Expand Down Expand Up @@ -4919,6 +4921,55 @@ private void VerifyPropertyTrackingLoggingScenario(string envVarValue, Action<Mo
}
}

/// <summary>
/// Log when a property is being assigned a new value.
/// </summary>
[Fact]
public void VerifyLogPropertyReassignment()
{
string propertyName = "Prop";
string propertyOldValue = "OldValue";
string propertyNewValue = "NewValue";
string testtargets = ObjectModelHelpers.CleanupFileContents(@$"
<Project xmlns='msbuildnamespace'>
<PropertyGroup>
<{propertyName}>{propertyOldValue}</{propertyName}>
<{propertyName}>{propertyNewValue}</{propertyName}>
</PropertyGroup>
<Target Name=""Test""/>
</Project>");

string tempPath = Path.GetTempPath();
string targetDirectory = Path.Combine(tempPath, "LogPropertyAssignments");
string testTargetPath = Path.Combine(targetDirectory, "test.proj");
YuliiaKovalova marked this conversation as resolved.
Show resolved Hide resolved

using (TestEnvironment env = TestEnvironment.Create())
{
env.CreateFolder(targetDirectory);
env.CreateFile(testTargetPath, testtargets);

MockLogger logger = new()
{
Verbosity = LoggerVerbosity.Diagnostic,
};
ProjectCollection pc = new();
pc.RegisterLogger(logger);
Project project = pc.LoadProject(testTargetPath);

bool result = project.Build();
result.ShouldBeTrue();
logger.BuildMessageEvents
.OfType<PropertyReassignmentEventArgs>()
.ShouldContain(r => r.PropertyName == propertyName
&& r.PreviousValue == propertyOldValue
&& r.NewValue == propertyNewValue
&& r.Message.StartsWith($"{
ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword(
"PropertyReassignment", propertyName, propertyNewValue, propertyOldValue, string.Empty)}"));
logger.BuildMessageEvents.ShouldBeOfTypes(new[] { typeof(PropertyReassignmentEventArgs) });
}
}

#if FEATURE_HTTP_LISTENER
/// <summary>
/// HTTP server code running on a separate thread that expects a connection request
Expand Down
31 changes: 24 additions & 7 deletions src/Build/Evaluation/Evaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1348,13 +1348,30 @@ private void LogPropertyReassignment(P predecessor, P property, string location)

if (newValue != oldValue)
{
_evaluationLoggingContext.LogComment(
MessageImportance.Low,
"PropertyReassignment",
property.Name,
newValue,
KirillOsenkov marked this conversation as resolved.
Show resolved Hide resolved
oldValue,
location);
if (ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_10))
{
var args = new PropertyReassignmentEventArgs(
property.Name,
oldValue,
newValue,
location,
message: null)
{
BuildEventContext = _evaluationLoggingContext.BuildEventContext,
};

_evaluationLoggingContext.LogBuildEvent(args);
}
else
{
_evaluationLoggingContext.LogComment(
MessageImportance.Low,
"PropertyReassignment",
property.Name,
newValue,
oldValue,
location);
}
}
}

Expand Down
Loading