From 95f2f4425b900374c7d7b583ae810b096121b3c4 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Sat, 2 Dec 2017 00:46:11 -0800 Subject: Implement support for IExtensionCommandLine and IPreprocessorExtension --- src/WixToolset.Core/CommandLine/BuildCommand.cs | 15 ++++++++---- src/WixToolset.Core/CommandLine/CommandLine.cs | 29 +++++++++++++---------- src/WixToolset.Core/CommandLine/CompileCommand.cs | 13 +++++++++- 3 files changed, 39 insertions(+), 18 deletions(-) (limited to 'src/WixToolset.Core/CommandLine') diff --git a/src/WixToolset.Core/CommandLine/BuildCommand.cs b/src/WixToolset.Core/CommandLine/BuildCommand.cs index 54bf688d..79bacd22 100644 --- a/src/WixToolset.Core/CommandLine/BuildCommand.cs +++ b/src/WixToolset.Core/CommandLine/BuildCommand.cs @@ -40,6 +40,8 @@ namespace WixToolset.Core public IExtensionManager ExtensionManager { get; } + public IEnumerable IncludeSearchPaths { get; } + public IEnumerable LocFiles { get; } public IEnumerable LibraryFiles { get; } @@ -102,15 +104,18 @@ namespace WixToolset.Core { var intermediates = new List(); - foreach (var sourceFile in this.SourceFiles) { - //var preprocessContext = this.ServiceProvider.GetService(); - //preprocessContext.SourcePath = sourceFile.SourcePath; - //preprocessContext.Variables = this.PreprocessorVariables; + var preprocessContext = this.ServiceProvider.GetService(); + preprocessContext.Messaging = Messaging.Instance; + preprocessContext.Extensions = this.ExtensionManager.Create(); + preprocessContext.Platform = Platform.X86; // TODO: set this correctly + preprocessContext.IncludeSearchPaths = this.IncludeSearchPaths?.ToList() ?? new List(); + preprocessContext.SourceFile = sourceFile.SourcePath; + preprocessContext.Variables = new Dictionary(this.PreprocessorVariables); var preprocessor = new Preprocessor(); - var document = preprocessor.Process(sourceFile.SourcePath, this.PreprocessorVariables); + var document = preprocessor.Process(preprocessContext); var compileContext = this.ServiceProvider.GetService(); compileContext.Messaging = Messaging.Instance; diff --git a/src/WixToolset.Core/CommandLine/CommandLine.cs b/src/WixToolset.Core/CommandLine/CommandLine.cs index c6fe11b7..9bedca9a 100644 --- a/src/WixToolset.Core/CommandLine/CommandLine.cs +++ b/src/WixToolset.Core/CommandLine/CommandLine.cs @@ -22,7 +22,7 @@ namespace WixToolset.Core Bind, } - internal class CommandLine : ICommandLine + internal class CommandLine : ICommandLine, IParseCommandLine { public CommandLine() { @@ -57,10 +57,10 @@ namespace WixToolset.Core args = CommandLine.ParseArgumentsToArray(context.Arguments).Union(args).ToArray(); } - return this.ParseStandardCommandLine(args); + return this.ParseStandardCommandLine(context, args); } - private ICommandLineCommand ParseStandardCommandLine(string[] args) + private ICommandLineCommand ParseStandardCommandLine(ICommandLineContext context, string[] args) { var next = String.Empty; @@ -90,7 +90,7 @@ namespace WixToolset.Core var builtOutputsFile = String.Empty; var wixProjectFile = String.Empty; - this.Parse(args, (cmdline, arg) => Enum.TryParse(arg, true, out command), (cmdline, arg) => + this.Parse(context, args, (cmdline, arg) => Enum.TryParse(arg, true, out command), (cmdline, arg) => { if (cmdline.IsSwitch(arg)) { @@ -279,13 +279,13 @@ namespace WixToolset.Core } #endif - private ICommandLine Parse(string[] commandLineArguments, Func parseCommand, Func parseArgument) + private ICommandLine Parse(ICommandLineContext context, string[] commandLineArguments, Func parseCommand, Func parseArgument) { this.FlattenArgumentsWithResponseFilesIntoOriginalArguments(commandLineArguments); this.QueueArgumentsAndLoadExtensions(this.OriginalArguments); - this.ProcessRemainingArguments(parseArgument, parseCommand); + this.ProcessRemainingArguments(context, parseArgument, parseCommand); return this; } @@ -413,7 +413,7 @@ namespace WixToolset.Core /// True if a valid switch exists there, false if not. public bool IsSwitch(string arg) { - return arg != null && ('/' == arg[0] || '-' == arg[0]); + return arg != null && arg.Length > 1 && ('/' == arg[0] || '-' == arg[0]); } /// @@ -522,10 +522,15 @@ namespace WixToolset.Core } } - private void ProcessRemainingArguments(Func parseArgument, Func parseCommand) + private void ProcessRemainingArguments(ICommandLineContext context, Func parseArgument, Func parseCommand) { var extensions = this.ExtensionManager.Create(); + foreach (var extension in extensions) + { + extension.PreParse(context); + } + while (!this.ShowHelp && String.IsNullOrEmpty(this.ErrorArgument) && TryDequeue(this.RemainingArguments, out var arg)) @@ -566,10 +571,10 @@ namespace WixToolset.Core { foreach (var extension in extensions) { - //if (extension.ParseArgument(this, arg)) - //{ - // return true; - //} + if (extension.TryParseArgument(this, arg)) + { + return true; + } } return false; diff --git a/src/WixToolset.Core/CommandLine/CompileCommand.cs b/src/WixToolset.Core/CommandLine/CompileCommand.cs index 58ba9d29..e7fcdd4d 100644 --- a/src/WixToolset.Core/CommandLine/CompileCommand.cs +++ b/src/WixToolset.Core/CommandLine/CompileCommand.cs @@ -4,6 +4,7 @@ namespace WixToolset.Core { using System; using System.Collections.Generic; + using System.Linq; using WixToolset.Data; using WixToolset.Extensibility; using WixToolset.Extensibility.Services; @@ -22,6 +23,8 @@ namespace WixToolset.Core private IExtensionManager ExtensionManager { get; } + public IEnumerable IncludeSearchPaths { get; } + private IEnumerable SourceFiles { get; } private IDictionary PreprocessorVariables { get; } @@ -30,8 +33,16 @@ namespace WixToolset.Core { foreach (var sourceFile in this.SourceFiles) { + var preprocessContext = this.ServiceProvider.GetService(); + preprocessContext.Messaging = Messaging.Instance; + preprocessContext.Extensions = this.ExtensionManager.Create(); + preprocessContext.Platform = Platform.X86; // TODO: set this correctly + preprocessContext.IncludeSearchPaths = this.IncludeSearchPaths?.ToList() ?? new List(); + preprocessContext.SourceFile = sourceFile.SourcePath; + preprocessContext.Variables = new Dictionary(this.PreprocessorVariables); + var preprocessor = new Preprocessor(); - var document = preprocessor.Process(sourceFile.SourcePath, this.PreprocessorVariables); + var document = preprocessor.Process(preprocessContext); var compileContext = this.ServiceProvider.GetService(); compileContext.Messaging = Messaging.Instance; -- cgit v1.2.3-55-g6feb