From c6e2213e818b869c44c1af7355fc06f45ebf1a1f Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Thu, 11 Feb 2021 13:46:45 -0800 Subject: Replace Win64 attribute with Bitness attribute Closes wixtoolset/#4707 --- .../Decompile/Decompiler.cs | 12 +-- src/WixToolset.Core/CompileContext.cs | 2 + src/WixToolset.Core/Compiler.cs | 105 ++++++++++++--------- src/WixToolset.Core/Compiler_Bundle.cs | 25 ++++- .../ApprovedExeFixture.cs | 64 +++++++++++++ .../MsiQueryFixture.cs | 34 +++++++ .../DecompiledNestedDirSearchUnderRegSearch.wxs | 12 +-- .../TestData/AppSearch/RegistrySearch64.wxs | 12 +++ .../TestData/BundleWithApprovedExe/Bundle.wxs | 5 + .../TestData/BundleWithApprovedExe/Bundle64.wxs | 5 + .../TestData/Class/DecompiledOldClassTableDef.wxs | 4 +- .../TestData/CustomTable/CustomTable-Expected.wxs | 4 +- .../TestData/DecompileNullComponent/Expected.wxs | 4 +- .../DecompileSingleFileCompressed/Expected.wxs | 4 +- .../DecompileSingleFileCompressed64/Expected.wxs | 4 +- .../SequenceTables/DecompiledSequenceTables.wxs | 4 +- .../TestData/Shortcut/DecompiledShortcuts.wxs | 4 +- 17 files changed, 228 insertions(+), 76 deletions(-) create mode 100644 src/test/WixToolsetTest.CoreIntegration/ApprovedExeFixture.cs create mode 100644 src/test/WixToolsetTest.CoreIntegration/TestData/AppSearch/RegistrySearch64.wxs create mode 100644 src/test/WixToolsetTest.CoreIntegration/TestData/BundleWithApprovedExe/Bundle.wxs create mode 100644 src/test/WixToolsetTest.CoreIntegration/TestData/BundleWithApprovedExe/Bundle64.wxs diff --git a/src/WixToolset.Core.WindowsInstaller/Decompile/Decompiler.cs b/src/WixToolset.Core.WindowsInstaller/Decompile/Decompiler.cs index 29e15c91..c62e8153 100644 --- a/src/WixToolset.Core.WindowsInstaller/Decompile/Decompiler.cs +++ b/src/WixToolset.Core.WindowsInstaller/Decompile/Decompiler.cs @@ -3950,12 +3950,12 @@ namespace WixToolset.Core.WindowsInstaller if (WindowsInstallerConstants.MsidbCustomActionType64BitScript == (type & WindowsInstallerConstants.MsidbCustomActionType64BitScript)) { - xCustomAction.SetAttributeValue("Win64", "yes"); + xCustomAction.SetAttributeValue("Bitness", "always64"); } else if (WindowsInstallerConstants.MsidbCustomActionTypeVBScript == (type & WindowsInstallerConstants.MsidbCustomActionTypeVBScript) || WindowsInstallerConstants.MsidbCustomActionTypeJScript == (type & WindowsInstallerConstants.MsidbCustomActionTypeJScript)) { - xCustomAction.SetAttributeValue("Win64", "no"); + xCustomAction.SetAttributeValue("Bitness", "always32"); } switch (type & WindowsInstallerConstants.MsidbCustomActionTypeExecuteBits) @@ -4191,11 +4191,11 @@ namespace WixToolset.Core.WindowsInstaller if (WindowsInstallerConstants.MsidbComponentAttributes64bit == (attributes & WindowsInstallerConstants.MsidbComponentAttributes64bit)) { - xComponent.SetAttributeValue("Win64", "yes"); + xComponent.SetAttributeValue("Bitness", "always64"); } else { - xComponent.SetAttributeValue("Win64", "no"); + xComponent.SetAttributeValue("Bitness", "always32"); } if (WindowsInstallerConstants.MsidbComponentAttributesDisableRegistryReflection == (attributes & WindowsInstallerConstants.MsidbComponentAttributesDisableRegistryReflection)) @@ -6479,12 +6479,12 @@ namespace WixToolset.Core.WindowsInstaller if (WindowsInstallerConstants.MsidbLocatorType64bit == (type & WindowsInstallerConstants.MsidbLocatorType64bit)) { - xRegistrySearch.SetAttributeValue("Win64", "yes"); + xRegistrySearch.SetAttributeValue("Bitness", "always64"); type &= ~WindowsInstallerConstants.MsidbLocatorType64bit; } else { - xRegistrySearch.SetAttributeValue("Win64", "no"); + xRegistrySearch.SetAttributeValue("Bitness", "always32"); } switch (type) diff --git a/src/WixToolset.Core/CompileContext.cs b/src/WixToolset.Core/CompileContext.cs index 44da6c8a..e781b692 100644 --- a/src/WixToolset.Core/CompileContext.cs +++ b/src/WixToolset.Core/CompileContext.cs @@ -25,6 +25,8 @@ namespace WixToolset.Core public Platform Platform { get; set; } + public bool IsCurrentPlatform64Bit => this.Platform == Platform.ARM64 || this.Platform == Platform.X64; + public XDocument Source { get; set; } public CancellationToken CancellationToken { get; set; } diff --git a/src/WixToolset.Core/Compiler.cs b/src/WixToolset.Core/Compiler.cs index 5267a232..85261cce 100644 --- a/src/WixToolset.Core/Compiler.cs +++ b/src/WixToolset.Core/Compiler.cs @@ -59,13 +59,9 @@ namespace WixToolset.Core internal Compiler(IWixToolsetServiceProvider serviceProvider) { - this.ServiceProvider = serviceProvider; - this.Messaging = serviceProvider.GetService(); } - private IWixToolsetServiceProvider ServiceProvider { get; } - public IMessaging Messaging { get; } private ICompileContext Context { get; set; } @@ -78,12 +74,6 @@ namespace WixToolset.Core /// The platform which the compiler will use when defaulting 64-bit attributes and elements. public Platform CurrentPlatform => this.Context.Platform; - /// - /// Gets or sets the platform which the compiler will use when defaulting 64-bit attributes and elements. - /// - /// The platform which the compiler will use when defaulting 64-bit attributes and elements. - public bool IsCurrentPlatform64Bit => this.Context.Platform == Platform.ARM64 || this.Context.Platform == Platform.X64; - /// /// Gets or sets the option to show pedantic messages. /// @@ -1724,14 +1714,12 @@ namespace WixToolset.Core private string ParseRegistrySearchElement(XElement node) { var sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node); - var explicitWin64 = false; Identifier id = null; string key = null; string name = null; - string signature = null; RegistryRootType? root = null; RegLocatorType? type = null; - var search64bit = false; + var search64bit = this.Context.IsCurrentPlatform64Bit; foreach (var attrib in node.Attributes()) { @@ -1742,6 +1730,24 @@ namespace WixToolset.Core case "Id": id = this.Core.GetAttributeIdentifier(sourceLineNumbers, attrib); break; + case "Bitness": + var bitnessValue = this.Core.GetAttributeValue(sourceLineNumbers, attrib); + switch (bitnessValue) + { + case "always32": + search64bit = false; + break; + case "always64": + search64bit = true; + break; + case "default": + case "": + break; + default: + this.Core.Write(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, node.Name.LocalName, attrib.Name.LocalName, bitnessValue, "default", "always32", "always64")); + break; + } + break; case "Key": key = this.Core.GetAttributeValue(sourceLineNumbers, attrib); break; @@ -1771,10 +1777,6 @@ namespace WixToolset.Core break; } break; - case "Win64": - explicitWin64 = true; - search64bit = YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib); - break; default: this.Core.UnexpectedAttribute(node, attrib); break; @@ -1786,11 +1788,6 @@ namespace WixToolset.Core } } - if (!explicitWin64 && this.IsCurrentPlatform64Bit) - { - search64bit = true; - } - if (null == id) { id = this.Core.CreateIdentifier("reg", root.ToString(), key, name, type.ToString(), search64bit.ToString()); @@ -1811,7 +1808,7 @@ namespace WixToolset.Core this.Core.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Type")); } - signature = id.Id; + var signature = id.Id; var oneChild = false; foreach (var child in node.Elements()) { @@ -2125,8 +2122,7 @@ namespace WixToolset.Core var sharedDllRefCount = false; var transitive = false; var uninstallWhenSuperseded = false; - var explicitWin64 = false; - var win64 = false; + var win64 = this.Context.IsCurrentPlatform64Bit; var multiInstance = false; var symbols = new List(); @@ -2141,6 +2137,24 @@ namespace WixToolset.Core case "Id": id = this.Core.GetAttributeIdentifier(sourceLineNumbers, attrib); break; + case "Bitness": + var bitnessValue = this.Core.GetAttributeValue(sourceLineNumbers, attrib); + switch (bitnessValue) + { + case "always32": + win64 = false; + break; + case "always64": + win64 = true; + break; + case "default": + case "": + break; + default: + this.Core.Write(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, node.Name.LocalName, attrib.Name.LocalName, bitnessValue, "default", "always32", "always64")); + break; + } + break; case "ComPlusFlags": comPlusBits = this.Core.GetAttributeIntegerValue(sourceLineNumbers, attrib, 0, Int16.MaxValue); break; @@ -2240,15 +2254,6 @@ namespace WixToolset.Core // bits |= MsiInterop.MsidbComponentAttributesUninstallOnSupersedence; //} break; - case "Win64": - explicitWin64 = true; - win64 = YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib); - //if (YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib)) - //{ - // bits |= MsiInterop.MsidbComponentAttributes64bit; - // win64 = true; - //} - break; default: this.Core.UnexpectedAttribute(node, attrib); break; @@ -2260,12 +2265,6 @@ namespace WixToolset.Core } } - if (!explicitWin64 && this.IsCurrentPlatform64Bit) - { - //bits |= MsiInterop.MsidbComponentAttributes64bit; - win64 = true; - } - if (id == null) { // Placeholder id for defaulting Component/@Id to keypath id. @@ -3157,6 +3156,26 @@ namespace WixToolset.Core sourceType = CustomActionSourceType.Binary; this.Core.CreateSimpleReference(sourceLineNumbers, SymbolDefinitions.Binary, source); // add a reference to the appropriate Binary break; + case "Bitness": + var bitnessValue = this.Core.GetAttributeValue(sourceLineNumbers, attrib); + switch (bitnessValue) + { + case "always32": + explicitWin64 = true; + win64 = false; + break; + case "always64": + explicitWin64 = true; + win64 = true; + break; + case "default": + case "": + break; + default: + this.Core.Write(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, node.Name.LocalName, attrib.Name.LocalName, bitnessValue, "default", "always32", "always64")); + break; + } + break; case "Directory": if (null != source) { @@ -3345,10 +3364,6 @@ namespace WixToolset.Core target = this.Core.GetAttributeValue(sourceLineNumbers, attrib, EmptyRule.CanBeEmpty); // one of the few cases where an empty string value is valid targetType = CustomActionTargetType.VBScript; break; - case "Win64": - explicitWin64 = true; - win64 = YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib); - break; default: this.Core.UnexpectedAttribute(node, attrib); break; @@ -3366,7 +3381,7 @@ namespace WixToolset.Core id = Identifier.Invalid; } - if (!explicitWin64 && this.IsCurrentPlatform64Bit && (CustomActionTargetType.VBScript == targetType || CustomActionTargetType.JScript == targetType)) + if (!explicitWin64 && this.Context.IsCurrentPlatform64Bit && (CustomActionTargetType.VBScript == targetType || CustomActionTargetType.JScript == targetType)) { win64 = true; } diff --git a/src/WixToolset.Core/Compiler_Bundle.cs b/src/WixToolset.Core/Compiler_Bundle.cs index 944f089e..7a386de7 100644 --- a/src/WixToolset.Core/Compiler_Bundle.cs +++ b/src/WixToolset.Core/Compiler_Bundle.cs @@ -33,7 +33,7 @@ namespace WixToolset.Core Identifier id = null; string key = null; string valueName = null; - var win64 = YesNoType.NotSet; + var win64 = this.Context.IsCurrentPlatform64Bit; foreach (var attrib in node.Attributes()) { @@ -44,15 +44,30 @@ namespace WixToolset.Core case "Id": id = this.Core.GetAttributeIdentifier(sourceLineNumbers, attrib); break; + case "Bitness": + var bitnessValue = this.Core.GetAttributeValue(sourceLineNumbers, attrib); + switch (bitnessValue) + { + case "always32": + win64 = false; + break; + case "always64": + win64 = true; + break; + case "default": + case "": + break; + default: + this.Core.Write(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, node.Name.LocalName, attrib.Name.LocalName, bitnessValue, "default", "always32", "always64")); + break; + } + break; case "Key": key = this.Core.GetAttributeValue(sourceLineNumbers, attrib); break; case "Value": valueName = this.Core.GetAttributeValue(sourceLineNumbers, attrib); break; - case "Win64": - win64 = this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib); - break; default: this.Core.UnexpectedAttribute(node, attrib); break; @@ -76,7 +91,7 @@ namespace WixToolset.Core var attributes = WixApprovedExeForElevationAttributes.None; - if (win64 == YesNoType.Yes) + if (win64) { attributes |= WixApprovedExeForElevationAttributes.Win64; } diff --git a/src/test/WixToolsetTest.CoreIntegration/ApprovedExeFixture.cs b/src/test/WixToolsetTest.CoreIntegration/ApprovedExeFixture.cs new file mode 100644 index 00000000..47b47ef5 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/ApprovedExeFixture.cs @@ -0,0 +1,64 @@ +// 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. + +namespace WixToolsetTest.CoreIntegration +{ + using System.IO; + using WixBuildTools.TestSupport; + using WixToolset.Core.TestPackage; + using Xunit; + + public class ApprovedExeFixture + { + [Fact] + public void CanBuildWithApprovedExe() + { + var folder = TestData.Get(@"TestData"); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + var intermediateFolder = Path.Combine(baseFolder, "obj"); + var exePath = Path.Combine(baseFolder, @"bin\test.exe"); + + var result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "BundleWithApprovedExe", "Bundle.wxs"), + "-bindpath", Path.Combine(folder, "SimpleBundle", "data"), + "-bindpath", Path.Combine(folder, ".Data"), + "-intermediateFolder", intermediateFolder, + "-o", exePath, + }); + + Assert.NotEqual(0, result.ExitCode); + Assert.False(File.Exists(exePath)); + } + } + + [Fact] + public void CanBuildWithApprovedExe64() + { + var folder = TestData.Get(@"TestData"); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + var intermediateFolder = Path.Combine(baseFolder, "obj"); + var exePath = Path.Combine(baseFolder, @"bin\test.exe"); + + var result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "BundleWithApprovedExe", "Bundle64.wxs"), + "-bindpath", Path.Combine(folder, "SimpleBundle", "data"), + "-bindpath", Path.Combine(folder, ".Data"), + "-intermediateFolder", intermediateFolder, + "-o", exePath, + }); + + Assert.NotEqual(0, result.ExitCode); + Assert.False(File.Exists(exePath)); + } + } + } +} diff --git a/src/test/WixToolsetTest.CoreIntegration/MsiQueryFixture.cs b/src/test/WixToolsetTest.CoreIntegration/MsiQueryFixture.cs index 00738965..8c3487f0 100644 --- a/src/test/WixToolsetTest.CoreIntegration/MsiQueryFixture.cs +++ b/src/test/WixToolsetTest.CoreIntegration/MsiQueryFixture.cs @@ -185,6 +185,40 @@ namespace WixToolsetTest.CoreIntegration } } + [Fact] + public void PopulatesAppSearchTablesFromRegistrySearch64() + { + var folder = TestData.Get(@"TestData"); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + var intermediateFolder = Path.Combine(baseFolder, "obj"); + var msiPath = Path.Combine(baseFolder, @"bin\test.msi"); + + var result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "AppSearch", "RegistrySearch64.wxs"), + Path.Combine(folder, "ProductWithComponentGroupRef", "MinimalComponentGroup.wxs"), + Path.Combine(folder, "ProductWithComponentGroupRef", "Product.wxs"), + "-bindpath", Path.Combine(folder, "SingleFile", "data"), + "-intermediateFolder", intermediateFolder, + "-o", msiPath + }); + + result.AssertSuccess(); + + Assert.True(File.Exists(msiPath)); + var results = Query.QueryDatabase(msiPath, new[] { "AppSearch", "RegLocator" }); + WixAssert.CompareLineByLine(new[] + { + "AppSearch:SAMPLEREGFOUND\tSampleRegSearch", + "RegLocator:SampleRegSearch\t2\tSampleReg\t\t18", + }, results); + } + } + [Fact] public void PopulatesClassTablesWhenIconIndexIsZero() { diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/AppSearch/DecompiledNestedDirSearchUnderRegSearch.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/AppSearch/DecompiledNestedDirSearchUnderRegSearch.wxs index 8d1e5de2..b67abbde 100644 --- a/src/test/WixToolsetTest.CoreIntegration/TestData/AppSearch/DecompiledNestedDirSearchUnderRegSearch.wxs +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/AppSearch/DecompiledNestedDirSearchUnderRegSearch.wxs @@ -1,9 +1,9 @@ - + - + @@ -15,10 +15,10 @@ - + - + @@ -29,12 +29,12 @@ - + - + diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/AppSearch/RegistrySearch64.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/AppSearch/RegistrySearch64.wxs new file mode 100644 index 00000000..8be5abb2 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/AppSearch/RegistrySearch64.wxs @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/BundleWithApprovedExe/Bundle.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/BundleWithApprovedExe/Bundle.wxs new file mode 100644 index 00000000..78e754c1 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/BundleWithApprovedExe/Bundle.wxs @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/BundleWithApprovedExe/Bundle64.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/BundleWithApprovedExe/Bundle64.wxs new file mode 100644 index 00000000..18cdfd32 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/BundleWithApprovedExe/Bundle64.wxs @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/Class/DecompiledOldClassTableDef.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/Class/DecompiledOldClassTableDef.wxs index 08ced0c2..43af2ffe 100644 --- a/src/test/WixToolsetTest.CoreIntegration/TestData/Class/DecompiledOldClassTableDef.wxs +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/Class/DecompiledOldClassTableDef.wxs @@ -1,9 +1,9 @@ - + - + diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/CustomTable/CustomTable-Expected.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/CustomTable/CustomTable-Expected.wxs index f87c9387..935cc8b3 100644 --- a/src/test/WixToolsetTest.CoreIntegration/TestData/CustomTable/CustomTable-Expected.wxs +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/CustomTable/CustomTable-Expected.wxs @@ -1,4 +1,4 @@ - + @@ -16,7 +16,7 @@ - + diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/DecompileNullComponent/Expected.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/DecompileNullComponent/Expected.wxs index 89592150..050adbd5 100644 --- a/src/test/WixToolsetTest.CoreIntegration/TestData/DecompileNullComponent/Expected.wxs +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/DecompileNullComponent/Expected.wxs @@ -1,9 +1,9 @@ - + - + diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/DecompileSingleFileCompressed/Expected.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/DecompileSingleFileCompressed/Expected.wxs index e2557fe1..e1fb426e 100644 --- a/src/test/WixToolsetTest.CoreIntegration/TestData/DecompileSingleFileCompressed/Expected.wxs +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/DecompileSingleFileCompressed/Expected.wxs @@ -1,9 +1,9 @@ - + - + diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/DecompileSingleFileCompressed64/Expected.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/DecompileSingleFileCompressed64/Expected.wxs index 38ce54b8..fed69a1e 100644 --- a/src/test/WixToolsetTest.CoreIntegration/TestData/DecompileSingleFileCompressed64/Expected.wxs +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/DecompileSingleFileCompressed64/Expected.wxs @@ -1,9 +1,9 @@ - + - + diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/SequenceTables/DecompiledSequenceTables.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/SequenceTables/DecompiledSequenceTables.wxs index 08af1950..6924f37a 100644 --- a/src/test/WixToolsetTest.CoreIntegration/TestData/SequenceTables/DecompiledSequenceTables.wxs +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/SequenceTables/DecompiledSequenceTables.wxs @@ -1,10 +1,10 @@ - + - + diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/Shortcut/DecompiledShortcuts.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/Shortcut/DecompiledShortcuts.wxs index 1b602588..13412b50 100644 --- a/src/test/WixToolsetTest.CoreIntegration/TestData/Shortcut/DecompiledShortcuts.wxs +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/Shortcut/DecompiledShortcuts.wxs @@ -1,9 +1,9 @@ - + - + -- cgit v1.2.3-55-g6feb