@joebigelow / wix-1 / commits / f18d7e62

Correctly process build -outputType switch

Also add a few additional output types to built-in backends. Fixes 7708

Rob Mensching committed Sep 4, 2023 at 23:40 UTC f18d7e628361cd3f2ff14dd3326cbeea68df004f
14 files changed +73 -14
src/api/wix/WixToolset.Extensibility/Data/IBindContext.cs
+5
@@ -72,6 +72,11 @@ namespace WixToolset.Extensibility.Data
72 /// </summary>
73 string OutputPath { get; set; }
74
75 + /// <summary>
76 + /// Output type to bind to.
77 + /// </summary>
78 + string OutputType { get; set; }
79 +
80 /// <summary>
81 /// Type of PDB to create.
82 /// </summary>
src/test/burn/TestData/DependencyTests/PatchA/PatchA.wixproj
+1 -1
@@ -1,7 +1,7 @@
1 <!-- 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. -->
2 <Project Sdk="WixToolset.Sdk">
3 <PropertyGroup>
4 - <OutputType>PatchCreation</OutputType>
4 + <OutputType>Patch</OutputType>
5 <TargetExt>.msp</TargetExt>
6 <SuppressSpecificWarnings>1079</SuppressSpecificWarnings>
7 </PropertyGroup>
src/test/burn/TestData/DependencyTests/PatchB/PatchB.wixproj
+1 -1
@@ -1,7 +1,7 @@
1 <!-- 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. -->
2 <Project Sdk="WixToolset.Sdk">
3 <PropertyGroup>
4 - <OutputType>PatchCreation</OutputType>
4 + <OutputType>Patch</OutputType>
5 <TargetExt>.msp</TargetExt>
6 <SuppressSpecificWarnings>1079</SuppressSpecificWarnings>
7 </PropertyGroup>
src/test/burn/TestData/PatchTests/PatchA2/PatchA2.wixproj
+2 -2
@@ -1,7 +1,7 @@
1 <!-- 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. -->
2 <Project Sdk="WixToolset.Sdk">
3 <PropertyGroup>
4 - <OutputType>PatchCreation</OutputType>
4 + <OutputType>Patch</OutputType>
5 <TargetExt>.msp</TargetExt>
6 <SuppressSpecificWarnings>1079</SuppressSpecificWarnings>
7 </PropertyGroup>
@@ -9,4 +9,4 @@
9 <ProjectReference Include="..\PackageAv1\PackageAv1.wixproj" />
10 <ProjectReference Include="..\PackageAv1_0_1\PackageAv1_0_1.wixproj" />
11 </ItemGroup>
12 -</Project>
\ No newline at end of file
12 +</Project>
src/test/burn/TestData/SlipstreamTests/PatchA/PatchA.wixproj
+2 -2
@@ -1,7 +1,7 @@
1 <!-- 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. -->
2 <Project Sdk="WixToolset.Sdk">
3 <PropertyGroup>
4 - <OutputType>PatchCreation</OutputType>
4 + <OutputType>Patch</OutputType>
5 <TargetExt>.msp</TargetExt>
6 <SuppressSpecificWarnings>1079</SuppressSpecificWarnings>
7 </PropertyGroup>
@@ -9,4 +9,4 @@
9 <ProjectReference Include="..\PackageAv1\PackageAv1.wixproj" />
10 <ProjectReference Include="..\PackageAv1_0_1\PackageAv1_0_1.wixproj" />
11 </ItemGroup>
12 -</Project>
\ No newline at end of file
12 +</Project>
src/test/burn/TestData/SlipstreamTests/PatchAB/PatchAB.wixproj
+2 -2
@@ -1,7 +1,7 @@
1 <!-- 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. -->
2 <Project Sdk="WixToolset.Sdk">
3 <PropertyGroup>
4 - <OutputType>PatchCreation</OutputType>
4 + <OutputType>Patch</OutputType>
5 <TargetExt>.msp</TargetExt>
6 <SuppressSpecificWarnings>1079</SuppressSpecificWarnings>
7 </PropertyGroup>
@@ -11,4 +11,4 @@
11 <ProjectReference Include="..\PackageBv1\PackageBv1.wixproj" />
12 <ProjectReference Include="..\PackageBv1_0_1\PackageBv1_0_1.wixproj" />
13 </ItemGroup>
14 -</Project>
\ No newline at end of file
14 +</Project>
src/test/burn/TestData/SlipstreamTests/PatchAB2/PatchAB2.wixproj
+2 -2
@@ -1,7 +1,7 @@
1 <!-- 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. -->
2 <Project Sdk="WixToolset.Sdk">
3 <PropertyGroup>
4 - <OutputType>PatchCreation</OutputType>
4 + <OutputType>Patch</OutputType>
5 <TargetExt>.msp</TargetExt>
6 <SuppressSpecificWarnings>1079</SuppressSpecificWarnings>
7 </PropertyGroup>
@@ -11,4 +11,4 @@
11 <ProjectReference Include="..\PackageBv1\PackageBv1.wixproj" />
12 <ProjectReference Include="..\PackageBv1_0_1\PackageBv1_0_1.wixproj" />
13 </ItemGroup>
14 -</Project>
\ No newline at end of file
14 +</Project>
src/wix/WixToolset.Core.Burn/BurnBackendFactory.cs
+1
@@ -18,6 +18,7 @@ namespace WixToolset.Core.Burn
18 switch (outputType.ToLowerInvariant())
19 {
20 case "bundle":
21 + case "burn":
22 case ".exe":
23 backend = new BundleBackend();
24 return true;
src/wix/WixToolset.Core.WindowsInstaller/WindowsInstallerBackendFactory.cs
+4
@@ -18,6 +18,7 @@ namespace WixToolset.Core.WindowsInstaller
18 switch (outputType?.ToLowerInvariant())
19 {
20 case "module":
21 + case "msm":
22 case ".msm":
23 backend = new MsmBackend();
24 return true;
@@ -25,11 +26,14 @@ namespace WixToolset.Core.WindowsInstaller
26 case "msipackage":
27 case "package":
28 case "product":
29 + case "msi":
30 case ".msi":
31 backend = new MsiBackend();
32 return true;
33
34 + case "msppackage":
35 case "patch":
36 + case "msp":
37 case ".msp":
38 backend = new MspBackend();
39 return true;
src/wix/WixToolset.Core/BindContext.cs
+2
@@ -42,6 +42,8 @@ namespace WixToolset.Core
42
43 public string OutputPath { get; set; }
44
45 + public string OutputType { get; set; }
46 +
47 public PdbType PdbType { get; set; }
48
49 public string PdbPath { get; set; }
src/wix/WixToolset.Core/Binder.cs
+4 -4
@@ -58,18 +58,18 @@ namespace WixToolset.Core
58
59 var backendFactories = extensionManager.GetServices<IBackendFactory>();
60
61 - var entrySection = context.IntermediateRepresentation.Sections.First();
62 -
61 foreach (var factory in backendFactories)
62 {
65 - if (factory.TryCreateBackend(entrySection.Type.ToString(), context.OutputPath, out var backend))
63 + if (factory.TryCreateBackend(context.OutputType, context.OutputPath, out var backend))
64 {
65 var result = backend.Bind(context);
66 return result;
67 }
68 }
69
72 - // TODO: messaging that a backend could not be found to bind the output type?
70 + var messaging = context.ServiceProvider.GetService<IMessaging>();
71 +
72 + messaging.Write(CoreErrors.BackendNotFound(context.OutputType, context.OutputPath));
73
74 return null;
75 }
src/wix/WixToolset.Core/CommandLine/BuildCommand.cs
+8
@@ -312,10 +312,18 @@ namespace WixToolset.Core.CommandLine
312 context.IntermediateFolder = this.IntermediateFolder;
313 context.IntermediateRepresentation = resolveResult.IntermediateRepresentation;
314 context.OutputPath = this.OutputPath;
315 + context.OutputType = this.commandLine.OutputType;
316 context.PdbType = inputsOutputs.PdbType;
317 context.PdbPath = inputsOutputs.PdbPath;
318 context.CancellationToken = cancellationToken;
319
320 + if (String.IsNullOrEmpty(context.OutputType))
321 + {
322 + var entrySection = context.IntermediateRepresentation.Sections.First();
323 +
324 + context.OutputType = entrySection.Type.ToString();
325 + }
326 +
327 var binder = this.ServiceProvider.GetService<IBinder>();
328 bindResult = binder.Bind(context);
329 }
src/wix/WixToolset.Core/CoreErrors.cs
+6
@@ -26,6 +26,11 @@ namespace WixToolset.Core
26 return Message(sourceLineNumbers, Ids.UnableToOpenFile, "Unable to open file: {0}. Error detail: {1}", path, detail);
27 }
28
29 + public static Message BackendNotFound(string outputType, string outputPath)
30 + {
31 + 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);
32 + }
33 +
34 private static Message Message(SourceLineNumber sourceLineNumber, Ids id, string format, params object[] args)
35 {
36 return new Message(sourceLineNumber, MessageLevel.Error, (int)id, format, args);
@@ -37,6 +42,7 @@ namespace WixToolset.Core
42 UnableToDeleteFile = 7011,
43 UnableToMoveFile = 7012,
44 UnableToOpenFile = 7013,
45 + BackendNotFound = 7014,
46 } // last available is 7099. 7100 is WindowsInstallerBackendWarnings.
47 }
48 }
src/wix/test/WixToolsetTest.CoreIntegration/BadInputFixture.cs
+33
@@ -221,6 +221,39 @@ namespace WixToolsetTest.CoreIntegration
221 }
222 }
223
224 + [Fact]
225 + public void CannotBuildWithUnknownOutputType()
226 + {
227 + var folder = TestData.Get(@"TestData");
228 +
229 + using (var fs = new DisposableFileSystem())
230 + {
231 + var baseFolder = fs.GetFolder();
232 + var intermediateFolder = Path.Combine(baseFolder, "obj");
233 + var outputPath = Path.Combine(intermediateFolder, @"test.pkg");
234 +
235 + var result = WixRunner.Execute(new[]
236 + {
237 + "build",
238 + Path.Combine(folder, "SimplePackage", "SimplePackage.wxs"),
239 + "-intermediateFolder", intermediateFolder,
240 + "-bindpath", Path.Combine(folder, ".Data"),
241 + "-outputType", "invalid",
242 + "-o", outputPath,
243 + });
244 +
245 + var messages = result.Messages.Select(m => m.ToString()).ToList();
246 + messages.Sort();
247 +
248 + WixAssert.CompareLineByLine(new[]
249 + {
250 + @"Unable to find a backend to process output type: invalid for output file: <folder>\test.pkg. Specify a different output type or output file extension.",
251 + }, messages.Select(s => s.Replace(intermediateFolder, "<folder>")).ToArray());
252 +
253 + Assert.Equal(7014, result.ExitCode);
254 + }
255 + }
256 +
257 [Fact]
258 public void GuardsAgainstVariousBundleValuesFromLoc()
259 {