From da5cc586114e537461b239a882c5bbea470d812d Mon Sep 17 00:00:00 2001 From: Bob Arnson Date: Sun, 14 Aug 2022 23:56:32 -0400 Subject: Clean up error message when BA is missing. Fixes https://github.com/wixtoolset/issues/issues/6852. --- src/api/wix/WixToolset.Data/ErrorMessages.cs | 4 +-- .../WixToolset.Core.Burn/Bind/BindBundleCommand.cs | 18 ++++-------- .../BundleFixture.cs | 32 ++++++++++++++++++++++ .../BundleWithInvalid/BundleWithMissingBA.wxs | 7 +++++ 4 files changed, 47 insertions(+), 14 deletions(-) create mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/TestData/BundleWithInvalid/BundleWithMissingBA.wxs diff --git a/src/api/wix/WixToolset.Data/ErrorMessages.cs b/src/api/wix/WixToolset.Data/ErrorMessages.cs index bb0bdaab..40378a2e 100644 --- a/src/api/wix/WixToolset.Data/ErrorMessages.cs +++ b/src/api/wix/WixToolset.Data/ErrorMessages.cs @@ -1425,9 +1425,9 @@ namespace WixToolset.Data return Message(sourceLineNumbers, Ids.MergePlatformMismatch, "'{0}' is a 64-bit merge module but the product consuming it is 32-bit. 32-bit products can consume only 32-bit merge modules.", mergeModuleFile); } - public static Message MissingBundleInformation(string data) + public static Message MissingBundleInformation(string friendlyName) { - return Message(null, Ids.MissingBundleInformation, "The Bundle is missing '{0}' data, and cannot continue.", data); + return Message(null, Ids.MissingBundleInformation, "The Bundle is missing {0} data, and cannot continue.", friendlyName); } public static Message MissingBundleSearch(SourceLineNumber sourceLineNumbers, string searchId) diff --git a/src/wix/WixToolset.Core.Burn/Bind/BindBundleCommand.cs b/src/wix/WixToolset.Core.Burn/Bind/BindBundleCommand.cs index 45718031..75a080a8 100644 --- a/src/wix/WixToolset.Core.Burn/Bind/BindBundleCommand.cs +++ b/src/wix/WixToolset.Core.Burn/Bind/BindBundleCommand.cs @@ -96,9 +96,7 @@ namespace WixToolset.Core.Burn var wixGroupSymbols = this.GetRequiredSymbols(); // Ensure there is one and only one WixBundleSymbol. - // The compiler and linker behavior should have colluded to get - // this behavior. - var bundleSymbol = this.GetSingleSymbol(); + var bundleSymbol = this.GetSingleSymbol("bundle"); bundleSymbol.ProviderKey = bundleSymbol.BundleId = Guid.NewGuid().ToString("B").ToUpperInvariant(); @@ -107,14 +105,10 @@ namespace WixToolset.Core.Burn this.NormalizeRelatedBundles(bundleSymbol, section); // Ensure there is one and only one WixBootstrapperApplicationDllSymbol. - // The compiler and linker behavior should have colluded to get - // this behavior. - var bundleApplicationDllSymbol = this.GetSingleSymbol(); + var bundleApplicationDllSymbol = this.GetSingleSymbol("bootstrapper application"); // Ensure there is one and only one WixChainSymbol. - // The compiler and linker behavior should have colluded to get - // this behavior. - var chainSymbol = this.GetSingleSymbol(); + var chainSymbol = this.GetSingleSymbol("package chain"); if (this.Messaging.EncounteredError) { @@ -317,7 +311,7 @@ namespace WixToolset.Core.Burn if (0 == uxPayloadIndex) { // If we didn't get any UX payloads, it's an error! - throw new WixException(ErrorMessages.MissingBundleInformation("BootstrapperApplication")); + throw new WixException(ErrorMessages.MissingBundleInformation("bootstrapper application")); } // Give the embedded payloads without an embedded id yet an embedded id. @@ -691,13 +685,13 @@ namespace WixToolset.Core.Burn return symbols; } - private T GetSingleSymbol() where T : IntermediateSymbol + private T GetSingleSymbol(string elementName) where T : IntermediateSymbol { var symbols = this.Output.Sections.Single().Symbols.OfType().ToList(); if (1 != symbols.Count) { - throw new WixException(ErrorMessages.MissingBundleInformation(typeof(T).Name)); + throw new WixException(ErrorMessages.MissingBundleInformation(elementName)); } return symbols[0]; diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/BundleFixture.cs b/src/wix/test/WixToolsetTest.CoreIntegration/BundleFixture.cs index c7dd4cfa..8b65e4aa 100644 --- a/src/wix/test/WixToolsetTest.CoreIntegration/BundleFixture.cs +++ b/src/wix/test/WixToolsetTest.CoreIntegration/BundleFixture.cs @@ -730,5 +730,37 @@ namespace WixToolsetTest.CoreIntegration Assert.Equal(7004, result.ExitCode); } } + + [Fact] + public void CannotBuildWithMissingBootstrapperApplication() + { + 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"); + + try + { + WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "BundleWithInvalid", "BundleWithMissingBA.wxs"), + "-bindpath", Path.Combine(folder, ".Data"), + "-intermediateFolder", intermediateFolder, + "-o", exePath, + }); + } + catch (WixException we) + { + Assert.Equal(341, we.Error.Id); + return; + } + + Assert.False(true, "Expected exception not accepted."); + } + } } } diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/BundleWithInvalid/BundleWithMissingBA.wxs b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/BundleWithInvalid/BundleWithMissingBA.wxs new file mode 100644 index 00000000..e663f055 --- /dev/null +++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/BundleWithInvalid/BundleWithMissingBA.wxs @@ -0,0 +1,7 @@ + + + + + + + -- cgit v1.2.3-55-g6feb