From fb2df0e24c0709ce94c396624cf86c70e02da01f Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Sat, 2 Dec 2017 00:45:33 -0800 Subject: Fix IExtensionCommandLine and IPreprocessorExtension --- src/Directory.Build.props | 4 +- .../BaseCompilerExtension.cs | 7 ++ .../BasePreprocessorExtension.cs | 84 ++++++++++++++++++ .../IExtensionCommandLine.cs | 17 +--- src/WixToolset.Extensibility/IExtensionData.cs | 4 +- src/WixToolset.Extensibility/IPreprocessContext.cs | 31 +++++++ src/WixToolset.Extensibility/IPreprocessorCore.cs | 21 ----- .../IPreprocessorExtension.cs | 26 +----- .../PreprocessorExtension.cs | 99 ---------------------- .../Services/IParseCommandLine.cs | 21 +++++ .../Services/IParseHelper.cs | 9 +- .../Services/IPreprocessHelper.cs | 89 +++++++++++++++++++ 12 files changed, 252 insertions(+), 160 deletions(-) create mode 100644 src/WixToolset.Extensibility/BasePreprocessorExtension.cs create mode 100644 src/WixToolset.Extensibility/IPreprocessContext.cs delete mode 100644 src/WixToolset.Extensibility/IPreprocessorCore.cs delete mode 100644 src/WixToolset.Extensibility/PreprocessorExtension.cs create mode 100644 src/WixToolset.Extensibility/Services/IParseCommandLine.cs create mode 100644 src/WixToolset.Extensibility/Services/IPreprocessHelper.cs (limited to 'src') diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 25cb6d36..7cd6767f 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -5,11 +5,13 @@ Debug $(MSBuildThisFileDirectory)..\build\obj\$(MSBuildProjectName)\ - $(MSBuildThisFileDirectory)..\build\$(Configuration)\ + $(MSBuildThisFileDirectory)..\build\$(Configuration)\ + $(BaseOutputPath) WiX Toolset Team WiX Toolset Copyright (c) .NET Foundation and contributors. All rights reserved. + WiX Toolset diff --git a/src/WixToolset.Extensibility/BaseCompilerExtension.cs b/src/WixToolset.Extensibility/BaseCompilerExtension.cs index 508886d3..5dfe5dcf 100644 --- a/src/WixToolset.Extensibility/BaseCompilerExtension.cs +++ b/src/WixToolset.Extensibility/BaseCompilerExtension.cs @@ -12,6 +12,11 @@ namespace WixToolset.Extensibility /// public abstract class BaseCompilerExtension : ICompilerExtension { + /// + /// Messaging for use by the extension. + /// + protected Messaging Messaging { get; private set; } + /// /// ParserHelper for use by the extension. /// @@ -28,6 +33,8 @@ namespace WixToolset.Extensibility /// public virtual void PreCompile(ICompileContext context) { + this.Messaging = context.Messaging; + this.ParseHelper = context.ServiceProvider.GetService(); } diff --git a/src/WixToolset.Extensibility/BasePreprocessorExtension.cs b/src/WixToolset.Extensibility/BasePreprocessorExtension.cs new file mode 100644 index 00000000..acfcd5b9 --- /dev/null +++ b/src/WixToolset.Extensibility/BasePreprocessorExtension.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 WixToolset.Extensibility +{ + using System.Xml.Linq; + using WixToolset.Extensibility.Services; + + /// + /// Base class for creating a preprocessor extension. + /// + public abstract class BasePreprocessorExtension : IPreprocessorExtension + { + /// + /// Context for use by the extension. + /// + protected IPreprocessContext Context { get; private set; } + + /// + /// ParserHelper for use by the extension. + /// + protected IPreprocessHelper PreprocessHelper { get; private set; } + + /// + /// Gets or sets the variable prefixes for the extension. + /// + /// The variable prefixes for the extension. + public string[] Prefixes { get; protected set; } + + /// + /// Called at the beginning of the preprocessing of a source file. + /// + public virtual void PrePreprocess(IPreprocessContext context) + { + this.Context = context; + + this.PreprocessHelper = context.ServiceProvider.GetService(); + } + + /// + /// Gets the value of a variable whose prefix matches the extension. + /// + /// The prefix of the variable to be processed by the extension. + /// The name of the variable. + /// The value of the variable or null if the variable is undefined. + public virtual string GetVariableValue(string prefix, string name) + { + return null; + } + + /// + /// Evaluates a function defined in the extension. + /// + /// The prefix of the function to be processed by the extension. + /// The name of the function. + /// The list of arguments. + /// The value of the function or null if the function is not defined. + public virtual string EvaluateFunction(string prefix, string function, string[] args) + { + return null; + } + + /// + /// Processes a pragma defined in the extension. + /// + /// The location of this pragma's PI. + /// The prefix of the pragma to be processed by the extension. + /// The name of the pragma. + /// The pragma's arguments. + /// The parent node of the pragma. + /// false if the pragma is not defined. + /// Don't return false for any condition except for unrecognized pragmas. Throw errors that are fatal to the compile. use core.OnMessage for warnings and messages. + public virtual bool ProcessPragma(string prefix, string pragma, string args, XContainer parent) + { + return false; + } + + /// + /// Called at the end of the preprocessing of a source file. + /// + public virtual void PostPreprocess(XDocument document) + { + } + } +} diff --git a/src/WixToolset.Extensibility/IExtensionCommandLine.cs b/src/WixToolset.Extensibility/IExtensionCommandLine.cs index b6cff5d0..1f8e6ed8 100644 --- a/src/WixToolset.Extensibility/IExtensionCommandLine.cs +++ b/src/WixToolset.Extensibility/IExtensionCommandLine.cs @@ -3,7 +3,7 @@ namespace WixToolset.Extensibility { using System.Collections.Generic; - using WixToolset.Data; + using WixToolset.Extensibility.Services; /// /// A command line option. @@ -20,23 +20,14 @@ namespace WixToolset.Extensibility /// public interface IExtensionCommandLine { - /// - /// Sets the message handler for the extension. - /// - /// Message handler for the extension. - IMessageHandler MessageHandler { set; } - /// /// Gets the supported command line types for this extension. /// /// The supported command line types for this extension. IEnumerable CommandLineSwitches { get; } - /// - /// Parse the commandline arguments. - /// - /// Commandline arguments. - /// Unparsed commandline arguments. - string[] ParseCommandLine(string[] args); + void PreParse(ICommandLineContext context); + + bool TryParseArgument(IParseCommandLine parseCommandLine, string arg); } } diff --git a/src/WixToolset.Extensibility/IExtensionData.cs b/src/WixToolset.Extensibility/IExtensionData.cs index f0e339d4..1721a76c 100644 --- a/src/WixToolset.Extensibility/IExtensionData.cs +++ b/src/WixToolset.Extensibility/IExtensionData.cs @@ -26,8 +26,8 @@ namespace WixToolset.Extensibility /// /// Gets the library associated with this extension. /// - /// The table definitions to use while loading the library. + /// The tuple definitions to use while loading the library. /// The library for this extension or null if there is no library. - Library GetLibrary(ITupleDefinitionCreator tupleDefinitions); + Intermediate GetLibrary(ITupleDefinitionCreator tupleDefinitions); } } diff --git a/src/WixToolset.Extensibility/IPreprocessContext.cs b/src/WixToolset.Extensibility/IPreprocessContext.cs new file mode 100644 index 00000000..0f9c90bf --- /dev/null +++ b/src/WixToolset.Extensibility/IPreprocessContext.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 WixToolset.Extensibility +{ + using System; + using System.Collections.Generic; + using WixToolset.Data; + + public interface IPreprocessContext + { + IServiceProvider ServiceProvider { get; } + + Messaging Messaging { get; set; } + + IEnumerable Extensions { get; set; } + + /// + /// Gets 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. + Platform Platform { get; set; } + + IList IncludeSearchPaths { get; set; } + + string SourceFile { get; set; } + + IDictionary Variables { get; set; } + + SourceLineNumber CurrentSourceLineNumber { get; set; } + } +} diff --git a/src/WixToolset.Extensibility/IPreprocessorCore.cs b/src/WixToolset.Extensibility/IPreprocessorCore.cs deleted file mode 100644 index a0449139..00000000 --- a/src/WixToolset.Extensibility/IPreprocessorCore.cs +++ /dev/null @@ -1,21 +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 WixToolset.Extensibility -{ - using WixToolset.Data; - - public interface IPreprocessorCore : IMessageHandler - { - /// - /// 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. - Platform CurrentPlatform { get; } - - /// - /// Gets whether the core encountered an error while processing. - /// - /// Flag if core encountered an error during processing. - bool EncounteredError { get; } - } -} diff --git a/src/WixToolset.Extensibility/IPreprocessorExtension.cs b/src/WixToolset.Extensibility/IPreprocessorExtension.cs index de415526..8511abbc 100644 --- a/src/WixToolset.Extensibility/IPreprocessorExtension.cs +++ b/src/WixToolset.Extensibility/IPreprocessorExtension.cs @@ -11,12 +11,6 @@ namespace WixToolset.Extensibility /// public interface IPreprocessorExtension { - /// - /// Gets or sets the preprocessor core for the extension. - /// - /// Preprocessor core for the extension. - IPreprocessorCore Core { get; set; } - /// /// Gets the variable prefixes for the extension. /// @@ -26,7 +20,7 @@ namespace WixToolset.Extensibility /// /// Called at the beginning of the preprocessing of a source file. /// - void Initialize(); + void PrePreprocess(IPreprocessContext context); /// /// Gets the value of a variable whose prefix matches the extension. @@ -55,25 +49,11 @@ namespace WixToolset.Extensibility /// The parent node of the pragma. /// false if the pragma is not defined. /// Don't return false for any condition except for unrecognized pragmas. Use Core.OnMessage for errors, warnings and messages. - bool ProcessPragma(SourceLineNumber sourceLineNumbers, string prefix, string pragma, string args, XContainer parent); - - /// - /// Preprocess a document after normal preprocessing has completed. - /// - /// The document to preprocess. - void PreprocessDocument(XDocument document); - - /// - /// Preprocesses a parameter. - /// - /// Name of parameter that matches extension. - /// The value of the parameter after processing. - /// By default this method will cause an error if its called. - string PreprocessParameter(string name); + bool ProcessPragma(string prefix, string pragma, string args, XContainer parent); /// /// Called at the end of the preprocessing of a source file. /// - void Finish(); + void PostPreprocess(XDocument document); } } diff --git a/src/WixToolset.Extensibility/PreprocessorExtension.cs b/src/WixToolset.Extensibility/PreprocessorExtension.cs deleted file mode 100644 index 2af30a95..00000000 --- a/src/WixToolset.Extensibility/PreprocessorExtension.cs +++ /dev/null @@ -1,99 +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 WixToolset.Extensibility -{ - using System.Xml.Linq; - using WixToolset.Data; - - /// - /// Base class for creating a preprocessor extension. - /// - public abstract class PreprocessorExtension : IPreprocessorExtension - { - /// - /// Gets or sets the preprocessor core for the extension. - /// - /// Preprocessor core for the extension. - public IPreprocessorCore Core { get; set; } - - /// - /// Gets or sets the variable prefixes for the extension. - /// - /// The variable prefixes for the extension. - public virtual string[] Prefixes - { - get { return null; } - } - - /// - /// Called at the beginning of the preprocessing of a source file. - /// - public virtual void Initialize() - { - } - - /// - /// Gets the value of a variable whose prefix matches the extension. - /// - /// The prefix of the variable to be processed by the extension. - /// The name of the variable. - /// The value of the variable or null if the variable is undefined. - public virtual string GetVariableValue(string prefix, string name) - { - return null; - } - - /// - /// Evaluates a function defined in the extension. - /// - /// The prefix of the function to be processed by the extension. - /// The name of the function. - /// The list of arguments. - /// The value of the function or null if the function is not defined. - public virtual string EvaluateFunction(string prefix, string function, string[] args) - { - return null; - } - - /// - /// Processes a pragma defined in the extension. - /// - /// The location of this pragma's PI. - /// The prefix of the pragma to be processed by the extension. - /// The name of the pragma. - /// The pragma's arguments. - /// The parent node of the pragma. - /// false if the pragma is not defined. - /// Don't return false for any condition except for unrecognized pragmas. Throw errors that are fatal to the compile. use core.OnMessage for warnings and messages. - public virtual bool ProcessPragma(SourceLineNumber sourceLineNumbers, string prefix, string pragma, string args, XContainer parent) - { - return false; - } - - /// - /// Preprocess a document after normal preprocessing has completed. - /// - /// The document to preprocess. - public virtual void PreprocessDocument(XDocument document) - { - } - - /// - /// Preprocesses a parameter. - /// - /// Name of parameter that matches extension. - /// The value of the parameter after processing. - /// By default this method will cause an error if its called. - public virtual string PreprocessParameter(string name) - { - return null; - } - - /// - /// Called at the end of the preprocessing of a source file. - /// - public virtual void Finish() - { - } - } -} diff --git a/src/WixToolset.Extensibility/Services/IParseCommandLine.cs b/src/WixToolset.Extensibility/Services/IParseCommandLine.cs new file mode 100644 index 00000000..1b23be14 --- /dev/null +++ b/src/WixToolset.Extensibility/Services/IParseCommandLine.cs @@ -0,0 +1,21 @@ +// 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.Extensibility.Services +{ + using System.Collections.Generic; + + public interface IParseCommandLine + { + bool IsSwitch(string arg); + + bool IsSwitchAt(IEnumerable args, int index); + + void GetNextArgumentOrError(ref string arg); + + void GetNextArgumentOrError(IList args); + + void GetNextArgumentAsFilePathOrError(IList args, string fileType); + + bool TryGetNextArgumentOrError(out string arg); + } +} diff --git a/src/WixToolset.Extensibility/Services/IParseHelper.cs b/src/WixToolset.Extensibility/Services/IParseHelper.cs index 46ade2e1..ad15c063 100644 --- a/src/WixToolset.Extensibility/Services/IParseHelper.cs +++ b/src/WixToolset.Extensibility/Services/IParseHelper.cs @@ -8,7 +8,7 @@ namespace WixToolset.Extensibility.Services using WixToolset.Data; /// - /// Core interface provided by the compiler. + /// Interface provided to help compiler extensions parse. /// public interface IParseHelper { @@ -242,6 +242,13 @@ namespace WixToolset.Extensibility.Services /// The attribute's YesNoType value. YesNoDefaultType GetAttributeYesNoDefaultValue(SourceLineNumber sourceLineNumbers, XAttribute attribute); + /// + /// Gets a source line number for an element. + /// + /// Element to get source line number. + /// Source line number. + SourceLineNumber GetSourceLineNumbers(XElement element); + /// /// Gets node's inner text and ensure's it is safe for use in a condition by trimming any extra whitespace. /// diff --git a/src/WixToolset.Extensibility/Services/IPreprocessHelper.cs b/src/WixToolset.Extensibility/Services/IPreprocessHelper.cs new file mode 100644 index 00000000..01c55009 --- /dev/null +++ b/src/WixToolset.Extensibility/Services/IPreprocessHelper.cs @@ -0,0 +1,89 @@ +// 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.Extensibility.Services +{ + using System.Xml.Linq; + + /// + /// Interface provided to help preprocessor extensions. + /// + public interface IPreprocessHelper + { + /// + /// Add a variable. + /// + /// The preprocess context. + /// The variable name. + /// The variable value. + void AddVariable(IPreprocessContext context, string name, string value); + + /// + /// Add a variable. + /// + /// The preprocess context. + /// The variable name. + /// The variable value. + /// Set to true to show variable overwrite warning. + void AddVariable(IPreprocessContext context, string name, string value, bool showWarning); + + /// + /// Evaluate a function. + /// + /// The preprocess context. + /// The function expression including the prefix and name. + /// The function value. + string EvaluateFunction(IPreprocessContext context, string function); + + /// + /// Evaluate a function. + /// + /// The preprocess context. + /// The function prefix. + /// The function name. + /// The arguments for the function. + /// The function value or null if the function is not defined. + string EvaluateFunction(IPreprocessContext context, string prefix, string function, string[] args); + + /// + /// Get the value of a variable expression like var.name. + /// + /// The preprocess context. + /// The variable expression including the optional prefix and name. + /// true to allow the variable prefix to be missing. + /// The variable value. + string GetVariableValue(IPreprocessContext context, string variable, bool allowMissingPrefix); + + /// + /// Get the value of a variable. + /// + /// The preprocess context. + /// The variable prefix. + /// The variable name. + /// The variable value or null if the variable is not set. + string GetVariableValue(IPreprocessContext context, string prefix, string name); + + /// + /// Evaluate a Pragma. + /// + /// The preprocess context. + /// The pragma's full name (.). + /// The arguments to the pragma. + /// The parent element of the pragma. + void PreprocessPragma(IPreprocessContext context, string pragmaName, string args, XContainer parent); + + /// + /// Replaces parameters in the source text. + /// + /// The preprocess context. + /// Text that may contain parameters to replace. + /// Text after parameters have been replaced. + string PreprocessString(IPreprocessContext context, string value); + + /// + /// Remove a variable. + /// + /// The preprocess context. + /// The variable name. + void RemoveVariable(IPreprocessContext context, string name); + } +} -- cgit v1.2.3-55-g6feb