From 5ba862bfa618c89a563d555e8ce7b44a904df406 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Wed, 6 Dec 2017 11:39:26 -0800 Subject: Add support for loading Intermediates from extensions --- src/WixToolset.Core/Bind/ExtractEmbeddedFiles.cs | 7 +- src/WixToolset.Core/CommandLine/BuildCommand.cs | 4 +- src/WixToolset.Core/LinkContext.cs | 4 + src/WixToolset.Core/Linker.cs | 52 +++---------- .../Example.Extension/Example.Extension.csproj | 18 ----- .../Example.Extension/ExampleCompilerExtension.cs | 84 --------------------- src/test/Example.Extension/ExampleExtensionData.cs | 33 -------- .../Example.Extension/ExampleExtensionFactory.cs | 39 ---------- .../ExamplePreprocessorExtensionAndCommandLine.cs | 46 ----------- src/test/Example.Extension/ExampleTuple.cs | 31 -------- src/test/Example.Extension/TupleDefinitions.cs | 18 ----- .../TestData/Example.Extension/Data/example.txt | 1 + .../TestData/Example.Extension/Data/example.wir | Bin 0 -> 534 bytes .../TestData/Example.Extension/Data/example.wxs | 8 ++ .../Example.Extension/Example.Extension.csproj | 22 ++++++ .../Example.Extension/ExampleCompilerExtension.cs | 84 +++++++++++++++++++++ .../Example.Extension/ExampleExtensionData.cs | 33 ++++++++ .../Example.Extension/ExampleExtensionFactory.cs | 39 ++++++++++ .../ExamplePreprocessorExtensionAndCommandLine.cs | 46 +++++++++++ .../TestData/Example.Extension/ExampleTuple.cs | 31 ++++++++ .../TestData/Example.Extension/TupleDefinitions.cs | 18 +++++ .../ExtensionFixture.cs | 6 +- .../TestData/ExampleExtension/Package.wxs | 2 + .../WixToolsetTest.CoreIntegration.csproj | 2 +- 24 files changed, 308 insertions(+), 320 deletions(-) delete mode 100644 src/test/Example.Extension/Example.Extension.csproj delete mode 100644 src/test/Example.Extension/ExampleCompilerExtension.cs delete mode 100644 src/test/Example.Extension/ExampleExtensionData.cs delete mode 100644 src/test/Example.Extension/ExampleExtensionFactory.cs delete mode 100644 src/test/Example.Extension/ExamplePreprocessorExtensionAndCommandLine.cs delete mode 100644 src/test/Example.Extension/ExampleTuple.cs delete mode 100644 src/test/Example.Extension/TupleDefinitions.cs create mode 100644 src/test/TestData/Example.Extension/Data/example.txt create mode 100644 src/test/TestData/Example.Extension/Data/example.wir create mode 100644 src/test/TestData/Example.Extension/Data/example.wxs create mode 100644 src/test/TestData/Example.Extension/Example.Extension.csproj create mode 100644 src/test/TestData/Example.Extension/ExampleCompilerExtension.cs create mode 100644 src/test/TestData/Example.Extension/ExampleExtensionData.cs create mode 100644 src/test/TestData/Example.Extension/ExampleExtensionFactory.cs create mode 100644 src/test/TestData/Example.Extension/ExamplePreprocessorExtensionAndCommandLine.cs create mode 100644 src/test/TestData/Example.Extension/ExampleTuple.cs create mode 100644 src/test/TestData/Example.Extension/TupleDefinitions.cs (limited to 'src') diff --git a/src/WixToolset.Core/Bind/ExtractEmbeddedFiles.cs b/src/WixToolset.Core/Bind/ExtractEmbeddedFiles.cs index 28fc4817..c6e21973 100644 --- a/src/WixToolset.Core/Bind/ExtractEmbeddedFiles.cs +++ b/src/WixToolset.Core/Bind/ExtractEmbeddedFiles.cs @@ -28,19 +28,16 @@ namespace WixToolset.Core.Bind /// The extract path for the embedded file. public string AddEmbeddedFileIndex(Uri uri, int embeddedFileIndex, string tempPath) { - string extractPath; - SortedList extracts; - // If the uri to the file that contains the embedded file does not already have embedded files // being extracted, create the dictionary to track that. - if (!filesWithEmbeddedFiles.TryGetValue(uri, out extracts)) + if (!filesWithEmbeddedFiles.TryGetValue(uri, out var extracts)) { extracts = new SortedList(); filesWithEmbeddedFiles.Add(uri, extracts); } // If the embedded file is not already tracked in the dictionary of extracts, add it. - if (!extracts.TryGetValue(embeddedFileIndex, out extractPath)) + if (!extracts.TryGetValue(embeddedFileIndex, out var extractPath)) { string localFileNameWithoutExtension = Path.GetFileNameWithoutExtension(uri.LocalPath); string unique = this.HashUri(uri.AbsoluteUri); diff --git a/src/WixToolset.Core/CommandLine/BuildCommand.cs b/src/WixToolset.Core/CommandLine/BuildCommand.cs index 79bacd22..7a63b869 100644 --- a/src/WixToolset.Core/CommandLine/BuildCommand.cs +++ b/src/WixToolset.Core/CommandLine/BuildCommand.cs @@ -168,8 +168,10 @@ namespace WixToolset.Core var context = this.ServiceProvider.GetService(); context.Messaging = Messaging.Instance; context.Extensions = this.ExtensionManager.Create(); - context.Intermediates = intermediates.Union(libraries).ToList(); + context.ExtensionData = this.ExtensionManager.Create(); context.ExpectedOutputType = this.OutputType; + context.Intermediates = intermediates.Union(libraries).ToList(); + context.TupleDefinitionCreator = creator; var linker = new Linker(); var output = linker.Link(context); diff --git a/src/WixToolset.Core/LinkContext.cs b/src/WixToolset.Core/LinkContext.cs index c3631f72..1384cf98 100644 --- a/src/WixToolset.Core/LinkContext.cs +++ b/src/WixToolset.Core/LinkContext.cs @@ -21,8 +21,12 @@ namespace WixToolset.Core public IEnumerable Extensions { get; set; } + public IEnumerable ExtensionData { get; set; } + public OutputType ExpectedOutputType { get; set; } public IEnumerable Intermediates { get; set; } + + public ITupleDefinitionCreator TupleDefinitionCreator { get; set; } } } diff --git a/src/WixToolset.Core/Linker.cs b/src/WixToolset.Core/Linker.cs index 7faf69ba..c893a01d 100644 --- a/src/WixToolset.Core/Linker.cs +++ b/src/WixToolset.Core/Linker.cs @@ -55,32 +55,6 @@ namespace WixToolset.Core /// The Wix variable resolver. //internal IBindVariableResolver WixVariableResolver { get; set; } - /// - /// Adds an extension. - /// - /// The extension to add. - //public void AddExtensionData(IExtensionData extension) - //{ - // if (null != extension.TableDefinitions) - // { - // foreach (TableDefinition tableDefinition in extension.TableDefinitions) - // { - // if (!this.tableDefinitions.Contains(tableDefinition.Name)) - // { - // this.tableDefinitions.Add(tableDefinition); - // } - // else - // { - // throw new WixException(WixErrors.DuplicateExtensionTable(extension.GetType().ToString(), tableDefinition.Name)); - // } - // } - // } - - // // keep track of extension data so the libraries can be loaded from these later once all the table definitions - // // are loaded; this will allow extensions to have cross table definition dependencies - // this.extensionData.Add(extension); - //} - /// /// Links a collection of sections into an output. /// @@ -91,10 +65,19 @@ namespace WixToolset.Core { this.Context = context ?? throw new ArgumentNullException(nameof(context)); - //IEnumerable
inputs, OutputType expectedOutputType - var sections = this.Context.Intermediates.SelectMany(i => i.Sections).ToList(); + // Add sections from the extensions with data. + foreach (var data in context.ExtensionData) + { + var library = data.GetLibrary(context.TupleDefinitionCreator); + + if (library != null) + { + sections.AddRange(library.Sections); + } + } + #if MOVE_TO_BACKEND bool containsModuleSubstitution = false; bool containsModuleConfiguration = false; @@ -144,19 +127,6 @@ namespace WixToolset.Core } #endif -#if TODO - // Add sections from the extensions with data. - foreach (IExtensionData data in this.extensionData) - { - Library library = data.GetLibrary(this.tableDefinitions); - - if (null != library) - { - sections.AddRange(library.Sections); - } - } -#endif - // First find the entry section and while processing all sections load all the symbols from all of the sections. // sections.FindEntrySectionAndLoadSymbols(false, this, expectedOutputType, out entrySection, out allSymbols); var find = new FindEntrySectionAndLoadSymbolsCommand(sections); diff --git a/src/test/Example.Extension/Example.Extension.csproj b/src/test/Example.Extension/Example.Extension.csproj deleted file mode 100644 index 80c64b25..00000000 --- a/src/test/Example.Extension/Example.Extension.csproj +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - netstandard2.0 - false - - - - - - - - - - - diff --git a/src/test/Example.Extension/ExampleCompilerExtension.cs b/src/test/Example.Extension/ExampleCompilerExtension.cs deleted file mode 100644 index 5b20e48f..00000000 --- a/src/test/Example.Extension/ExampleCompilerExtension.cs +++ /dev/null @@ -1,84 +0,0 @@ -// 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 Example.Extension -{ - using System; - using System.Collections.Generic; - using System.Xml.Linq; - using WixToolset.Data; - using WixToolset.Extensibility; - - internal class ExampleCompilerExtension : BaseCompilerExtension - { - public ExampleCompilerExtension() - { - this.Namespace = "http://www.example.com/scheams/v1/wxs"; - } - - public override void ParseElement(Intermediate intermediate, IntermediateSection section, XElement parentElement, XElement element, IDictionary context) - { - var processed = false; - - switch (parentElement.Name.LocalName) - { - case "Component": - switch (element.Name.LocalName) - { - case "Example": - this.ParseExampleElement(intermediate, section, element); - processed = true; - break; - } - break; - } - - if (!processed) - { - base.ParseElement(intermediate, section, parentElement, element, context); - } - } - - private void ParseExampleElement(Intermediate intermediate, IntermediateSection section, XElement element) - { - var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element); - Identifier id = null; - string value = null; - - 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 "Value": - value = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); - break; - - default: - this.ParseHelper.UnexpectedAttribute(element, attrib); - break; - } - } - else - { - this.ParseAttribute(intermediate, section, element, attrib, null); - } - } - - if (null == id) - { - //this.Messaging(WixErrors.ExpectedAttribute(sourceLineNumbers, element.Name.LocalName, "Id")); - } - - if (!this.Messaging.EncounteredError) - { - var tuple = this.ParseHelper.CreateRow(section, sourceLineNumbers, "Example", id); - tuple.Set(1, value); - } - } - } -} diff --git a/src/test/Example.Extension/ExampleExtensionData.cs b/src/test/Example.Extension/ExampleExtensionData.cs deleted file mode 100644 index c3cb0473..00000000 --- a/src/test/Example.Extension/ExampleExtensionData.cs +++ /dev/null @@ -1,33 +0,0 @@ -// 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 Example.Extension -{ - using WixToolset.Data; - using WixToolset.Extensibility; - - internal class ExampleExtensionData : IExtensionData - { - public string DefaultCulture => null; - - public Intermediate GetLibrary(ITupleDefinitionCreator tupleDefinitions) - { - return null; - } - - public bool TryGetTupleDefinitionByName(string name, out IntermediateTupleDefinition tupleDefinition) - { - switch (name) - { - case "Example": - tupleDefinition = TupleDefinitions.Example; - break; - - default: - tupleDefinition = null; - break; - } - - return tupleDefinition != null; - } - } -} \ No newline at end of file diff --git a/src/test/Example.Extension/ExampleExtensionFactory.cs b/src/test/Example.Extension/ExampleExtensionFactory.cs deleted file mode 100644 index b91d06e9..00000000 --- a/src/test/Example.Extension/ExampleExtensionFactory.cs +++ /dev/null @@ -1,39 +0,0 @@ -// 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 Example.Extension -{ - using System; - using WixToolset.Extensibility; - - public class ExampleExtensionFactory : IExtensionFactory - { - private ExamplePreprocessorExtensionAndCommandLine preprocessorExtension; - - public bool TryCreateExtension(Type extensionType, out object extension) - { - if (extensionType == typeof(IExtensionCommandLine) || extensionType == typeof(IPreprocessorExtension)) - { - if (preprocessorExtension == null) - { - preprocessorExtension = new ExamplePreprocessorExtensionAndCommandLine(); - } - - extension = preprocessorExtension; - } - else if (extensionType == typeof(ICompilerExtension)) - { - extension = new ExampleCompilerExtension(); - } - else if (extensionType == typeof(IExtensionData)) - { - extension = new ExampleExtensionData(); - } - else - { - extension = null; - } - - return extension != null; - } - } -} diff --git a/src/test/Example.Extension/ExamplePreprocessorExtensionAndCommandLine.cs b/src/test/Example.Extension/ExamplePreprocessorExtensionAndCommandLine.cs deleted file mode 100644 index 53394ea3..00000000 --- a/src/test/Example.Extension/ExamplePreprocessorExtensionAndCommandLine.cs +++ /dev/null @@ -1,46 +0,0 @@ -// 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 Example.Extension -{ - using System; - using System.Collections.Generic; - using WixToolset.Extensibility; - using WixToolset.Extensibility.Services; - - internal class ExamplePreprocessorExtensionAndCommandLine : BasePreprocessorExtension, IExtensionCommandLine - { - private string exampleValueFromCommandLine; - - public IEnumerable CommandLineSwitches => throw new NotImplementedException(); - - public ExamplePreprocessorExtensionAndCommandLine() - { - this.Prefixes = new[] { "ex" }; - } - - public void PreParse(ICommandLineContext context) - { - } - - public bool TryParseArgument(IParseCommandLine parseCommandLine, string arg) - { - if (parseCommandLine.IsSwitch(arg) && arg.Substring(1).Equals("example", StringComparison.OrdinalIgnoreCase)) - { - parseCommandLine.GetNextArgumentOrError(ref this.exampleValueFromCommandLine); - return true; - } - - return false; - } - - public override string GetVariableValue(string prefix, string name) - { - if (prefix == "ex" && "test".Equals(name, StringComparison.OrdinalIgnoreCase)) - { - return String.IsNullOrWhiteSpace(this.exampleValueFromCommandLine) ? "(null)" : this.exampleValueFromCommandLine; - } - - return null; - } - } -} \ No newline at end of file diff --git a/src/test/Example.Extension/ExampleTuple.cs b/src/test/Example.Extension/ExampleTuple.cs deleted file mode 100644 index f280a5c8..00000000 --- a/src/test/Example.Extension/ExampleTuple.cs +++ /dev/null @@ -1,31 +0,0 @@ -// 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 Example.Extension -{ - using WixToolset.Data; - - public enum ExampleTupleFields - { - Example, - Value, - } - - public class ExampleTuple : IntermediateTuple - { - public ExampleTuple() : base(TupleDefinitions.Example, null, null) - { - } - - public ExampleTuple(SourceLineNumber sourceLineNumber, Identifier id = null) : base(TupleDefinitions.Example, sourceLineNumber, id) - { - } - - public IntermediateField this[ExampleTupleFields index] => this.Fields[(int)index]; - - public string Value - { - get => this.Fields[(int)ExampleTupleFields.Value]?.AsString(); - set => this.Set((int)ExampleTupleFields.Value, value); - } - } -} diff --git a/src/test/Example.Extension/TupleDefinitions.cs b/src/test/Example.Extension/TupleDefinitions.cs deleted file mode 100644 index 2c320fbc..00000000 --- a/src/test/Example.Extension/TupleDefinitions.cs +++ /dev/null @@ -1,18 +0,0 @@ -// 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 Example.Extension -{ - using WixToolset.Data; - - public static class TupleDefinitions - { - public static readonly IntermediateTupleDefinition Example = new IntermediateTupleDefinition( - "Example", - new[] - { - new IntermediateFieldDefinition(nameof(ExampleTupleFields.Example), IntermediateFieldType.String), - new IntermediateFieldDefinition(nameof(ExampleTupleFields.Value), IntermediateFieldType.String), - }, - typeof(ExampleTuple)); - } -} diff --git a/src/test/TestData/Example.Extension/Data/example.txt b/src/test/TestData/Example.Extension/Data/example.txt new file mode 100644 index 00000000..1b4ffe8a --- /dev/null +++ b/src/test/TestData/Example.Extension/Data/example.txt @@ -0,0 +1 @@ +This is example.txt. \ No newline at end of file diff --git a/src/test/TestData/Example.Extension/Data/example.wir b/src/test/TestData/Example.Extension/Data/example.wir new file mode 100644 index 00000000..674f63fc Binary files /dev/null and b/src/test/TestData/Example.Extension/Data/example.wir differ diff --git a/src/test/TestData/Example.Extension/Data/example.wxs b/src/test/TestData/Example.Extension/Data/example.wxs new file mode 100644 index 00000000..53531e99 --- /dev/null +++ b/src/test/TestData/Example.Extension/Data/example.wxs @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/src/test/TestData/Example.Extension/Example.Extension.csproj b/src/test/TestData/Example.Extension/Example.Extension.csproj new file mode 100644 index 00000000..d04ce553 --- /dev/null +++ b/src/test/TestData/Example.Extension/Example.Extension.csproj @@ -0,0 +1,22 @@ + + + + + + netstandard2.0 + false + + + + + + + + + + + + + + + diff --git a/src/test/TestData/Example.Extension/ExampleCompilerExtension.cs b/src/test/TestData/Example.Extension/ExampleCompilerExtension.cs new file mode 100644 index 00000000..5b20e48f --- /dev/null +++ b/src/test/TestData/Example.Extension/ExampleCompilerExtension.cs @@ -0,0 +1,84 @@ +// 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 Example.Extension +{ + using System; + using System.Collections.Generic; + using System.Xml.Linq; + using WixToolset.Data; + using WixToolset.Extensibility; + + internal class ExampleCompilerExtension : BaseCompilerExtension + { + public ExampleCompilerExtension() + { + this.Namespace = "http://www.example.com/scheams/v1/wxs"; + } + + public override void ParseElement(Intermediate intermediate, IntermediateSection section, XElement parentElement, XElement element, IDictionary context) + { + var processed = false; + + switch (parentElement.Name.LocalName) + { + case "Component": + switch (element.Name.LocalName) + { + case "Example": + this.ParseExampleElement(intermediate, section, element); + processed = true; + break; + } + break; + } + + if (!processed) + { + base.ParseElement(intermediate, section, parentElement, element, context); + } + } + + private void ParseExampleElement(Intermediate intermediate, IntermediateSection section, XElement element) + { + var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element); + Identifier id = null; + string value = null; + + 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 "Value": + value = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); + break; + + default: + this.ParseHelper.UnexpectedAttribute(element, attrib); + break; + } + } + else + { + this.ParseAttribute(intermediate, section, element, attrib, null); + } + } + + if (null == id) + { + //this.Messaging(WixErrors.ExpectedAttribute(sourceLineNumbers, element.Name.LocalName, "Id")); + } + + if (!this.Messaging.EncounteredError) + { + var tuple = this.ParseHelper.CreateRow(section, sourceLineNumbers, "Example", id); + tuple.Set(1, value); + } + } + } +} diff --git a/src/test/TestData/Example.Extension/ExampleExtensionData.cs b/src/test/TestData/Example.Extension/ExampleExtensionData.cs new file mode 100644 index 00000000..6b179ea6 --- /dev/null +++ b/src/test/TestData/Example.Extension/ExampleExtensionData.cs @@ -0,0 +1,33 @@ +// 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 Example.Extension +{ + using WixToolset.Data; + using WixToolset.Extensibility; + + internal class ExampleExtensionData : IExtensionData + { + public string DefaultCulture => null; + + public Intermediate GetLibrary(ITupleDefinitionCreator tupleDefinitions) + { + return Intermediate.Load(typeof(ExampleExtensionData).Assembly, "Example.Extension.Data.Example.wir", tupleDefinitions); + } + + public bool TryGetTupleDefinitionByName(string name, out IntermediateTupleDefinition tupleDefinition) + { + switch (name) + { + case "Example": + tupleDefinition = TupleDefinitions.Example; + break; + + default: + tupleDefinition = null; + break; + } + + return tupleDefinition != null; + } + } +} \ No newline at end of file diff --git a/src/test/TestData/Example.Extension/ExampleExtensionFactory.cs b/src/test/TestData/Example.Extension/ExampleExtensionFactory.cs new file mode 100644 index 00000000..b91d06e9 --- /dev/null +++ b/src/test/TestData/Example.Extension/ExampleExtensionFactory.cs @@ -0,0 +1,39 @@ +// 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 Example.Extension +{ + using System; + using WixToolset.Extensibility; + + public class ExampleExtensionFactory : IExtensionFactory + { + private ExamplePreprocessorExtensionAndCommandLine preprocessorExtension; + + public bool TryCreateExtension(Type extensionType, out object extension) + { + if (extensionType == typeof(IExtensionCommandLine) || extensionType == typeof(IPreprocessorExtension)) + { + if (preprocessorExtension == null) + { + preprocessorExtension = new ExamplePreprocessorExtensionAndCommandLine(); + } + + extension = preprocessorExtension; + } + else if (extensionType == typeof(ICompilerExtension)) + { + extension = new ExampleCompilerExtension(); + } + else if (extensionType == typeof(IExtensionData)) + { + extension = new ExampleExtensionData(); + } + else + { + extension = null; + } + + return extension != null; + } + } +} diff --git a/src/test/TestData/Example.Extension/ExamplePreprocessorExtensionAndCommandLine.cs b/src/test/TestData/Example.Extension/ExamplePreprocessorExtensionAndCommandLine.cs new file mode 100644 index 00000000..53394ea3 --- /dev/null +++ b/src/test/TestData/Example.Extension/ExamplePreprocessorExtensionAndCommandLine.cs @@ -0,0 +1,46 @@ +// 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 Example.Extension +{ + using System; + using System.Collections.Generic; + using WixToolset.Extensibility; + using WixToolset.Extensibility.Services; + + internal class ExamplePreprocessorExtensionAndCommandLine : BasePreprocessorExtension, IExtensionCommandLine + { + private string exampleValueFromCommandLine; + + public IEnumerable CommandLineSwitches => throw new NotImplementedException(); + + public ExamplePreprocessorExtensionAndCommandLine() + { + this.Prefixes = new[] { "ex" }; + } + + public void PreParse(ICommandLineContext context) + { + } + + public bool TryParseArgument(IParseCommandLine parseCommandLine, string arg) + { + if (parseCommandLine.IsSwitch(arg) && arg.Substring(1).Equals("example", StringComparison.OrdinalIgnoreCase)) + { + parseCommandLine.GetNextArgumentOrError(ref this.exampleValueFromCommandLine); + return true; + } + + return false; + } + + public override string GetVariableValue(string prefix, string name) + { + if (prefix == "ex" && "test".Equals(name, StringComparison.OrdinalIgnoreCase)) + { + return String.IsNullOrWhiteSpace(this.exampleValueFromCommandLine) ? "(null)" : this.exampleValueFromCommandLine; + } + + return null; + } + } +} \ No newline at end of file diff --git a/src/test/TestData/Example.Extension/ExampleTuple.cs b/src/test/TestData/Example.Extension/ExampleTuple.cs new file mode 100644 index 00000000..f280a5c8 --- /dev/null +++ b/src/test/TestData/Example.Extension/ExampleTuple.cs @@ -0,0 +1,31 @@ +// 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 Example.Extension +{ + using WixToolset.Data; + + public enum ExampleTupleFields + { + Example, + Value, + } + + public class ExampleTuple : IntermediateTuple + { + public ExampleTuple() : base(TupleDefinitions.Example, null, null) + { + } + + public ExampleTuple(SourceLineNumber sourceLineNumber, Identifier id = null) : base(TupleDefinitions.Example, sourceLineNumber, id) + { + } + + public IntermediateField this[ExampleTupleFields index] => this.Fields[(int)index]; + + public string Value + { + get => this.Fields[(int)ExampleTupleFields.Value]?.AsString(); + set => this.Set((int)ExampleTupleFields.Value, value); + } + } +} diff --git a/src/test/TestData/Example.Extension/TupleDefinitions.cs b/src/test/TestData/Example.Extension/TupleDefinitions.cs new file mode 100644 index 00000000..2c320fbc --- /dev/null +++ b/src/test/TestData/Example.Extension/TupleDefinitions.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 Example.Extension +{ + using WixToolset.Data; + + public static class TupleDefinitions + { + public static readonly IntermediateTupleDefinition Example = new IntermediateTupleDefinition( + "Example", + new[] + { + new IntermediateFieldDefinition(nameof(ExampleTupleFields.Example), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(ExampleTupleFields.Value), IntermediateFieldType.String), + }, + typeof(ExampleTuple)); + } +} diff --git a/src/test/WixToolsetTest.CoreIntegration/ExtensionFixture.cs b/src/test/WixToolsetTest.CoreIntegration/ExtensionFixture.cs index 6acf3472..bd4b70da 100644 --- a/src/test/WixToolsetTest.CoreIntegration/ExtensionFixture.cs +++ b/src/test/WixToolsetTest.CoreIntegration/ExtensionFixture.cs @@ -44,13 +44,13 @@ namespace WixToolsetTest.CoreIntegration Assert.True(File.Exists(Path.Combine(intermediateFolder, @"bin\MsiPackage\example.txt"))); var intermediate = Intermediate.Load(Path.Combine(intermediateFolder, @"bin\extest.wir")); - Assert.Single(intermediate.Sections); + var section = intermediate.Sections.Single(); - var wixFile = intermediate.Sections.SelectMany(s => s.Tuples).OfType().Single(); + var wixFile = section.Tuples.OfType().Single(); Assert.Equal(Path.Combine(folder, @"data\example.txt"), wixFile[WixFileTupleFields.Source].AsPath().Path); Assert.Equal(@"example.txt", wixFile[WixFileTupleFields.Source].PreviousValue.AsPath().Path); - var example = intermediate.Sections.SelectMany(s => s.Tuples).Where(t => t.Definition.Type == TupleDefinitionType.MustBeFromAnExtension).Single(); + var example = section.Tuples.Where(t => t.Definition.Type == TupleDefinitionType.MustBeFromAnExtension).Single(); Assert.Equal("Foo", example.Id.Id); Assert.Equal("Foo", example[0].AsString()); Assert.Equal("Bar", example[1].AsString()); diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/ExampleExtension/Package.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/ExampleExtension/Package.wxs index 9fd42214..bff5f609 100644 --- a/src/test/WixToolsetTest.CoreIntegration/TestData/ExampleExtension/Package.wxs +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/ExampleExtension/Package.wxs @@ -8,6 +8,8 @@ + + diff --git a/src/test/WixToolsetTest.CoreIntegration/WixToolsetTest.CoreIntegration.csproj b/src/test/WixToolsetTest.CoreIntegration/WixToolsetTest.CoreIntegration.csproj index ed0d5f5e..af520116 100644 --- a/src/test/WixToolsetTest.CoreIntegration/WixToolsetTest.CoreIntegration.csproj +++ b/src/test/WixToolsetTest.CoreIntegration/WixToolsetTest.CoreIntegration.csproj @@ -31,7 +31,7 @@ - + -- cgit v1.2.3-55-g6feb