From 155a6e96346e0cb3d9ab6f5372fa29b46ebaee89 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Tue, 19 Dec 2017 12:25:40 -0800 Subject: Integrate simplified message handling --- src/WixToolset.Core/CommandLine/BuildCommand.cs | 59 +++++++++++++--------- src/WixToolset.Core/CommandLine/CommandLine.cs | 26 +++++----- .../CommandLine/CommandLineContext.cs | 3 +- src/WixToolset.Core/CommandLine/CompileCommand.cs | 9 ++-- 4 files changed, 54 insertions(+), 43 deletions(-) (limited to 'src/WixToolset.Core/CommandLine') diff --git a/src/WixToolset.Core/CommandLine/BuildCommand.cs b/src/WixToolset.Core/CommandLine/BuildCommand.cs index 7a63b869..43b75f33 100644 --- a/src/WixToolset.Core/CommandLine/BuildCommand.cs +++ b/src/WixToolset.Core/CommandLine/BuildCommand.cs @@ -13,9 +13,10 @@ namespace WixToolset.Core internal class BuildCommand : ICommandLineCommand { - public BuildCommand(IServiceProvider serviceProvider, IExtensionManager extensions, IEnumerable sources, IDictionary preprocessorVariables, IEnumerable locFiles, IEnumerable libraryFiles, string outputPath, OutputType outputType, string cabCachePath, IEnumerable cultures, bool bindFiles, IEnumerable bindPaths, string intermediateFolder, string contentsFile, string outputsFile, string builtOutputsFile, string wixProjectFile) + public BuildCommand(IServiceProvider serviceProvider, IMessaging messaging, IExtensionManager extensions, IEnumerable sources, IDictionary preprocessorVariables, IEnumerable locFiles, IEnumerable libraryFiles, string outputPath, OutputType outputType, string cabCachePath, IEnumerable cultures, bool bindFiles, IEnumerable bindPaths, string intermediateFolder, string contentsFile, string outputsFile, string builtOutputsFile, string wixProjectFile) { this.ServiceProvider = serviceProvider; + this.Messaging = messaging; this.ExtensionManager = extensions; this.LocFiles = locFiles; this.LibraryFiles = libraryFiles; @@ -38,6 +39,8 @@ namespace WixToolset.Core public IServiceProvider ServiceProvider { get; } + public IMessaging Messaging { get; } + public IExtensionManager ExtensionManager { get; } public IEnumerable IncludeSearchPaths { get; } @@ -91,13 +94,13 @@ namespace WixToolset.Core { var output = this.LinkPhase(intermediates); - if (!Messaging.Instance.EncounteredError) + if (!this.Messaging.EncounteredError) { this.BindPhase(output); } } - return Messaging.Instance.LastErrorNumber; + return this.Messaging.LastErrorNumber; } private IEnumerable CompilePhase() @@ -107,7 +110,7 @@ namespace WixToolset.Core foreach (var sourceFile in this.SourceFiles) { var preprocessContext = this.ServiceProvider.GetService(); - preprocessContext.Messaging = Messaging.Instance; + preprocessContext.Messaging = this.Messaging; preprocessContext.Extensions = this.ExtensionManager.Create(); preprocessContext.Platform = Platform.X86; // TODO: set this correctly preprocessContext.IncludeSearchPaths = this.IncludeSearchPaths?.ToList() ?? new List(); @@ -117,18 +120,24 @@ namespace WixToolset.Core var preprocessor = new Preprocessor(); var document = preprocessor.Process(preprocessContext); - var compileContext = this.ServiceProvider.GetService(); - compileContext.Messaging = Messaging.Instance; - compileContext.CompilationId = Guid.NewGuid().ToString("N"); - compileContext.Extensions = this.ExtensionManager.Create(); - compileContext.OutputPath = sourceFile.OutputPath; - compileContext.Platform = Platform.X86; // TODO: set this correctly - compileContext.Source = document; - - var compiler = new Compiler(); - var intermediate = compiler.Compile(compileContext); - - intermediates.Add(intermediate); + if (!this.Messaging.EncounteredError) + { + var compileContext = this.ServiceProvider.GetService(); + compileContext.Messaging = this.Messaging; + compileContext.CompilationId = Guid.NewGuid().ToString("N"); + compileContext.Extensions = this.ExtensionManager.Create(); + compileContext.OutputPath = sourceFile.OutputPath; + compileContext.Platform = Platform.X86; // TODO: set this correctly + compileContext.Source = document; + + var compiler = new Compiler(); + var intermediate = compiler.Compile(compileContext); + + if (!this.Messaging.EncounteredError) + { + intermediates.Add(intermediate); + } + } } return intermediates; @@ -139,7 +148,7 @@ namespace WixToolset.Core var localizations = this.LoadLocalizationFiles().ToList(); // If there was an error adding localization files, then bail. - if (Messaging.Instance.EncounteredError) + if (this.Messaging.EncounteredError) { return null; } @@ -166,7 +175,7 @@ namespace WixToolset.Core var libraries = this.LoadLibraries(creator); var context = this.ServiceProvider.GetService(); - context.Messaging = Messaging.Instance; + context.Messaging = this.Messaging; context.Extensions = this.ExtensionManager.Create(); context.ExtensionData = this.ExtensionManager.Create(); context.ExpectedOutputType = this.OutputType; @@ -182,7 +191,7 @@ namespace WixToolset.Core { var localizations = this.LoadLocalizationFiles().ToList(); - var localizer = new Localizer(localizations); + var localizer = new Localizer(this.Messaging, localizations); var resolver = CreateWixResolverWithVariables(localizer, output); @@ -193,7 +202,7 @@ namespace WixToolset.Core } var context = this.ServiceProvider.GetService(); - context.Messaging = Messaging.Instance; + context.Messaging = this.Messaging; context.ExtensionManager = this.ExtensionManager; context.BindPaths = this.BindPaths ?? Array.Empty(); //context.CabbingThreadCount = this.CabbingThreadCount; @@ -234,11 +243,11 @@ namespace WixToolset.Core } catch (WixCorruptFileException e) { - Messaging.Instance.OnMessage(e.Error); + this.Messaging.Write(e.Error); } catch (WixUnexpectedFileFormatException e) { - Messaging.Instance.OnMessage(e.Error); + this.Messaging.Write(e.Error); } } } @@ -250,15 +259,15 @@ namespace WixToolset.Core { foreach (var loc in this.LocFiles) { - var localization = Localizer.ParseLocalizationFile(loc); + var localization = Localizer.ParseLocalizationFile(this.Messaging, loc); yield return localization; } } - private static WixVariableResolver CreateWixResolverWithVariables(Localizer localizer, Intermediate output) + private WixVariableResolver CreateWixResolverWithVariables(Localizer localizer, Intermediate output) { - var resolver = new WixVariableResolver(localizer); + var resolver = new WixVariableResolver(this.Messaging, localizer); // Gather all the wix variables. var wixVariables = output?.Sections.SelectMany(s => s.Tuples).OfType(); diff --git a/src/WixToolset.Core/CommandLine/CommandLine.cs b/src/WixToolset.Core/CommandLine/CommandLine.cs index 9bedca9a..9db1b2f9 100644 --- a/src/WixToolset.Core/CommandLine/CommandLine.cs +++ b/src/WixToolset.Core/CommandLine/CommandLine.cs @@ -24,12 +24,10 @@ namespace WixToolset.Core internal class CommandLine : ICommandLine, IParseCommandLine { - public CommandLine() - { - } - private IServiceProvider ServiceProvider { get; set; } + private IMessaging Messaging { get; set; } + public static string ExpectedArgument { get; } = "expected argument"; public string ActiveCommand { get; private set; } @@ -48,6 +46,8 @@ namespace WixToolset.Core { this.ServiceProvider = context.ServiceProvider; + this.Messaging = context.Messaging ?? this.ServiceProvider.GetService(); + this.ExtensionManager = context.ExtensionManager ?? this.ServiceProvider.GetService(); var args = context.ParsedArguments ?? Array.Empty(); @@ -186,7 +186,7 @@ namespace WixToolset.Core } }); - Messaging.Instance.ShowVerboseMessages = verbose; + this.Messaging.ShowVerboseMessages = verbose; if (showVersion) { @@ -208,17 +208,17 @@ namespace WixToolset.Core case Commands.Build: { var sourceFiles = GatherSourceFiles(files, outputFolder); - var variables = GatherPreprocessorVariables(defines); - var bindPathList = GatherBindPaths(bindPaths); + var variables = this.GatherPreprocessorVariables(defines); + var bindPathList = this.GatherBindPaths(bindPaths); var type = CalculateOutputType(outputType, outputFile); - return new BuildCommand(this.ServiceProvider, this.ExtensionManager, sourceFiles, variables, locFiles, libraryFiles, outputFile, type, cabCachePath, cultures, bindFiles, bindPathList, intermediateFolder, contentsFile, outputsFile, builtOutputsFile, wixProjectFile); + return new BuildCommand(this.ServiceProvider, this.Messaging, this.ExtensionManager, sourceFiles, variables, locFiles, libraryFiles, outputFile, type, cabCachePath, cultures, bindFiles, bindPathList, intermediateFolder, contentsFile, outputsFile, builtOutputsFile, wixProjectFile); } case Commands.Compile: { var sourceFiles = GatherSourceFiles(files, outputFolder); var variables = GatherPreprocessorVariables(defines); - return new CompileCommand(this.ServiceProvider, this.ExtensionManager, sourceFiles, variables); + return new CompileCommand(this.ServiceProvider, this.Messaging, this.ExtensionManager, sourceFiles, variables); } } @@ -305,7 +305,7 @@ namespace WixToolset.Core return files; } - private static IDictionary GatherPreprocessorVariables(IEnumerable defineConstants) + private IDictionary GatherPreprocessorVariables(IEnumerable defineConstants) { var variables = new Dictionary(); @@ -315,7 +315,7 @@ namespace WixToolset.Core if (variables.ContainsKey(value[0])) { - Messaging.Instance.OnMessage(WixErrors.DuplicateVariableDefinition(value[0], (1 == value.Length) ? String.Empty : value[1], variables[value[0]])); + this.Messaging.Write(ErrorMessages.DuplicateVariableDefinition(value[0], (1 == value.Length) ? String.Empty : value[1], variables[value[0]])); continue; } @@ -325,7 +325,7 @@ namespace WixToolset.Core return variables; } - private static IEnumerable GatherBindPaths(IEnumerable bindPaths) + private IEnumerable GatherBindPaths(IEnumerable bindPaths) { var result = new List(); @@ -339,7 +339,7 @@ namespace WixToolset.Core } else if (File.Exists(bp.Path)) { - Messaging.Instance.OnMessage(WixErrors.ExpectedDirectoryGotFile("-bindpath", bp.Path)); + this.Messaging.Write(ErrorMessages.ExpectedDirectoryGotFile("-bindpath", bp.Path)); } } diff --git a/src/WixToolset.Core/CommandLine/CommandLineContext.cs b/src/WixToolset.Core/CommandLine/CommandLineContext.cs index 96c149be..cbb9af53 100644 --- a/src/WixToolset.Core/CommandLine/CommandLineContext.cs +++ b/src/WixToolset.Core/CommandLine/CommandLineContext.cs @@ -3,7 +3,6 @@ namespace WixToolset.Core { using System; - using WixToolset.Data; using WixToolset.Extensibility.Services; internal class CommandLineContext : ICommandLineContext @@ -15,7 +14,7 @@ namespace WixToolset.Core public IServiceProvider ServiceProvider { get; } - public Messaging Messaging { get; set; } + public IMessaging Messaging { get; set; } public IExtensionManager ExtensionManager { get; set; } diff --git a/src/WixToolset.Core/CommandLine/CompileCommand.cs b/src/WixToolset.Core/CommandLine/CompileCommand.cs index e7fcdd4d..856dd29f 100644 --- a/src/WixToolset.Core/CommandLine/CompileCommand.cs +++ b/src/WixToolset.Core/CommandLine/CompileCommand.cs @@ -11,16 +11,19 @@ namespace WixToolset.Core internal class CompileCommand : ICommandLineCommand { - public CompileCommand(IServiceProvider serviceProvider, IExtensionManager extensions, IEnumerable sources, IDictionary preprocessorVariables) + public CompileCommand(IServiceProvider serviceProvider, IMessaging messaging, IExtensionManager extensions, IEnumerable sources, IDictionary preprocessorVariables) { this.PreprocessorVariables = preprocessorVariables; this.ServiceProvider = serviceProvider; + this.Messaging = messaging; this.ExtensionManager = extensions; this.SourceFiles = sources; } private IServiceProvider ServiceProvider { get; } + private IMessaging Messaging { get; } + private IExtensionManager ExtensionManager { get; } public IEnumerable IncludeSearchPaths { get; } @@ -34,7 +37,7 @@ namespace WixToolset.Core foreach (var sourceFile in this.SourceFiles) { var preprocessContext = this.ServiceProvider.GetService(); - preprocessContext.Messaging = Messaging.Instance; + preprocessContext.Messaging = this.Messaging; preprocessContext.Extensions = this.ExtensionManager.Create(); preprocessContext.Platform = Platform.X86; // TODO: set this correctly preprocessContext.IncludeSearchPaths = this.IncludeSearchPaths?.ToList() ?? new List(); @@ -45,7 +48,7 @@ namespace WixToolset.Core var document = preprocessor.Process(preprocessContext); var compileContext = this.ServiceProvider.GetService(); - compileContext.Messaging = Messaging.Instance; + compileContext.Messaging = this.Messaging; compileContext.CompilationId = Guid.NewGuid().ToString("N"); compileContext.Extensions = this.ExtensionManager.Create(); compileContext.OutputPath = sourceFile.OutputPath; -- cgit v1.2.3-55-g6feb