Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
21f2ab8
Fix to properly serialize TargetFinishedEventArgs.TargetOutput
rokonec Jun 20, 2023
efc9def
New extended EventArgs for custom events data
rokonec Jun 20, 2023
c09abb4
Fix log LogMessagePacketBase constructor
rokonec Jun 20, 2023
c64a832
Issue warning when EventArgs is serialized by BinaryFormatter
rokonec Jun 20, 2023
7d13c0d
Make ExternalProject*EventArgs serialize without BinaryFormatter
rokonec Jun 20, 2023
1ea7e5b
Various unit tests
rokonec Jun 20, 2023
2f7a910
Minor fixes
rokonec Jun 20, 2023
8c5a524
Fix unit test - AssemblyLoadBuildEventArgs_Tests
rokonec Jun 20, 2023
579a8bb
Covering missing events by UnitTests and fixing them
rokonec Jun 20, 2023
30bef08
Remove AggressiveInlining
rokonec Jun 20, 2023
e576224
Removing MethodImplOptions.AggressiveInlining
rokonec Jun 20, 2023
9441a38
Improve comment
rokonec Jun 22, 2023
364ef7b
Fix LoggingService warn => msg | error mapping for extended data
rokonec Jun 22, 2023
5e9253f
Merge branch 'main' into rokonec/8823-deprecate-binfmt-in-BuildEventArgs
rokonec Jun 27, 2023
b2fd7c0
Issue warnings only on dotnetcore runtime.
rokonec Jun 30, 2023
87430c4
Merge branch 'rokonec/8823-deprecate-binfmt-in-BuildEventArgs' of htt…
rokonec Jun 30, 2023
1382cc2
Fix aka link in deprecated resx
rokonec Jul 12, 2023
f62fdf1
Regenerate xlf after resx changes
rokonec Jul 19, 2023
2cf14c8
add global variable for displaying custom build event warning
YuliiaKovalova Jul 20, 2023
cbee4cd
remove unused directive
YuliiaKovalova Jul 20, 2023
b62ad4b
apply code changes + add shallow test case
YuliiaKovalova Jul 25, 2023
68c52d5
Fixing Code and unit tests
rokonec Jul 25, 2023
9c5d88b
Merge branch 'main' into rokonec/8823-deprecate-binfmt-in-BuildEventArgs
YuliiaKovalova Jul 26, 2023
8a30ff3
add tests coverage
YuliiaKovalova Jul 26, 2023
54ecd83
Merge branch 'rokonec/8823-deprecate-binfmt-in-BuildEventArgs' of htt…
YuliiaKovalova Jul 26, 2023
c02e047
update test attribute
YuliiaKovalova Jul 26, 2023
de6e2b6
update theory attribute
YuliiaKovalova Jul 26, 2023
5285736
fix review comments
YuliiaKovalova Jul 27, 2023
f46d557
fix compilation error
YuliiaKovalova Jul 27, 2023
8cb2350
Send error on CORE
rokonec Jul 27, 2023
3a5a318
Using switch
rokonec Aug 9, 2023
1e9069d
Revert deprecated resx changes
rokonec Aug 9, 2023
7dc20cd
Make deser constructors internal
rokonec Aug 9, 2023
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
3 changes: 3 additions & 0 deletions eng/dependabot/Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<PackageVersion Include="BenchmarkDotNet" Version="0.13.1" />
<PackageVersion Update="BenchmarkDotNet" Condition="'$(BenchmarkDotNetVersion)' != ''" Version="$(BenchmarkDotNetVersion)" />

<PackageVersion Include="FluentAssertions" Version="6.11.0" />
<PackageVersion Update="FluentAssertions" Condition="'$(FluentAssertionsVersion)' != ''" Version="$(FluentAssertionsVersion)" />

