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 ++++++++++++++----------- 1 file changed, 34 insertions(+), 25 deletions(-) (limited to 'src/WixToolset.Core/CommandLine/BuildCommand.cs') 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(); -- cgit v1.2.3-55-g6feb