Skip to content

Commit

Permalink
Tasks Log.HasLoggedError now respects MSBuildWarningsAsErrors (#6174
Browse files Browse the repository at this point in the history
)

IBuildEngine8 exposes a `ShouldTreatWarningAsError` method that tasks can now take advantage of.
  • Loading branch information
benvillalobos authored Mar 13, 2021
1 parent 2da32a0 commit 14c3714
Show file tree
Hide file tree
Showing 20 changed files with 771 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ public partial interface IBuildEngine7 : Microsoft.Build.Framework.IBuildEngine,
{
bool AllowFailureWithoutError { get; set; }
}
public partial interface IBuildEngine8 : Microsoft.Build.Framework.IBuildEngine, Microsoft.Build.Framework.IBuildEngine2, Microsoft.Build.Framework.IBuildEngine3, Microsoft.Build.Framework.IBuildEngine4, Microsoft.Build.Framework.IBuildEngine5, Microsoft.Build.Framework.IBuildEngine6, Microsoft.Build.Framework.IBuildEngine7
{
bool ShouldTreatWarningAsError(string warningCode);
}
public partial interface ICancelableTask : Microsoft.Build.Framework.ITask
{
void Cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ public partial interface IBuildEngine7 : Microsoft.Build.Framework.IBuildEngine,
{
bool AllowFailureWithoutError { get; set; }
}
public partial interface IBuildEngine8 : Microsoft.Build.Framework.IBuildEngine, Microsoft.Build.Framework.IBuildEngine2, Microsoft.Build.Framework.IBuildEngine3, Microsoft.Build.Framework.IBuildEngine4, Microsoft.Build.Framework.IBuildEngine5, Microsoft.Build.Framework.IBuildEngine6, Microsoft.Build.Framework.IBuildEngine7
{
bool ShouldTreatWarningAsError(string warningCode);
}
public partial interface ICancelableTask : Microsoft.Build.Framework.ITask
{
void Cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ protected Task(System.Resources.ResourceManager taskResources, string helpKeywor
public Microsoft.Build.Framework.IBuildEngine5 BuildEngine5 { get { throw null; } }
public Microsoft.Build.Framework.IBuildEngine6 BuildEngine6 { get { throw null; } }
public Microsoft.Build.Framework.IBuildEngine7 BuildEngine7 { get { throw null; } }
public Microsoft.Build.Framework.IBuildEngine8 BuildEngine8 { get { throw null; } }
protected string HelpKeywordPrefix { get { throw null; } set { } }
public Microsoft.Build.Framework.ITaskHost HostObject { get { throw null; } set { } }
public Microsoft.Build.Utilities.TaskLoggingHelper Log { get { throw null; } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ protected Task(System.Resources.ResourceManager taskResources, string helpKeywor
public Microsoft.Build.Framework.IBuildEngine5 BuildEngine5 { get { throw null; } }
public Microsoft.Build.Framework.IBuildEngine6 BuildEngine6 { get { throw null; } }
public Microsoft.Build.Framework.IBuildEngine7 BuildEngine7 { get { throw null; } }
public Microsoft.Build.Framework.IBuildEngine8 BuildEngine8 { get { throw null; } }
protected string HelpKeywordPrefix { get { throw null; } set { } }
public Microsoft.Build.Framework.ITaskHost HostObject { get { throw null; } set { } }
public Microsoft.Build.Utilities.TaskLoggingHelper Log { get { throw null; } }
Expand Down
39 changes: 39 additions & 0 deletions src/Build.UnitTests/BackEnd/CustomLogAndReturnTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
namespace Microsoft.Build.UnitTests
{
public class CustomLogAndReturnTask : Task
{
public string WarningCode { get; set; }

public string ErrorCode { get; set; }

public bool ReturnHasLoggedErrors { get; set; }

[Required]
public bool Return { get; set; }

// Unused for now, created for task batching.
public ITaskItem[] Sources { get; set; }

/// <summary>
/// This task returns and logs what you want based on the running test.
/// </summary>
public override bool Execute()
{
if(!string.IsNullOrEmpty(WarningCode))
{
Log.LogWarning(null, WarningCode, null, null, 0, 0, 0, 0, "Warning Logged!", null);
}

if(!string.IsNullOrEmpty(ErrorCode))
{
Log.LogError(null, ErrorCode, null, null, 0, 0, 0, 0, "Error Logged!", null);
}
return ReturnHasLoggedErrors ? !Log.HasLoggedErrors : Return;
}
}
}
5 changes: 5 additions & 0 deletions src/Build.UnitTests/BackEnd/MockLoggingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,11 @@ public bool HasBuildSubmissionLoggedErrors(int submissionId)
return false;
}

public ICollection<string> GetWarningsToBeLoggedAsErrorsByProject(BuildEventContext context)
{
throw new NotImplementedException();
}

#endregion
}
}
Loading

0 comments on commit 14c3714

Please sign in to comment.