Skip to content
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

Use an unnamed bindpath as a default root for... #565

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -199,14 +199,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 @@ -236,7 +236,7 @@ public void CanHarvestFilesInModules()
}

[Fact]
public void CanHarvestFilesWithBindPaths()
public void CanHarvestFilesWithNamedBindPaths()
{
var expected = new[]
{
Expand All @@ -254,6 +254,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 @@ -319,7 +340,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, params string[] additionalCommandLineArguments)
private static void Build(string file, Action<string, WixRunnerResult> tester, bool isPackage = true, bool addUnnamedBindPath = false, params string[] additionalCommandLineArguments)
{
var folder = TestData.Get("TestData", "HarvestFiles");

Expand All @@ -335,12 +356,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.
Loading