From f4709371fa21ca1d0c06e04d1b53c0b10bfafeed Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Sat, 24 Apr 2021 16:28:44 -0500 Subject: Perform more bundle validation during linking. #5273, #6291, #6398 --- src/WixToolset.Core.Burn/BurnBackendErrors.cs | 2 +- src/WixToolset.Core.Burn/BurnBackendWarnings.cs | 2 +- .../WindowsInstallerBackendErrors.cs | 4 +- .../WindowsInstallerBackendWarnings.cs | 4 +- src/WixToolset.Core/CompilerErrors.cs | 2 +- src/WixToolset.Core/CompilerWarnings.cs | 2 +- src/WixToolset.Core/Compiler_Bundle.cs | 1 + .../Link/FlattenAndProcessBundleTablesCommand.cs | 121 +++++++++++-- src/WixToolset.Core/Link/WixGroupingOrdering.cs | 11 +- src/WixToolset.Core/LinkerErrors.cs | 48 +++++ src/WixToolset.Core/LinkerWarnings.cs | 30 ++++ src/WixToolset.Core/WixToolset.Core.csproj | 12 ++ .../BundleFixture.cs | 63 ++++++- .../BundleManifestFixture.cs | 6 +- .../ContainerFixture.cs | 197 +++++++++++++-------- .../PayloadFixture.cs | 5 +- .../TestData/BadInput/OrphanPayload.wxs | 11 ++ .../BadInput/PackageInMultipleContainers.wxs | 14 ++ .../TestData/BadInput/UnscheduledPackage.wxs | 6 +- .../BadInput/UnscheduledRollbackBoundary.wxs | 4 +- .../Container/LayoutPayloadInContainer.wxs | 28 +++ .../Container/PayloadInMultipleContainers.wxs | 28 +++ .../Payload/SharedBAAndPackagePayloadBundle.wxs | 2 +- .../SharedPayloadsBetweenPackages.wxs | 4 +- 24 files changed, 492 insertions(+), 115 deletions(-) create mode 100644 src/WixToolset.Core/LinkerErrors.cs create mode 100644 src/WixToolset.Core/LinkerWarnings.cs create mode 100644 src/test/WixToolsetTest.CoreIntegration/TestData/BadInput/OrphanPayload.wxs create mode 100644 src/test/WixToolsetTest.CoreIntegration/TestData/BadInput/PackageInMultipleContainers.wxs create mode 100644 src/test/WixToolsetTest.CoreIntegration/TestData/Container/LayoutPayloadInContainer.wxs create mode 100644 src/test/WixToolsetTest.CoreIntegration/TestData/Container/PayloadInMultipleContainers.wxs (limited to 'src') diff --git a/src/WixToolset.Core.Burn/BurnBackendErrors.cs b/src/WixToolset.Core.Burn/BurnBackendErrors.cs index f23db47d..854c84e0 100644 --- a/src/WixToolset.Core.Burn/BurnBackendErrors.cs +++ b/src/WixToolset.Core.Burn/BurnBackendErrors.cs @@ -67,6 +67,6 @@ namespace WixToolset.Core.Burn PackageCachePayloadCollision = 8006, PackageCachePayloadCollision2 = 8007, MultipleAttachedContainersUnsupported = 8008, - } + } // last available is 8499. 8500 is BurnBackendWarnings. } } diff --git a/src/WixToolset.Core.Burn/BurnBackendWarnings.cs b/src/WixToolset.Core.Burn/BurnBackendWarnings.cs index 5edbbd67..a0ffa1dc 100644 --- a/src/WixToolset.Core.Burn/BurnBackendWarnings.cs +++ b/src/WixToolset.Core.Burn/BurnBackendWarnings.cs @@ -31,6 +31,6 @@ namespace WixToolset.Core.Burn AttachedContainerPayloadCollision = 8500, AttachedContainerPayloadCollision2 = 8501, EmptyContainer = 8502, - } + } // last available is 8999. 9000 is VerboseMessages. } } diff --git a/src/WixToolset.Core.WindowsInstaller/WindowsInstallerBackendErrors.cs b/src/WixToolset.Core.WindowsInstaller/WindowsInstallerBackendErrors.cs index c1232dcc..0c15ad05 100644 --- a/src/WixToolset.Core.WindowsInstaller/WindowsInstallerBackendErrors.cs +++ b/src/WixToolset.Core.WindowsInstaller/WindowsInstallerBackendErrors.cs @@ -18,7 +18,7 @@ namespace WixToolset.Core.WindowsInstaller public enum Ids { - // ReplaceThisWithTheFirstError = 7000, - } + // ReplaceThisWithTheFirstError = 7500, + } // last available is 7999. 8000 is BurnBackendErrors. } } diff --git a/src/WixToolset.Core.WindowsInstaller/WindowsInstallerBackendWarnings.cs b/src/WixToolset.Core.WindowsInstaller/WindowsInstallerBackendWarnings.cs index 0eaadbe1..d0986a4d 100644 --- a/src/WixToolset.Core.WindowsInstaller/WindowsInstallerBackendWarnings.cs +++ b/src/WixToolset.Core.WindowsInstaller/WindowsInstallerBackendWarnings.cs @@ -18,7 +18,7 @@ namespace WixToolset.Core.WindowsInstaller public enum Ids { - // ReplaceThisWithTheFirstWarning = 7500, - } + // ReplaceThisWithTheFirstWarning = 7100, + } // last available is 7499. 7500 is WindowsInstallerBackendErrors. } } diff --git a/src/WixToolset.Core/CompilerErrors.cs b/src/WixToolset.Core/CompilerErrors.cs index 9b3d85b9..10646dfd 100644 --- a/src/WixToolset.Core/CompilerErrors.cs +++ b/src/WixToolset.Core/CompilerErrors.cs @@ -38,6 +38,6 @@ namespace WixToolset.Core IllegalName = 6601, ExampleRegid = 6602, - } + } // 5400-5499 and 6600-6699 were the ranges for Dependency and Tag which are now in Core between CompilerWarnings and CompilerErrors. } } diff --git a/src/WixToolset.Core/CompilerWarnings.cs b/src/WixToolset.Core/CompilerWarnings.cs index eb838ae2..5c11b878 100644 --- a/src/WixToolset.Core/CompilerWarnings.cs +++ b/src/WixToolset.Core/CompilerWarnings.cs @@ -60,6 +60,6 @@ namespace WixToolset.Core Win64Component = 5435, DirectoryRefStandardDirectoryDeprecated = 5436, DefiningStandardDirectoryDeprecated = 5437, - } + } // 5400-5499 and 6600-6699 were the ranges for Dependency and Tag which are now in Core between CompilerWarnings and CompilerErrors. } } diff --git a/src/WixToolset.Core/Compiler_Bundle.cs b/src/WixToolset.Core/Compiler_Bundle.cs index 779ad376..e09246df 100644 --- a/src/WixToolset.Core/Compiler_Bundle.cs +++ b/src/WixToolset.Core/Compiler_Bundle.cs @@ -2375,6 +2375,7 @@ namespace WixToolset.Core } this.CreateChainPackageMetaRows(sourceLineNumbers, parentType, parentId, ComplexReferenceChildType.Package, id.Id, previousType, previousId, after); + this.Core.CreateGroupAndOrderingRows(sourceLineNumbers, parentType, parentId, ComplexReferenceChildType.ContainerPackage, id.Id, ComplexReferenceChildType.Unknown, null); } return id.Id; diff --git a/src/WixToolset.Core/Link/FlattenAndProcessBundleTablesCommand.cs b/src/WixToolset.Core/Link/FlattenAndProcessBundleTablesCommand.cs index 0fa48d8c..e8df25ed 100644 --- a/src/WixToolset.Core/Link/FlattenAndProcessBundleTablesCommand.cs +++ b/src/WixToolset.Core/Link/FlattenAndProcessBundleTablesCommand.cs @@ -42,46 +42,143 @@ namespace WixToolset.Core.Link // We need to flatten the nested PayloadGroups and PackageGroups under // UX, Chain, and any Containers. When we're done, the WixGroups table // will hold Payloads under UX, ChainPackages (references?) under Chain, - // and ChainPackages/Payloads under the attached and any detatched - // Containers. + // and ContainerPackages/Payloads under any authored Containers. var groups = new WixGroupingOrdering(this.EntrySection, this.Messaging); - // Create UX payloads and Package payloads + // Create UX payloads and Package payloads and Container packages groups.UseTypes(new[] { ComplexReferenceParentType.Container, ComplexReferenceParentType.Layout, ComplexReferenceParentType.PackageGroup, ComplexReferenceParentType.PayloadGroup, ComplexReferenceParentType.Package }, - new[] { ComplexReferenceChildType.PackageGroup, ComplexReferenceChildType.Package, ComplexReferenceChildType.PackagePayload, ComplexReferenceChildType.PayloadGroup, ComplexReferenceChildType.Payload }); + new[] { ComplexReferenceChildType.ContainerPackage, ComplexReferenceChildType.PackageGroup, ComplexReferenceChildType.Package, ComplexReferenceChildType.PackagePayload, ComplexReferenceChildType.PayloadGroup, ComplexReferenceChildType.Payload }); groups.FlattenAndRewriteGroups(ComplexReferenceParentType.Package, false); groups.FlattenAndRewriteGroups(ComplexReferenceParentType.Container, false); groups.FlattenAndRewriteGroups(ComplexReferenceParentType.Layout, false); // Create Chain packages... groups.UseTypes(new[] { ComplexReferenceParentType.PackageGroup }, new[] { ComplexReferenceChildType.Package, ComplexReferenceChildType.PackageGroup }); - groups.FlattenAndRewriteRows(ComplexReferenceChildType.PackageGroup, "WixChain", false); + groups.FlattenAndRewriteRows(ComplexReferenceParentType.PackageGroup, "WixChain", false); groups.RemoveUsedGroupRows(); } private void ProcessBundleComplexReferences() { + var containersById = this.EntrySection.Symbols.OfType().ToDictionary(c => c.Id.Id); var groups = this.EntrySection.Symbols.OfType().ToList(); var payloadsById = this.EntrySection.Symbols.OfType().ToDictionary(c => c.Id.Id); + var containerByPackage = new Dictionary(); + var referencedPackages = new HashSet(); + var payloadsInBA = new HashSet(); + var payloadsInPackageOrLayout = new HashSet(); + + foreach (var groupSymbol in groups) + { + switch (groupSymbol.ChildType) + { + case ComplexReferenceChildType.ContainerPackage: + switch (groupSymbol.ParentType) + { + case ComplexReferenceParentType.Container: + if (containerByPackage.TryGetValue(groupSymbol.ChildId, out var collisionContainer)) + { + this.Messaging.Write(LinkerErrors.PackageInMultipleContainers(groupSymbol.SourceLineNumbers, groupSymbol.ChildId, groupSymbol.ParentId, collisionContainer.Id.Id)); + } + else + { + containerByPackage.Add(groupSymbol.ChildId, containersById[groupSymbol.ParentId]); + } + break; + } + break; + case ComplexReferenceChildType.Package: + switch (groupSymbol.ParentType) + { + case ComplexReferenceParentType.PackageGroup: + if (groupSymbol.ParentId == "WixChain") + { + referencedPackages.Add(groupSymbol.ChildId); + } + break; + } + break; + case ComplexReferenceChildType.Payload: + switch (groupSymbol.ParentType) + { + case ComplexReferenceParentType.Container: + if (groupSymbol.ParentId == BurnConstants.BurnUXContainerName) + { + payloadsInBA.Add(groupSymbol.ChildId); + } + break; + case ComplexReferenceParentType.Layout: + payloadsById[groupSymbol.ChildId].LayoutOnly = true; + payloadsInPackageOrLayout.Add(groupSymbol.ChildId); + break; + case ComplexReferenceParentType.Package: + payloadsInPackageOrLayout.Add(groupSymbol.ChildId); + break; + } + break; + } + } + + foreach (var package in this.EntrySection.Symbols.OfType()) + { + if (!referencedPackages.Contains(package.Id.Id)) + { + this.Messaging.Write(LinkerErrors.UnscheduledChainPackage(package.SourceLineNumbers, package.Id.Id)); + } + } + + foreach (var rollbackBoundary in this.EntrySection.Symbols.OfType()) + { + if (!referencedPackages.Contains(rollbackBoundary.Id.Id)) + { + this.Messaging.Write(LinkerErrors.UnscheduledRollbackBoundary(rollbackBoundary.SourceLineNumbers, rollbackBoundary.Id.Id)); + } + } + + foreach (var payload in payloadsById.Values) + { + var payloadId = payload.Id.Id; + if (payloadsInBA.Contains(payloadId)) + { + if (payloadsInPackageOrLayout.Contains(payloadId)) + { + this.Messaging.Write(LinkerErrors.PayloadSharedWithBA(payload.SourceLineNumbers, payloadId)); + } + } + else if (!payloadsInPackageOrLayout.Contains(payloadId)) + { + this.Messaging.Write(LinkerErrors.OrphanedPayload(payload.SourceLineNumbers, payloadId)); + } + } + + if (this.Messaging.EncounteredError) + { + return; + } + // Assign authored payloads to authored containers. // Compressed Payloads not assigned to a container here will get assigned to the default attached container during binding. foreach (var groupSymbol in groups) { - if (ComplexReferenceChildType.Payload == groupSymbol.ChildType) + if (groupSymbol.ChildType == ComplexReferenceChildType.Payload && groupSymbol.ParentType == ComplexReferenceParentType.Container) { var payloadSymbol = payloadsById[groupSymbol.ChildId]; + var containerId = groupSymbol.ParentId; - if (ComplexReferenceParentType.Container == groupSymbol.ParentType) + if (String.IsNullOrEmpty(payloadSymbol.ContainerRef)) + { + payloadSymbol.ContainerRef = containerId; + } + else { - // TODO: v3 didn't warn if we overwrote the payload's container. - // Should we warn now? - payloadSymbol.ContainerRef = groupSymbol.ParentId; + this.Messaging.Write(LinkerWarnings.PayloadInMultipleContainers(groupSymbol.SourceLineNumbers, groupSymbol.ChildId, containerId, payloadSymbol.ContainerRef)); } - else if (ComplexReferenceParentType.Layout == groupSymbol.ParentType) + + if (payloadSymbol.LayoutOnly) { - payloadSymbol.LayoutOnly = true; + this.Messaging.Write(LinkerWarnings.LayoutPayloadInContainer(groupSymbol.SourceLineNumbers, groupSymbol.ChildId, containerId)); } } } diff --git a/src/WixToolset.Core/Link/WixGroupingOrdering.cs b/src/WixToolset.Core/Link/WixGroupingOrdering.cs index 99220900..f9de82a9 100644 --- a/src/WixToolset.Core/Link/WixGroupingOrdering.cs +++ b/src/WixToolset.Core/Link/WixGroupingOrdering.cs @@ -62,7 +62,7 @@ namespace WixToolset.Core.Link /// The group type for the parent group to flatten. /// The identifier of the parent group to flatten. /// Whether to remove used group rows before returning. - public void FlattenAndRewriteRows(ComplexReferenceChildType parentType, string parentId, bool removeUsedRows) + public void FlattenAndRewriteRows(ComplexReferenceParentType parentType, string parentId, bool removeUsedRows) { var parentTypeString = parentType.ToString(); Debug.Assert(this.groupTypes.Contains(parentTypeString)); @@ -648,14 +648,11 @@ namespace WixToolset.Core.Link // We *don't* propagate ordering information from Packages or // Containers to their children, because ordering doesn't matter // for them, and a Payload in two Packages (or Containers) can - // cause a circular reference to occur. We do, however, need to - // track the ordering in the UX Container, because we need the - // first payload to be the entrypoint. + // cause a circular reference to occur. private bool ShouldItemPropagateChildOrdering() { - if (String.Equals(nameof(ComplexReferenceChildType.Package), this.Type, StringComparison.Ordinal) || - (String.Equals(nameof(ComplexReferenceParentType.Container), this.Type, StringComparison.Ordinal) && - !String.Equals(BurnConstants.BurnUXContainerName, this.Id, StringComparison.Ordinal))) + if (String.Equals(nameof(ComplexReferenceParentType.Package), this.Type, StringComparison.Ordinal) || + String.Equals(nameof(ComplexReferenceParentType.Container), this.Type, StringComparison.Ordinal)) { return false; } diff --git a/src/WixToolset.Core/LinkerErrors.cs b/src/WixToolset.Core/LinkerErrors.cs new file mode 100644 index 00000000..7ce8c00e --- /dev/null +++ b/src/WixToolset.Core/LinkerErrors.cs @@ -0,0 +1,48 @@ +// 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 LinkerErrors + { + public static Message OrphanedPayload(SourceLineNumber sourceLineNumbers, string payloadId) + { + return Message(sourceLineNumbers, Ids.OrphanedPayload, "Found orphaned Payload '{0}'. Make sure to reference it from a Package, the BootstrapperApplication, or the Bundle or move it into its own Fragment so it only gets linked in when actually used.", payloadId); + } + + public static Message PackageInMultipleContainers(SourceLineNumber sourceLineNumbers, string packageId, string containerId1, string containerId2) + { + return Message(sourceLineNumbers, Ids.PackageInMultipleContainers, "The Package '{0}' is referenced from multiple containers - Container '{1}' and Container '{2}'. This is not currently supported.", packageId, containerId1, containerId2); + } + + public static Message PayloadSharedWithBA(SourceLineNumber sourceLineNumbers, string payloadId) + { + return Message(sourceLineNumbers, Ids.PayloadSharedWithBA, "The Payload '{0}' is shared with the BootstrapperApplication. This is not currently supported.", payloadId); + } + + public static Message UnscheduledChainPackage(SourceLineNumber sourceLineNumbers, string packageId) + { + return Message(sourceLineNumbers, Ids.UnscheduledChainPackage, "Found orphaned Package '{0}'. Make sure to reference it from the Chain or move it into its own Fragment so it only gets linked in when actually used.", packageId); + } + + public static Message UnscheduledRollbackBoundary(SourceLineNumber sourceLineNumbers, string rollbackBoundaryId) + { + return Message(sourceLineNumbers, Ids.UnscheduledRollbackBoundary, "Found orphaned RollbackBoundary '{0}'. Make sure to reference it from the Chain or move it into its own Fragment so it only gets linked in when actually used.", rollbackBoundaryId); + } + + private static Message Message(SourceLineNumber sourceLineNumber, Ids id, string format, params object[] args) + { + return new Message(sourceLineNumber, MessageLevel.Error, (int)id, format, args); + } + + public enum Ids + { + OrphanedPayload = 7000, + PackageInMultipleContainers = 7001, + PayloadSharedWithBA = 7002, + UnscheduledChainPackage = 7003, + UnscheduledRollbackBoundary = 7004, + } // last available is 7099. 7100 is WindowsInstallerBackendWarnings. + } +} diff --git a/src/WixToolset.Core/LinkerWarnings.cs b/src/WixToolset.Core/LinkerWarnings.cs new file mode 100644 index 00000000..0eca090e --- /dev/null +++ b/src/WixToolset.Core/LinkerWarnings.cs @@ -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 LinkerWarnings + { + public static Message LayoutPayloadInContainer(SourceLineNumber sourceLineNumbers, string payloadId, string containerId) + { + return Message(sourceLineNumbers, Ids.LayoutPayloadInContainer, "The layout-only Payload '{0}' is being added to Container '{1}'. It will not be extracted during layout.", payloadId, containerId); + } + + public static Message PayloadInMultipleContainers(SourceLineNumber sourceLineNumbers, string payloadId, string containerId1, string containerId2) + { + return Message(sourceLineNumbers, Ids.PayloadInMultipleContainers, "The Payload '{0}' can't be added to Container '{1}' because it was already added to Container '{2}'.", payloadId, containerId1, containerId2); + } + + private static Message Message(SourceLineNumber sourceLineNumber, Ids id, string format, params object[] args) + { + return new Message(sourceLineNumber, MessageLevel.Warning, (int)id, format, args); + } + + public enum Ids + { + LayoutPayloadInContainer = 6900, + PayloadInMultipleContainers = 6901, + } // last available is 6999. 7000 is LinkerErrors. + } +} diff --git a/src/WixToolset.Core/WixToolset.Core.csproj b/src/WixToolset.Core/WixToolset.Core.csproj index 902f63ce..7242d500 100644 --- a/src/WixToolset.Core/WixToolset.Core.csproj +++ b/src/WixToolset.Core/WixToolset.Core.csproj @@ -13,6 +13,18 @@ true + + + <_Parameter1>WixToolset.Core.TestPackage, PublicKey=0024000004800000940000000602000000240000525341310004000001000100a9967ec28982f42ee51a47dd5204315975a6ed69294b982146a99a70130a2fa13e226aaddde14c17d1bf3af69e8956d69a86585e74d208efcc5ac98a0686055327b2e87960d3c39bf3a6bc1e572863327d19dbf4fd2616dda124dbea260755a2d1d39d3cf1049ea526493eb2bf996b8ad985e3012308529e5b9b0f5cd5fa04bd + + + <_Parameter1>WixToolsetTest.Core.Burn, PublicKey=0024000004800000940000000602000000240000525341310004000001000100a9967ec28982f42ee51a47dd5204315975a6ed69294b982146a99a70130a2fa13e226aaddde14c17d1bf3af69e8956d69a86585e74d208efcc5ac98a0686055327b2e87960d3c39bf3a6bc1e572863327d19dbf4fd2616dda124dbea260755a2d1d39d3cf1049ea526493eb2bf996b8ad985e3012308529e5b9b0f5cd5fa04bd + + + <_Parameter1>WixToolsetTest.CoreIntegration, PublicKey=0024000004800000940000000602000000240000525341310004000001000100a9967ec28982f42ee51a47dd5204315975a6ed69294b982146a99a70130a2fa13e226aaddde14c17d1bf3af69e8956d69a86585e74d208efcc5ac98a0686055327b2e87960d3c39bf3a6bc1e572863327d19dbf4fd2616dda124dbea260755a2d1d39d3cf1049ea526493eb2bf996b8ad985e3012308529e5b9b0f5cd5fa04bd + + + diff --git a/src/test/WixToolsetTest.CoreIntegration/BundleFixture.cs b/src/test/WixToolsetTest.CoreIntegration/BundleFixture.cs index cc91d212..ab644080 100644 --- a/src/test/WixToolsetTest.CoreIntegration/BundleFixture.cs +++ b/src/test/WixToolsetTest.CoreIntegration/BundleFixture.cs @@ -10,6 +10,7 @@ namespace WixToolsetTest.CoreIntegration using System.Xml; using Example.Extension; using WixBuildTools.TestSupport; + using WixToolset.Core; using WixToolset.Core.Burn; using WixToolset.Core.TestPackage; using WixToolset.Data; @@ -368,7 +369,61 @@ namespace WixToolsetTest.CoreIntegration } } - [Fact(Skip = "https://github.com/wixtoolset/issues/issues/6291")] + [Fact] + public void CantBuildWithOrphanPayload() + { + var folder = TestData.Get(@"TestData"); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + var intermediateFolder = Path.Combine(baseFolder, "obj"); + var exePath = Path.Combine(baseFolder, @"bin\test.exe"); + + var result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "BadInput", "OrphanPayload.wxs"), + Path.Combine(folder, "BundleWithPackageGroupRef", "Bundle.wxs"), + Path.Combine(folder, "BundleWithPackageGroupRef", "MinimalPackageGroup.wxs"), + "-bindpath", Path.Combine(folder, "SimpleBundle", "data"), + "-bindpath", Path.Combine(folder, ".Data"), + "-intermediateFolder", intermediateFolder, + "-o", exePath, + }); + + Assert.Equal((int)LinkerErrors.Ids.OrphanedPayload, result.ExitCode); + } + } + + [Fact] + public void CantBuildWithPackageInMultipleContainers() + { + var folder = TestData.Get(@"TestData"); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + var intermediateFolder = Path.Combine(baseFolder, "obj"); + var exePath = Path.Combine(baseFolder, @"bin\test.exe"); + + var result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "BadInput", "PackageInMultipleContainers.wxs"), + Path.Combine(folder, "BundleWithPackageGroupRef", "Bundle.wxs"), + Path.Combine(folder, "BundleWithPackageGroupRef", "MinimalPackageGroup.wxs"), + "-bindpath", Path.Combine(folder, "SimpleBundle", "data"), + "-bindpath", Path.Combine(folder, ".Data"), + "-intermediateFolder", intermediateFolder, + "-o", exePath, + }); + + Assert.Equal((int)LinkerErrors.Ids.PackageInMultipleContainers, result.ExitCode); + } + } + + [Fact] public void CantBuildWithUnscheduledPackage() { var folder = TestData.Get(@"TestData"); @@ -390,11 +445,11 @@ namespace WixToolsetTest.CoreIntegration "-o", exePath, }); - Assert.InRange(result.ExitCode, 2, Int32.MaxValue); + Assert.Equal((int)LinkerErrors.Ids.UnscheduledChainPackage, result.ExitCode); } } - [Fact(Skip = "https://github.com/wixtoolset/issues/issues/6291")] + [Fact] public void CantBuildWithUnscheduledRollbackBoundary() { var folder = TestData.Get(@"TestData"); @@ -416,7 +471,7 @@ namespace WixToolsetTest.CoreIntegration "-o", exePath, }); - Assert.InRange(result.ExitCode, 2, Int32.MaxValue); + Assert.Equal((int)LinkerErrors.Ids.UnscheduledRollbackBoundary, result.ExitCode); } } } diff --git a/src/test/WixToolsetTest.CoreIntegration/BundleManifestFixture.cs b/src/test/WixToolsetTest.CoreIntegration/BundleManifestFixture.cs index 4a8473df..29c741dc 100644 --- a/src/test/WixToolsetTest.CoreIntegration/BundleManifestFixture.cs +++ b/src/test/WixToolsetTest.CoreIntegration/BundleManifestFixture.cs @@ -291,7 +291,7 @@ namespace WixToolsetTest.CoreIntegration var baFolderPath = Path.Combine(baseFolder, "ba"); var extractFolderPath = Path.Combine(baseFolder, "extract"); - var result = WixRunner.Execute(false, new[] + var result = WixRunner.Execute(new[] { "build", Path.Combine(folder, "SharedPayloadsBetweenPackages", "SharedPayloadsBetweenPackages.wxs"), @@ -315,8 +315,8 @@ namespace WixToolsetTest.CoreIntegration { "ExePackage", new List { "CacheId", "InstallSize", "Size" } }, }; Assert.Equal(2, exePackageElements.Count); - Assert.Equal("", exePackageElements[0].GetTestXml(ignoreAttributesByElementName)); - Assert.Equal("", exePackageElements[1].GetTestXml(ignoreAttributesByElementName)); + Assert.Equal("", exePackageElements[0].GetTestXml(ignoreAttributesByElementName)); + Assert.Equal("", exePackageElements[1].GetTestXml(ignoreAttributesByElementName)); } } diff --git a/src/test/WixToolsetTest.CoreIntegration/ContainerFixture.cs b/src/test/WixToolsetTest.CoreIntegration/ContainerFixture.cs index f24429f7..ffeda069 100644 --- a/src/test/WixToolsetTest.CoreIntegration/ContainerFixture.cs +++ b/src/test/WixToolsetTest.CoreIntegration/ContainerFixture.cs @@ -8,10 +8,9 @@ namespace WixToolsetTest.CoreIntegration using System.Linq; using System.Xml; using WixBuildTools.TestSupport; + using WixToolset.Core; using WixToolset.Core.Burn; using WixToolset.Core.TestPackage; - using WixToolset.Data; - using WixToolset.Data.Symbols; using Xunit; public class ContainerFixture @@ -30,33 +29,9 @@ namespace WixToolsetTest.CoreIntegration var baFolderPath = Path.Combine(baseFolder, "ba"); var extractFolderPath = Path.Combine(baseFolder, "extract"); - var result = WixRunner.Execute(new[] - { - "build", - Path.Combine(folder, "MsiTransaction", "FirstX86.wxs"), - Path.Combine(folder, "ProductWithComponentGroupRef", "MinimalComponentGroup.wxs"), - Path.Combine(folder, "ProductWithComponentGroupRef", "Product.wxs"), - "-bindpath", Path.Combine(folder, "SingleFile", "data"), - "-intermediateFolder", intermediateFolder, - "-o", Path.Combine(binFolder, "FirstX86.msi"), - }); - - result.AssertSuccess(); + this.BuildMsis(folder, intermediateFolder, binFolder); - result = WixRunner.Execute(new[] - { - "build", - Path.Combine(folder, "MsiTransaction", "FirstX64.wxs"), - Path.Combine(folder, "ProductWithComponentGroupRef", "MinimalComponentGroup.wxs"), - Path.Combine(folder, "ProductWithComponentGroupRef", "Product.wxs"), - "-bindpath", Path.Combine(folder, "SingleFile", "data"), - "-intermediateFolder", intermediateFolder, - "-o", Path.Combine(binFolder, "FirstX64.msi"), - }); - - result.AssertSuccess(); - - result = WixRunner.Execute(new[] + var result = WixRunner.Execute(new[] { "build", Path.Combine(folder, "Container", "HarvestIntoDetachedContainer.wxs"), @@ -98,33 +73,9 @@ namespace WixToolsetTest.CoreIntegration var baFolderPath = Path.Combine(baseFolder, "ba"); var extractFolderPath = Path.Combine(baseFolder, "extract"); - var result = WixRunner.Execute(new[] - { - "build", - Path.Combine(folder, "MsiTransaction", "FirstX86.wxs"), - Path.Combine(folder, "ProductWithComponentGroupRef", "MinimalComponentGroup.wxs"), - Path.Combine(folder, "ProductWithComponentGroupRef", "Product.wxs"), - "-bindpath", Path.Combine(folder, "SingleFile", "data"), - "-intermediateFolder", intermediateFolder, - "-o", Path.Combine(binFolder, "FirstX86.msi"), - }); - - result.AssertSuccess(); - - result = WixRunner.Execute(new[] - { - "build", - Path.Combine(folder, "MsiTransaction", "FirstX64.wxs"), - Path.Combine(folder, "ProductWithComponentGroupRef", "MinimalComponentGroup.wxs"), - Path.Combine(folder, "ProductWithComponentGroupRef", "Product.wxs"), - "-bindpath", Path.Combine(folder, "SingleFile", "data"), - "-intermediateFolder", intermediateFolder, - "-o", Path.Combine(binFolder, "FirstX64.msi"), - }); - - result.AssertSuccess(); + this.BuildMsis(folder, intermediateFolder, binFolder); - result = WixRunner.Execute(new[] + var result = WixRunner.Execute(new[] { "build", Path.Combine(folder, "Container", "HarvestIntoDetachedContainer.wxs"), @@ -174,7 +125,7 @@ namespace WixToolsetTest.CoreIntegration } [Fact] - public void MultipleAttachedContainersAreNotCurrentlySupported() + public void LayoutPayloadIsPutInContainer() { var folder = TestData.Get(@"TestData"); @@ -187,36 +138,92 @@ namespace WixToolsetTest.CoreIntegration var baFolderPath = Path.Combine(baseFolder, "ba"); var extractFolderPath = Path.Combine(baseFolder, "extract"); - var result = WixRunner.Execute(new[] + this.BuildMsis(folder, intermediateFolder, binFolder); + + var result = WixRunner.Execute(false, new[] { "build", - Path.Combine(folder, "MsiTransaction", "FirstX86.wxs"), - Path.Combine(folder, "ProductWithComponentGroupRef", "MinimalComponentGroup.wxs"), - Path.Combine(folder, "ProductWithComponentGroupRef", "Product.wxs"), - "-bindpath", Path.Combine(folder, "SingleFile", "data"), + Path.Combine(folder, "Container", "LayoutPayloadInContainer.wxs"), + "-bindpath", Path.Combine(folder, "SimpleBundle", "data"), + "-bindpath", binFolder, "-intermediateFolder", intermediateFolder, - "-o", Path.Combine(binFolder, "FirstX86.msi"), + "-o", bundlePath }); + WixAssert.CompareLineByLine(new string[] + { + "The layout-only Payload 'SharedPayload' is being added to Container 'FirstX64'. It will not be extracted during layout.", + }, result.Messages.Select(m => m.ToString()).ToArray()); result.AssertSuccess(); - result = WixRunner.Execute(new[] + Assert.True(File.Exists(bundlePath)); + + var extractResult = BundleExtractor.ExtractBAContainer(null, bundlePath, baFolderPath, extractFolderPath); + extractResult.AssertSuccess(); + + var ignoreAttributes = new Dictionary> { { "Payload", new List { "FileSize", "Hash" } } }; + var payloads = extractResult.SelectManifestNodes("/burn:BurnManifest/burn:Payload[@Id='SharedPayload']") + .Cast() + .Select(e => e.GetTestXml(ignoreAttributes)) + .ToArray(); + WixAssert.CompareLineByLine(new string[] + { + "", + }, payloads); + } + } + + [Fact] + public void MultipleAttachedContainersAreNotCurrentlySupported() + { + var folder = TestData.Get(@"TestData"); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + var intermediateFolder = Path.Combine(baseFolder, "obj"); + var binFolder = Path.Combine(baseFolder, "bin"); + var bundlePath = Path.Combine(binFolder, "test.exe"); + var baFolderPath = Path.Combine(baseFolder, "ba"); + var extractFolderPath = Path.Combine(baseFolder, "extract"); + + this.BuildMsis(folder, intermediateFolder, binFolder); + + var result = WixRunner.Execute(new[] { "build", - Path.Combine(folder, "MsiTransaction", "FirstX64.wxs"), - Path.Combine(folder, "ProductWithComponentGroupRef", "MinimalComponentGroup.wxs"), - Path.Combine(folder, "ProductWithComponentGroupRef", "Product.wxs"), - "-bindpath", Path.Combine(folder, "SingleFile", "data"), + Path.Combine(folder, "Container", "MultipleAttachedContainers.wxs"), + Path.Combine(folder, "BundleWithPackageGroupRef", "Bundle.wxs"), + "-bindpath", Path.Combine(folder, "SimpleBundle", "data"), + "-bindpath", binFolder, "-intermediateFolder", intermediateFolder, - "-o", Path.Combine(binFolder, "FirstX64.msi"), + "-o", bundlePath }); - result.AssertSuccess(); + Assert.Equal((int)BurnBackendErrors.Ids.MultipleAttachedContainersUnsupported, result.ExitCode); + } + } + + [Fact] + public void PayloadIsNotPutInMultipleContainers() + { + var folder = TestData.Get(@"TestData"); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + var intermediateFolder = Path.Combine(baseFolder, "obj"); + var binFolder = Path.Combine(baseFolder, "bin"); + var bundlePath = Path.Combine(binFolder, "test.exe"); + var baFolderPath = Path.Combine(baseFolder, "ba"); + var extractFolderPath = Path.Combine(baseFolder, "extract"); + + this.BuildMsis(folder, intermediateFolder, binFolder); - result = WixRunner.Execute(new[] + var result = WixRunner.Execute(false, new[] { "build", - Path.Combine(folder, "Container", "MultipleAttachedContainers.wxs"), + Path.Combine(folder, "Container", "PayloadInMultipleContainers.wxs"), Path.Combine(folder, "BundleWithPackageGroupRef", "Bundle.wxs"), "-bindpath", Path.Combine(folder, "SimpleBundle", "data"), "-bindpath", binFolder, @@ -224,8 +231,56 @@ namespace WixToolsetTest.CoreIntegration "-o", bundlePath }); - Assert.Equal((int)BurnBackendErrors.Ids.MultipleAttachedContainersUnsupported, result.ExitCode); + WixAssert.CompareLineByLine(new string[] + { + "The Payload 'SharedPayload' can't be added to Container 'FirstX64' because it was already added to Container 'FirstX86'.", + }, result.Messages.Select(m => m.ToString()).ToArray()); + result.AssertSuccess(); + + Assert.True(File.Exists(bundlePath)); + + var extractResult = BundleExtractor.ExtractBAContainer(null, bundlePath, baFolderPath, extractFolderPath); + extractResult.AssertSuccess(); + + var ignoreAttributes = new Dictionary> { { "Payload", new List { "FileSize", "Hash" } } }; + var payloads = extractResult.SelectManifestNodes("/burn:BurnManifest/burn:Payload[@Id='SharedPayload']") + .Cast() + .Select(e => e.GetTestXml(ignoreAttributes)) + .ToArray(); + WixAssert.CompareLineByLine(new string[] + { + "", + }, payloads); } } + + private void BuildMsis(string folder, string intermediateFolder, string binFolder) + { + var result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "MsiTransaction", "FirstX86.wxs"), + Path.Combine(folder, "ProductWithComponentGroupRef", "MinimalComponentGroup.wxs"), + Path.Combine(folder, "ProductWithComponentGroupRef", "Product.wxs"), + "-bindpath", Path.Combine(folder, "SingleFile", "data"), + "-intermediateFolder", intermediateFolder, + "-o", Path.Combine(binFolder, "FirstX86.msi"), + }); + + result.AssertSuccess(); + + result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "MsiTransaction", "FirstX64.wxs"), + Path.Combine(folder, "ProductWithComponentGroupRef", "MinimalComponentGroup.wxs"), + Path.Combine(folder, "ProductWithComponentGroupRef", "Product.wxs"), + "-bindpath", Path.Combine(folder, "SingleFile", "data"), + "-intermediateFolder", intermediateFolder, + "-o", Path.Combine(binFolder, "FirstX64.msi"), + }); + + result.AssertSuccess(); + } } } diff --git a/src/test/WixToolsetTest.CoreIntegration/PayloadFixture.cs b/src/test/WixToolsetTest.CoreIntegration/PayloadFixture.cs index e9e59b9e..da87bf6c 100644 --- a/src/test/WixToolsetTest.CoreIntegration/PayloadFixture.cs +++ b/src/test/WixToolsetTest.CoreIntegration/PayloadFixture.cs @@ -8,6 +8,7 @@ namespace WixToolsetTest.CoreIntegration using System.Linq; using System.Xml; using WixBuildTools.TestSupport; + using WixToolset.Core; using WixToolset.Core.TestPackage; using WixToolset.Data; using WixToolset.Data.Symbols; @@ -117,7 +118,7 @@ namespace WixToolsetTest.CoreIntegration } } - [Fact(Skip = "https://github.com/wixtoolset/issues/issues/5273")] + [Fact] public void RejectsPayloadSharedBetweenPackageAndBA() { var folder = TestData.Get(@"TestData"); @@ -139,7 +140,7 @@ namespace WixToolsetTest.CoreIntegration "-o", bundlePath, }); - Assert.InRange(result.ExitCode, 2, int.MaxValue); + Assert.Equal((int)LinkerErrors.Ids.PayloadSharedWithBA, result.ExitCode); } } diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/BadInput/OrphanPayload.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/BadInput/OrphanPayload.wxs new file mode 100644 index 00000000..92a9602f --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/BadInput/OrphanPayload.wxs @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/BadInput/PackageInMultipleContainers.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/BadInput/PackageInMultipleContainers.wxs new file mode 100644 index 00000000..a00874ce --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/BadInput/PackageInMultipleContainers.wxs @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/BadInput/UnscheduledPackage.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/BadInput/UnscheduledPackage.wxs index ab86982d..fc53c4a2 100644 --- a/src/test/WixToolsetTest.CoreIntegration/TestData/BadInput/UnscheduledPackage.wxs +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/BadInput/UnscheduledPackage.wxs @@ -2,15 +2,15 @@ - - + + - + diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/BadInput/UnscheduledRollbackBoundary.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/BadInput/UnscheduledRollbackBoundary.wxs index 8015ed92..6cf8528e 100644 --- a/src/test/WixToolsetTest.CoreIntegration/TestData/BadInput/UnscheduledRollbackBoundary.wxs +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/BadInput/UnscheduledRollbackBoundary.wxs @@ -2,8 +2,8 @@ - - + + diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/Container/LayoutPayloadInContainer.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/Container/LayoutPayloadInContainer.wxs new file mode 100644 index 00000000..0c5f8c7e --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/Container/LayoutPayloadInContainer.wxs @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/Container/PayloadInMultipleContainers.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/Container/PayloadInMultipleContainers.wxs new file mode 100644 index 00000000..c7f549a3 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/Container/PayloadInMultipleContainers.wxs @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/Payload/SharedBAAndPackagePayloadBundle.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/Payload/SharedBAAndPackagePayloadBundle.wxs index 4cfeb99f..5263cbd4 100644 --- a/src/test/WixToolsetTest.CoreIntegration/TestData/Payload/SharedBAAndPackagePayloadBundle.wxs +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/Payload/SharedBAAndPackagePayloadBundle.wxs @@ -2,7 +2,7 @@ - + diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/SharedPayloadsBetweenPackages/SharedPayloadsBetweenPackages.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/SharedPayloadsBetweenPackages/SharedPayloadsBetweenPackages.wxs index 3457a3b7..f16fce0d 100644 --- a/src/test/WixToolsetTest.CoreIntegration/TestData/SharedPayloadsBetweenPackages/SharedPayloadsBetweenPackages.wxs +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/SharedPayloadsBetweenPackages/SharedPayloadsBetweenPackages.wxs @@ -2,10 +2,10 @@ - + - + -- cgit v1.2.3-55-g6feb