-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Deprecate binfmt in build event args #8917
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
Merged
rokonec
merged 33 commits into
dotnet:main
from
rokonec:rokonec/8823-deprecate-binfmt-in-BuildEventArgs
Aug 9, 2023
Merged
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 efc9def
New extended EventArgs for custom events data
rokonec c09abb4
Fix log LogMessagePacketBase constructor
rokonec c64a832
Issue warning when EventArgs is serialized by BinaryFormatter
rokonec 7d13c0d
Make ExternalProject*EventArgs serialize without BinaryFormatter
rokonec 1ea7e5b
Various unit tests
rokonec 2f7a910
Minor fixes
rokonec 8c5a524
Fix unit test - AssemblyLoadBuildEventArgs_Tests
rokonec 579a8bb
Covering missing events by UnitTests and fixing them
rokonec 30bef08
Remove AggressiveInlining
rokonec e576224
Removing MethodImplOptions.AggressiveInlining
rokonec 9441a38
Improve comment
rokonec 364ef7b
Fix LoggingService warn => msg | error mapping for extended data
rokonec 5e9253f
Merge branch 'main' into rokonec/8823-deprecate-binfmt-in-BuildEventArgs
rokonec b2fd7c0
Issue warnings only on dotnetcore runtime.
rokonec 87430c4
Merge branch 'rokonec/8823-deprecate-binfmt-in-BuildEventArgs' of htt…
rokonec 1382cc2
Fix aka link in deprecated resx
rokonec f62fdf1
Regenerate xlf after resx changes
rokonec 2cf14c8
add global variable for displaying custom build event warning
YuliiaKovalova cbee4cd
remove unused directive
YuliiaKovalova b62ad4b
apply code changes + add shallow test case
YuliiaKovalova 68c52d5
Fixing Code and unit tests
rokonec 9c5d88b
Merge branch 'main' into rokonec/8823-deprecate-binfmt-in-BuildEventArgs
YuliiaKovalova 8a30ff3
add tests coverage
YuliiaKovalova 54ecd83
Merge branch 'rokonec/8823-deprecate-binfmt-in-BuildEventArgs' of htt…
YuliiaKovalova c02e047
update test attribute
YuliiaKovalova de6e2b6
update theory attribute
YuliiaKovalova 5285736
fix review comments
YuliiaKovalova f46d557
fix compilation error
YuliiaKovalova 8cb2350
Send error on CORE
rokonec 3a5a318
Using switch
rokonec 1e9069d
Revert deprecated resx changes
rokonec 7dc20cd
Make deser constructors internal
rokonec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
163 changes: 163 additions & 0 deletions
163
src/Build.UnitTests/BackEnd/BuildManager_Logging_Tests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| => 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(); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.