Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly process build -outputType switch #454

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
15 changes: 12 additions & 3 deletions src/wix/WixToolset.Core/Binder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,27 @@ private IBindResult BackendBind(IBindContext context)

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

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<IMessaging>();

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

return null;
}
Expand Down
5 changes: 5 additions & 0 deletions src/wix/WixToolset.Core/CommandLine/BuildCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ private void BindPhase(Intermediate output, IReadOnlyCollection<Localization> lo
context.PdbPath = inputsOutputs.PdbPath;
context.CancellationToken = cancellationToken;

if (context is BindContext bindContext)
{
bindContext.OutputType = this.commandLine.OutputType;
}

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