Skip to content

Commit

Permalink
Add verbose messages around harvesting.
Browse files Browse the repository at this point in the history
  • Loading branch information
barnson committed Aug 19, 2024
1 parent ce73352 commit 1ade630
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/wix/WixToolset.Core/HarvestFilesCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ private void HarvestFiles(HarvestFilesSymbol harvestFile, IntermediateSection se
var included = this.GetWildcardFiles(harvestFile, inclusions);
var excluded = this.GetWildcardFiles(harvestFile, exclusions);

foreach (var excludedFile in excluded)
{
this.Messaging.Write(OptimizerVerboses.ExcludedFile(harvestFile.SourceLineNumbers, excludedFile.Path));
}

resolvedFiles = included.Except(excluded, comparer).ToList();

if (!resolvedFiles.Any())
Expand Down Expand Up @@ -90,6 +95,8 @@ private void HarvestFiles(HarvestFilesSymbol harvestFile, IntermediateSection se

var id = this.ParseHelper.CreateIdentifier("fls", directoryId, name);

this.Messaging.Write(OptimizerVerboses.HarvestedFile(harvestFile.SourceLineNumbers, file));

section.AddSymbol(new FileSymbol(harvestFile.SourceLineNumbers, id)
{
ComponentRef = id.Id,
Expand Down
30 changes: 30 additions & 0 deletions src/wix/WixToolset.Core/OptimizerVerboses.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.

namespace WixToolset.Core
{
using WixToolset.Data;

internal static class OptimizerVerboses
{
public static Message HarvestedFile(SourceLineNumber sourceLineNumbers, string harvestedFile)
{
return Message(sourceLineNumbers, Ids.HarvestedFile, "Harvested file: {0}", harvestedFile);
}

public static Message ExcludedFile(SourceLineNumber sourceLineNumbers, string excludedFile)
{
return Message(sourceLineNumbers, Ids.ExcludedFile, "File excluded from harvesting: {0}", excludedFile);
}

private static Message Message(SourceLineNumber sourceLineNumber, Ids id, string format, params object[] args)
{
return new Message(sourceLineNumber, MessageLevel.Verbose, (int)id, format, args);
}

public enum Ids
{
HarvestedFile = 8700,
ExcludedFile = 8701,
}
}
}
29 changes: 26 additions & 3 deletions src/wix/test/WixToolsetTest.CoreIntegration/HarvestFilesFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace WixToolsetTest.CoreIntegration
{
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -291,6 +292,23 @@ public void CanHarvestFilesInFiveLines()
Build("PackageFiveLiner.wxs", (msiPath, _) => AssertFileIdsAndTargetPaths(msiPath, expected));
}

[Fact]
public void CanGetVerboseHarvestingDetails()
{
Build("Feature.wxs", (_, result) =>
{
var messages = result.Messages.Select(m => m.Id).Where(i => i >= 8700 && i < 8800);
Assert.Equal(new[]
{
8701,
8700,
8701,
8700,
8700,
}, messages);
}, additionalCommandLineArguments: "-v");
}

private static void AssertFileIdsAndTargetPaths(string msiPath, string[] expected)
{
var pkg = new WixToolset.Dtf.WindowsInstaller.Package.InstallPackage(msiPath,
Expand All @@ -301,7 +319,7 @@ private static void AssertFileIdsAndTargetPaths(string msiPath, string[] expecte
Assert.Equal(sortedExpected, actual);
}

private static void Build(string file, Action<string, WixRunnerResult> tester, bool isPackage = true)
private static void Build(string file, Action<string, WixRunnerResult> tester, bool isPackage = true, params string[] additionalCommandLineArguments)
{
var folder = TestData.Get("TestData", "HarvestFiles");

Expand All @@ -312,7 +330,7 @@ private static void Build(string file, Action<string, WixRunnerResult> tester, b
var binFolder = Path.Combine(baseFolder, "bin");
var msiPath = Path.Combine(binFolder, isPackage ? "test.msi" : "test.msm");

var arguments = new[]
var arguments = new List<string>()
{
"build",
Path.Combine(folder, file),
Expand All @@ -323,7 +341,12 @@ private static void Build(string file, Action<string, WixRunnerResult> tester, b
"-o", msiPath,
};

var result = WixRunner.Execute(arguments);
if (additionalCommandLineArguments.Length > 0)
{
arguments.AddRange(additionalCommandLineArguments);
}

var result = WixRunner.Execute(arguments.ToArray());

tester(msiPath, result);
}
Expand Down

0 comments on commit 1ade630

Please sign in to comment.