Skip to content

Commit

Permalink
Correctly process build -outputType switch
Browse files Browse the repository at this point in the history
Also add a few additional output types to built-in backends.

Fixes 7708
  • Loading branch information
robmen authored and barnson committed Sep 5, 2023
1 parent e29b4aa commit f18d7e6
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 14 deletions.
5 changes: 5 additions & 0 deletions src/api/wix/WixToolset.Extensibility/Data/IBindContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public interface IBindContext
/// </summary>
string OutputPath { get; set; }

/// <summary>
/// Output type to bind to.
/// </summary>
string OutputType { get; set; }

/// <summary>
/// Type of PDB to create.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- 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. -->
<Project Sdk="WixToolset.Sdk">
<PropertyGroup>
<OutputType>PatchCreation</OutputType>
<OutputType>Patch</OutputType>
<TargetExt>.msp</TargetExt>
<SuppressSpecificWarnings>1079</SuppressSpecificWarnings>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- 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. -->
<Project Sdk="WixToolset.Sdk">
<PropertyGroup>
<OutputType>PatchCreation</OutputType>
<OutputType>Patch</OutputType>
<TargetExt>.msp</TargetExt>
<SuppressSpecificWarnings>1079</SuppressSpecificWarnings>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/test/burn/TestData/PatchTests/PatchA2/PatchA2.wixproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<!-- 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. -->
<Project Sdk="WixToolset.Sdk">
<PropertyGroup>
<OutputType>PatchCreation</OutputType>
<OutputType>Patch</OutputType>
<TargetExt>.msp</TargetExt>
<SuppressSpecificWarnings>1079</SuppressSpecificWarnings>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\PackageAv1\PackageAv1.wixproj" />
<ProjectReference Include="..\PackageAv1_0_1\PackageAv1_0_1.wixproj" />
</ItemGroup>
</Project>
</Project>
4 changes: 2 additions & 2 deletions src/test/burn/TestData/SlipstreamTests/PatchA/PatchA.wixproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<!-- 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. -->
<Project Sdk="WixToolset.Sdk">
<PropertyGroup>
<OutputType>PatchCreation</OutputType>
<OutputType>Patch</OutputType>
<TargetExt>.msp</TargetExt>
<SuppressSpecificWarnings>1079</SuppressSpecificWarnings>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\PackageAv1\PackageAv1.wixproj" />
<ProjectReference Include="..\PackageAv1_0_1\PackageAv1_0_1.wixproj" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- 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. -->
<Project Sdk="WixToolset.Sdk">
<PropertyGroup>
<OutputType>PatchCreation</OutputType>
<OutputType>Patch</OutputType>
<TargetExt>.msp</TargetExt>
<SuppressSpecificWarnings>1079</SuppressSpecificWarnings>
</PropertyGroup>
Expand All @@ -11,4 +11,4 @@
<ProjectReference Include="..\PackageBv1\PackageBv1.wixproj" />
<ProjectReference Include="..\PackageBv1_0_1\PackageBv1_0_1.wixproj" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- 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. -->
<Project Sdk="WixToolset.Sdk">
<PropertyGroup>
<OutputType>PatchCreation</OutputType>
<OutputType>Patch</OutputType>
<TargetExt>.msp</TargetExt>
<SuppressSpecificWarnings>1079</SuppressSpecificWarnings>
</PropertyGroup>
Expand All @@ -11,4 +11,4 @@
<ProjectReference Include="..\PackageBv1\PackageBv1.wixproj" />
<ProjectReference Include="..\PackageBv1_0_1\PackageBv1_0_1.wixproj" />
</ItemGroup>
</Project>
</Project>
1 change: 1 addition & 0 deletions src/wix/WixToolset.Core.Burn/BurnBackendFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,22 @@ public bool TryCreateBackend(string outputType, string outputFile, out IBackend
switch (outputType?.ToLowerInvariant())
{
case "module":
case "msm":
case ".msm":
backend = new MsmBackend();
return true;

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;
Expand Down
2 changes: 2 additions & 0 deletions src/wix/WixToolset.Core/BindContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
8 changes: 4 additions & 4 deletions src/wix/WixToolset.Core/Binder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,18 @@ private IBindResult BackendBind(IBindContext context)

var backendFactories = extensionManager.GetServices<IBackendFactory>();

var entrySection = context.IntermediateRepresentation.Sections.First();

foreach (var factory in backendFactories)
{
if (factory.TryCreateBackend(entrySection.Type.ToString(), context.OutputPath, out var backend))
if (factory.TryCreateBackend(context.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<IMessaging>();

messaging.Write(CoreErrors.BackendNotFound(context.OutputType, context.OutputPath));

return null;
}
Expand Down
8 changes: 8 additions & 0 deletions src/wix/WixToolset.Core/CommandLine/BuildCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,18 @@ private void BindPhase(Intermediate output, IReadOnlyCollection<Localization> lo
context.IntermediateFolder = this.IntermediateFolder;
context.IntermediateRepresentation = resolveResult.IntermediateRepresentation;
context.OutputPath = this.OutputPath;
context.OutputType = this.commandLine.OutputType;
context.PdbType = inputsOutputs.PdbType;
context.PdbPath = inputsOutputs.PdbPath;
context.CancellationToken = cancellationToken;

if (String.IsNullOrEmpty(context.OutputType))
{
var entrySection = context.IntermediateRepresentation.Sections.First();

context.OutputType = entrySection.Type.ToString();
}

var binder = this.ServiceProvider.GetService<IBinder>();
bindResult = binder.Bind(context);
}
Expand Down
6 changes: 6 additions & 0 deletions src/wix/WixToolset.Core/CoreErrors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -37,6 +42,7 @@ public enum Ids
UnableToDeleteFile = 7011,
UnableToMoveFile = 7012,
UnableToOpenFile = 7013,
BackendNotFound = 7014,
} // last available is 7099. 7100 is WindowsInstallerBackendWarnings.
}
}
33 changes: 33 additions & 0 deletions src/wix/test/WixToolsetTest.CoreIntegration/BadInputFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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: <folder>\test.pkg. Specify a different output type or output file extension.",
}, messages.Select(s => s.Replace(intermediateFolder, "<folder>")).ToArray());

Assert.Equal(7014, result.ExitCode);
}
}

[Fact]
public void GuardsAgainstVariousBundleValuesFromLoc()
{
Expand Down

0 comments on commit f18d7e6

Please sign in to comment.