<PackageVersion Include="LargeAddressAware" Version="1.0.5" />
<PackageVersion Update="LargeAddressAware" Condition="'$(LargeAddressAwareVersion)' != ''" Version="$(LargeAddressAwareVersion)" />

Expand Down
320 changes: 73 additions & 247 deletions src/Build.UnitTests/BackEnd/NodePackets_Tests.cs

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions src/Build.UnitTests/BackEnd/TaskHost_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,61 @@ public void TestLogCustomEventNotSerializableSP()
Assert.Equal("testCustomBuildEvent", _customLogger.LastCustom.Message);
}

/// <summary>
/// Test that extended custom events are logged properly
/// </summary>
[Fact]
public void TestLogExtendedCustomEventNotSerializableMP()
{
_mockHost.BuildParameters.MaxNodeCount = 4;

// Log the custom event args. (Pretend that the task actually did this.)
_taskHost.LogCustomEvent(new ExtendedCustomBuildEventArgs("testExtCustomBuildEvent", "ext message", null, null));

// Make sure our custom logger received the actual custom event and not some fake.
Assert.True(_customLogger.LastCustom is ExtendedCustomBuildEventArgs); // "Expected custom build Event"
Assert.Equal("ext message", _customLogger.LastCustom.Message);
}

[Fact]
public void TestLogExtendedCustomErrorNotSerializableMP()
{
_mockHost.BuildParameters.MaxNodeCount = 4;

// Log the custom event args. (Pretend that the task actually did this.)
_taskHost.LogErrorEvent(new ExtendedBuildErrorEventArgs("testExtCustomBuildError", null, null, null, 0, 0, 0, 0,"ext err message", null, null));

// Make sure our custom logger received the actual custom event and not some fake.
Assert.True(_customLogger.LastError is ExtendedBuildErrorEventArgs); // "Expected custom build Event"
Assert.Equal("ext err message", _customLogger.LastError.Message);
}

[Fact]
public void TestLogExtendedCustomWarningNotSerializableMP()
{
_mockHost.BuildParameters.MaxNodeCount = 4;

// Log the custom event args. (Pretend that the task actually did this.)
_taskHost.LogWarningEvent(new ExtendedBuildWarningEventArgs("testExtCustomBuildWarning", null, null, null, 0, 0, 0, 0, "ext warn message", null, null));

// Make sure our custom logger received the actual custom event and not some fake.
Assert.True(_customLogger.LastWarning is ExtendedBuildWarningEventArgs); // "Expected custom build Event"
Assert.Equal("ext warn message", _customLogger.LastWarning.Message);
}

[Fact]
public void TestLogExtendedCustomMessageNotSerializableMP()
{
_mockHost.BuildParameters.MaxNodeCount = 4;

// Log the custom event args. (Pretend that the task actually did this.)
_taskHost.LogMessageEvent(new ExtendedBuildMessageEventArgs("testExtCustomBuildMessage", "ext message", null, null, MessageImportance.Normal));

// Make sure our custom logger received the actual custom event and not some fake.
Assert.True(_customLogger.LastMessage is ExtendedBuildMessageEventArgs); // "Expected custom build Event"
Assert.Equal("ext message", _customLogger.LastMessage.Message);
}

/// <summary>
/// Test that errors are logged properly
/// </summary>
Expand Down
187 changes: 186 additions & 1 deletion src/Build.UnitTests/BuildEventArgsSerialization_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Microsoft.Build.Logging;
using Microsoft.Build.Shared;
using Microsoft.Build.UnitTests.BackEnd;
using Shouldly;
using Xunit;

