diff options
Diffstat (limited to 'src/WixToolset.Core/CommandLine/CommandLine.cs')
-rw-r--r-- | src/WixToolset.Core/CommandLine/CommandLine.cs | 64 |
1 files changed, 30 insertions, 34 deletions
diff --git a/src/WixToolset.Core/CommandLine/CommandLine.cs b/src/WixToolset.Core/CommandLine/CommandLine.cs index 2f203ecb..b0594348 100644 --- a/src/WixToolset.Core/CommandLine/CommandLine.cs +++ b/src/WixToolset.Core/CommandLine/CommandLine.cs | |||
@@ -6,11 +6,11 @@ namespace WixToolset.Core | |||
6 | using System.Collections.Generic; | 6 | using System.Collections.Generic; |
7 | using System.IO; | 7 | using System.IO; |
8 | using System.Linq; | 8 | using System.Linq; |
9 | using System.Reflection; | ||
10 | using System.Text; | 9 | using System.Text; |
11 | using System.Text.RegularExpressions; | 10 | using System.Text.RegularExpressions; |
12 | using WixToolset.Data; | 11 | using WixToolset.Data; |
13 | using WixToolset.Extensibility; | 12 | using WixToolset.Extensibility; |
13 | using WixToolset.Extensibility.Services; | ||
14 | 14 | ||
15 | internal enum Commands | 15 | internal enum Commands |
16 | { | 16 | { |
@@ -22,12 +22,14 @@ namespace WixToolset.Core | |||
22 | Bind, | 22 | Bind, |
23 | } | 23 | } |
24 | 24 | ||
25 | public class CommandLine | 25 | internal class CommandLine : ICommandLine |
26 | { | 26 | { |
27 | private CommandLine() | 27 | public CommandLine() |
28 | { | 28 | { |
29 | } | 29 | } |
30 | 30 | ||
31 | private IServiceProvider ServiceProvider { get; set; } | ||
32 | |||
31 | public static string ExpectedArgument { get; } = "expected argument"; | 33 | public static string ExpectedArgument { get; } = "expected argument"; |
32 | 34 | ||
33 | public string ActiveCommand { get; private set; } | 35 | public string ActiveCommand { get; private set; } |
@@ -36,20 +38,29 @@ namespace WixToolset.Core | |||
36 | 38 | ||
37 | public Queue<string> RemainingArguments { get; } = new Queue<string>(); | 39 | public Queue<string> RemainingArguments { get; } = new Queue<string>(); |
38 | 40 | ||
39 | public ExtensionManager ExtensionManager { get; } = new ExtensionManager(); | 41 | public IExtensionManager ExtensionManager { get; private set; } |
40 | 42 | ||
41 | public string ErrorArgument { get; set; } | 43 | public string ErrorArgument { get; set; } |
42 | 44 | ||
43 | public bool ShowHelp { get; set; } | 45 | public bool ShowHelp { get; set; } |
44 | 46 | ||
45 | public static ICommandLineCommand ParseStandardCommandLine(string commandLineString) | 47 | public ICommandLineCommand ParseStandardCommandLine(ICommandLineContext context) |
46 | { | 48 | { |
47 | var args = CommandLine.ParseArgumentsToArray(commandLineString).ToArray(); | 49 | this.ServiceProvider = context.ServiceProvider; |
50 | |||
51 | this.ExtensionManager = context.ExtensionManager ?? this.ServiceProvider.GetService<IExtensionManager>(); | ||
52 | |||
53 | var args = context.ParsedArguments ?? Array.Empty<string>(); | ||
54 | |||
55 | if (!String.IsNullOrEmpty(context.Arguments)) | ||
56 | { | ||
57 | args = CommandLine.ParseArgumentsToArray(context.Arguments).Union(args).ToArray(); | ||
58 | } | ||
48 | 59 | ||
49 | return ParseStandardCommandLine(args); | 60 | return this.ParseStandardCommandLine(args); |
50 | } | 61 | } |
51 | 62 | ||
52 | public static ICommandLineCommand ParseStandardCommandLine(string[] args) | 63 | private ICommandLineCommand ParseStandardCommandLine(string[] args) |
53 | { | 64 | { |
54 | var next = String.Empty; | 65 | var next = String.Empty; |
55 | 66 | ||
@@ -79,7 +90,7 @@ namespace WixToolset.Core | |||
79 | var builtOutputsFile = String.Empty; | 90 | var builtOutputsFile = String.Empty; |
80 | var wixProjectFile = String.Empty; | 91 | var wixProjectFile = String.Empty; |
81 | 92 | ||
82 | var cli = CommandLine.Parse(args, (cmdline, arg) => Enum.TryParse(arg, true, out command), (cmdline, arg) => | 93 | this.Parse(args, (cmdline, arg) => Enum.TryParse(arg, true, out command), (cmdline, arg) => |
83 | { | 94 | { |
84 | if (cmdline.IsSwitch(arg)) | 95 | if (cmdline.IsSwitch(arg)) |
85 | { | 96 | { |
@@ -103,7 +114,7 @@ namespace WixToolset.Core | |||
103 | case "cc": | 114 | case "cc": |
104 | cmdline.GetNextArgumentOrError(ref cabCachePath); | 115 | cmdline.GetNextArgumentOrError(ref cabCachePath); |
105 | return true; | 116 | return true; |
106 | 117 | ||
107 | case "cultures": | 118 | case "cultures": |
108 | cmdline.GetNextArgumentOrError(cultures); | 119 | cmdline.GetNextArgumentOrError(cultures); |
109 | return true; | 120 | return true; |
@@ -187,7 +198,7 @@ namespace WixToolset.Core | |||
187 | AppCommon.DisplayToolHeader(); | 198 | AppCommon.DisplayToolHeader(); |
188 | } | 199 | } |
189 | 200 | ||
190 | if (cli.ShowHelp) | 201 | if (this.ShowHelp) |
191 | { | 202 | { |
192 | return new HelpCommand(command); | 203 | return new HelpCommand(command); |
193 | } | 204 | } |
@@ -196,14 +207,11 @@ namespace WixToolset.Core | |||
196 | { | 207 | { |
197 | case Commands.Build: | 208 | case Commands.Build: |
198 | { | 209 | { |
199 | LoadStandardBackends(cli.ExtensionManager); | ||
200 | |||
201 | var sourceFiles = GatherSourceFiles(files, outputFolder); | 210 | var sourceFiles = GatherSourceFiles(files, outputFolder); |
202 | var variables = GatherPreprocessorVariables(defines); | 211 | var variables = GatherPreprocessorVariables(defines); |
203 | var bindPathList = GatherBindPaths(bindPaths); | 212 | var bindPathList = GatherBindPaths(bindPaths); |
204 | var extensions = cli.ExtensionManager; | ||
205 | var type = CalculateOutputType(outputType, outputFile); | 213 | var type = CalculateOutputType(outputType, outputFile); |
206 | return new BuildCommand(extensions, sourceFiles, variables, locFiles, libraryFiles, outputFile, type, cabCachePath, cultures, bindFiles, bindPathList, intermediateFolder, contentsFile, outputsFile, builtOutputsFile, wixProjectFile); | 214 | return new BuildCommand(this.ServiceProvider, this.ExtensionManager, sourceFiles, variables, locFiles, libraryFiles, outputFile, type, cabCachePath, cultures, bindFiles, bindPathList, intermediateFolder, contentsFile, outputsFile, builtOutputsFile, wixProjectFile); |
207 | } | 215 | } |
208 | 216 | ||
209 | case Commands.Compile: | 217 | case Commands.Compile: |
@@ -217,18 +225,6 @@ namespace WixToolset.Core | |||
217 | return null; | 225 | return null; |
218 | } | 226 | } |
219 | 227 | ||
220 | private static void LoadStandardBackends(ExtensionManager extensionManager) | ||
221 | { | ||
222 | var folder = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath); | ||
223 | |||
224 | foreach (var backendAssemblyName in new[] { "WixToolset.Core.Burn.dll", "WixToolset.Core.WindowsInstaller.dll" }) | ||
225 | { | ||
226 | var path = Path.Combine(folder, backendAssemblyName); | ||
227 | |||
228 | extensionManager.Load(path); | ||
229 | } | ||
230 | } | ||
231 | |||
232 | private static OutputType CalculateOutputType(string outputType, string outputFile) | 228 | private static OutputType CalculateOutputType(string outputType, string outputFile) |
233 | { | 229 | { |
234 | if (String.IsNullOrEmpty(outputType)) | 230 | if (String.IsNullOrEmpty(outputType)) |
@@ -269,6 +265,7 @@ namespace WixToolset.Core | |||
269 | return OutputType.Unknown; | 265 | return OutputType.Unknown; |
270 | } | 266 | } |
271 | 267 | ||
268 | #if UNUSED | ||
272 | private static CommandLine Parse(string commandLineString, Func<CommandLine, string, bool> parseArgument) | 269 | private static CommandLine Parse(string commandLineString, Func<CommandLine, string, bool> parseArgument) |
273 | { | 270 | { |
274 | var arguments = CommandLine.ParseArgumentsToArray(commandLineString).ToArray(); | 271 | var arguments = CommandLine.ParseArgumentsToArray(commandLineString).ToArray(); |
@@ -280,18 +277,17 @@ namespace WixToolset.Core | |||
280 | { | 277 | { |
281 | return CommandLine.Parse(commandLineArguments, null, parseArgument); | 278 | return CommandLine.Parse(commandLineArguments, null, parseArgument); |
282 | } | 279 | } |
280 | #endif | ||
283 | 281 | ||
284 | private static CommandLine Parse(string[] commandLineArguments, Func<CommandLine, string, bool> parseCommand, Func<CommandLine, string, bool> parseArgument) | 282 | private ICommandLine Parse(string[] commandLineArguments, Func<CommandLine, string, bool> parseCommand, Func<CommandLine, string, bool> parseArgument) |
285 | { | 283 | { |
286 | var cmdline = new CommandLine(); | 284 | this.FlattenArgumentsWithResponseFilesIntoOriginalArguments(commandLineArguments); |
287 | |||
288 | cmdline.FlattenArgumentsWithResponseFilesIntoOriginalArguments(commandLineArguments); | ||
289 | 285 | ||
290 | cmdline.QueueArgumentsAndLoadExtensions(cmdline.OriginalArguments); | 286 | this.QueueArgumentsAndLoadExtensions(this.OriginalArguments); |
291 | 287 | ||
292 | cmdline.ProcessRemainingArguments(parseArgument, parseCommand); | 288 | this.ProcessRemainingArguments(parseArgument, parseCommand); |
293 | 289 | ||
294 | return cmdline; | 290 | return this; |
295 | } | 291 | } |
296 | 292 | ||
297 | private static IEnumerable<SourceFile> GatherSourceFiles(IEnumerable<string> sourceFiles, string intermediateDirectory) | 293 | private static IEnumerable<SourceFile> GatherSourceFiles(IEnumerable<string> sourceFiles, string intermediateDirectory) |