Skip to content

Commit

Permalink
Accept TaskOutput when filtering events for EmbedInBinlog (#7869)
Browse files Browse the repository at this point in the history
Co-authored-by: Forgind <Forgind@users.noreply.github.com>
  • Loading branch information
MeikTranel and Forgind authored Aug 16, 2022
1 parent 50f6081 commit 5d102ae
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
30 changes: 29 additions & 1 deletion src/Build.UnitTests/BinaryLogger_Tests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Text;

using Microsoft.Build.BackEnd.Logging;
Expand Down Expand Up @@ -178,6 +179,34 @@ public void UnusedEnvironmentVariablesDoNotAppearInBinaryLog()
}
}

[Fact]
public void BinaryLoggerShouldEmbedFilesViaTaskOutput()
{
using var buildManager = new BuildManager();
var binaryLogger = new BinaryLogger()
{
Parameters = $"LogFile={_logFile}",
CollectProjectImports = BinaryLogger.ProjectImportsCollectionMode.ZipFile,
};
var testProject = @"
<Project>
<Target Name=""Build"">
<WriteLinesToFile File=""testtaskoutputfile.txt"" Lines=""abc;def;ghi""/>
<CreateItem Include=""testtaskoutputfile.txt"">
<Output TaskParameter=""Include"" ItemName=""EmbedInBinlog"" />
</CreateItem>
</Target>
</Project>";
ObjectModelHelpers.BuildProjectExpectSuccess(testProject, binaryLogger);
var projectImportsZipPath = Path.ChangeExtension(_logFile, ".ProjectImports.zip");
using var fileStream = new FileStream(projectImportsZipPath, FileMode.Open);
using var zipArchive = new ZipArchive(fileStream, ZipArchiveMode.Read);

// Can't just compare `Name` because `ZipArchive` does not handle unix directory separators well
// thus producing garbled fully qualified paths in the actual .ProjectImports.zip entries
zipArchive.Entries.ShouldContain(zE => zE.Name.EndsWith("testtaskoutputfile.txt"));
}

[Fact]
public void BinaryLoggerShouldNotThrowWhenMetadataCannotBeExpanded()
{
Expand Down Expand Up @@ -245,7 +274,6 @@ public void MessagesCanBeLoggedWhenProjectsAreCached()
.OverallResult.ShouldBe(BuildResultCode.Success);
}


public void Dispose()
{
_env.Dispose();
Expand Down
3 changes: 2 additions & 1 deletion src/Build/Logging/BinaryLogger/BuildEventArgsWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,8 @@ private void Write(TaskParameterEventArgs e)
Write((int)e.Kind);
WriteDeduplicatedString(e.ItemType);
WriteTaskItemList(e.Items, e.LogItemMetadata);
if (e.Kind == TaskParameterMessageKind.AddItem)
if (e.Kind == TaskParameterMessageKind.AddItem
|| e.Kind == TaskParameterMessageKind.TaskOutput)
{
CheckForFilesToEmbed(e.ItemType, e.Items);
}
Expand Down

0 comments on commit 5d102ae

Please sign in to comment.