#nullable disable
Expand Down Expand Up @@ -242,6 +243,40 @@ public void RoundtripBuildErrorEventArgs(bool useArguments)
e => string.Join(", ", e.RawArguments ?? Array.Empty<object>()));
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public void RoundtripExtendedErrorEventArgs_SerializedAsError(bool useArguments)
{
var args = new ExtendedBuildErrorEventArgs(
"extendedDataType",
"Subcategory",
"Code",
"File",
1,
2,
3,
4,
"Message with arguments: '{0}'",
"Help",
"SenderName",
DateTime.Parse("9/1/2021 12:02:07 PM"),
useArguments ? new object[] { "argument0" } : null);

// For now we don't serialize extended data into binary log
Roundtrip<BuildErrorEventArgs>(args,
e => e.Code,
e => e.ColumnNumber.ToString(),
e => e.EndColumnNumber.ToString(),
e => e.EndLineNumber.ToString(),
e => e.File,
e => e.LineNumber.ToString(),
e => e.Message,
e => e.ProjectFile,
e => e.Subcategory,
e => string.Join(", ", e.RawArguments ?? Array.Empty<object>()));
}

[Theory]
[InlineData(true)]
[InlineData(false)]
Expand Down Expand Up @@ -274,6 +309,40 @@ public void RoundtripBuildWarningEventArgs(bool useArguments)
e => string.Join(", ", e.RawArguments ?? Array.Empty<object>()));
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public void RoundtripExtendedWarningEventArgs_SerializedAsWarning(bool useArguments)
{
var args = new ExtendedBuildWarningEventArgs(
"extendedDataType",
"Subcategory",
"Code",
"File",
1,
2,
3,
4,
"Message with arguments: '{0}'",
"Help",
"SenderName",
DateTime.Parse("9/1/2021 12:02:07 PM"),
useArguments ? new object[] { "argument0" } : null);

// For now we don't serialize extended data into binary log
Roundtrip<BuildWarningEventArgs>(args,
e => e.Code,
e => e.ColumnNumber.ToString(),
e => e.EndColumnNumber.ToString(),
e => e.EndLineNumber.ToString(),
e => e.File,
e => e.LineNumber.ToString(),
e => e.Message,
e => e.ProjectFile,
e => e.Subcategory,
e => string.Join(", ", e.RawArguments ?? Array.Empty<object>()));
}

[Theory]
[InlineData(true)]
[InlineData(false)]
Expand Down Expand Up @@ -308,6 +377,122 @@ public void RoundtripBuildMessageEventArgs(bool useArguments)
e => string.Join(", ", e.RawArguments ?? Array.Empty<object>()));
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public void RoundtripExtendedBuildMessageEventArgs_SerializedAsMessage(bool useArguments)
{
var args = new ExtendedBuildMessageEventArgs(
"extendedDataType",
"Subcategory",
"Code",
"File",
1,
2,
3,
4,
"Message",
"Help",
"SenderName",
MessageImportance.High,
DateTime.Parse("12/12/2015 06:11:56 PM"),
useArguments ? new object[] { "argument0" } : null);

Roundtrip<BuildMessageEventArgs>(args,
e => e.Code,
e => e.ColumnNumber.ToString(),
e => e.EndColumnNumber.ToString(),
e => e.EndLineNumber.ToString(),
e => e.File,
e => e.LineNumber.ToString(),
e => e.Message,
e => e.Importance.ToString(),
e => e.ProjectFile,
e => e.Subcategory,
e => string.Join(", ", e.RawArguments ?? Array.Empty<object>()));
}

