Skip to content

Commit

Permalink
Use an unnamed bindpath as a default root for...
Browse files Browse the repository at this point in the history
...harvesting files (as documented).

- Fixes wixtoolset/issues#8585
  • Loading branch information
barnson committed Dec 27, 2024
1 parent 172d144 commit d04caf2
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private string MustResolveUsingBindPaths(string source, IntermediateSymbolDefini
if (-1 != closeParen)
{
bindName = source.Substring(BindPathOpenString.Length, closeParen - BindPathOpenString.Length);
path = source.Substring(BindPathOpenString.Length + bindName.Length + 1); // +1 for the closing brace.
path = source.Substring(BindPathOpenString.Length + bindName.Length + 1); // +1 for the closing paren.
path = path.TrimStart('\\'); // remove starting '\\' char so the path doesn't look rooted.
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/wix/WixToolset.Core/HarvestFilesCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,16 @@ private IEnumerable<string> ResolveBindPaths(SourceLineNumber sourceLineNumbers,
if (-1 != closeParen)
{
bindName = source.Substring(BindPathOpenString.Length, closeParen - BindPathOpenString.Length);
path = source.Substring(BindPathOpenString.Length + bindName.Length + 1); // +1 for the closing brace.
path = source.Substring(BindPathOpenString.Length + bindName.Length + 1); // +1 for the closing paren.
path = path.TrimStart('\\'); // remove starting '\\' char so the path doesn't look rooted.
}
}

if (String.IsNullOrEmpty(bindName))
{
resultingDirectories.Add(path);
var unnamedBindPath = this.Context.BindPaths.SingleOrDefault(bp => bp.Name == null)?.Path;

resultingDirectories.Add(unnamedBindPath is null ? path : Path.Combine(unnamedBindPath, path));
}
else
{
Expand Down
32 changes: 29 additions & 3 deletions src/wix/test/WixToolsetTest.CoreIntegration/HarvestFilesFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public void CanHarvestFilesInModules()
}

[Fact]
public void CanHarvestFilesWithBindPaths()
public void CanHarvestFilesWithNamedBindPaths()
{
var expected = new[]
{
Expand All @@ -256,6 +256,27 @@ public void CanHarvestFilesWithBindPaths()
Build("BindPaths.wxs", (msiPath, _) => AssertFileIdsAndTargetPaths(msiPath, expected));
}

[Fact]
public void CanHarvestFilesWithUnnamedBindPaths()
{
var expected = new[]
{
@"flsNNsTNrgmjASmTBbP.45J1F50dEc=PFiles\HarvestedFiles\test1.txt",
@"flsASLR5pHQzLmWRE.Snra7ndH7sIA=PFiles\HarvestedFiles\test2.txt",
@"flsTZFPiMHb.qfUxdGKQYrnXOhZ.8M=PFiles\HarvestedFiles\files1_sub1\test10.txt",
@"flsLGcTTZPIU3ELiWybqnm.PQ0Ih_g=PFiles\HarvestedFiles\files1_sub1\files1_sub2\test120.txt",
@"fls1Jx2Y9Vea_.WZBH_h2e79arvDRU=PFiles\HarvestedFiles\test3.txt",
@"flsJ9gNxWaau2X3ufphQuCV9WwAgcw=PFiles\HarvestedFiles\test4.txt",
@"flswcmX9dpMQytmD_5QA5aJ5szoQVA=PFiles\HarvestedFiles\files2_sub2\test20.txt",
@"flskKeCKFUtCYMuvw564rgPLJmyBx0=PFiles\HarvestedFiles\files2_sub2\test21.txt",
@"fls2agLZFnQwjoijShwT9Z0RwHyGrI=PFiles\HarvestedFiles\files2_sub3\FileName.Extension",
@"fls9UMOE.TOv61JuYF8IhvCKb8eous=PFiles\HarvestedFiles\namedfile.txt",
@"flsu53T_9CcaBegDflAImGHTajDbJ0=PFiles\HarvestedFiles\unnamedfile.txt",
};

Build("BindPathsUnnamed.wxs", (msiPath, _) => AssertFileIdsAndTargetPaths(msiPath, expected), addUnnamedBindPath: true);
}

[Fact]
public void CanHarvestFilesInStandardDirectory()
{
Expand Down Expand Up @@ -325,7 +346,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, bool warningsAsErrors = true, params string[] additionalCommandLineArguments)
private static void Build(string file, Action<string, WixRunnerResult> tester, bool isPackage = true, bool warningsAsErrors = true, bool addUnnamedBindPath = false, params string[] additionalCommandLineArguments)
{
var folder = TestData.Get("TestData", "HarvestFiles");

Expand All @@ -341,12 +362,17 @@ private static void Build(string file, Action<string, WixRunnerResult> tester, b
"build",
Path.Combine(folder, file),
"-intermediateFolder", intermediateFolder,
"-bindpath", folder,
"-bindpath", @$"ToBeHarvested={folder}\files1",
"-bindpath", @$"ToBeHarvested={folder}\files2",
"-o", msiPath,
};

if (addUnnamedBindPath)
{
arguments.Add("-bindpath");
arguments.Add(Path.Combine(folder, "unnamedbindpath"));
}

if (additionalCommandLineArguments.Length > 0)
{
arguments.AddRange(additionalCommandLineArguments);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package Name="HarvestedFiles" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a">
<MajorUpgrade DowngradeErrorMessage="Downgrade error message." />

<Feature Id="ProductFeature">
<ComponentGroupRef Id="Files" />
</Feature>

<ComponentGroup Id="Files" Directory="ProgramFilesFolder" Subdirectory="HarvestedFiles">
<Files Include="!(bindpath.ToBeHarvested)\**">
<Exclude Files="!(bindpath.ToBeHarvested)\notatest.txt" />
<Exclude Files="!(bindpath.ToBeHarvested)\**\pleasedontincludeme.dat" />
</Files>

<!-- Include everything from the unnamed bindpath too. -->
<Files Include="**" />
</ComponentGroup>
</Package>
</Wix>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is test.txt.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is test.txt.

0 comments on commit d04caf2

Please sign in to comment.