@joebigelow / wix / commits / 2067f5ac

Preprocessor only fails if current document does not parse

Previously, preprocessor would not return successfully processed files if an error was encountered with this file or any previous file. No the preprocessor will only fail if the current processed file generates any errors.

Rob Mensching committed Aug 10, 2022 at 12:57 UTC 2067f5acbfd7593f10ac2607f96df4457002b4c3
5 files changed +41 -15
src/api/wix/WixToolset.Extensibility/Services/IMessaging.cs
+6
@@ -15,6 +15,12 @@ namespace WixToolset.Extensibility.Services
15 /// <value>A bool indicating whether an error has been found.</value>
16 bool EncounteredError { get; }
17
18 + /// <summary>
19 + /// Gets the number of errors encountered thus far.
20 + /// </summary>
21 + /// <value>The number of errors encountered.</value>
22 + int ErrorCount { get; }
23 +
24 /// <summary>
25 /// Gets the last error code encountered during messaging.
26 /// </summary>
src/wix/WixToolset.Core/CommandLine/BuildCommand.cs
+2 -2
@@ -157,7 +157,7 @@ namespace WixToolset.Core.CommandLine
157 {
158 var document = this.Preprocess(preprocessorVariables, sourceFile, includeSearchPaths, cancellationToken);
159
160 - if (this.Messaging.EncounteredError)
160 + if (document == null)
161 {
162 continue;
163 }
@@ -358,7 +358,7 @@ namespace WixToolset.Core.CommandLine
358 {
359 var document = this.Preprocess(preprocessorVariables, loc, includeSearchPaths, cancellationToken);
360
361 - if (this.Messaging.EncounteredError)
361 + if (document == null)
362 {
363 continue;
364 }
src/wix/WixToolset.Core/ExtensibilityServices/Messaging.cs
+4 -2
@@ -13,7 +13,9 @@ namespace WixToolset.Core.ExtensibilityServices
13 private readonly HashSet<int> suppressedWarnings = new HashSet<int>();
14 private readonly HashSet<int> warningsAsErrors = new HashSet<int>();
15
16 - public bool EncounteredError { get; private set; }
16 + public bool EncounteredError => this.ErrorCount > 0;
17 +
18 + public int ErrorCount { get; private set; }
19
20 public int LastErrorNumber { get; private set; }
21
@@ -49,7 +51,7 @@ namespace WixToolset.Core.ExtensibilityServices
51
52 if (level == MessageLevel.Error)
53 {
52 - this.EncounteredError = true;
54 + ++this.ErrorCount;
55 this.LastErrorNumber = message.Id;
56 }
57
src/wix/WixToolset.Core/Preprocessor.cs
+6 -5
@@ -141,6 +141,8 @@ namespace WixToolset.Core
141 {
142 state.CurrentFileStack.Push(state.Helper.GetVariableValue(state.Context, "sys", "SOURCEFILEDIR"));
143
144 + var beforeErrorCount = this.Messaging.ErrorCount;
145 +
146 // Process the reader into the output.
147 IPreprocessResult result = null;
148 try
@@ -150,7 +152,7 @@ namespace WixToolset.Core
152 // Fire event with post-processed document.
153 this.ProcessedStream?.Invoke(this, new ProcessedStreamEventArgs(state.Context.SourcePath, state.Output));
154
153 - if (!this.Messaging.EncounteredError)
155 + if (beforeErrorCount == this.Messaging.ErrorCount)
156 {
157 result = this.ServiceProvider.GetService<IPreprocessResult>();
158 result.Document = state.Output;
@@ -292,7 +294,7 @@ namespace WixToolset.Core
294 if (XmlNodeType.ProcessingInstruction == reader.NodeType)
295 {
296 var ignore = false;
295 - string name = null;
297 + string name;
298
299 switch (reader.LocalName)
300 {
@@ -423,7 +425,6 @@ namespace WixToolset.Core
425 break;
426 }
427 }
426 -
428 }
429 //else
430 //{
@@ -826,7 +827,7 @@ namespace WixToolset.Core
827 private string GetNextToken(ProcessingState state, string originalExpression, ref string expression, out bool stringLiteral)
828 {
829 stringLiteral = false;
829 - var token = String.Empty;
830 + string token;
831 expression = expression.Trim();
832 if (0 == expression.Length)
833 {
@@ -1280,7 +1281,7 @@ namespace WixToolset.Core
1281 /// <returns>Boolean to indicate if the expression is true or false</returns>
1282 private bool EvaluateExpressionRecurse(ProcessingState state, string originalExpression, ref string expression, PreprocessorOperation prevResultOperation, bool prevResult)
1283 {
1283 - var expressionValue = false;
1284 + bool expressionValue;
1285 expression = expression.Trim();
1286 if (expression.Length == 0)
1287 {
src/wix/test/WixToolsetTest.Converters/Mocks/MockMessaging.cs
+23 -6
@@ -12,7 +12,9 @@ namespace WixToolsetTest.Converters.Mocks
12 {
13 public List<Message> Messages { get; } = new List<Message>();
14
15 - public bool EncounteredError { get; private set; }
15 + public bool EncounteredError => this.ErrorCount > 0;
16 +
17 + public int ErrorCount { get; private set; }
18
19 public int LastErrorNumber { get; }
20
@@ -22,18 +24,33 @@ namespace WixToolsetTest.Converters.Mocks
24
25 public bool WarningsAsError { get; set; }
26
25 - public void ElevateWarningMessage(int warningNumber) => throw new NotImplementedException();
27 + public void ElevateWarningMessage(int warningNumber)
28 + {
29 + throw new NotImplementedException();
30 + }
31
27 - public void SetListener(IMessageListener listener) => throw new NotImplementedException();
32 + public void SetListener(IMessageListener listener)
33 + {
34 + throw new NotImplementedException();
35 + }
36
29 - public void SuppressWarningMessage(int warningNumber) => throw new NotImplementedException();
37 + public void SuppressWarningMessage(int warningNumber)
38 + {
39 + throw new NotImplementedException();
40 + }
41
42 public void Write(Message message)
43 {
44 this.Messages.Add(message);
34 - this.EncounteredError |= message.Level == MessageLevel.Error;
45 + if (message.Level == MessageLevel.Error)
46 + {
47 + ++this.ErrorCount;
48 + }
49 }
50
37 - public void Write(string message, bool verbose = false) => throw new NotImplementedException();
51 + public void Write(string message, bool verbose = false)
52 + {
53 + throw new NotImplementedException();
54 + }
55 }
56 }