-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements wixtoolset/issues#7696. `File` elements can appear where `Component` elements do in WiX v4. The compiler generates an appropriate per-file component. Naked files under `Directory`, `DirectoryRef`, `Fragment`, `StandardDirectory`, or `Package` elements are included in a package via the [default-feature feature](wixtoolset/issues#7581). Naked files appearing under `ComponentGroup`, `Feature`, `FeatureRef`, and `FeatureGroup` generate the component and the reference to the parent element. Components and naked Files default to being installed to INSTALLFOLDER (including a default INSTALLFOLDER if one isn't otherwise authored).
- Loading branch information
Showing
27 changed files
with
751 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
247 changes: 247 additions & 0 deletions
247
src/wix/test/WixToolsetTest.CoreIntegration/NakedFileFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,247 @@ | ||
// 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 WixToolsetTest.CoreIntegration | ||
{ | ||
using System.Data; | ||
using System.IO; | ||
using System.Linq; | ||
using WixInternal.Core.TestPackage; | ||
using WixInternal.TestSupport; | ||
using WixToolset.Data.WindowsInstaller; | ||
using Xunit; | ||
|
||
public class NakedFileFixture | ||
{ | ||
[Fact] | ||
public void CanBuildNakedFilesInComponentGroup() | ||
{ | ||
var rows = BuildAndQueryComponentAndFileTables("ComponentGroup.wxs"); | ||
|
||
AssertFileComponentIds(2, rows); | ||
} | ||
|
||
[Fact] | ||
public void CanBuildNakedFilesInFeature() | ||
{ | ||
var rows = BuildAndQueryComponentAndFileTables("Feature.wxs"); | ||
|
||
AssertFileComponentIds(2, rows); | ||
} | ||
|
||
[Fact] | ||
public void CanBuildNakedFilesInDirectory() | ||
{ | ||
var rows = BuildAndQueryComponentAndFileTables("Directory.wxs"); | ||
|
||
AssertFileComponentIds(2, rows); | ||
} | ||
|
||
[Fact] | ||
public void CanBuildNakedFilesInDirectoryRef() | ||
{ | ||
var rows = BuildAndQueryComponentAndFileTables("DirectoryRef.wxs"); | ||
|
||
AssertFileComponentIds(2, rows); | ||
} | ||
|
||
[Fact] | ||
public void CanBuildNakedFilesInFeatureRef() | ||
{ | ||
var rows = BuildAndQueryComponentAndFileTables("FeatureRef.wxs"); | ||
|
||
AssertFileComponentIds(2, rows); | ||
} | ||
|
||
[Fact] | ||
public void CanBuildNakedFilesInFeatureGroup() | ||
{ | ||
var rows = BuildAndQueryComponentAndFileTables("FeatureGroup.wxs"); | ||
|
||
AssertFileComponentIds(2, rows); | ||
} | ||
|
||
[Fact] | ||
public void CanBuildNakedFilesInFragments() | ||
{ | ||
var rows = BuildAndQueryComponentAndFileTables("Fragment.wxs"); | ||
|
||
AssertFileComponentIds(2, rows); | ||
} | ||
|
||
[Fact] | ||
public void CanBuildNakedFilesInStandardDirectory() | ||
{ | ||
var rows = BuildAndQueryComponentAndFileTables("StandardDirectory.wxs"); | ||
|
||
AssertFileComponentIds(2, rows); | ||
} | ||
|
||
[Fact] | ||
public void CanBuildNakedFilesInModule() | ||
{ | ||
var rows = BuildAndQueryComponentAndFileTables("Module.wxs", isPackage: false); | ||
|
||
AssertFileComponentIds(2, rows); | ||
} | ||
|
||
[Fact] | ||
public void CanBuildNakedFilesWithConditions() | ||
{ | ||
var rows = BuildAndQueryComponentAndFileTables("Condition.wxs"); | ||
var componentRows = rows.Where(row => row.StartsWith("Component:")).ToArray(); | ||
|
||
// Coincidentally, the files' ids are the same as the component conditions. | ||
foreach (var componentRow in componentRows) | ||
{ | ||
var columns = componentRow.Split(':', '\t'); | ||
Assert.Equal(columns[1], columns[5]); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void CanBuildNakedFilesUnderPackage() | ||
{ | ||
var rows = BuildAndQueryComponentAndFileTables("Package.wxs"); | ||
AssertFileComponentIds(4, rows); | ||
} | ||
|
||
[Fact] | ||
public void CanBuildNakedFilesUnderPackageWithDefaultInstallFolder() | ||
{ | ||
var rows = BuildAndQueryComponentAndFileTables("PackageWithDefaultInstallFolder.wxs"); | ||
AssertFileComponentIds(4, rows); | ||
} | ||
|
||
[Fact] | ||
public void NakedFilesUnderPackageWithAuthoredFeatureAreOrphaned() | ||
{ | ||
var messages = BuildAndQueryComponentAndFileTables("PackageWithoutDefaultFeature.wxs", isPackage: true, 267); | ||
Assert.Equal(new[] | ||
{ | ||
"267", | ||
"267", | ||
}, messages); | ||
} | ||
|
||
[Fact] | ||
public void IllegalAttributesWhenNonNakedFailTheBuild() | ||
{ | ||
var messages = BuildAndQueryComponentAndFileTables("BadAttributes.wxs", isPackage: true, 62); | ||
Assert.Equal(new[] | ||
{ | ||
"62", | ||
"62", | ||
"62", | ||
"62", | ||
}, messages); | ||
} | ||
|
||
[Fact] | ||
public void CanBuildNakedFileFromWixlibComponentGroup() | ||
{ | ||
var rows = BuildPackageWithWixlib("WixlibComponentGroup.wxs", "WixlibComponentGroupPackage.wxs"); | ||
|
||
AssertFileComponentIds(2, rows); | ||
} | ||
|
||
private static string[] BuildPackageWithWixlib(string wixlibSourcePath, string msiSourcePath) | ||
{ | ||
var folder = TestData.Get("TestData", "NakedFile"); | ||
|
||
using (var fs = new DisposableFileSystem()) | ||
{ | ||
var baseFolder = fs.GetFolder(); | ||
var intermediateFolder = Path.Combine(baseFolder, "obj"); | ||
var binFolder = Path.Combine(baseFolder, "bin"); | ||
var wixlibPath = Path.Combine(binFolder, Path.ChangeExtension(wixlibSourcePath, ".wixlib")); | ||
|
||
var result = WixRunner.Execute(new[] | ||
{ | ||
"build", | ||
Path.Combine(folder, wixlibSourcePath), | ||
"-intermediateFolder", intermediateFolder, | ||
"-bindpath", folder, | ||
"-o", wixlibPath, | ||
}); | ||
|
||
result.AssertSuccess(); | ||
|
||
var msiPath = Path.Combine(binFolder, "test.msi"); | ||
|
||
result = WixRunner.Execute(new[] | ||
{ | ||
"build", | ||
Path.Combine(folder, msiSourcePath), | ||
wixlibPath, | ||
"-intermediateFolder", intermediateFolder, | ||
"-bindpath", folder, | ||
"-o", msiPath, | ||
}); | ||
result.AssertSuccess(); | ||
|
||
return Query.QueryDatabase(msiPath, new[] { "Component", "File" }) | ||
.OrderBy(s => s) | ||
.ToArray(); | ||
} | ||
} | ||
|
||
private static string[] BuildAndQueryComponentAndFileTables(string file, bool isPackage = true, int? exitCode = null) | ||
{ | ||
var folder = TestData.Get("TestData", "NakedFile"); | ||
|
||
using (var fs = new DisposableFileSystem()) | ||
{ | ||
var baseFolder = fs.GetFolder(); | ||
var intermediateFolder = Path.Combine(baseFolder, "obj"); | ||
var binFolder = Path.Combine(baseFolder, "bin"); | ||
var msiPath = Path.Combine(binFolder, isPackage ? "test.msi" : "test.msm"); | ||
|
||
var result = WixRunner.Execute(new[] | ||
{ | ||
"build", | ||
Path.Combine(folder, file), | ||
"-intermediateFolder", intermediateFolder, | ||
"-bindpath", folder, | ||
"-o", msiPath, | ||
}); | ||
|
||
if (exitCode.HasValue) | ||
{ | ||
Assert.Equal(exitCode.Value, result.ExitCode); | ||
|
||
return result.Messages.Select(m => m.Id.ToString()).ToArray(); | ||
} | ||
else | ||
{ | ||
result.AssertSuccess(); | ||
|
||
return Query.QueryDatabase(msiPath, new[] { "Component", "File" }) | ||
.OrderBy(s => s) | ||
.ToArray(); | ||
} | ||
} | ||
} | ||
|
||
private static void AssertFileComponentIds(int fileCount, string[] rows) | ||
{ | ||
var componentRows = rows.Where(row => row.StartsWith("Component:")).ToArray(); | ||
var fileRows = rows.Where(row => row.StartsWith("File:")).ToArray(); | ||
|
||
Assert.Equal(fileCount, componentRows.Length); | ||
Assert.Equal(componentRows.Length, fileRows.Length); | ||
|
||
// Component id == Component keypath == File id | ||
foreach (var componentRow in componentRows) | ||
{ | ||
var columns = componentRow.Split(':', '\t'); | ||
Assert.Equal(columns[1], columns[6]); | ||
} | ||
|
||
foreach (var fileRow in fileRows) | ||
{ | ||
var columns = fileRow.Split(':', '\t'); | ||
Assert.Equal(columns[1], columns[2]); | ||
} | ||
} | ||
} | ||
} |
10 changes: 0 additions & 10 deletions
10
...st/WixToolsetTest.CoreIntegration/TestData/Component/MissingDirectoryWithSubdirectory.wxs
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
src/wix/test/WixToolsetTest.CoreIntegration/TestData/NakedFile/BadAttributes.wxs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<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"> | ||
<Component Directory="ProgramFilesFolder" Subdirectory="MsiPackage"> | ||
<File Source="test.txt" Bitness="always64" Condition="BLAHBLAHBLAH" Directory="ProgramFilesFolder" Subdirectory="MsiPackage" /> | ||
</Component> | ||
</Feature> | ||
</Package> | ||
</Wix> |
14 changes: 14 additions & 0 deletions
14
src/wix/test/WixToolsetTest.CoreIntegration/TestData/NakedFile/ComponentGroup.wxs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<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> | ||
|
||
<ComponentGroup Id="Files" Directory="ProgramFilesFolder" Subdirectory="MsiPackage"> | ||
<File Source="test.txt" /> | ||
<File Source="test.txt" Name="test2.txt" /> | ||
</ComponentGroup> | ||
</Package> | ||
</Wix> |
10 changes: 10 additions & 0 deletions
10
src/wix/test/WixToolsetTest.CoreIntegration/TestData/NakedFile/Condition.wxs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<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"> | ||
<File Id="FILE1" Condition="FILE1" Directory="ProgramFilesFolder" Subdirectory="MsiPackage" Source="test.txt" /> | ||
<File Id="FILE2" Condition="FILE2" Directory="ProgramFilesFolder" Subdirectory="MsiPackage" Source="test.txt" Name="test2.txt" /> | ||
</Feature> | ||
</Package> | ||
</Wix> |
Oops, something went wrong.