From c2b00d75493798d9f2452d5e5014b14afcb14889 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Wed, 5 Jan 2022 21:51:00 -0600 Subject: Always run upgrade related bundles last. #5128 --- .../ForTestingUseOnly.wixext.csproj | 15 +++++ .../ForTestingUseOnlyBurnBackendExtension.cs | 43 ++++++++++++ .../ForTestingUseOnlyCompiler.cs | 77 ++++++++++++++++++++++ .../ForTestingUseOnlyExtensionData.cs | 16 +++++ .../ForTestingUseOnlyExtensionFactory.cs | 18 +++++ .../Symbols/ForTestingUseOnlyBundleSymbol.cs | 47 +++++++++++++ .../Symbols/ForTestingUseOnlySymbolDefinitions.cs | 43 ++++++++++++ 7 files changed, 259 insertions(+) create mode 100644 src/test/burn/ForTestingUseOnlyExtension/ForTestingUseOnly.wixext.csproj create mode 100644 src/test/burn/ForTestingUseOnlyExtension/ForTestingUseOnlyBurnBackendExtension.cs create mode 100644 src/test/burn/ForTestingUseOnlyExtension/ForTestingUseOnlyCompiler.cs create mode 100644 src/test/burn/ForTestingUseOnlyExtension/ForTestingUseOnlyExtensionData.cs create mode 100644 src/test/burn/ForTestingUseOnlyExtension/ForTestingUseOnlyExtensionFactory.cs create mode 100644 src/test/burn/ForTestingUseOnlyExtension/Symbols/ForTestingUseOnlyBundleSymbol.cs create mode 100644 src/test/burn/ForTestingUseOnlyExtension/Symbols/ForTestingUseOnlySymbolDefinitions.cs (limited to 'src/test/burn/ForTestingUseOnlyExtension') diff --git a/src/test/burn/ForTestingUseOnlyExtension/ForTestingUseOnly.wixext.csproj b/src/test/burn/ForTestingUseOnlyExtension/ForTestingUseOnly.wixext.csproj new file mode 100644 index 00000000..c3861a96 --- /dev/null +++ b/src/test/burn/ForTestingUseOnlyExtension/ForTestingUseOnly.wixext.csproj @@ -0,0 +1,15 @@ + + + + + + netstandard2.0 + ForTestingUseOnly + embedded + true + + + + + + diff --git a/src/test/burn/ForTestingUseOnlyExtension/ForTestingUseOnlyBurnBackendExtension.cs b/src/test/burn/ForTestingUseOnlyExtension/ForTestingUseOnlyBurnBackendExtension.cs new file mode 100644 index 00000000..fff23274 --- /dev/null +++ b/src/test/burn/ForTestingUseOnlyExtension/ForTestingUseOnlyBurnBackendExtension.cs @@ -0,0 +1,43 @@ +// 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 ForTestingUseOnly +{ + using System.Collections.Generic; + using System.Linq; + using ForTestingUseOnly.Symbols; + using WixToolset.Data; + using WixToolset.Data.Symbols; + using WixToolset.Extensibility; + + /// + /// Extension for doing completely unsupported things in the name of testing. + /// + public class ForTestingUseOnlyBurnBackendExtension : BaseBurnBackendBinderExtension + { + private static readonly IntermediateSymbolDefinition[] BurnSymbolDefinitions = + { + ForTestingUseOnlySymbolDefinitions.ForTestingUseOnlyBundle, + }; + + protected override IReadOnlyCollection SymbolDefinitions => BurnSymbolDefinitions; + + public override void SymbolsFinalized(IntermediateSection section) + { + base.SymbolsFinalized(section); + + this.FinalizeBundleSymbol(section); + } + + private void FinalizeBundleSymbol(IntermediateSection section) + { + var forTestingUseOnlyBundleSymbol = section.Symbols.OfType().SingleOrDefault(); + if (null == forTestingUseOnlyBundleSymbol) + { + return; + } + + var bundleSymbol = section.Symbols.OfType().Single(); + bundleSymbol.ProviderKey = bundleSymbol.BundleId = forTestingUseOnlyBundleSymbol.BundleId; + } + } +} diff --git a/src/test/burn/ForTestingUseOnlyExtension/ForTestingUseOnlyCompiler.cs b/src/test/burn/ForTestingUseOnlyExtension/ForTestingUseOnlyCompiler.cs new file mode 100644 index 00000000..4963c941 --- /dev/null +++ b/src/test/burn/ForTestingUseOnlyExtension/ForTestingUseOnlyCompiler.cs @@ -0,0 +1,77 @@ +// 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 ForTestingUseOnly +{ + using System; + using System.Collections.Generic; + using System.Xml.Linq; + using ForTestingUseOnly.Symbols; + using WixToolset.Data; + using WixToolset.Extensibility; + + /// + /// Extension for doing completely unsupported things in the name of testing. + /// + public sealed class ForTestingUseOnlyCompiler : BaseCompilerExtension + { + public override XNamespace Namespace => "http://wixtoolset.org/schemas/v4/wxs/fortestinguseonly"; + + public override void ParseElement(Intermediate intermediate, IntermediateSection section, XElement parentElement, XElement element, IDictionary context) + { + switch (element.Name.LocalName) + { + case "ForTestingUseOnlyBundle": + this.ParseForTestingUseOnlyBundleElement(intermediate, section, element); + break; + default: + this.ParseHelper.UnexpectedElement(parentElement, element); + break; + } + } + + private void ParseForTestingUseOnlyBundleElement(Intermediate intermediate, IntermediateSection section, XElement element) + { + var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element); + string bundleId = null; + + foreach (var attrib in element.Attributes()) + { + if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace) + { + switch (attrib.Name.LocalName) + { + case "Id": + bundleId = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); + break; + default: + this.ParseHelper.UnexpectedAttribute(element, attrib); + break; + } + } + else + { + this.ParseHelper.ParseExtensionAttribute(this.Context.Extensions, intermediate, section, element, attrib); + } + } + + if (null == bundleId) + { + this.Messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, element.Name.LocalName, "Id")); + } + else + { + bundleId = Guid.Parse(bundleId).ToString("B").ToUpperInvariant(); + } + + this.ParseHelper.ParseForExtensionElements(this.Context.Extensions, intermediate, section, element); + + if (!this.Messaging.EncounteredError) + { + section.AddSymbol(new ForTestingUseOnlyBundleSymbol(sourceLineNumbers, new Identifier(AccessModifier.Global, "ForTestingUseOnlyBundle")) + { + BundleId = bundleId, + }); + } + } + } +} diff --git a/src/test/burn/ForTestingUseOnlyExtension/ForTestingUseOnlyExtensionData.cs b/src/test/burn/ForTestingUseOnlyExtension/ForTestingUseOnlyExtensionData.cs new file mode 100644 index 00000000..3276b2db --- /dev/null +++ b/src/test/burn/ForTestingUseOnlyExtension/ForTestingUseOnlyExtensionData.cs @@ -0,0 +1,16 @@ +// 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 ForTestingUseOnly +{ + using WixToolset.Data; + using WixToolset.Extensibility; + + public sealed class ForTestingUseOnlyExtensionData : BaseExtensionData + { + public override bool TryGetSymbolDefinitionByName(string name, out IntermediateSymbolDefinition symbolDefinition) + { + symbolDefinition = ForTestingUseOnlySymbolDefinitions.ByName(name); + return symbolDefinition != null; + } + } +} diff --git a/src/test/burn/ForTestingUseOnlyExtension/ForTestingUseOnlyExtensionFactory.cs b/src/test/burn/ForTestingUseOnlyExtension/ForTestingUseOnlyExtensionFactory.cs new file mode 100644 index 00000000..f71a0c2e --- /dev/null +++ b/src/test/burn/ForTestingUseOnlyExtension/ForTestingUseOnlyExtensionFactory.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 ForTestingUseOnly +{ + using System; + using System.Collections.Generic; + using WixToolset.Extensibility; + + public class ForTestingUseOnlyExtensionFactory : BaseExtensionFactory + { + protected override IReadOnlyCollection ExtensionTypes => new[] + { + typeof(ForTestingUseOnlyCompiler), + typeof(ForTestingUseOnlyExtensionData), + typeof(ForTestingUseOnlyBurnBackendExtension), + }; + } +} diff --git a/src/test/burn/ForTestingUseOnlyExtension/Symbols/ForTestingUseOnlyBundleSymbol.cs b/src/test/burn/ForTestingUseOnlyExtension/Symbols/ForTestingUseOnlyBundleSymbol.cs new file mode 100644 index 00000000..a17dfe31 --- /dev/null +++ b/src/test/burn/ForTestingUseOnlyExtension/Symbols/ForTestingUseOnlyBundleSymbol.cs @@ -0,0 +1,47 @@ +// 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 ForTestingUseOnly +{ + using WixToolset.Data; + using ForTestingUseOnly.Symbols; + + public static partial class ForTestingUseOnlySymbolDefinitions + { + public static readonly IntermediateSymbolDefinition ForTestingUseOnlyBundle = new IntermediateSymbolDefinition( + ForTestingUseOnlySymbolDefinitionType.ForTestingUseOnlyBundle.ToString(), + new[] + { + new IntermediateFieldDefinition(nameof(ForTestingUseOnlyBundleSymbolFields.BundleId), IntermediateFieldType.String), + }, + typeof(ForTestingUseOnlyBundleSymbol)); + } +} + +namespace ForTestingUseOnly.Symbols +{ + using WixToolset.Data; + + public enum ForTestingUseOnlyBundleSymbolFields + { + BundleId, + } + + public class ForTestingUseOnlyBundleSymbol : IntermediateSymbol + { + public ForTestingUseOnlyBundleSymbol() : base(ForTestingUseOnlySymbolDefinitions.ForTestingUseOnlyBundle, null, null) + { + } + + public ForTestingUseOnlyBundleSymbol(SourceLineNumber sourceLineNumber, Identifier id = null) : base(ForTestingUseOnlySymbolDefinitions.ForTestingUseOnlyBundle, sourceLineNumber, id) + { + } + + public IntermediateField this[ForTestingUseOnlyBundleSymbolFields index] => this.Fields[(int)index]; + + public string BundleId + { + get => this.Fields[(int)ForTestingUseOnlyBundleSymbolFields.BundleId].AsString(); + set => this.Set((int)ForTestingUseOnlyBundleSymbolFields.BundleId, value); + } + } +} diff --git a/src/test/burn/ForTestingUseOnlyExtension/Symbols/ForTestingUseOnlySymbolDefinitions.cs b/src/test/burn/ForTestingUseOnlyExtension/Symbols/ForTestingUseOnlySymbolDefinitions.cs new file mode 100644 index 00000000..82c3833e --- /dev/null +++ b/src/test/burn/ForTestingUseOnlyExtension/Symbols/ForTestingUseOnlySymbolDefinitions.cs @@ -0,0 +1,43 @@ +// 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 ForTestingUseOnly +{ + using System; + using WixToolset.Data; + using WixToolset.Data.Burn; + + public enum ForTestingUseOnlySymbolDefinitionType + { + ForTestingUseOnlyBundle, + } + + public static partial class ForTestingUseOnlySymbolDefinitions + { + public static IntermediateSymbolDefinition ByName(string name) + { + if (!Enum.TryParse(name, out ForTestingUseOnlySymbolDefinitionType type)) + { + return null; + } + + return ByType(type); + } + + public static IntermediateSymbolDefinition ByType(ForTestingUseOnlySymbolDefinitionType type) + { + switch (type) + { + case ForTestingUseOnlySymbolDefinitionType.ForTestingUseOnlyBundle: + return ForTestingUseOnlySymbolDefinitions.ForTestingUseOnlyBundle; + + default: + throw new ArgumentOutOfRangeException(nameof(type)); + } + } + + static ForTestingUseOnlySymbolDefinitions() + { + ForTestingUseOnlyBundle.AddTag(BurnConstants.BootstrapperApplicationDataSymbolDefinitionTag); + } + } +} -- cgit v1.2.3-55-g6feb