From 2067f5acbfd7593f10ac2607f96df4457002b4c3 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Wed, 10 Aug 2022 12:57:14 -0700 Subject: 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. --- .../Services/IMessaging.cs | 6 +++++ .../WixToolset.Core/CommandLine/BuildCommand.cs | 4 +-- .../ExtensibilityServices/Messaging.cs | 6 +++-- src/wix/WixToolset.Core/Preprocessor.cs | 11 ++++---- .../Mocks/MockMessaging.cs | 29 +++++++++++++++++----- 5 files changed, 41 insertions(+), 15 deletions(-) diff --git a/src/api/wix/WixToolset.Extensibility/Services/IMessaging.cs b/src/api/wix/WixToolset.Extensibility/Services/IMessaging.cs index fe77f2a4..15e17e63 100644 --- a/src/api/wix/WixToolset.Extensibility/Services/IMessaging.cs +++ b/src/api/wix/WixToolset.Extensibility/Services/IMessaging.cs @@ -15,6 +15,12 @@ namespace WixToolset.Extensibility.Services /// A bool indicating whether an error has been found. bool EncounteredError { get; } + /// + /// Gets the number of errors encountered thus far. + /// + /// The number of errors encountered. + int ErrorCount { get; } + /// /// Gets the last error code encountered during messaging. /// diff --git a/src/wix/WixToolset.Core/CommandLine/BuildCommand.cs b/src/wix/WixToolset.Core/CommandLine/BuildCommand.cs index e63c727c..a00b4b12 100644 --- a/src/wix/WixToolset.Core/CommandLine/BuildCommand.cs +++ b/src/wix/WixToolset.Core/CommandLine/BuildCommand.cs @@ -157,7 +157,7 @@ namespace WixToolset.Core.CommandLine { var document = this.Preprocess(preprocessorVariables, sourceFile, includeSearchPaths, cancellationToken); - if (this.Messaging.EncounteredError) + if (document == null) { continue; } @@ -358,7 +358,7 @@ namespace WixToolset.Core.CommandLine { var document = this.Preprocess(preprocessorVariables, loc, includeSearchPaths, cancellationToken); - if (this.Messaging.EncounteredError) + if (document == null) { continue; } diff --git a/src/wix/WixToolset.Core/ExtensibilityServices/Messaging.cs b/src/wix/WixToolset.Core/ExtensibilityServices/Messaging.cs index 280d845c..9a7413f4 100644 --- a/src/wix/WixToolset.Core/ExtensibilityServices/Messaging.cs +++ b/src/wix/WixToolset.Core/ExtensibilityServices/Messaging.cs @@ -13,7 +13,9 @@ namespace WixToolset.Core.ExtensibilityServices private readonly HashSet suppressedWarnings = new HashSet(); private readonly HashSet warningsAsErrors = new HashSet(); - public bool EncounteredError { get; private set; } + public bool EncounteredError => this.ErrorCount > 0; + + public int ErrorCount { get; private set; } public int LastErrorNumber { get; private set; } @@ -49,7 +51,7 @@ namespace WixToolset.Core.ExtensibilityServices if (level == MessageLevel.Error) { - this.EncounteredError = true; + ++this.ErrorCount; this.LastErrorNumber = message.Id; } diff --git a/src/wix/WixToolset.Core/Preprocessor.cs b/src/wix/WixToolset.Core/Preprocessor.cs index 084da8d0..a71e5bb7 100644 --- a/src/wix/WixToolset.Core/Preprocessor.cs +++ b/src/wix/WixToolset.Core/Preprocessor.cs @@ -141,6 +141,8 @@ namespace WixToolset.Core { state.CurrentFileStack.Push(state.Helper.GetVariableValue(state.Context, "sys", "SOURCEFILEDIR")); + var beforeErrorCount = this.Messaging.ErrorCount; + // Process the reader into the output. IPreprocessResult result = null; try @@ -150,7 +152,7 @@ namespace WixToolset.Core // Fire event with post-processed document. this.ProcessedStream?.Invoke(this, new ProcessedStreamEventArgs(state.Context.SourcePath, state.Output)); - if (!this.Messaging.EncounteredError) + if (beforeErrorCount == this.Messaging.ErrorCount) { result = this.ServiceProvider.GetService(); result.Document = state.Output; @@ -292,7 +294,7 @@ namespace WixToolset.Core if (XmlNodeType.ProcessingInstruction == reader.NodeType) { var ignore = false; - string name = null; + string name; switch (reader.LocalName) { @@ -423,7 +425,6 @@ namespace WixToolset.Core break; } } - } //else //{ @@ -826,7 +827,7 @@ namespace WixToolset.Core private string GetNextToken(ProcessingState state, string originalExpression, ref string expression, out bool stringLiteral) { stringLiteral = false; - var token = String.Empty; + string token; expression = expression.Trim(); if (0 == expression.Length) { @@ -1280,7 +1281,7 @@ namespace WixToolset.Core /// Boolean to indicate if the expression is true or false private bool EvaluateExpressionRecurse(ProcessingState state, string originalExpression, ref string expression, PreprocessorOperation prevResultOperation, bool prevResult) { - var expressionValue = false; + bool expressionValue; expression = expression.Trim(); if (expression.Length == 0) { diff --git a/src/wix/test/WixToolsetTest.Converters/Mocks/MockMessaging.cs b/src/wix/test/WixToolsetTest.Converters/Mocks/MockMessaging.cs index 77821a1c..2bc10772 100644 --- a/src/wix/test/WixToolsetTest.Converters/Mocks/MockMessaging.cs +++ b/src/wix/test/WixToolsetTest.Converters/Mocks/MockMessaging.cs @@ -12,7 +12,9 @@ namespace WixToolsetTest.Converters.Mocks { public List Messages { get; } = new List(); - public bool EncounteredError { get; private set; } + public bool EncounteredError => this.ErrorCount > 0; + + public int ErrorCount { get; private set; } public int LastErrorNumber { get; } @@ -22,18 +24,33 @@ namespace WixToolsetTest.Converters.Mocks public bool WarningsAsError { get; set; } - public void ElevateWarningMessage(int warningNumber) => throw new NotImplementedException(); + public void ElevateWarningMessage(int warningNumber) + { + throw new NotImplementedException(); + } - public void SetListener(IMessageListener listener) => throw new NotImplementedException(); + public void SetListener(IMessageListener listener) + { + throw new NotImplementedException(); + } - public void SuppressWarningMessage(int warningNumber) => throw new NotImplementedException(); + public void SuppressWarningMessage(int warningNumber) + { + throw new NotImplementedException(); + } public void Write(Message message) { this.Messages.Add(message); - this.EncounteredError |= message.Level == MessageLevel.Error; + if (message.Level == MessageLevel.Error) + { + ++this.ErrorCount; + } } - public void Write(string message, bool verbose = false) => throw new NotImplementedException(); + public void Write(string message, bool verbose = false) + { + throw new NotImplementedException(); + } } } -- cgit v1.2.3-55-g6feb