aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/CommandLine
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Core/CommandLine')
-rw-r--r--src/WixToolset.Core/CommandLine/BuildCommand.cs10
-rw-r--r--src/WixToolset.Core/CommandLine/CommandLine.cs64
-rw-r--r--src/WixToolset.Core/CommandLine/CommandLineContext.cs26
-rw-r--r--src/WixToolset.Core/CommandLine/CompileCommand.cs3
-rw-r--r--src/WixToolset.Core/CommandLine/HelpCommand.cs1
-rw-r--r--src/WixToolset.Core/CommandLine/ICommandLineCommand.cs9
-rw-r--r--src/WixToolset.Core/CommandLine/VersionCommand.cs5
7 files changed, 68 insertions, 50 deletions
diff --git a/src/WixToolset.Core/CommandLine/BuildCommand.cs b/src/WixToolset.Core/CommandLine/BuildCommand.cs
index b3909451..4a1fc1ed 100644
--- a/src/WixToolset.Core/CommandLine/BuildCommand.cs
+++ b/src/WixToolset.Core/CommandLine/BuildCommand.cs
@@ -9,11 +9,13 @@ namespace WixToolset.Core
9 using WixToolset.Data; 9 using WixToolset.Data;
10 using WixToolset.Data.Rows; 10 using WixToolset.Data.Rows;
11 using WixToolset.Extensibility; 11 using WixToolset.Extensibility;
12 using WixToolset.Extensibility.Services;
12 13
13 internal class BuildCommand : ICommandLineCommand 14 internal class BuildCommand : ICommandLineCommand
14 { 15 {
15 public BuildCommand(ExtensionManager extensions, IEnumerable<SourceFile> sources, IDictionary<string, string> preprocessorVariables, IEnumerable<string> locFiles, IEnumerable<string> libraryFiles, string outputPath, OutputType outputType, string cabCachePath, IEnumerable<string> cultures, bool bindFiles, IEnumerable<BindPath> bindPaths, string intermediateFolder, string contentsFile, string outputsFile, string builtOutputsFile, string wixProjectFile) 16 public BuildCommand(IServiceProvider serviceProvider, IExtensionManager extensions, IEnumerable<SourceFile> sources, IDictionary<string, string> preprocessorVariables, IEnumerable<string> locFiles, IEnumerable<string> libraryFiles, string outputPath, OutputType outputType, string cabCachePath, IEnumerable<string> cultures, bool bindFiles, IEnumerable<BindPath> bindPaths, string intermediateFolder, string contentsFile, string outputsFile, string builtOutputsFile, string wixProjectFile)
16 { 17 {
18 this.ServiceProvider = serviceProvider;
17 this.ExtensionManager = extensions; 19 this.ExtensionManager = extensions;
18 this.LocFiles = locFiles; 20 this.LocFiles = locFiles;
19 this.LibraryFiles = libraryFiles; 21 this.LibraryFiles = libraryFiles;
@@ -34,7 +36,9 @@ namespace WixToolset.Core
34 this.WixProjectFile = wixProjectFile; 36 this.WixProjectFile = wixProjectFile;
35 } 37 }
36 38
37 public ExtensionManager ExtensionManager { get; } 39 public IServiceProvider ServiceProvider { get; }
40
41 public IExtensionManager ExtensionManager { get; }
38 42
39 public IEnumerable<string> LocFiles { get; } 43 public IEnumerable<string> LocFiles { get; }
40 44
@@ -173,7 +177,7 @@ namespace WixToolset.Core
173 intermediateFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); 177 intermediateFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
174 } 178 }
175 179
176 var context = new BindContext(); 180 var context = this.ServiceProvider.GetService<IBindContext>();
177 context.Messaging = Messaging.Instance; 181 context.Messaging = Messaging.Instance;
178 context.ExtensionManager = this.ExtensionManager; 182 context.ExtensionManager = this.ExtensionManager;
179 context.BindPaths = this.BindPaths ?? Array.Empty<BindPath>(); 183 context.BindPaths = this.BindPaths ?? Array.Empty<BindPath>();
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)
diff --git a/src/WixToolset.Core/CommandLine/CommandLineContext.cs b/src/WixToolset.Core/CommandLine/CommandLineContext.cs
new file mode 100644
index 00000000..96c149be
--- /dev/null
+++ b/src/WixToolset.Core/CommandLine/CommandLineContext.cs
@@ -0,0 +1,26 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3namespace WixToolset.Core
4{
5 using System;
6 using WixToolset.Data;
7 using WixToolset.Extensibility.Services;
8
9 internal class CommandLineContext : ICommandLineContext
10 {
11 public CommandLineContext(IServiceProvider serviceProvider)
12 {
13 this.ServiceProvider = serviceProvider;
14 }
15
16 public IServiceProvider ServiceProvider { get; }
17
18 public Messaging Messaging { get; set; }
19
20 public IExtensionManager ExtensionManager { get; set; }
21
22 public string Arguments { get; set; }
23
24 public string[] ParsedArguments { get; set; }
25 }
26}
diff --git a/src/WixToolset.Core/CommandLine/CompileCommand.cs b/src/WixToolset.Core/CommandLine/CompileCommand.cs
index bbcc8270..855e7c6a 100644
--- a/src/WixToolset.Core/CommandLine/CompileCommand.cs
+++ b/src/WixToolset.Core/CommandLine/CompileCommand.cs
@@ -2,9 +2,8 @@
2 2
3namespace WixToolset.Core 3namespace WixToolset.Core
4{ 4{
5 using System;
6 using System.Collections.Generic; 5 using System.Collections.Generic;
7 using WixToolset.Data; 6 using WixToolset.Extensibility.Services;
8 7
9 internal class CompileCommand : ICommandLineCommand 8 internal class CompileCommand : ICommandLineCommand
10 { 9 {
diff --git a/src/WixToolset.Core/CommandLine/HelpCommand.cs b/src/WixToolset.Core/CommandLine/HelpCommand.cs
index e57ad132..2a2eab24 100644
--- a/src/WixToolset.Core/CommandLine/HelpCommand.cs
+++ b/src/WixToolset.Core/CommandLine/HelpCommand.cs
@@ -3,6 +3,7 @@
3namespace WixToolset.Core 3namespace WixToolset.Core
4{ 4{
5 using System; 5 using System;
6 using WixToolset.Extensibility.Services;
6 7
7 internal class HelpCommand : ICommandLineCommand 8 internal class HelpCommand : ICommandLineCommand
8 { 9 {
diff --git a/src/WixToolset.Core/CommandLine/ICommandLineCommand.cs b/src/WixToolset.Core/CommandLine/ICommandLineCommand.cs
deleted file mode 100644
index f1471355..00000000
--- a/src/WixToolset.Core/CommandLine/ICommandLineCommand.cs
+++ /dev/null
@@ -1,9 +0,0 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3namespace WixToolset.Core
4{
5 public interface ICommandLineCommand
6 {
7 int Execute();
8 }
9}
diff --git a/src/WixToolset.Core/CommandLine/VersionCommand.cs b/src/WixToolset.Core/CommandLine/VersionCommand.cs
index d13e07a3..12941bdc 100644
--- a/src/WixToolset.Core/CommandLine/VersionCommand.cs
+++ b/src/WixToolset.Core/CommandLine/VersionCommand.cs
@@ -1,9 +1,10 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. 1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2 2
3using System;
4
5namespace WixToolset.Core 3namespace WixToolset.Core
6{ 4{
5 using System;
6 using WixToolset.Extensibility.Services;
7
7 internal class VersionCommand : ICommandLineCommand 8 internal class VersionCommand : ICommandLineCommand
8 { 9 {
9 public int Execute() 10 public int Execute()