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

Handle directories a bit better for Files. #507

Merged
merged 1 commit into from
Mar 14, 2024
Merged
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
Handle directories a bit better for Files.
barnson committed Mar 14, 2024
commit 4ffe9c69706384a5045625632cd23f8b939c10df
4 changes: 2 additions & 2 deletions src/wix/WixToolset.Core/HarvestFilesCommand.cs
Original file line number Diff line number Diff line change
@@ -45,8 +45,6 @@ private void HarvestFiles(HarvestFilesSymbol harvestFile, IntermediateSection se
{
var unusedSectionCachedInlinedDirectoryIds = new Dictionary<string, string>();

var directoryId = harvestFile.DirectoryRef;

var inclusions = harvestFile.Inclusions.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
var exclusions = harvestFile.Exclusions.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

@@ -75,6 +73,8 @@ private void HarvestFiles(HarvestFilesSymbol harvestFile, IntermediateSection se

foreach (var fileByRecursiveDir in resolvedFiles.GroupBy(resolvedFile => resolvedFile.RecursiveDir, resolvedFile => resolvedFile.Path))
{
var directoryId = harvestFile.DirectoryRef;

var recursiveDir = fileByRecursiveDir.Key;

if (!String.IsNullOrEmpty(recursiveDir))
47 changes: 36 additions & 11 deletions src/wix/test/WixToolsetTest.CoreIntegration/HarvestFilesFixture.cs
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ public class HarvestFilesFixture
[Fact]
public void MustIncludeSomeFiles()
{
var messages = BuildAndQueryComponentAndFileTables("BadAuthoring.wxs", isPackage: true, 10);
var messages = BuildAndQueryComponentFileDirectoryTables("BadAuthoring.wxs", isPackage: true, 10);
Assert.Equal(new[]
{
"10",
@@ -24,7 +24,7 @@ public void MustIncludeSomeFiles()
[Fact]
public void ZeroFilesHarvestedIsAWarning()
{
var messages = BuildAndQueryComponentAndFileTables("ZeroFiles.wxs", isPackage: true, 8600);
var messages = BuildAndQueryComponentFileDirectoryTables("ZeroFiles.wxs", isPackage: true, 8600);
Assert.Equal(new[]
{
"8600",
@@ -34,7 +34,7 @@ public void ZeroFilesHarvestedIsAWarning()
[Fact]
public void MissingHarvestDirectoryIsAWarning()
{
var messages = BuildAndQueryComponentAndFileTables("BadDirectory.wxs", isPackage: true, 8601);
var messages = BuildAndQueryComponentFileDirectoryTables("BadDirectory.wxs", isPackage: true, 8601);
Assert.Equal(new[]
{
"8601",
@@ -45,7 +45,7 @@ public void MissingHarvestDirectoryIsAWarning()
[Fact]
public void DuplicateFilesSomethingSomething()
{
var messages = BuildAndQueryComponentAndFileTables("DuplicateFiles.wxs", isPackage: true, 8602);
var messages = BuildAndQueryComponentFileDirectoryTables("DuplicateFiles.wxs", isPackage: true, 8602);
Assert.Equal(new[]
{
"8602",
@@ -58,7 +58,7 @@ public void DuplicateFilesSomethingSomething()
[Fact]
public void CanHarvestFilesInComponentGroup()
{
BuildQueryAssertFiles("ComponentGroup.wxs", new[]
BuildQueryAssertFiles("ComponentGroup.wxs", new[]
{
"FileName.Extension",
"test20.txt",
@@ -71,7 +71,7 @@ public void CanHarvestFilesInComponentGroup()
[Fact]
public void CanHarvestFilesInDirectory()
{
BuildQueryAssertFiles("Directory.wxs", new[]
BuildQueryAssertFiles("Directory.wxs", new[]
{
"test10.txt",
"test120.txt",
@@ -101,7 +101,7 @@ public void CanHarvestFilesInDirectoryRef()
[Fact]
public void CanHarvestFilesInFeature()
{
var rows = BuildAndQueryComponentAndFileTables("Feature.wxs");
var rows = BuildAndQueryComponentFileDirectoryTables("Feature.wxs");

AssertFileComponentIds(3, rows);
}
@@ -123,6 +123,22 @@ public void CanHarvestFilesInFeatureGroup()
});
}

[Fact]
public void CanHarvestFilesInStraightAndCrookedTrees()
{
var rows = BuildAndQueryComponentFileDirectoryTables("CrookedTree.wxs");
var directoryRows = rows.Where(row => row.StartsWith("Directory:")).Select(d => d.Substring(10)).ToArray();

var rootDirectoryId = directoryRows.Single(r => r.EndsWith("\troot")).Split('\t')[0];

foreach (var ch in new[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'z' })
{
var directoryRow = directoryRows.Single(r => r.EndsWith($"\t{ch}"));
var parentDirectory = directoryRow.Split('\t')[1];
Assert.Equal(rootDirectoryId, parentDirectory);
}
}

[Fact]
public void CanHarvestFilesInFeatureRef()
{
@@ -186,7 +202,7 @@ public void CanHarvestFilesWithBindPaths()
[Fact]
public void HarvestedFilesUnderPackageWithAuthoredFeatureAreOrphaned()
{
var messages = BuildAndQueryComponentAndFileTables("PackageWithoutDefaultFeature.wxs", isPackage: true, 267);
var messages = BuildAndQueryComponentFileDirectoryTables("PackageWithoutDefaultFeature.wxs", isPackage: true, 267);
Assert.Equal(new[]
{
"267",
@@ -232,14 +248,23 @@ public void CanHarvestFilesInFiveLines()

private static void BuildQueryAssertFiles(string file, string[] expectedFileNames, bool isPackage = true, int? exitCode = null)
{
var rows = BuildAndQueryComponentAndFileTables(file, isPackage, exitCode);
var rows = BuildAndQueryComponentFileDirectoryTables(file, isPackage, exitCode);

var fileNames = AssertFileComponentIds(expectedFileNames.Length, rows);

Assert.Equal(expectedFileNames, fileNames);
}

private static void BuildQueryDirectoryComponent(string file, string[] expectedFileNames, bool isPackage = true, int? exitCode = null)
{
var rows = BuildAndQueryComponentFileDirectoryTables(file, isPackage, exitCode);

var fileNames = AssertFileComponentIds(expectedFileNames.Length, rows);

Assert.Equal(expectedFileNames, fileNames);
}

private static string[] BuildAndQueryComponentAndFileTables(string file, bool isPackage = true, int? exitCode = null)
private static string[] BuildAndQueryComponentFileDirectoryTables(string file, bool isPackage = true, int? exitCode = null)
{
var folder = TestData.Get("TestData", "HarvestFiles");

@@ -273,7 +298,7 @@ private static string[] BuildAndQueryComponentAndFileTables(string file, bool is
{
result.AssertSuccess();

return Query.QueryDatabase(msiPath, new[] { "Component", "File" })
return Query.QueryDatabase(msiPath, new[] { "Component", "File", "Directory" })
.OrderBy(s => s)
.ToArray();
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package Name="MsiPackage" 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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package Name="MsiPackage" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a">
<Files Directory="ProgramFiles6432Folder" Subdirectory="root" Include="$(sys.SOURCEFILEDIR)\bigtree\**" />
</Package>
</Wix>
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.