Remove ICompilerCore, introduce IParseHelper and other small fixes
Rob Mensching committed
Nov 14, 2017 at 23:08 UTC
404f34f00ecce034a8a06fe4757789c6ce62f3f6
7 files changed
+77
-122
src/WixToolset.Extensibility/BaseCompilerExtension.cs
renamed
+11
-10
@@ -5,17 +5,17 @@ namespace WixToolset.Extensibility
5
using System.Collections.Generic;
6
using System.Xml.Linq;
7
using WixToolset.Data;
8
+ using WixToolset.Extensibility.Services;
9
10
/// <summary>
11
/// Base class for creating a compiler extension.
12
/// </summary>
12
- public abstract class CompilerExtension : ICompilerExtension
13
+ public abstract class BaseCompilerExtension : ICompilerExtension
14
{
15
/// <summary>
15
- /// Gets or sets the compiler core for the extension.
16
+ /// ParserHelper for use by the extension.
17
/// </summary>
17
- /// <value>Compiler core for the extension.</value>
18
- public ICompilerCore Core { get; set; }
18
+ protected IParseHelper ParseHelper { get; private set; }
19
20
/// <summary>
21
/// Gets the schema namespace for this extension.
@@ -28,6 +28,7 @@ namespace WixToolset.Extensibility
28
/// </summary>
29
public virtual void PreCompile(ICompileContext context)
30
{
31
+ this.ParseHelper = context.ServiceProvider.GetService<IParseHelper>();
32
}
33
34
/// <summary>
@@ -36,9 +37,9 @@ namespace WixToolset.Extensibility
37
/// <param name="parentElement">Parent element of attribute.</param>
38
/// <param name="attribute">Attribute to process.</param>
39
/// <param name="context">Extra information about the context in which this element is being parsed.</param>
39
- public virtual void ParseAttribute(XElement parentElement, XAttribute attribute, IDictionary<string, string> context)
40
+ public virtual void ParseAttribute(Intermediate intermediate, IntermediateSection section, XElement parentElement, XAttribute attribute, IDictionary<string, string> context)
41
{
41
- this.Core.UnexpectedAttribute(parentElement, attribute);
42
+ this.ParseHelper.UnexpectedAttribute(parentElement, attribute);
43
}
44
45
/// <summary>
@@ -47,9 +48,9 @@ namespace WixToolset.Extensibility
48
/// <param name="parentElement">Parent element of element to process.</param>
49
/// <param name="element">Element to process.</param>
50
/// <param name="contextValues">Extra information about the context in which this element is being parsed.</param>
50
- public virtual void ParseElement(XElement parentElement, XElement element, IDictionary<string, string> context)
51
+ public virtual void ParseElement(Intermediate intermediate, IntermediateSection section, XElement parentElement, XElement element, IDictionary<string, string> context)
52
{
52
- this.Core.UnexpectedElement(parentElement, element);
53
+ this.ParseHelper.UnexpectedElement(parentElement, element);
54
}
55
56
/// <summary>
@@ -59,9 +60,9 @@ namespace WixToolset.Extensibility
60
/// <param name="element">Element to process.</param>
61
/// <param name="keyPath">Explicit key path.</param>
62
/// <param name="contextValues">Extra information about the context in which this element is being parsed.</param>
62
- public virtual ComponentKeyPath ParsePossibleKeyPathElement(XElement parentElement, XElement element, IDictionary<string, string> context)
63
+ public virtual ComponentKeyPath ParsePossibleKeyPathElement(Intermediate intermediate, IntermediateSection section, XElement parentElement, XElement element, IDictionary<string, string> context)
64
{
64
- this.ParseElement(parentElement, element, context);
65
+ this.ParseElement(intermediate, section, parentElement, element, context);
66
return null;
67
}
68
src/WixToolset.Extensibility/CompilerConstants.cs
+1
-1
@@ -1,6 +1,6 @@
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
3
+namespace WixToolset.Extensibility
4
{
5
using System;
6
src/WixToolset.Extensibility/ComponentKeyPath.cs
-2
@@ -2,8 +2,6 @@
2
3
namespace WixToolset.Extensibility
4
{
5
- using System;
6
-
5
public enum ComponentKeyPathType
6
{
7
/// <summary>
src/WixToolset.Extensibility/IBinderCore.cs
deleted
-35
@@ -1,35 +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 IBinderCore : IMessageHandler
8
- {
9
- /// <summary>
10
- /// Gets or sets the file manager core for the extension.
11
- /// </summary>
12
- /// <value>File manager core for the extension.</value>
13
- IBinderFileManagerCore FileManagerCore { get; set; }
14
-
15
- /// <summary>
16
- /// Gets whether the binder 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
- /// <summary>
22
- /// Gets the table definitions used by the Binder.
23
- /// </summary>
24
- /// <value>Table definitions used by the binder.</value>
25
- //TableDefinitionCollection TableDefinitions { get; }
26
-
27
- /// <summary>
28
- /// Generate an identifier by hashing data from the row.
29
- /// </summary>
30
- /// <param name="prefix">Three letter or less prefix for generated row identifier.</param>
31
- /// <param name="args">Information to hash.</param>
32
- /// <returns>The generated identifier.</returns>
33
- string CreateIdentifier(string prefix, params string[] args);
34
- }
35
-}
src/WixToolset.Extensibility/ICompileContext.cs
+4
@@ -19,6 +19,10 @@ namespace WixToolset.Extensibility
19
20
string OutputPath { get; set; }
21
22
+ /// <summary>
23
+ /// Gets or sets the platform which the compiler will use when defaulting 64-bit attributes and elements.
24
+ /// </summary>
25
+ /// <value>The platform which the compiler will use when defaulting 64-bit attributes and elements.</value>
26
Platform Platform { get; set; }
27
28
XDocument Source { get; set; }
src/WixToolset.Extensibility/ICompilerExtension.cs
+3
-11
@@ -5,20 +5,12 @@ namespace WixToolset.Extensibility
5
using System.Collections.Generic;
6
using System.Xml.Linq;
7
using WixToolset.Data;
8
- using WixToolset.Extensibility.Services;
8
9
/// <summary>
10
/// Interface all compiler extensions implement.
11
/// </summary>
12
public interface ICompilerExtension
13
{
15
-#if false
16
- /// <summary>
17
- /// Gets or sets the compiler core for the extension.
18
- /// </summary>
19
- /// <value>Compiler core for the extension.</value>
20
- ICompilerCore Core { get; set; }
21
-#endif
14
/// <summary>
15
/// Gets the schema namespace for this extension.
16
/// </summary>
@@ -36,7 +28,7 @@ namespace WixToolset.Extensibility
28
/// <param name="parentElement">Parent element of attribute.</param>
29
/// <param name="attribute">Attribute to process.</param>
30
/// <param name="context">Extra information about the context in which this element is being parsed.</param>
39
- void ParseAttribute(XElement parentElement, XAttribute attribute, IDictionary<string, string> context);
31
+ void ParseAttribute(Intermediate intermediate, IntermediateSection section, XElement parentElement, XAttribute attribute, IDictionary<string, string> context);
32
33
/// <summary>
34
/// Processes an element for the Compiler.
@@ -44,7 +36,7 @@ namespace WixToolset.Extensibility
36
/// <param name="parentElement">Parent element of element to process.</param>
37
/// <param name="element">Element to process.</param>
38
/// <param name="context">Extra information about the context in which this element is being parsed.</param>
47
- void ParseElement(XElement parentElement, XElement element, IDictionary<string, string> context);
39
+ void ParseElement(Intermediate intermediate, IntermediateSection section, XElement parentElement, XElement element, IDictionary<string, string> context);
40
41
/// <summary>
42
/// Processes an element for the Compiler, with the ability to supply a component keypath.
@@ -52,7 +44,7 @@ namespace WixToolset.Extensibility
44
/// <param name="parentElement">Parent element of element to process.</param>
45
/// <param name="element">Element to process.</param>
46
/// <param name="contextValues">Extra information about the context in which this element is being parsed.</param>
55
- ComponentKeyPath ParsePossibleKeyPathElement(XElement parentElement, XElement element, IDictionary<string, string> context);
47
+ ComponentKeyPath ParsePossibleKeyPathElement(Intermediate intermediate, IntermediateSection section, XElement parentElement, XElement element, IDictionary<string, string> context);
48
49
/// <summary>
50
/// Called at the end of the compilation of a source file.
src/WixToolset.Extensibility/Services/IParseHelper.cs
renamed
+58
-63
@@ -1,9 +1,8 @@
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
3
+namespace WixToolset.Extensibility.Services
4
{
5
using System;
6
- using System.Collections;
6
using System.Collections.Generic;
7
using System.Xml.Linq;
8
using WixToolset.Data;
@@ -11,20 +10,8 @@ namespace WixToolset.Extensibility
10
/// <summary>
11
/// Core interface provided by the compiler.
12
/// </summary>
14
- public interface ICompilerCore : IMessageHandler
13
+ public interface IParseHelper
14
{
16
- /// <summary>
17
- /// Gets whether the compiler core encountered an error while processing.
18
- /// </summary>
19
- /// <value>Flag if core encountered an error during processing.</value>
20
- bool EncounteredError { get; }
21
-
22
- /// <summary>
23
- /// Gets the platform which the compiler will use when defaulting 64-bit attributes and elements.
24
- /// </summary>
25
- /// <value>The platform which the compiler will use when defaulting 64-bit attributes and elements.</value>
26
- Platform CurrentPlatform { get; }
27
-
15
/// <summary>
16
/// Creates a version 3 name-based UUID.
17
/// </summary>
@@ -49,20 +36,38 @@ namespace WixToolset.Extensibility
36
Identifier CreateIdentifierFromFilename(string filename);
37
38
/// <summary>
52
- /// Convert a bit array into an int value.
39
+ /// Creates a row in the section.
40
/// </summary>
54
- /// <param name="bits">The bit array to convert.</param>
55
- /// <returns>The converted int value.</returns>
56
- int CreateIntegerFromBitArray(BitArray bits);
41
+ /// <param name="section">Section to add the new tuple to.</param>
42
+ /// <param name="sourceLineNumbers">Source and line number of current row.</param>
43
+ /// <param name="tableName">Name of table to create row in.</param>
44
+ /// <param name="identifier">Optional identifier for the row.</param>
45
+ /// <returns>New row.</returns>
46
+ IntermediateTuple CreateRow(IntermediateSection section, SourceLineNumber sourceLineNumbers, string tableName, Identifier identifier = null);
47
48
/// <summary>
59
- /// Creates a row in the active section.
49
+ /// Creates a row in the section.
50
/// </summary>
51
+ /// <param name="section">Section to add the new tuple to.</param>
52
/// <param name="sourceLineNumbers">Source and line number of current row.</param>
62
- /// <param name="tableName">Name of table to create row in.</param>
53
+ /// <param name="tupleType">Type of tuple to create.</param>
54
/// <param name="identifier">Optional identifier for the row.</param>
55
/// <returns>New row.</returns>
65
- IntermediateTuple CreateRow(SourceLineNumber sourceLineNumbers, string tableName, Identifier identifier = null);
56
+ IntermediateTuple CreateRow(IntermediateSection section, SourceLineNumber sourceLineNumbers, TupleDefinitionType tupleType, Identifier identifier = null);
57
+
58
+ /// <summary>
59
+ /// Creates a directory row from a name.
60
+ /// </summary>
61
+ /// <param name="section">Section to add the new tuple to.</param>
62
+ /// <param name="sourceLineNumbers">Source line information.</param>
63
+ /// <param name="id">Optional identifier for the new row.</param>
64
+ /// <param name="parentId">Optional identifier for the parent row.</param>
65
+ /// <param name="name">Long name of the directory.</param>
66
+ /// <param name="shortName">Optional short name of the directory.</param>
67
+ /// <param name="sourceName">Optional source name for the directory.</param>
68
+ /// <param name="shortSourceName">Optional short source name for the directory.</param>
69
+ /// <returns>Identifier for the newly created row.</returns>
70
+ Identifier CreateDirectoryRow(IntermediateSection section, SourceLineNumber sourceLineNumbers, Identifier id, string parentId, string name, string shortName = null, string sourceName = null, string shortSourceName = null, ISet<string> sectionInlinedDirectoryIds = null);
71
72
/// <summary>
73
/// Creates directories using the inline directory syntax.
@@ -71,7 +76,7 @@ namespace WixToolset.Extensibility
76
/// <param name="attribute">The attribute to parse.</param>
77
/// <param name="parentId">Optional identifier of parent directory.</param>
78
/// <returns>Identifier of the leaf directory created.</returns>
74
- string CreateDirectoryReferenceFromInlineSyntax(SourceLineNumber sourceLineNumbers, XAttribute attribute, string parentId);
79
+ string CreateDirectoryReferenceFromInlineSyntax(IntermediateSection section, SourceLineNumber sourceLineNumbers, XAttribute attribute, string parentId);
80
81
/// <summary>
82
/// Creates a Registry row in the active section.
@@ -83,7 +88,7 @@ namespace WixToolset.Extensibility
88
/// <param name="value">The registry entry value.</param>
89
/// <param name="componentId">The component which will control installation/uninstallation of the registry entry.</param>
90
/// <param name="escapeLeadingHash">If true, "escape" leading '#' characters so the value is written as a REG_SZ.</param>
86
- Identifier CreateRegistryRow(SourceLineNumber sourceLineNumbers, int root, string key, string name, string value, string componentId, bool escapeLeadingHash = false);
91
+ Identifier CreateRegistryRow(IntermediateSection section, SourceLineNumber sourceLineNumbers, int root, string key, string name, string value, string componentId, bool escapeLeadingHash);
92
93
/// <summary>
94
/// Creates a short file/directory name using an identifier and long file/directory name as input.
@@ -101,7 +106,7 @@ namespace WixToolset.Extensibility
106
/// <param name="sourceLineNumbers">Source line information for the row.</param>
107
/// <param name="tableName">The table name of the simple reference.</param>
108
/// <param name="primaryKeys">The primary keys of the simple reference.</param>
104
- void CreateSimpleReference(SourceLineNumber sourceLineNumbers, string tableName, params string[] primaryKeys);
109
+ void CreateSimpleReference(IntermediateSection section, SourceLineNumber sourceLineNumbers, string tableName, params string[] primaryKeys);
110
111
/// <summary>
112
/// Creates WixComplexReference and WixGroup rows in the active section.
@@ -113,16 +118,17 @@ namespace WixToolset.Extensibility
118
/// <param name="childType">The child type.</param>
119
/// <param name="childId">The child id.</param>
120
/// <param name="isPrimary">Whether the child is primary.</param>
116
- void CreateComplexReference(SourceLineNumber sourceLineNumbers, ComplexReferenceParentType parentType, string parentId, string parentLanguage, ComplexReferenceChildType childType, string childId, bool isPrimary);
121
+ void CreateComplexReference(IntermediateSection section, SourceLineNumber sourceLineNumbers, ComplexReferenceParentType parentType, string parentId, string parentLanguage, ComplexReferenceChildType childType, string childId, bool isPrimary);
122
123
/// <summary>
119
- /// Creates a patch resource reference to the list of resoures to be filtered when producing a patch. This method should only be used when processing children of a patch family.
124
+ /// A row in the WixGroup table is added for this child node and its parent node.
125
/// </summary>
121
- /// <param name="sourceLineNumbers">Source and line number of current row.</param>
122
- /// <param name="tableName">Name of table to create row in.</param>
123
- /// <param name="primaryKeys">Array of keys that make up the primary key of the table.</param>
124
- /// <returns>New row.</returns>
125
- void CreatePatchFamilyChildReference(SourceLineNumber sourceLineNumbers, string tableName, params string[] primaryKeys);
126
+ /// <param name="sourceLineNumbers">Source line information for the row.</param>
127
+ /// <param name="parentType">Type of child's complex reference parent.</param>
128
+ /// <param name="parentId">Id of the parenet node.</param>
129
+ /// <param name="childType">Complex reference type of child</param>
130
+ /// <param name="childId">Id of the Child Node.</param>
131
+ void CreateWixGroupRow(IntermediateSection section, SourceLineNumber sourceLineNumbers, ComplexReferenceParentType parentType, string parentId, ComplexReferenceChildType childType, string childId);
132
133
/// <summary>
134
/// Checks if the string contains a property (i.e. "foo[Property]bar")
@@ -136,7 +142,7 @@ namespace WixToolset.Extensibility
142
/// </summary>
143
/// <param name="sourceLineNumbers">Source line numbers.</param>
144
/// <param name="tableName">Name of the table to ensure existance of.</param>
139
- void EnsureTable(SourceLineNumber sourceLineNumbers, string tableName);
145
+ void EnsureTable(IntermediateSection section, SourceLineNumber sourceLineNumbers, string tableName);
146
147
/// <summary>
148
/// Get an attribute value and displays an error if the value is empty by default.
@@ -147,14 +153,6 @@ namespace WixToolset.Extensibility
153
/// <returns>The attribute's value.</returns>
154
string GetAttributeValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, EmptyRule emptyRule = EmptyRule.CanBeWhitespaceOnly);
155
150
- /// <summary>
151
- /// Gets a Bundle variable value and displays an error for an illegal value.
152
- /// </summary>
153
- /// <param name="sourceLineNumbers">Source line information about the owner element.</param>
154
- /// <param name="attribute">The attribute containing the value to get.</param>
155
- /// <returns>The attribute's value.</returns>
156
- string GetAttributeBundleVariableValue(SourceLineNumber sourceLineNumbers, XAttribute attribute);
157
-
156
/// <summary>
157
/// Get a guid attribute value and displays an error for an illegal guid value.
158
/// </summary>
@@ -181,6 +179,15 @@ namespace WixToolset.Extensibility
179
/// <returns>The attribute's identifier value or a special value if an error occurred.</returns>
180
string GetAttributeIdentifierValue(SourceLineNumber sourceLineNumbers, XAttribute attribute);
181
182
+ /// <summary>
183
+ /// Gets the attribute value as inline directory syntax.
184
+ /// </summary>
185
+ /// <param name="sourceLineNumbers">Source line information.</param>
186
+ /// <param name="attribute">Attribute containing the value to get.</param>
187
+ /// <param name="resultUsedToCreateReference">Flag indicates whether the inline directory syntax should be processed to create a directory row or to create a directory reference.</param>
188
+ /// <returns>Inline directory syntax split into array of strings or null if the syntax did not parse.</returns>
189
+ string[] GetAttributeInlineDirectorySyntax(SourceLineNumber sourceLineNumbers, XAttribute attribute, bool resultUsedToCreateReference);
190
+
191
/// <summary>
192
/// Get an integer attribute value and displays an error for an illegal integer value.
193
/// </summary>
@@ -211,15 +218,6 @@ namespace WixToolset.Extensibility
218
/// <returns>The attribute's long filename value.</returns>
219
string GetAttributeLongFilename(SourceLineNumber sourceLineNumbers, XAttribute attribute, bool allowWildcards = false, bool allowRelative = false);
220
214
- /// <summary>
215
- /// Gets a RegistryRoot as a MsiInterop.MsidbRegistryRoot value and displays an error for an illegal value.
216
- /// </summary>
217
- /// <param name="sourceLineNumbers">Source line information about the owner element.</param>
218
- /// <param name="attribute">The attribute containing the value to get.</param>
219
- /// <param name="allowHkmu">Whether HKMU is returned as -1 (true), or treated as an error (false).</param>
220
- /// <returns>The attribute's RegisitryRootType value.</returns>
221
- int GetAttributeMsidbRegistryRootValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, bool allowHkmu);
222
-
221
/// <summary>
222
/// Gets a version value or possibly a binder variable and displays an error for an illegal version value.
223
/// </summary>
@@ -295,7 +293,7 @@ namespace WixToolset.Extensibility
293
/// <param name="element">Element containing attribute to be parsed.</param>
294
/// <param name="attribute">Attribute to be parsed.</param>
295
/// <param name="context">Extra information about the context in which this element is being parsed.</param>
298
- void ParseExtensionAttribute(XElement element, XAttribute attribute, IDictionary<string, string> context = null);
296
+ void ParseExtensionAttribute(IEnumerable<ICompilerExtension> extensions, Intermediate intermediate, IntermediateSection section, XElement element, XAttribute attribute, IDictionary<string, string> context = null);
297
298
/// <summary>
299
/// Attempts to use an extension to parse the element.
@@ -303,24 +301,21 @@ namespace WixToolset.Extensibility
301
/// <param name="parentElement">Element containing element to be parsed.</param>
302
/// <param name="element">Element to be parsed.</param>
303
/// <param name="contextValues">Extra information about the context in which this element is being parsed.</param>
306
- void ParseExtensionElement(XElement parentElement, XElement element, IDictionary<string, string> context = null);
304
+ void ParseExtensionElement(IEnumerable<ICompilerExtension> extensions, Intermediate intermediate, IntermediateSection section, XElement parentElement, XElement element, IDictionary<string, string> context = null);
305
306
/// <summary>
309
- /// Process all children of the element looking for extensions and erroring on the unexpected.
307
+ /// Attempts to use an extension to parse the element, with support for setting component keypath.
308
/// </summary>
311
- /// <param name="element">Element to parse children.</param>
312
- void ParseForExtensionElements(XElement element);
309
+ /// <param name="parentElement">Element containing element to be parsed.</param>
310
+ /// <param name="element">Element to be parsed.</param>
311
+ /// <param name="contextValues">Extra information about the context in which this element is being parsed.</param>
312
+ ComponentKeyPath ParsePossibleKeyPathExtensionElement(IEnumerable<ICompilerExtension> extensions, Intermediate intermediate, IntermediateSection section, XElement parentElement, XElement element, IDictionary<string, string> context);
313
314
/// <summary>
315
- /// Sets a bit in a bit array based on the index at which an attribute name was found in a string array.
315
+ /// Process all children of the element looking for extensions and erroring on the unexpected.
316
/// </summary>
317
- /// <param name="attributeNames">Array of attributes that map to bits.</param>
318
- /// <param name="attributeName">Name of attribute to check.</param>
319
- /// <param name="attributeValue">Value of attribute to check.</param>
320
- /// <param name="bits">The bit array in which the bit will be set if found.</param>
321
- /// <param name="offset">The offset into the bit array.</param>
322
- /// <returns>true if the bit was set; false otherwise.</returns>
323
- bool TrySetBitFromName(string[] attributeNames, string attributeName, YesNoType attributeValue, BitArray bits, int offset);
317
+ /// <param name="element">Element to parse children.</param>
318
+ void ParseForExtensionElements(IEnumerable<ICompilerExtension> extensions, Intermediate intermediate, IntermediateSection section, XElement element);
319
320
/// <summary>
321
/// Called when the compiler encounters an unexpected attribute.