From 13eedbfcf97e402ade06f2be29f98723ef7ff286 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Thu, 18 Oct 2018 13:42:54 -0700 Subject: Extract interfaces for Preprocess/Compile/Link/Bind/etc --- src/WixToolset.Core/CommandLine/BuildCommand.cs | 194 +++++++++++++--------- src/WixToolset.Core/CommandLine/CompileCommand.cs | 31 ++-- 2 files changed, 137 insertions(+), 88 deletions(-) (limited to 'src/WixToolset.Core/CommandLine') diff --git a/src/WixToolset.Core/CommandLine/BuildCommand.cs b/src/WixToolset.Core/CommandLine/BuildCommand.cs index 76502bb0..6052d979 100644 --- a/src/WixToolset.Core/CommandLine/BuildCommand.cs +++ b/src/WixToolset.Core/CommandLine/BuildCommand.cs @@ -8,6 +8,7 @@ namespace WixToolset.Core.CommandLine using System.Linq; using System.Xml.Linq; using WixToolset.Data; + using WixToolset.Extensibility; using WixToolset.Extensibility.Data; using WixToolset.Extensibility.Services; @@ -172,16 +173,24 @@ namespace WixToolset.Core.CommandLine foreach (var sourceFile in sourceFiles) { - var preprocessor = new Preprocessor(this.ServiceProvider); - preprocessor.IncludeSearchPaths = this.IncludeSearchPaths; - preprocessor.Platform = this.Platform; - preprocessor.SourcePath = sourceFile.SourcePath; - preprocessor.Variables = this.PreprocessorVariables; + var document = this.Preprocess(sourceFile.SourcePath); - XDocument document = null; + if (this.Messaging.EncounteredError) + { + continue; + } + + var context = this.ServiceProvider.GetService(); + context.Extensions = this.ExtensionManager.Create(); + context.OutputPath = sourceFile.OutputPath; + context.Platform = this.Platform; + context.Source = document; + + Intermediate intermediate = null; try { - document = preprocessor.Execute(); + var compiler = this.ServiceProvider.GetService(); + intermediate = compiler.Compile(context); } catch (WixException e) { @@ -193,17 +202,6 @@ namespace WixToolset.Core.CommandLine continue; } - var compiler = new Compiler(this.ServiceProvider); - compiler.OutputPath = sourceFile.OutputPath; - compiler.Platform = this.Platform; - compiler.SourceDocument = document; - var intermediate = compiler.Execute(); - - if (this.Messaging.EncounteredError) - { - continue; - } - intermediates.Add(intermediate); } @@ -212,14 +210,27 @@ namespace WixToolset.Core.CommandLine private Intermediate LibraryPhase(IEnumerable intermediates, IEnumerable localizations) { - var librarian = new Librarian(this.ServiceProvider); - librarian.BindFiles = this.BindFiles; - librarian.BindPaths = this.BindPaths; - librarian.Intermediates = intermediates; - librarian.Localizations = localizations; - return librarian.Execute(); - } + var context = this.ServiceProvider.GetService(); + context.BindFiles = this.BindFiles; + context.BindPaths = this.BindPaths; + context.Extensions = this.ExtensionManager.Create(); + context.Localizations = localizations; + context.Intermediates = intermediates; + + Intermediate library = null; + try + { + var librarian = this.ServiceProvider.GetService(); + library = librarian.Combine(context); + } + catch (WixException e) + { + this.Messaging.Write(e.Error); + } + return library; + } + private Intermediate LinkPhase(IEnumerable intermediates, ITupleDefinitionCreator creator) { var libraries = this.LoadLibraries(creator); @@ -229,26 +240,39 @@ namespace WixToolset.Core.CommandLine return null; } - var linker = new Linker(this.ServiceProvider); - linker.OutputType = this.OutputType; - linker.Intermediates = intermediates; - linker.Libraries = libraries; - linker.TupleDefinitionCreator = creator; - return linker.Execute(); + var context = this.ServiceProvider.GetService(); + context.Extensions = this.ExtensionManager.Create(); + context.ExtensionData = this.ExtensionManager.Create(); + context.ExpectedOutputType = this.OutputType; + context.Intermediates = intermediates.Concat(libraries).ToList(); + context.TupleDefinitionCreator = creator; + + var linker = this.ServiceProvider.GetService(); + return linker.Link(context); } private void BindPhase(Intermediate output, IEnumerable localizations) { + var intermediateFolder = this.IntermediateFolder; + if (String.IsNullOrEmpty(intermediateFolder)) + { + intermediateFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); + } + ResolveResult resolveResult; { - var resolver = new Resolver(this.ServiceProvider); - resolver.BindPaths = this.BindPaths; - resolver.FilterCultures = this.FilterCultures; - resolver.IntermediateFolder = this.IntermediateFolder; - resolver.IntermediateRepresentation = output; - resolver.Localizations = localizations; - - resolveResult = resolver.Execute(); + var context = this.ServiceProvider.GetService(); + context.BindPaths = this.BindPaths; + context.Extensions = this.ExtensionManager.Create(); + context.ExtensionData = this.ExtensionManager.Create(); + context.FilterCultures = this.FilterCultures; + context.IntermediateFolder = intermediateFolder; + context.IntermediateRepresentation = output; + context.Localizations = localizations; + context.VariableResolver = new WixVariableResolver(this.Messaging); + + var resolver = this.ServiceProvider.GetService(); + resolveResult = resolver.Resolve(context); } if (this.Messaging.EncounteredError) @@ -258,28 +282,24 @@ namespace WixToolset.Core.CommandLine BindResult bindResult; { - var intermediateFolder = this.IntermediateFolder; - if (String.IsNullOrEmpty(intermediateFolder)) - { - intermediateFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); - } - - var binder = new Binder(this.ServiceProvider); - //binder.CabbingThreadCount = this.CabbingThreadCount; - binder.CabCachePath = this.CabCachePath; - binder.Codepage = resolveResult.Codepage; - //binder.DefaultCompressionLevel = this.DefaultCompressionLevel; - binder.DelayedFields = resolveResult.DelayedFields; - binder.ExpectedEmbeddedFiles = resolveResult.ExpectedEmbeddedFiles; - binder.Ices = Array.Empty(); // TODO: set this correctly - binder.IntermediateFolder = intermediateFolder; - binder.IntermediateRepresentation = resolveResult.IntermediateRepresentation; - binder.OutputPath = this.OutputPath; - binder.OutputPdbPath = Path.ChangeExtension(this.OutputPath, ".wixpdb"); - binder.SuppressIces = Array.Empty(); // TODO: set this correctly - binder.SuppressValidation = true; // TODO: set this correctly - - bindResult = binder.Execute(); + var context = this.ServiceProvider.GetService(); + //context.CabbingThreadCount = this.CabbingThreadCount; + context.CabCachePath = this.CabCachePath; + context.Codepage = resolveResult.Codepage; + //context.DefaultCompressionLevel = this.DefaultCompressionLevel; + context.DelayedFields = resolveResult.DelayedFields; + context.ExpectedEmbeddedFiles = resolveResult.ExpectedEmbeddedFiles; + context.Extensions = this.ExtensionManager.Create(); + context.Ices = Array.Empty(); // TODO: set this correctly + context.IntermediateFolder = intermediateFolder; + context.IntermediateRepresentation = resolveResult.IntermediateRepresentation; + context.OutputPath = this.OutputPath; + context.OutputPdbPath = Path.ChangeExtension(this.OutputPath, ".wixpdb"); + context.SuppressIces = Array.Empty(); // TODO: set this correctly + context.SuppressValidation = true; // TODO: set this correctly + + var binder = this.ServiceProvider.GetService(); + bindResult = binder.Bind(context); } if (this.Messaging.EncounteredError) @@ -288,16 +308,18 @@ namespace WixToolset.Core.CommandLine } { - var layout = new Layout(this.ServiceProvider); - layout.TrackedFiles = bindResult.TrackedFiles; - layout.FileTransfers = bindResult.FileTransfers; - layout.IntermediateFolder = this.IntermediateFolder; - layout.ContentsFile = this.ContentsFile; - layout.OutputsFile = this.OutputsFile; - layout.BuiltOutputsFile = this.BuiltOutputsFile; - layout.SuppressAclReset = false; // TODO: correctly set SuppressAclReset - - layout.Execute(); + var context = this.ServiceProvider.GetService(); + context.Extensions = this.ExtensionManager.Create(); + context.TrackedFiles = bindResult.TrackedFiles; + context.FileTransfers = bindResult.FileTransfers; + context.IntermediateFolder = intermediateFolder; + context.ContentsFile = this.ContentsFile; + context.OutputsFile = this.OutputsFile; + context.BuiltOutputsFile = this.BuiltOutputsFile; + context.SuppressAclReset = false; // TODO: correctly set SuppressAclReset + + var layout = this.ServiceProvider.GetService(); + layout.Layout(context); } } @@ -335,12 +357,7 @@ namespace WixToolset.Core.CommandLine foreach (var loc in this.LocFiles) { - var preprocessor = new Preprocessor(this.ServiceProvider); - preprocessor.IncludeSearchPaths = this.IncludeSearchPaths; - preprocessor.Platform = Platform.X86; // TODO: set this correctly - preprocessor.SourcePath = loc; - preprocessor.Variables = this.PreprocessorVariables; - var document = preprocessor.Execute(); + var document = this.Preprocess(loc); if (this.Messaging.EncounteredError) { @@ -351,5 +368,28 @@ namespace WixToolset.Core.CommandLine yield return localization; } } + + private XDocument Preprocess(string sourcePath) + { + var context = this.ServiceProvider.GetService(); + context.Extensions = this.ExtensionManager.Create(); + context.Platform = this.Platform; + context.IncludeSearchPaths = this.IncludeSearchPaths; + context.SourcePath = sourcePath; + context.Variables = this.PreprocessorVariables; + + XDocument document = null; + try + { + var preprocessor = this.ServiceProvider.GetService(); + document = preprocessor.Preprocess(context); + } + catch (WixException e) + { + this.Messaging.Write(e.Error); + } + + return document; + } } } diff --git a/src/WixToolset.Core/CommandLine/CompileCommand.cs b/src/WixToolset.Core/CommandLine/CompileCommand.cs index 621571b1..4007c263 100644 --- a/src/WixToolset.Core/CommandLine/CompileCommand.cs +++ b/src/WixToolset.Core/CommandLine/CompileCommand.cs @@ -6,6 +6,7 @@ namespace WixToolset.Core.CommandLine using System.Collections.Generic; using System.Xml.Linq; using WixToolset.Data; + using WixToolset.Extensibility; using WixToolset.Extensibility.Data; using WixToolset.Extensibility.Services; @@ -15,6 +16,7 @@ namespace WixToolset.Core.CommandLine { this.ServiceProvider = serviceProvider; this.Messaging = serviceProvider.GetService(); + this.ExtensionManager = serviceProvider.GetService(); this.SourceFiles = sources; this.PreprocessorVariables = preprocessorVariables; this.Platform = platform; @@ -24,6 +26,8 @@ namespace WixToolset.Core.CommandLine public IMessaging Messaging { get; } + public IExtensionManager ExtensionManager { get; } + private IEnumerable SourceFiles { get; } private IDictionary PreprocessorVariables { get; } @@ -36,16 +40,18 @@ namespace WixToolset.Core.CommandLine { foreach (var sourceFile in this.SourceFiles) { - var preprocessor = new Preprocessor(this.ServiceProvider); - preprocessor.IncludeSearchPaths = this.IncludeSearchPaths; - preprocessor.Platform = Platform.X86; // TODO: set this correctly - preprocessor.SourcePath = sourceFile.SourcePath; - preprocessor.Variables = new Dictionary(this.PreprocessorVariables); + var context = this.ServiceProvider.GetService(); + context.Extensions = this.ExtensionManager.Create(); + context.Platform = this.Platform; + context.IncludeSearchPaths = this.IncludeSearchPaths; + context.SourcePath = sourceFile.SourcePath; + context.Variables = this.PreprocessorVariables; XDocument document = null; try { - document = preprocessor.Execute(); + var preprocessor = this.ServiceProvider.GetService(); + document = preprocessor.Preprocess(context); } catch (WixException e) { @@ -57,11 +63,14 @@ namespace WixToolset.Core.CommandLine continue; } - var compiler = new Compiler(this.ServiceProvider); - compiler.OutputPath = sourceFile.OutputPath; - compiler.Platform = this.Platform; - compiler.SourceDocument = document; - var intermediate = compiler.Execute(); + var compileContext = this.ServiceProvider.GetService(); + compileContext.Extensions = this.ExtensionManager.Create(); + compileContext.OutputPath = sourceFile.OutputPath; + compileContext.Platform = this.Platform; + compileContext.Source = document; + + var compiler = this.ServiceProvider.GetService(); + var intermediate = compiler.Compile(compileContext); intermediate.Save(sourceFile.OutputPath); } -- cgit v1.2.3-55-g6feb