From 5fa73084c66505c8274d64cc4bf2b72e416a01a6 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Tue, 5 Sep 2023 06:27:10 -0700 Subject: Correctly process build -outputType switch Also add a few additional output types to built-in backends. Fixes 7708 --- .../TestData/DependencyTests/PatchA/PatchA.wixproj | 2 +- .../TestData/DependencyTests/PatchB/PatchB.wixproj | 2 +- .../TestData/PatchTests/PatchA2/PatchA2.wixproj | 4 +-- .../TestData/SlipstreamTests/PatchA/PatchA.wixproj | 4 +-- .../SlipstreamTests/PatchAB/PatchAB.wixproj | 4 +-- .../SlipstreamTests/PatchAB2/PatchAB2.wixproj | 4 +-- src/wix/WixToolset.Core.Burn/BurnBackendFactory.cs | 1 + .../WindowsInstallerBackendFactory.cs | 4 +++ src/wix/WixToolset.Core/BindContext.cs | 2 ++ src/wix/WixToolset.Core/Binder.cs | 15 ++++++++-- .../WixToolset.Core/CommandLine/BuildCommand.cs | 5 ++++ src/wix/WixToolset.Core/CoreErrors.cs | 6 ++++ .../BadInputFixture.cs | 33 ++++++++++++++++++++++ 13 files changed, 73 insertions(+), 13 deletions(-) diff --git a/src/test/burn/TestData/DependencyTests/PatchA/PatchA.wixproj b/src/test/burn/TestData/DependencyTests/PatchA/PatchA.wixproj index 4809934d..bf20b708 100644 --- a/src/test/burn/TestData/DependencyTests/PatchA/PatchA.wixproj +++ b/src/test/burn/TestData/DependencyTests/PatchA/PatchA.wixproj @@ -1,7 +1,7 @@ - PatchCreation + Patch .msp 1079 diff --git a/src/test/burn/TestData/DependencyTests/PatchB/PatchB.wixproj b/src/test/burn/TestData/DependencyTests/PatchB/PatchB.wixproj index c099f008..5fbdd549 100644 --- a/src/test/burn/TestData/DependencyTests/PatchB/PatchB.wixproj +++ b/src/test/burn/TestData/DependencyTests/PatchB/PatchB.wixproj @@ -1,7 +1,7 @@ - PatchCreation + Patch .msp 1079 diff --git a/src/test/burn/TestData/PatchTests/PatchA2/PatchA2.wixproj b/src/test/burn/TestData/PatchTests/PatchA2/PatchA2.wixproj index da9acb5e..3deb2263 100644 --- a/src/test/burn/TestData/PatchTests/PatchA2/PatchA2.wixproj +++ b/src/test/burn/TestData/PatchTests/PatchA2/PatchA2.wixproj @@ -1,7 +1,7 @@ - PatchCreation + Patch .msp 1079 @@ -9,4 +9,4 @@ - \ No newline at end of file + diff --git a/src/test/burn/TestData/SlipstreamTests/PatchA/PatchA.wixproj b/src/test/burn/TestData/SlipstreamTests/PatchA/PatchA.wixproj index da9acb5e..3deb2263 100644 --- a/src/test/burn/TestData/SlipstreamTests/PatchA/PatchA.wixproj +++ b/src/test/burn/TestData/SlipstreamTests/PatchA/PatchA.wixproj @@ -1,7 +1,7 @@ - PatchCreation + Patch .msp 1079 @@ -9,4 +9,4 @@ - \ No newline at end of file + diff --git a/src/test/burn/TestData/SlipstreamTests/PatchAB/PatchAB.wixproj b/src/test/burn/TestData/SlipstreamTests/PatchAB/PatchAB.wixproj index 81fa9e12..5f9ee5f6 100644 --- a/src/test/burn/TestData/SlipstreamTests/PatchAB/PatchAB.wixproj +++ b/src/test/burn/TestData/SlipstreamTests/PatchAB/PatchAB.wixproj @@ -1,7 +1,7 @@ - PatchCreation + Patch .msp 1079 @@ -11,4 +11,4 @@ - \ No newline at end of file + diff --git a/src/test/burn/TestData/SlipstreamTests/PatchAB2/PatchAB2.wixproj b/src/test/burn/TestData/SlipstreamTests/PatchAB2/PatchAB2.wixproj index 81fa9e12..5f9ee5f6 100644 --- a/src/test/burn/TestData/SlipstreamTests/PatchAB2/PatchAB2.wixproj +++ b/src/test/burn/TestData/SlipstreamTests/PatchAB2/PatchAB2.wixproj @@ -1,7 +1,7 @@ - PatchCreation + Patch .msp 1079 @@ -11,4 +11,4 @@ - \ No newline at end of file + diff --git a/src/wix/WixToolset.Core.Burn/BurnBackendFactory.cs b/src/wix/WixToolset.Core.Burn/BurnBackendFactory.cs index 03013a08..63f52200 100644 --- a/src/wix/WixToolset.Core.Burn/BurnBackendFactory.cs +++ b/src/wix/WixToolset.Core.Burn/BurnBackendFactory.cs @@ -18,6 +18,7 @@ namespace WixToolset.Core.Burn switch (outputType.ToLowerInvariant()) { case "bundle": + case "burn": case ".exe": backend = new BundleBackend(); return true; diff --git a/src/wix/WixToolset.Core.WindowsInstaller/WindowsInstallerBackendFactory.cs b/src/wix/WixToolset.Core.WindowsInstaller/WindowsInstallerBackendFactory.cs index d14743e9..42e1a45d 100644 --- a/src/wix/WixToolset.Core.WindowsInstaller/WindowsInstallerBackendFactory.cs +++ b/src/wix/WixToolset.Core.WindowsInstaller/WindowsInstallerBackendFactory.cs @@ -18,6 +18,7 @@ namespace WixToolset.Core.WindowsInstaller switch (outputType?.ToLowerInvariant()) { case "module": + case "msm": case ".msm": backend = new MsmBackend(); return true; @@ -25,11 +26,14 @@ namespace WixToolset.Core.WindowsInstaller case "msipackage": case "package": case "product": + case "msi": case ".msi": backend = new MsiBackend(); return true; + case "msppackage": case "patch": + case "msp": case ".msp": backend = new MspBackend(); return true; diff --git a/src/wix/WixToolset.Core/BindContext.cs b/src/wix/WixToolset.Core/BindContext.cs index 1c1f7528..50ccdec6 100644 --- a/src/wix/WixToolset.Core/BindContext.cs +++ b/src/wix/WixToolset.Core/BindContext.cs @@ -42,6 +42,8 @@ namespace WixToolset.Core public string OutputPath { get; set; } + public string OutputType { get; set; } + public PdbType PdbType { get; set; } public string PdbPath { get; set; } diff --git a/src/wix/WixToolset.Core/Binder.cs b/src/wix/WixToolset.Core/Binder.cs index 204ab6ee..fd6e1470 100644 --- a/src/wix/WixToolset.Core/Binder.cs +++ b/src/wix/WixToolset.Core/Binder.cs @@ -58,18 +58,27 @@ namespace WixToolset.Core var backendFactories = extensionManager.GetServices(); - var entrySection = context.IntermediateRepresentation.Sections.First(); + var outputType = context is BindContext bindContext ? bindContext.OutputType : null; + + if (String.IsNullOrEmpty(outputType)) + { + var entrySection = context.IntermediateRepresentation.Sections.First(); + + outputType = entrySection.Type.ToString(); + } foreach (var factory in backendFactories) { - if (factory.TryCreateBackend(entrySection.Type.ToString(), context.OutputPath, out var backend)) + if (factory.TryCreateBackend(outputType, context.OutputPath, out var backend)) { var result = backend.Bind(context); return result; } } - // TODO: messaging that a backend could not be found to bind the output type? + var messaging = context.ServiceProvider.GetService(); + + messaging.Write(CoreErrors.BackendNotFound(outputType, context.OutputPath)); return null; } diff --git a/src/wix/WixToolset.Core/CommandLine/BuildCommand.cs b/src/wix/WixToolset.Core/CommandLine/BuildCommand.cs index 965280d0..9ed68d81 100644 --- a/src/wix/WixToolset.Core/CommandLine/BuildCommand.cs +++ b/src/wix/WixToolset.Core/CommandLine/BuildCommand.cs @@ -316,6 +316,11 @@ namespace WixToolset.Core.CommandLine context.PdbPath = inputsOutputs.PdbPath; context.CancellationToken = cancellationToken; + if (context is BindContext bindContext) + { + bindContext.OutputType = this.commandLine.OutputType; + } + var binder = this.ServiceProvider.GetService(); bindResult = binder.Bind(context); } diff --git a/src/wix/WixToolset.Core/CoreErrors.cs b/src/wix/WixToolset.Core/CoreErrors.cs index 6dbd6c88..16feb9dc 100644 --- a/src/wix/WixToolset.Core/CoreErrors.cs +++ b/src/wix/WixToolset.Core/CoreErrors.cs @@ -26,6 +26,11 @@ namespace WixToolset.Core return Message(sourceLineNumbers, Ids.UnableToOpenFile, "Unable to open file: {0}. Error detail: {1}", path, detail); } + public static Message BackendNotFound(string outputType, string outputPath) + { + return Message(null, Ids.BackendNotFound, "Unable to find a backend to process output type: {0} for output file: {1}. Specify a different output type or output file extension.", outputType, outputPath); + } + private static Message Message(SourceLineNumber sourceLineNumber, Ids id, string format, params object[] args) { return new Message(sourceLineNumber, MessageLevel.Error, (int)id, format, args); @@ -37,6 +42,7 @@ namespace WixToolset.Core UnableToDeleteFile = 7011, UnableToMoveFile = 7012, UnableToOpenFile = 7013, + BackendNotFound = 7014, } // last available is 7099. 7100 is WindowsInstallerBackendWarnings. } } diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/BadInputFixture.cs b/src/wix/test/WixToolsetTest.CoreIntegration/BadInputFixture.cs index f571d13b..ce28faff 100644 --- a/src/wix/test/WixToolsetTest.CoreIntegration/BadInputFixture.cs +++ b/src/wix/test/WixToolsetTest.CoreIntegration/BadInputFixture.cs @@ -221,6 +221,39 @@ namespace WixToolsetTest.CoreIntegration } } + [Fact] + public void CannotBuildWithUnknownOutputType() + { + var folder = TestData.Get(@"TestData"); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + var intermediateFolder = Path.Combine(baseFolder, "obj"); + var outputPath = Path.Combine(intermediateFolder, @"test.pkg"); + + var result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "SimplePackage", "SimplePackage.wxs"), + "-intermediateFolder", intermediateFolder, + "-bindpath", Path.Combine(folder, ".Data"), + "-outputType", "invalid", + "-o", outputPath, + }); + + var messages = result.Messages.Select(m => m.ToString()).ToList(); + messages.Sort(); + + WixAssert.CompareLineByLine(new[] + { + @"Unable to find a backend to process output type: invalid for output file: \test.pkg. Specify a different output type or output file extension.", + }, messages.Select(s => s.Replace(intermediateFolder, "")).ToArray()); + + Assert.Equal(7014, result.ExitCode); + } + } + [Fact] public void GuardsAgainstVariousBundleValuesFromLoc() { -- cgit v1.2.3-55-g6feb