From 6bd9fb04a9a8c1805a3e909583cca85c54dea7e4 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Thu, 25 Aug 2022 15:05:40 -0500 Subject: Fix building `ExePackage/@ExitCode` elements. --- .../Symbols/WixBundlePackageExitCodeSymbol.cs | 2 +- .../Bundles/CreateBurnManifestCommand.cs | 2 +- src/wix/WixToolset.Core/Common.cs | 27 +++++++++++ src/wix/WixToolset.Core/CompilerCore.cs | 11 +++++ src/wix/WixToolset.Core/Compiler_Bundle.cs | 4 +- .../ExePackageFixture.cs | 54 ++++++++++++++++++++++ .../TestData/ExePackage/CustomExitCodes.wxs | 25 ++++++++++ 7 files changed, 121 insertions(+), 4 deletions(-) create mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/TestData/ExePackage/CustomExitCodes.wxs diff --git a/src/api/wix/WixToolset.Data/Symbols/WixBundlePackageExitCodeSymbol.cs b/src/api/wix/WixToolset.Data/Symbols/WixBundlePackageExitCodeSymbol.cs index d77d9d58..f025a493 100644 --- a/src/api/wix/WixToolset.Data/Symbols/WixBundlePackageExitCodeSymbol.cs +++ b/src/api/wix/WixToolset.Data/Symbols/WixBundlePackageExitCodeSymbol.cs @@ -32,7 +32,7 @@ namespace WixToolset.Data.Symbols public enum ExitCodeBehaviorType { NotSet = -1, - Success, + Success = 1, Error, ScheduleReboot, ForceReboot, diff --git a/src/wix/WixToolset.Core.Burn/Bundles/CreateBurnManifestCommand.cs b/src/wix/WixToolset.Core.Burn/Bundles/CreateBurnManifestCommand.cs index dda79aa1..7273918b 100644 --- a/src/wix/WixToolset.Core.Burn/Bundles/CreateBurnManifestCommand.cs +++ b/src/wix/WixToolset.Core.Burn/Bundles/CreateBurnManifestCommand.cs @@ -532,7 +532,7 @@ namespace WixToolset.Core.Burn.Bundles if (exitCode.Code.HasValue) { - writer.WriteAttributeString("Code", unchecked((uint)exitCode.Code).ToString(CultureInfo.InvariantCulture)); + writer.WriteAttributeString("Code", exitCode.Code.Value.ToString(CultureInfo.InvariantCulture)); } else { diff --git a/src/wix/WixToolset.Core/Common.cs b/src/wix/WixToolset.Core/Common.cs index 89cfe515..c838463d 100644 --- a/src/wix/WixToolset.Core/Common.cs +++ b/src/wix/WixToolset.Core/Common.cs @@ -680,6 +680,33 @@ namespace WixToolset.Core return integer; } + /// + /// Get an integer attribute value and displays an error for an illegal integer value. + /// + /// + /// Source line information about the owner element. + /// The attribute containing the value to get. + /// The attribute's integer value or null if an error occurred during conversion. + public static int? GetAttributeRawIntegerValue(IMessaging messaging, SourceLineNumber sourceLineNumbers, XAttribute attribute) + { + var value = Common.GetAttributeValue(messaging, sourceLineNumbers, attribute, EmptyRule.MustHaveNonWhitespaceCharacters); + int? integer = null; + + if (0 < value.Length) + { + if (Int32.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture.NumberFormat, out var integerValue)) + { + integer = integerValue; + } + else + { + messaging.Write(ErrorMessages.IllegalIntegerValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); + } + } + + return integer; + } + /// /// Gets a yes/no value and displays an error for an illegal yes/no value. /// diff --git a/src/wix/WixToolset.Core/CompilerCore.cs b/src/wix/WixToolset.Core/CompilerCore.cs index cbb8f1f0..c03305f0 100644 --- a/src/wix/WixToolset.Core/CompilerCore.cs +++ b/src/wix/WixToolset.Core/CompilerCore.cs @@ -500,6 +500,17 @@ namespace WixToolset.Core return this.parseHelper.GetAttributeIntegerValue(sourceLineNumbers, attribute, minimum, maximum); } + /// + /// Get an integer attribute value and displays an error for an illegal integer value. + /// + /// Source line information about the owner element. + /// The attribute containing the value to get. + /// The attribute's integer value or null if an error occurred during conversion. + public int? GetAttributeRawIntegerValue(SourceLineNumber sourceLineNumbers, XAttribute attribute) + { + return Common.GetAttributeRawIntegerValue(this.messaging, sourceLineNumbers, attribute); + } + /// /// Get a long integral attribute value and displays an error for an illegal long value. /// diff --git a/src/wix/WixToolset.Core/Compiler_Bundle.cs b/src/wix/WixToolset.Core/Compiler_Bundle.cs index 47eb646b..0a1e416f 100644 --- a/src/wix/WixToolset.Core/Compiler_Bundle.cs +++ b/src/wix/WixToolset.Core/Compiler_Bundle.cs @@ -1609,7 +1609,7 @@ namespace WixToolset.Core private void ParseExitCodeElement(XElement node, string packageId) { var sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node); - var value = CompilerConstants.IntegerNotSet; + int? value = null; var behavior = ExitCodeBehaviorType.NotSet; foreach (var attrib in node.Attributes()) @@ -1619,7 +1619,7 @@ namespace WixToolset.Core switch (attrib.Name.LocalName) { case "Value": - value = this.Core.GetAttributeIntegerValue(sourceLineNumbers, attrib, Int32.MinValue + 2, Int32.MaxValue); + value = this.Core.GetAttributeRawIntegerValue(sourceLineNumbers, attrib); break; case "Behavior": var behaviorString = this.Core.GetAttributeValue(sourceLineNumbers, attrib); diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/ExePackageFixture.cs b/src/wix/test/WixToolsetTest.CoreIntegration/ExePackageFixture.cs index 882a7861..a3ca2917 100644 --- a/src/wix/test/WixToolsetTest.CoreIntegration/ExePackageFixture.cs +++ b/src/wix/test/WixToolsetTest.CoreIntegration/ExePackageFixture.cs @@ -54,6 +54,60 @@ namespace WixToolsetTest.CoreIntegration } } + [Fact] + public void CanBuildWithCustomExitCodes() + { + var folder = TestData.Get(@"TestData"); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + var intermediateFolder = Path.Combine(baseFolder, "obj"); + var binFolder = Path.Combine(baseFolder, "bin"); + var bundlePath = Path.Combine(binFolder, "test.exe"); + var baFolderPath = Path.Combine(baseFolder, "ba"); + var extractFolderPath = Path.Combine(baseFolder, "extract"); + + var result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "ExePackage", "CustomExitCodes.wxs"), + Path.Combine(folder, "BundleWithPackageGroupRef", "Bundle.wxs"), + "-bindpath", Path.Combine(folder, "SimpleBundle", "data"), + "-bindpath", Path.Combine(folder, ".Data"), + "-intermediateFolder", intermediateFolder, + "-o", bundlePath, + }); + + result.AssertSuccess(); + + Assert.True(File.Exists(bundlePath)); + + var extractResult = BundleExtractor.ExtractBAContainer(null, bundlePath, baFolderPath, extractFolderPath); + extractResult.AssertSuccess(); + + var exePackages = extractResult.GetManifestTestXmlLines("/burn:BurnManifest/burn:Chain/burn:ExePackage"); + WixAssert.CompareLineByLine(new string[] + { + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "", + }, exePackages); + } + } + [Fact] public void WarningWhenInvalidArpEntryVersion() { diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/TestData/ExePackage/CustomExitCodes.wxs b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/ExePackage/CustomExitCodes.wxs new file mode 100644 index 00000000..9cbc9919 --- /dev/null +++ b/src/wix/test/WixToolsetTest.CoreIntegration/TestData/ExePackage/CustomExitCodes.wxs @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3-55-g6feb