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

Deprecate binfmt in build event args #8917

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
163 changes: 163 additions & 0 deletions src/Build.UnitTests/BackEnd/BuildManager_Logging_Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Microsoft.Build.BackEnd.Logging;
using Microsoft.Build.Evaluation;
using Microsoft.Build.Execution;
using Microsoft.Build.Framework;
using Microsoft.Build.Shared;
using Microsoft.Build.UnitTests;
using Shouldly;
using Xunit;
using Xunit.Abstractions;
using Xunit.NetCore.Extensions;
using static Microsoft.Build.UnitTests.ObjectModelHelpers;

#nullable disable

namespace Microsoft.Build.Engine.UnitTests.BackEnd
{
public class BuildManager_Logging_Tests : IDisposable
{
private string _mainProject = @"
<Project>

<Target Name=`MainTarget`>
<MSBuild Projects=`{0}` Targets=`ChildTarget` />
</Target>

</Project>";

private string _childProjectWithCustomBuildEvent = $@"
<Project>

<UsingTask TaskName=""CustomBuildEventTask"" AssemblyFile=""{Assembly.GetExecutingAssembly().Location}"" />
<Target Name=`ChildTarget`>
<CustomBuildEventTask />
</Target>

</Project>";


/// <summary>
/// The mock logger for testing.
/// </summary>
private readonly MockLogger _logger;

/// <summary>
/// The standard build manager for each test.
/// </summary>
private readonly BuildManager _buildManager;

/// <summary>
/// The project collection used.
/// </summary>
private readonly ProjectCollection _projectCollection;

private readonly TestEnvironment _env;
private readonly ITestOutputHelper _output;

/// <summary>
/// SetUp
/// </summary>
public BuildManager_Logging_Tests(ITestOutputHelper output)
{
_output = output;
// Ensure that any previous tests which may have been using the default BuildManager do not conflict with us.
BuildManager.DefaultBuildManager.Dispose();

_logger = new MockLogger(output);
_buildManager = new BuildManager();
_projectCollection = new ProjectCollection();

_env = TestEnvironment.Create(output);
}

[DotNetOnlyTheory]
[InlineData("1", true)]
[InlineData("0", false)]
[InlineData(null, true)]
public void Build_WithCustomBuildArgs_NetCore(string envVariableValue, bool isWarningExpected)
YuliiaKovalova marked this conversation as resolved.
Show resolved Hide resolved
=> TestCustomEventWarning<BuildErrorEventArgs>(envVariableValue, isWarningExpected);

[WindowsFullFrameworkOnlyTheory]
[InlineData("1", true)]
[InlineData("0", false)]
[InlineData(null, false)]
public void Build_WithCustomBuildArgs_Framework(string envVariableValue, bool isWarningExpected) =>
TestCustomEventWarning<BuildWarningEventArgs>(envVariableValue, isWarningExpected);

private void TestCustomEventWarning<T>(string envVariableValue, bool isWarningExpected) where T : LazyFormattedBuildEventArgs
{
var testFiles = _env.CreateTestProjectWithFiles(string.Empty, new[] { "main", "child1" }, string.Empty);

ILoggingService service = LoggingService.CreateLoggingService(LoggerMode.Synchronous, 1);
service.RegisterLogger(_logger);

_env.SetEnvironmentVariable("MSBUILDCUSTOMBUILDEVENTWARNING", envVariableValue);
_env.SetEnvironmentVariable("MSBUILDNOINPROCNODE", "1");

_buildManager.BeginBuild(BuildParameters);

try
{
var child1ProjectPath = testFiles.CreatedFiles[1];
var cleanedUpChildContents = CleanupFileContents(_childProjectWithCustomBuildEvent);
File.WriteAllText(child1ProjectPath, cleanedUpChildContents);

var mainProjectPath = testFiles.CreatedFiles[0];
var cleanedUpMainContents = CleanupFileContents(string.Format(_mainProject, child1ProjectPath));
File.WriteAllText(mainProjectPath, cleanedUpMainContents);

var buildRequestData = new BuildRequestData(
mainProjectPath,
new Dictionary<string, string>(),
MSBuildConstants.CurrentToolsVersion,
new[] { "MainTarget" },
null);

var submission = _buildManager.PendBuildRequest(buildRequestData);
var result = submission.Execute();
var allEvents = _logger.AllBuildEvents;

if (isWarningExpected)
{
allEvents.OfType<T>().ShouldHaveSingleItem();
allEvents.First(x => x is T).Message.ShouldContain(
string.Format(ResourceUtilities.GetResourceString("DeprecatedEventSerialization"),
"MyCustomBuildEventArgs"));
}
else
{
allEvents.OfType<T>().ShouldBeEmpty();
}
}
finally
{
_buildManager.EndBuild();
}
}

private BuildParameters BuildParameters => new BuildParameters(_projectCollection)
{
DisableInProcNode = true,
EnableNodeReuse = false,
Loggers = new ILogger[] { _logger }
};

/// <summary>
/// TearDown
/// </summary>
public void Dispose()
{
_buildManager.Dispose();
_projectCollection.Dispose();
_env.Dispose();
}
}
}
25 changes: 25 additions & 0 deletions src/Build.UnitTests/BackEnd/CustomBuildEventTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

#nullable disable

namespace Microsoft.Build.UnitTests
{
public class CustomBuildEventTask : Task
{
public override bool Execute()
{
MyCustomBuildEventArgs customBuildEvent = new() { RawMessage = "A message from MyCustomBuildEventArgs" };
BuildEngine.LogCustomEvent(customBuildEvent);

return true;
}

[Serializable]
public sealed class MyCustomBuildEventArgs : CustomBuildEventArgs { }
}
}
Loading
Loading