From 7ae59f086815a927a0bdbbcc93022a114beef444 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Tue, 5 Sep 2023 06:27:10 -0700 Subject: [PATCH] Correctly process build -outputType switch Also add a few additional output types to built-in backends. Fixes 7708 --- .../DependencyTests/PatchA/PatchA.wixproj | 2 +- .../DependencyTests/PatchB/PatchB.wixproj | 2 +- .../PatchTests/PatchA2/PatchA2.wixproj | 4 +-- .../SlipstreamTests/PatchA/PatchA.wixproj | 4 +-- .../SlipstreamTests/PatchAB/PatchAB.wixproj | 4 +-- .../SlipstreamTests/PatchAB2/PatchAB2.wixproj | 4 +-- .../BurnBackendFactory.cs | 1 + .../WindowsInstallerBackendFactory.cs | 4 +++ src/wix/WixToolset.Core/BindContext.cs | 2 ++ src/wix/WixToolset.Core/Binder.cs | 15 +++++++-- .../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 4809934d4..bf20b7087 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 c099f0083..5fbdd549f 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 da9acb5e0..3deb22636 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 da9acb5e0..3deb22636 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 81fa9e124..5f9ee5f66 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 81fa9e124..5f9ee5f66 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 03013a086..63f522006 100644 --- a/src/wix/WixToolset.Core.Burn/BurnBackendFactory.cs +++ b/src/wix/WixToolset.Core.Burn/BurnBackendFactory.cs @@ -18,6 +18,7 @@ public bool TryCreateBackend(string outputType, string outputFile, out IBackend 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 d14743e9e..42e1a45db 100644 --- a/src/wix/WixToolset.Core.WindowsInstaller/WindowsInstallerBackendFactory.cs +++ b/src/wix/WixToolset.Core.WindowsInstaller/WindowsInstallerBackendFactory.cs @@ -18,6 +18,7 @@ public bool TryCreateBackend(string outputType, string outputFile, out IBackend switch (outputType?.ToLowerInvariant()) { case "module": + case "msm": case ".msm": backend = new MsmBackend(); return true; @@ -25,11 +26,14 @@ public bool TryCreateBackend(string outputType, string outputFile, out IBackend 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 1c1f7528f..50ccdec69 100644 --- a/src/wix/WixToolset.Core/BindContext.cs +++ b/src/wix/WixToolset.Core/BindContext.cs @@ -42,6 +42,8 @@ internal BindContext(IServiceProvider serviceProvider) 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 204ab6eec..fd6e1470d 100644 --- a/src/wix/WixToolset.Core/Binder.cs +++ b/src/wix/WixToolset.Core/Binder.cs @@ -58,18 +58,27 @@ private IBindResult BackendBind(IBindContext context) 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 965280d0e..9ed68d811 100644 --- a/src/wix/WixToolset.Core/CommandLine/BuildCommand.cs +++ b/src/wix/WixToolset.Core/CommandLine/BuildCommand.cs @@ -316,6 +316,11 @@ private void BindPhase(Intermediate output, IReadOnlyCollection lo 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 6dbd6c885..16feb9dc8 100644 --- a/src/wix/WixToolset.Core/CoreErrors.cs +++ b/src/wix/WixToolset.Core/CoreErrors.cs @@ -26,6 +26,11 @@ public static Message UnableToOpenFile(SourceLineNumber sourceLineNumbers, strin 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 @@ public enum Ids 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 f571d13b0..ce28faff1 100644 --- a/src/wix/test/WixToolsetTest.CoreIntegration/BadInputFixture.cs +++ b/src/wix/test/WixToolsetTest.CoreIntegration/BadInputFixture.cs @@ -221,6 +221,39 @@ public void CannotBuildBundleWithReservedVariableNames() } } + [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() {