From 7bdd5e9159b298e0411afa689a06c44e36e293cd Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Mon, 3 May 2021 16:05:08 -0700 Subject: Move NetFx.wixext into ext --- src/ext/NetFx/wixext/NetFxCompiler.cs | 163 +++++++++++++++++++++ src/ext/NetFx/wixext/NetFxDecompiler.cs | 139 ++++++++++++++++++ src/ext/NetFx/wixext/NetFxExtensionData.cs | 25 ++++ src/ext/NetFx/wixext/NetfxExtensionFactory.cs | 18 +++ src/ext/NetFx/wixext/NetfxTableDefinitions.cs | 30 ++++ .../NetfxWindowsInstallerBackendExtension.cs | 13 ++ .../NetFx/wixext/Symbols/NetFxNativeImageSymbol.cs | 58 ++++++++ .../NetFx/wixext/Symbols/NetfxSymbolDefinitions.cs | 26 ++++ .../NetFx/wixext/WixToolset.Netfx.wixext.csproj | 31 ++++ .../NetFx/wixext/WixToolset.Netfx.wixext.nuspec | 25 ++++ .../NetFx/wixext/WixToolset.Netfx.wixext.targets | 11 ++ .../WixToolset.Netfx.wixext.v3.ncrunchproject | 7 + 12 files changed, 546 insertions(+) create mode 100644 src/ext/NetFx/wixext/NetFxCompiler.cs create mode 100644 src/ext/NetFx/wixext/NetFxDecompiler.cs create mode 100644 src/ext/NetFx/wixext/NetFxExtensionData.cs create mode 100644 src/ext/NetFx/wixext/NetfxExtensionFactory.cs create mode 100644 src/ext/NetFx/wixext/NetfxTableDefinitions.cs create mode 100644 src/ext/NetFx/wixext/NetfxWindowsInstallerBackendExtension.cs create mode 100644 src/ext/NetFx/wixext/Symbols/NetFxNativeImageSymbol.cs create mode 100644 src/ext/NetFx/wixext/Symbols/NetfxSymbolDefinitions.cs create mode 100644 src/ext/NetFx/wixext/WixToolset.Netfx.wixext.csproj create mode 100644 src/ext/NetFx/wixext/WixToolset.Netfx.wixext.nuspec create mode 100644 src/ext/NetFx/wixext/WixToolset.Netfx.wixext.targets create mode 100644 src/ext/NetFx/wixext/WixToolset.Netfx.wixext.v3.ncrunchproject (limited to 'src/ext/NetFx/wixext') diff --git a/src/ext/NetFx/wixext/NetFxCompiler.cs b/src/ext/NetFx/wixext/NetFxCompiler.cs new file mode 100644 index 00000000..90aa8bcb --- /dev/null +++ b/src/ext/NetFx/wixext/NetFxCompiler.cs @@ -0,0 +1,163 @@ +// 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 WixToolset.Netfx +{ + using System; + using System.Collections.Generic; + using System.Xml.Linq; + using WixToolset.Data; + using WixToolset.Extensibility; + using WixToolset.Extensibility.Data; + using WixToolset.Netfx.Symbols; + + /// + /// The compiler for the WiX Toolset .NET Framework Extension. + /// + public sealed class NetfxCompiler : BaseCompilerExtension + { + public override XNamespace Namespace => "http://wixtoolset.org/schemas/v4/wxs/netfx"; + + /// + /// Processes an element for the Compiler. + /// + /// Parent element of element to process. + /// Element to process. + /// Extra information about the context in which this element is being parsed. + public override void ParseElement(Intermediate intermediate, IntermediateSection section, XElement parentElement, XElement element, IDictionary context) + { + switch (parentElement.Name.LocalName) + { + case "File": + string fileId = context["FileId"]; + + switch (element.Name.LocalName) + { + case "NativeImage": + this.ParseNativeImageElement(intermediate, section, element, fileId); + break; + default: + this.ParseHelper.UnexpectedElement(parentElement, element); + break; + } + break; + default: + this.ParseHelper.UnexpectedElement(parentElement, element); + break; + } + } + + /// + /// Parses a NativeImage element. + /// + /// The element to parse. + /// The file identifier of the parent element. + private void ParseNativeImageElement(Intermediate intermediate, IntermediateSection section, XElement element, string fileId) + { + var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element); + Identifier id = null; + string appBaseDirectory = null; + string assemblyApplication = null; + int attributes = 0x8; // 32bit is on by default + int priority = 3; + + foreach (var attrib in element.Attributes()) + { + if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace) + { + switch (attrib.Name.LocalName) + { + case "Id": + id = this.ParseHelper.GetAttributeIdentifier(sourceLineNumbers, attrib); + break; + case "AppBaseDirectory": + appBaseDirectory = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); + + // See if a formatted value is specified. + if (-1 == appBaseDirectory.IndexOf("[", StringComparison.Ordinal)) + { + this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, SymbolDefinitions.Directory, appBaseDirectory); + } + break; + case "AssemblyApplication": + assemblyApplication = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); + + // See if a formatted value is specified. + if (-1 == assemblyApplication.IndexOf("[", StringComparison.Ordinal)) + { + this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, SymbolDefinitions.File, assemblyApplication); + } + break; + case "Debug": + if (YesNoType.Yes == this.ParseHelper.GetAttributeYesNoValue(sourceLineNumbers, attrib)) + { + attributes |= 0x1; + } + break; + case "Dependencies": + if (YesNoType.No == this.ParseHelper.GetAttributeYesNoValue(sourceLineNumbers, attrib)) + { + attributes |= 0x2; + } + break; + case "Platform": + string platformValue = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); + if (0 < platformValue.Length) + { + switch (platformValue) + { + case "32bit": + // 0x8 is already on by default + break; + case "64bit": + attributes &= ~0x8; + attributes |= 0x10; + break; + case "all": + attributes |= 0x10; + break; + } + } + break; + case "Priority": + priority = this.ParseHelper.GetAttributeIntegerValue(sourceLineNumbers, attrib, 0, 3); + break; + case "Profile": + if (YesNoType.Yes == this.ParseHelper.GetAttributeYesNoValue(sourceLineNumbers, attrib)) + { + attributes |= 0x4; + } + break; + default: + this.ParseHelper.UnexpectedAttribute(element, attrib); + break; + } + } + else + { + this.ParseHelper.ParseExtensionAttribute(this.Context.Extensions, intermediate, section, element, attrib); + } + } + + if (null == id) + { + id = this.ParseHelper.CreateIdentifier("nni", fileId); + } + + this.ParseHelper.ParseForExtensionElements(this.Context.Extensions, intermediate, section, element); + + this.ParseHelper.CreateCustomActionReference(sourceLineNumbers, section, "Wix4NetFxScheduleNativeImage", this.Context.Platform, CustomActionPlatforms.ARM64 | CustomActionPlatforms.X64 | CustomActionPlatforms.X86); + + if (!this.Messaging.EncounteredError) + { + section.AddSymbol(new NetFxNativeImageSymbol(sourceLineNumbers, id) + { + FileRef = fileId, + Priority = priority, + Attributes = attributes, + ApplicationFileRef = assemblyApplication, + ApplicationBaseDirectoryRef = appBaseDirectory, + }); + } + } + } +} diff --git a/src/ext/NetFx/wixext/NetFxDecompiler.cs b/src/ext/NetFx/wixext/NetFxDecompiler.cs new file mode 100644 index 00000000..e30905d1 --- /dev/null +++ b/src/ext/NetFx/wixext/NetFxDecompiler.cs @@ -0,0 +1,139 @@ +// 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 WixToolset.Extensions +{ +#if TODO_CONSIDER_DECOMPILER + using System; + using System.Collections; + using System.Diagnostics; + using System.Globalization; + using WixToolset.Data; + using WixToolset.Extensibility; + using NetFx = WixToolset.Extensions.Serialize.NetFx; + using Wix = WixToolset.Data.Serialize; + + /// + /// The decompiler for the WiX Toolset .NET Framework Extension. + /// + public sealed class NetFxDecompiler : DecompilerExtension + { + /// + /// Creates a decompiler for NetFx Extension. + /// + public NetFxDecompiler() + { + this.TableDefinitions = NetFxExtensionData.GetExtensionTableDefinitions(); + } + + /// + /// Get the extensions library to be removed. + /// + /// Table definitions for library. + /// Library to remove from decompiled output. + public override Library GetLibraryToRemove(TableDefinitionCollection tableDefinitions) + { + return NetFxExtensionData.GetExtensionLibrary(tableDefinitions); + } + + /// + /// Decompiles an extension table. + /// + /// The table to decompile. + public override void DecompileTable(Table table) + { + switch (table.Name) + { + case "NetFxNativeImage": + this.DecompileNetFxNativeImageTable(table); + break; + default: + base.DecompileTable(table); + break; + } + } + + /// + /// Decompile the NetFxNativeImage table. + /// + /// The table to decompile. + private void DecompileNetFxNativeImageTable(Table table) + { + foreach (Row row in table.Rows) + { + NetFx.NativeImage nativeImage = new NetFx.NativeImage(); + + nativeImage.Id = (string)row[0]; + + switch ((int)row[2]) + { + case 0: + nativeImage.Priority = NetFx.NativeImage.PriorityType.Item0; + break; + case 1: + nativeImage.Priority = NetFx.NativeImage.PriorityType.Item1; + break; + case 2: + nativeImage.Priority = NetFx.NativeImage.PriorityType.Item2; + break; + case 3: + nativeImage.Priority = NetFx.NativeImage.PriorityType.Item3; + break; + } + + if (null != row[3]) + { + int attributes = (int)row[3]; + + if (0x1 == (attributes & 0x1)) + { + nativeImage.Debug = NetFx.YesNoType.yes; + } + + if (0x2 == (attributes & 0x2)) + { + nativeImage.Dependencies = NetFx.YesNoType.no; + } + + if (0x4 == (attributes & 0x4)) + { + nativeImage.Profile = NetFx.YesNoType.yes; + } + + if (0x8 == (attributes & 0x8) && 0x10 == (attributes & 0x10)) + { + nativeImage.Platform = NetFx.NativeImage.PlatformType.all; + } + else if (0x8 == (attributes & 0x8)) + { + nativeImage.Platform = NetFx.NativeImage.PlatformType.Item32bit; + } + else if (0x10 == (attributes & 0x10)) + { + nativeImage.Platform = NetFx.NativeImage.PlatformType.Item64bit; + } + } + + if (null != row[4]) + { + nativeImage.AssemblyApplication = (string)row[4]; + } + + if (null != row[5]) + { + nativeImage.AppBaseDirectory = (string)row[5]; + } + + Wix.File file = (Wix.File)this.Core.GetIndexedElement("File", (string)row[1]); + if (null != file) + { + file.AddChild(nativeImage); + } + else + { + this.Core.OnMessage(WixWarnings.ExpectedForeignRow(row.SourceLineNumbers, table.Name, row.GetPrimaryKey(DecompilerConstants.PrimaryKeyDelimiter), "File_", (string)row[1], "File")); + } + } + } + } +#endif +} diff --git a/src/ext/NetFx/wixext/NetFxExtensionData.cs b/src/ext/NetFx/wixext/NetFxExtensionData.cs new file mode 100644 index 00000000..0a24ef1e --- /dev/null +++ b/src/ext/NetFx/wixext/NetFxExtensionData.cs @@ -0,0 +1,25 @@ +// 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 WixToolset.Netfx +{ + using WixToolset.Data; + using WixToolset.Extensibility; + using WixToolset.Netfx.Symbols; + + /// + /// The WiX Toolset .NET Framework Extension. + /// + public sealed class NetfxExtensionData : BaseExtensionData + { + public override bool TryGetSymbolDefinitionByName(string name, out IntermediateSymbolDefinition symbolDefinition) + { + symbolDefinition = (name == NetfxSymbolDefinitionNames.NetFxNativeImage) ? NetfxSymbolDefinitions.NetFxNativeImage : null; + return symbolDefinition != null; + } + + public override Intermediate GetLibrary(ISymbolDefinitionCreator symbolDefinitions) + { + return Intermediate.Load(typeof(NetfxExtensionData).Assembly, "WixToolset.Netfx.netfx.wixlib", symbolDefinitions); + } + } +} diff --git a/src/ext/NetFx/wixext/NetfxExtensionFactory.cs b/src/ext/NetFx/wixext/NetfxExtensionFactory.cs new file mode 100644 index 00000000..fe618460 --- /dev/null +++ b/src/ext/NetFx/wixext/NetfxExtensionFactory.cs @@ -0,0 +1,18 @@ +// 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 WixToolset.Netfx +{ + using System; + using System.Collections.Generic; + using WixToolset.Extensibility; + + public class NetfxExtensionFactory : BaseExtensionFactory + { + protected override IReadOnlyCollection ExtensionTypes => new[] + { + typeof(NetfxCompiler), + typeof(NetfxExtensionData), + typeof(NetfxWindowsInstallerBackendBinderExtension), + }; + } +} diff --git a/src/ext/NetFx/wixext/NetfxTableDefinitions.cs b/src/ext/NetFx/wixext/NetfxTableDefinitions.cs new file mode 100644 index 00000000..1b2a4d21 --- /dev/null +++ b/src/ext/NetFx/wixext/NetfxTableDefinitions.cs @@ -0,0 +1,30 @@ +// 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 WixToolset.Netfx +{ + using WixToolset.Data.WindowsInstaller; + using WixToolset.Netfx.Symbols; + + public static class NetfxTableDefinitions + { + public static readonly TableDefinition NetFxNativeImage = new TableDefinition( + "Wix4NetFxNativeImage", + NetfxSymbolDefinitions.NetFxNativeImage, + new[] + { + new ColumnDefinition("Wix4NetFxNativeImage", ColumnType.String, 72, primaryKey: true, nullable: false, ColumnCategory.Identifier, description: "The primary key, a non-localized token.", modularizeType: ColumnModularizeType.Column), + new ColumnDefinition("File_", ColumnType.String, 72, primaryKey: false, nullable: false, ColumnCategory.Identifier, keyTable: "File", keyColumn: 1, description: "The assembly for which a native image will be generated.", modularizeType: ColumnModularizeType.Column), + new ColumnDefinition("Priority", ColumnType.Number, 2, primaryKey: false, nullable: false, ColumnCategory.Integer, minValue: 0, maxValue: 3, description: "The priority for generating this native image: 0 is syncronous, 1-3 represent various levels of queued generation."), + new ColumnDefinition("Attributes", ColumnType.Number, 4, primaryKey: false, nullable: false, ColumnCategory.Integer, minValue: 0, maxValue: 2147483647, description: "Integer containing bit flags representing native image attributes."), + new ColumnDefinition("File_Application", ColumnType.String, 72, primaryKey: false, nullable: true, ColumnCategory.Formatted, description: "The application which loads this assembly.", modularizeType: ColumnModularizeType.Column), + new ColumnDefinition("Directory_ApplicationBase", ColumnType.String, 72, primaryKey: false, nullable: true, ColumnCategory.Formatted, description: "The directory containing the application which loads this assembly.", modularizeType: ColumnModularizeType.Column), + }, + symbolIdIsPrimaryKey: true + ); + + public static readonly TableDefinition[] All = new[] + { + NetFxNativeImage, + }; + } +} diff --git a/src/ext/NetFx/wixext/NetfxWindowsInstallerBackendExtension.cs b/src/ext/NetFx/wixext/NetfxWindowsInstallerBackendExtension.cs new file mode 100644 index 00000000..7d4fe475 --- /dev/null +++ b/src/ext/NetFx/wixext/NetfxWindowsInstallerBackendExtension.cs @@ -0,0 +1,13 @@ +// 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 WixToolset.Netfx +{ + using System.Collections.Generic; + using WixToolset.Data.WindowsInstaller; + using WixToolset.Extensibility; + + public class NetfxWindowsInstallerBackendBinderExtension : BaseWindowsInstallerBackendBinderExtension + { + public override IReadOnlyCollection TableDefinitions => NetfxTableDefinitions.All; + } +} diff --git a/src/ext/NetFx/wixext/Symbols/NetFxNativeImageSymbol.cs b/src/ext/NetFx/wixext/Symbols/NetFxNativeImageSymbol.cs new file mode 100644 index 00000000..3803abd6 --- /dev/null +++ b/src/ext/NetFx/wixext/Symbols/NetFxNativeImageSymbol.cs @@ -0,0 +1,58 @@ +// 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 WixToolset.Netfx.Symbols +{ + using WixToolset.Data; + + public enum NetFxNativeImageSymbolFields + { + FileRef, + Priority, + Attributes, + ApplicationFileRef, + ApplicationBaseDirectoryRef, + } + + public class NetFxNativeImageSymbol : IntermediateSymbol + { + public NetFxNativeImageSymbol() : base(NetfxSymbolDefinitions.NetFxNativeImage, null, null) + { + } + + public NetFxNativeImageSymbol(SourceLineNumber sourceLineNumber, Identifier id = null) : base(NetfxSymbolDefinitions.NetFxNativeImage, sourceLineNumber, id) + { + } + + public IntermediateField this[NetFxNativeImageSymbolFields index] => this.Fields[(int)index]; + + public string FileRef + { + get => this.Fields[(int)NetFxNativeImageSymbolFields.FileRef].AsString(); + set => this.Set((int)NetFxNativeImageSymbolFields.FileRef, value); + } + + public int Priority + { + get => this.Fields[(int)NetFxNativeImageSymbolFields.Priority].AsNumber(); + set => this.Set((int)NetFxNativeImageSymbolFields.Priority, value); + } + + public int Attributes + { + get => this.Fields[(int)NetFxNativeImageSymbolFields.Attributes].AsNumber(); + set => this.Set((int)NetFxNativeImageSymbolFields.Attributes, value); + } + + public string ApplicationFileRef + { + get => this.Fields[(int)NetFxNativeImageSymbolFields.ApplicationFileRef].AsString(); + set => this.Set((int)NetFxNativeImageSymbolFields.ApplicationFileRef, value); + } + + public string ApplicationBaseDirectoryRef + { + get => this.Fields[(int)NetFxNativeImageSymbolFields.ApplicationBaseDirectoryRef].AsString(); + set => this.Set((int)NetFxNativeImageSymbolFields.ApplicationBaseDirectoryRef, value); + } + } +} \ No newline at end of file diff --git a/src/ext/NetFx/wixext/Symbols/NetfxSymbolDefinitions.cs b/src/ext/NetFx/wixext/Symbols/NetfxSymbolDefinitions.cs new file mode 100644 index 00000000..3c0f1176 --- /dev/null +++ b/src/ext/NetFx/wixext/Symbols/NetfxSymbolDefinitions.cs @@ -0,0 +1,26 @@ +// 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 WixToolset.Netfx.Symbols +{ + using WixToolset.Data; + + public static class NetfxSymbolDefinitionNames + { + public static string NetFxNativeImage { get; } = "NetFxNativeImage"; + } + + public static class NetfxSymbolDefinitions + { + public static readonly IntermediateSymbolDefinition NetFxNativeImage = new IntermediateSymbolDefinition( + NetfxSymbolDefinitionNames.NetFxNativeImage, + new[] + { + new IntermediateFieldDefinition(nameof(NetFxNativeImageSymbolFields.FileRef), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(NetFxNativeImageSymbolFields.Priority), IntermediateFieldType.Number), + new IntermediateFieldDefinition(nameof(NetFxNativeImageSymbolFields.Attributes), IntermediateFieldType.Number), + new IntermediateFieldDefinition(nameof(NetFxNativeImageSymbolFields.ApplicationFileRef), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(NetFxNativeImageSymbolFields.ApplicationBaseDirectoryRef), IntermediateFieldType.String), + }, + typeof(NetFxNativeImageSymbol)); + } +} diff --git a/src/ext/NetFx/wixext/WixToolset.Netfx.wixext.csproj b/src/ext/NetFx/wixext/WixToolset.Netfx.wixext.csproj new file mode 100644 index 00000000..7c1d55c1 --- /dev/null +++ b/src/ext/NetFx/wixext/WixToolset.Netfx.wixext.csproj @@ -0,0 +1,31 @@ + + + + + + netstandard2.0 + embedded + WixToolset.Netfx + WiX Toolset .NET Framework Extension + WiX Toolset .NET Framework Extension + true + + + + + + + + + + + + + + + + + + + + diff --git a/src/ext/NetFx/wixext/WixToolset.Netfx.wixext.nuspec b/src/ext/NetFx/wixext/WixToolset.Netfx.wixext.nuspec new file mode 100644 index 00000000..ba3eaade --- /dev/null +++ b/src/ext/NetFx/wixext/WixToolset.Netfx.wixext.nuspec @@ -0,0 +1,25 @@ + + + + $id$ + $version$ + $title$ + $description$ + $authors$ + MS-RL + false + $copyright$ + $projectUrl$ + + + + + + + + + + + + + diff --git a/src/ext/NetFx/wixext/WixToolset.Netfx.wixext.targets b/src/ext/NetFx/wixext/WixToolset.Netfx.wixext.targets new file mode 100644 index 00000000..2ed9c488 --- /dev/null +++ b/src/ext/NetFx/wixext/WixToolset.Netfx.wixext.targets @@ -0,0 +1,11 @@ + + + + + + $(MSBuildThisFileDirectory)..\tools\WixToolset.Netfx.wixext.dll + + + + + diff --git a/src/ext/NetFx/wixext/WixToolset.Netfx.wixext.v3.ncrunchproject b/src/ext/NetFx/wixext/WixToolset.Netfx.wixext.v3.ncrunchproject new file mode 100644 index 00000000..93e4df3d --- /dev/null +++ b/src/ext/NetFx/wixext/WixToolset.Netfx.wixext.v3.ncrunchproject @@ -0,0 +1,7 @@ + + + + ..\..\build\Debug\netfx.wixlib + + + \ No newline at end of file -- cgit v1.2.3-55-g6feb