Fix IExtensionCommandLine and IPreprocessorExtension
Rob Mensching committed
Dec 2, 2017 at 00:45 UTC
fb2df0e24c0709ce94c396624cf86c70e02da01f
11 files changed
+184
-92
src/Directory.Build.props
+3
-1
@@ -5,11 +5,13 @@
5
<PropertyGroup>
6
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
7
<BaseIntermediateOutputPath>$(MSBuildThisFileDirectory)..\build\obj\$(MSBuildProjectName)\</BaseIntermediateOutputPath>
8
- <OutputPath>$(MSBuildThisFileDirectory)..\build\$(Configuration)\</OutputPath>
8
+ <BaseOutputPath>$(MSBuildThisFileDirectory)..\build\$(Configuration)\</BaseOutputPath>
9
+ <OutputPath>$(BaseOutputPath)</OutputPath>
10
11
<Authors>WiX Toolset Team</Authors>
12
<Company>WiX Toolset</Company>
13
<Copyright>Copyright (c) .NET Foundation and contributors. All rights reserved.</Copyright>
14
+ <Product>WiX Toolset</Product>
15
</PropertyGroup>
16
17
<PropertyGroup>
src/WixToolset.Extensibility/BaseCompilerExtension.cs
+7
@@ -12,6 +12,11 @@ namespace WixToolset.Extensibility
12
/// </summary>
13
public abstract class BaseCompilerExtension : ICompilerExtension
14
{
15
+ /// <summary>
16
+ /// Messaging for use by the extension.
17
+ /// </summary>
18
+ protected Messaging Messaging { get; private set; }
19
+
20
/// <summary>
21
/// ParserHelper for use by the extension.
22
/// </summary>
@@ -28,6 +33,8 @@ namespace WixToolset.Extensibility
33
/// </summary>
34
public virtual void PreCompile(ICompileContext context)
35
{
36
+ this.Messaging = context.Messaging;
37
+
38
this.ParseHelper = context.ServiceProvider.GetService<IParseHelper>();
39
}
40
src/WixToolset.Extensibility/BasePreprocessorExtension.cs
renamed
+16
-31
@@ -3,33 +3,37 @@
3
namespace WixToolset.Extensibility
4
{
5
using System.Xml.Linq;
6
- using WixToolset.Data;
6
+ using WixToolset.Extensibility.Services;
7
8
/// <summary>
9
/// Base class for creating a preprocessor extension.
10
/// </summary>
11
- public abstract class PreprocessorExtension : IPreprocessorExtension
11
+ public abstract class BasePreprocessorExtension : IPreprocessorExtension
12
{
13
/// <summary>
14
- /// Gets or sets the preprocessor core for the extension.
14
+ /// Context for use by the extension.
15
/// </summary>
16
- /// <value>Preprocessor core for the extension.</value>
17
- public IPreprocessorCore Core { get; set; }
16
+ protected IPreprocessContext Context { get; private set; }
17
+
18
+ /// <summary>
19
+ /// ParserHelper for use by the extension.
20
+ /// </summary>
21
+ protected IPreprocessHelper PreprocessHelper { get; private set; }
22
23
/// <summary>
24
/// Gets or sets the variable prefixes for the extension.
25
/// </summary>
26
/// <value>The variable prefixes for the extension.</value>
23
- public virtual string[] Prefixes
24
- {
25
- get { return null; }
26
- }
27
+ public string[] Prefixes { get; protected set; }
28
29
/// <summary>
30
/// Called at the beginning of the preprocessing of a source file.
31
/// </summary>
31
- public virtual void Initialize()
32
+ public virtual void PrePreprocess(IPreprocessContext context)
33
{
34
+ this.Context = context;
35
+
36
+ this.PreprocessHelper = context.ServiceProvider.GetService<IPreprocessHelper>();
37
}
38
39
/// <summary>
@@ -65,34 +69,15 @@ namespace WixToolset.Extensibility
69
/// <param name="parent">The parent node of the pragma.</param>
70
/// <returns>false if the pragma is not defined.</returns>
71
/// <comments>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.</comments>
68
- public virtual bool ProcessPragma(SourceLineNumber sourceLineNumbers, string prefix, string pragma, string args, XContainer parent)
72
+ public virtual bool ProcessPragma(string prefix, string pragma, string args, XContainer parent)
73
{
74
return false;
75
}
76
73
- /// <summary>
74
- /// Preprocess a document after normal preprocessing has completed.
75
- /// </summary>
76
- /// <param name="document">The document to preprocess.</param>
77
- public virtual void PreprocessDocument(XDocument document)
78
- {
79
- }
80
-
81
- /// <summary>
82
- /// Preprocesses a parameter.
83
- /// </summary>
84
- /// <param name="name">Name of parameter that matches extension.</param>
85
- /// <returns>The value of the parameter after processing.</returns>
86
- /// <remarks>By default this method will cause an error if its called.</remarks>
87
- public virtual string PreprocessParameter(string name)
88
- {
89
- return null;
90
- }
91
-
77
/// <summary>
78
/// Called at the end of the preprocessing of a source file.
79
/// </summary>
95
- public virtual void Finish()
80
+ public virtual void PostPreprocess(XDocument document)
81
{
82
}
83
}
src/WixToolset.Extensibility/IExtensionCommandLine.cs
+4
-13
@@ -3,7 +3,7 @@
3
namespace WixToolset.Extensibility
4
{
5
using System.Collections.Generic;
6
- using WixToolset.Data;
6
+ using WixToolset.Extensibility.Services;
7
8
/// <summary>
9
/// A command line option.
@@ -20,23 +20,14 @@ namespace WixToolset.Extensibility
20
/// </summary>
21
public interface IExtensionCommandLine
22
{
23
- /// <summary>
24
- /// Sets the message handler for the extension.
25
- /// </summary>
26
- /// <value>Message handler for the extension.</value>
27
- IMessageHandler MessageHandler { set; }
28
-
23
/// <summary>
24
/// Gets the supported command line types for this extension.
25
/// </summary>
26
/// <value>The supported command line types for this extension.</value>
27
IEnumerable<ExtensionCommandLineSwitch> CommandLineSwitches { get; }
28
35
- /// <summary>
36
- /// Parse the commandline arguments.
37
- /// </summary>
38
- /// <param name="args">Commandline arguments.</param>
39
- /// <returns>Unparsed commandline arguments.</returns>
40
- string[] ParseCommandLine(string[] args);
29
+ void PreParse(ICommandLineContext context);
30
+
31
+ bool TryParseArgument(IParseCommandLine parseCommandLine, string arg);
32
}
33
}
src/WixToolset.Extensibility/IExtensionData.cs
+2
-2
@@ -26,8 +26,8 @@ namespace WixToolset.Extensibility
26
/// <summary>
27
/// Gets the library associated with this extension.
28
/// </summary>
29
- /// <param name="tableDefinitions">The table definitions to use while loading the library.</param>
29
+ /// <param name="tupleDefinitions">The tuple definitions to use while loading the library.</param>
30
/// <returns>The library for this extension or null if there is no library.</returns>
31
- Library GetLibrary(ITupleDefinitionCreator tupleDefinitions);
31
+ Intermediate GetLibrary(ITupleDefinitionCreator tupleDefinitions);
32
}
33
}
src/WixToolset.Extensibility/IPreprocessContext.cs
new
+31
@@ -0,0 +1,31 @@
1
+// 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.
2
+
3
+namespace WixToolset.Extensibility
4
+{
5
+ using System;
6
+ using System.Collections.Generic;
7
+ using WixToolset.Data;
8
+
9
+ public interface IPreprocessContext
10
+ {
11
+ IServiceProvider ServiceProvider { get; }
12
+
13
+ Messaging Messaging { get; set; }
14
+
15
+ IEnumerable<IPreprocessorExtension> Extensions { get; set; }
16
+
17
+ /// <summary>
18
+ /// Gets the platform which the compiler will use when defaulting 64-bit attributes and elements.
19
+ /// </summary>
20
+ /// <value>The platform which the compiler will use when defaulting 64-bit attributes and elements.</value>
21
+ Platform Platform { get; set; }
22
+
23
+ IList<string> IncludeSearchPaths { get; set; }
24
+
25
+ string SourceFile { get; set; }
26
+
27
+ IDictionary<string, string> Variables { get; set; }
28
+
29
+ SourceLineNumber CurrentSourceLineNumber { get; set; }
30
+ }
31
+}
src/WixToolset.Extensibility/IPreprocessorCore.cs
deleted
-21
@@ -1,21 +0,0 @@
1
-// 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.
2
-
3
-namespace WixToolset.Extensibility
4
-{
5
- using WixToolset.Data;
6
-
7
- public interface IPreprocessorCore : IMessageHandler
8
- {
9
- /// <summary>
10
- /// Gets or sets the platform which the compiler will use when defaulting 64-bit attributes and elements.
11
- /// </summary>
12
- /// <value>The platform which the compiler will use when defaulting 64-bit attributes and elements.</value>
13
- Platform CurrentPlatform { get; }
14
-
15
- /// <summary>
16
- /// Gets whether the core encountered an error while processing.
17
- /// </summary>
18
- /// <value>Flag if core encountered an error during processing.</value>
19
- bool EncounteredError { get; }
20
- }
21
-}
src/WixToolset.Extensibility/IPreprocessorExtension.cs
+3
-23
@@ -11,12 +11,6 @@ namespace WixToolset.Extensibility
11
/// </summary>
12
public interface IPreprocessorExtension
13
{
14
- /// <summary>
15
- /// Gets or sets the preprocessor core for the extension.
16
- /// </summary>
17
- /// <value>Preprocessor core for the extension.</value>
18
- IPreprocessorCore Core { get; set; }
19
-
14
/// <summary>
15
/// Gets the variable prefixes for the extension.
16
/// </summary>
@@ -26,7 +20,7 @@ namespace WixToolset.Extensibility
20
/// <summary>
21
/// Called at the beginning of the preprocessing of a source file.
22
/// </summary>
29
- void Initialize();
23
+ void PrePreprocess(IPreprocessContext context);
24
25
/// <summary>
26
/// Gets the value of a variable whose prefix matches the extension.
@@ -55,25 +49,11 @@ namespace WixToolset.Extensibility
49
/// <param name="parent">The parent node of the pragma.</param>
50
/// <returns>false if the pragma is not defined.</returns>
51
/// <comments>Don't return false for any condition except for unrecognized pragmas. Use Core.OnMessage for errors, warnings and messages.</comments>
58
- bool ProcessPragma(SourceLineNumber sourceLineNumbers, string prefix, string pragma, string args, XContainer parent);
59
-
60
- /// <summary>
61
- /// Preprocess a document after normal preprocessing has completed.
62
- /// </summary>
63
- /// <param name="document">The document to preprocess.</param>
64
- void PreprocessDocument(XDocument document);
65
-
66
- /// <summary>
67
- /// Preprocesses a parameter.
68
- /// </summary>
69
- /// <param name="name">Name of parameter that matches extension.</param>
70
- /// <returns>The value of the parameter after processing.</returns>
71
- /// <remarks>By default this method will cause an error if its called.</remarks>
72
- string PreprocessParameter(string name);
52
+ bool ProcessPragma(string prefix, string pragma, string args, XContainer parent);
53
54
/// <summary>
55
/// Called at the end of the preprocessing of a source file.
56
/// </summary>
77
- void Finish();
57
+ void PostPreprocess(XDocument document);
58
}
59
}
src/WixToolset.Extensibility/Services/IParseCommandLine.cs
new
+21
@@ -0,0 +1,21 @@
1
+// 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.
2
+
3
+namespace WixToolset.Extensibility.Services
4
+{
5
+ using System.Collections.Generic;
6
+
7
+ public interface IParseCommandLine
8
+ {
9
+ bool IsSwitch(string arg);
10
+
11
+ bool IsSwitchAt(IEnumerable<string> args, int index);
12
+
13
+ void GetNextArgumentOrError(ref string arg);
14
+
15
+ void GetNextArgumentOrError(IList<string> args);
16
+
17
+ void GetNextArgumentAsFilePathOrError(IList<string> args, string fileType);
18
+
19
+ bool TryGetNextArgumentOrError(out string arg);
20
+ }
21
+}
src/WixToolset.Extensibility/Services/IParseHelper.cs
+8
-1
@@ -8,7 +8,7 @@ namespace WixToolset.Extensibility.Services
8
using WixToolset.Data;
9
10
/// <summary>
11
- /// Core interface provided by the compiler.
11
+ /// Interface provided to help compiler extensions parse.
12
/// </summary>
13
public interface IParseHelper
14
{
@@ -242,6 +242,13 @@ namespace WixToolset.Extensibility.Services
242
/// <returns>The attribute's YesNoType value.</returns>
243
YesNoDefaultType GetAttributeYesNoDefaultValue(SourceLineNumber sourceLineNumbers, XAttribute attribute);
244
245
+ /// <summary>
246
+ /// Gets a source line number for an element.
247
+ /// </summary>
248
+ /// <param name="element">Element to get source line number.</param>
249
+ /// <returns>Source line number.</returns>
250
+ SourceLineNumber GetSourceLineNumbers(XElement element);
251
+
252
/// <summary>
253
/// Gets node's inner text and ensure's it is safe for use in a condition by trimming any extra whitespace.
254
/// </summary>
src/WixToolset.Extensibility/Services/IPreprocessHelper.cs
new
+89
@@ -0,0 +1,89 @@
1
+// 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.
2
+
3
+namespace WixToolset.Extensibility.Services
4
+{
5
+ using System.Xml.Linq;
6
+
7
+ /// <summary>
8
+ /// Interface provided to help preprocessor extensions.
9
+ /// </summary>
10
+ public interface IPreprocessHelper
11
+ {
12
+ /// <summary>
13
+ /// Add a variable.
14
+ /// </summary>
15
+ /// <param name="context">The preprocess context.</param>
16
+ /// <param name="name">The variable name.</param>
17
+ /// <param name="value">The variable value.</param>
18
+ void AddVariable(IPreprocessContext context, string name, string value);
19
+
20
+ /// <summary>
21
+ /// Add a variable.
22
+ /// </summary>
23
+ /// <param name="context">The preprocess context.</param>
24
+ /// <param name="name">The variable name.</param>
25
+ /// <param name="value">The variable value.</param>
26
+ /// <param name="overwrite">Set to true to show variable overwrite warning.</param>
27
+ void AddVariable(IPreprocessContext context, string name, string value, bool showWarning);
28
+
29
+ /// <summary>
30
+ /// Evaluate a function.
31
+ /// </summary>
32
+ /// <param name="context">The preprocess context.</param>
33
+ /// <param name="function">The function expression including the prefix and name.</param>
34
+ /// <returns>The function value.</returns>
35
+ string EvaluateFunction(IPreprocessContext context, string function);
36
+
37
+ /// <summary>
38
+ /// Evaluate a function.
39
+ /// </summary>
40
+ /// <param name="context">The preprocess context.</param>
41
+ /// <param name="prefix">The function prefix.</param>
42
+ /// <param name="function">The function name.</param>
43
+ /// <param name="args">The arguments for the function.</param>
44
+ /// <returns>The function value or null if the function is not defined.</returns>
45
+ string EvaluateFunction(IPreprocessContext context, string prefix, string function, string[] args);
46
+
47
+ /// <summary>
48
+ /// Get the value of a variable expression like var.name.
49
+ /// </summary>
50
+ /// <param name="context">The preprocess context.</param>
51
+ /// <param name="variable">The variable expression including the optional prefix and name.</param>
52
+ /// <param name="allowMissingPrefix">true to allow the variable prefix to be missing.</param>
53
+ /// <returns>The variable value.</returns>
54
+ string GetVariableValue(IPreprocessContext context, string variable, bool allowMissingPrefix);
55
+
56
+ /// <summary>
57
+ /// Get the value of a variable.
58
+ /// </summary>
59
+ /// <param name="context">The preprocess context.</param>
60
+ /// <param name="prefix">The variable prefix.</param>
61
+ /// <param name="name">The variable name.</param>
62
+ /// <returns>The variable value or null if the variable is not set.</returns>
63
+ string GetVariableValue(IPreprocessContext context, string prefix, string name);
64
+
65
+ /// <summary>
66
+ /// Evaluate a Pragma.
67
+ /// </summary>
68
+ /// <param name="context">The preprocess context.</param>
69
+ /// <param name="pragmaName">The pragma's full name (<prefix>.<pragma>).</param>
70
+ /// <param name="args">The arguments to the pragma.</param>
71
+ /// <param name="parent">The parent element of the pragma.</param>
72
+ void PreprocessPragma(IPreprocessContext context, string pragmaName, string args, XContainer parent);
73
+
74
+ /// <summary>
75
+ /// Replaces parameters in the source text.
76
+ /// </summary>
77
+ /// <param name="context">The preprocess context.</param>
78
+ /// <param name="value">Text that may contain parameters to replace.</param>
79
+ /// <returns>Text after parameters have been replaced.</returns>
80
+ string PreprocessString(IPreprocessContext context, string value);
81
+
82
+ /// <summary>
83
+ /// Remove a variable.
84
+ /// </summary>
85
+ /// <param name="context">The preprocess context.</param>
86
+ /// <param name="name">The variable name.</param>
87
+ void RemoveVariable(IPreprocessContext context, string name);
88
+ }
89
+}