[Fact]
public void RoundtripAssemblyLoadBuild()
{
string assemblyName = Guid.NewGuid().ToString();
string assemblyPath = Guid.NewGuid().ToString();
Guid mvid = Guid.NewGuid();
string loadingInitiator = Guid.NewGuid().ToString();
string appDomainName = Guid.NewGuid().ToString();
AssemblyLoadingContext context =
(AssemblyLoadingContext)(new Random().Next(Enum.GetNames(typeof(AssemblyLoadingContext)).Length));

AssemblyLoadBuildEventArgs args = new(context, loadingInitiator, assemblyName, assemblyPath, mvid, appDomainName);

Roundtrip(args,
e => e.Code,
e => e.ColumnNumber.ToString(),
e => e.EndColumnNumber.ToString(),
e => e.EndLineNumber.ToString(),
e => e.File,
e => e.LineNumber.ToString(),
e => e.Message,
e => e.Importance.ToString(),
e => e.ProjectFile,
e => e.Subcategory,
e => e.LoadingContext.ToString(),
e => e.AssemblyName,
e => e.AssemblyPath,
e => e.MVID.ToString(),
e => e.AppDomainDescriptor,
e => string.Join(", ", e.RawArguments ?? Array.Empty<object>()));
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public void ExtendedCustomBuildEventArgs_SerializedAsMessage(bool withOptionalData)
{
ExtendedCustomBuildEventArgs args = new(
type: "TypeOfExtendedCustom",
message: withOptionalData ? "a message with args {0} {1}" : null,
helpKeyword: withOptionalData ? "MSBT123" : null,
senderName: withOptionalData ? $"UnitTest {Guid.NewGuid()}" : null,
eventTimestamp: withOptionalData ? DateTime.Parse("3/1/2017 11:11:56 AM") : DateTime.Now,
messageArgs: withOptionalData ? new object[] { "arg0val", "arg1val" } : null)
{
ExtendedData = withOptionalData ? "{'long-json':'mostly-strings'}" : null,
ExtendedMetadata = withOptionalData ? new Dictionary<string, string> { { "m1", "v1" }, { "m2", "v2" } } : null,
BuildEventContext = withOptionalData ? new BuildEventContext(1, 2, 3, 4, 5, 6, 7) : null,
};


var memoryStream = new MemoryStream();
var binaryWriter = new BinaryWriter(memoryStream);
var buildEventArgsWriter = new BuildEventArgsWriter(binaryWriter);
buildEventArgsWriter.Write(args);

memoryStream.Position = 0;
var binaryReader = new BinaryReader(memoryStream);

using var buildEventArgsReader = new BuildEventArgsReader(binaryReader, BinaryLogger.FileFormatVersion);
var deserialized = buildEventArgsReader.Read();
BuildMessageEventArgs desArgs = (BuildMessageEventArgs)deserialized;

desArgs.ShouldBeOfType(typeof(BuildMessageEventArgs));

desArgs.Message.ShouldBe(args.Message);
desArgs.HelpKeyword.ShouldBe(args.HelpKeyword);
desArgs.SenderName.ShouldBe(args.SenderName);
desArgs.Importance.ShouldBe(MessageImportance.Normal);
desArgs.Timestamp.ShouldBe(args.Timestamp);

if (withOptionalData)
{
desArgs.BuildEventContext.ShouldBe(args.BuildEventContext);
}
else
{
desArgs.BuildEventContext.ShouldBe(BuildEventContext.Invalid);
}
}

[Fact]
public void RoundtripResponseFileUsedEventArgs()
{
Expand Down Expand Up @@ -669,7 +854,7 @@ private void Roundtrip<T>(T args, params Func<T, string>[] fieldsToCompare)
Assert.Equal(length, memoryStream.Position);

Assert.NotNull(deserializedArgs);
Assert.Equal(args.GetType(), deserializedArgs.GetType());
Assert.Equal(typeof(T), deserializedArgs.GetType());

foreach (var field in fieldsToCompare)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<ItemGroup>
<Reference Include="System.IO.Compression" Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'" />

<PackageReference Include="FluentAssertions" />
<PackageReference Include="System.Configuration.ConfigurationManager" />
<PackageReference Include="Shouldly" />
<PackageReference Include="System.Net.Http" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal LogMessagePacket(KeyValuePair<int, BuildEventArgs>? nodeBuildEvent)
/// Constructor for deserialization
/// </summary>
private LogMessagePacket(ITranslator translator)
: base(translator)
: base(translator, new TargetFinishedTranslator(TranslateTargetFinishedEvent))
{
}

Expand Down
Loading