diff options
Diffstat (limited to 'src/WixToolset.Core/CommandLine')
-rw-r--r-- | src/WixToolset.Core/CommandLine/BuildCommand.cs | 62 | ||||
-rw-r--r-- | src/WixToolset.Core/CommandLine/CommandLineContext.cs | 2 | ||||
-rw-r--r-- | src/WixToolset.Core/CommandLine/CommandLineHelper.cs | 216 | ||||
-rw-r--r-- | src/WixToolset.Core/CommandLine/CommandLineParser.cs (renamed from src/WixToolset.Core/CommandLine/CommandLine.cs) | 92 | ||||
-rw-r--r-- | src/WixToolset.Core/CommandLine/CommandLineResponseFile.cs | 2 | ||||
-rw-r--r-- | src/WixToolset.Core/CommandLine/CompileCommand.cs | 2 | ||||
-rw-r--r-- | src/WixToolset.Core/CommandLine/HelpCommand.cs | 2 | ||||
-rw-r--r-- | src/WixToolset.Core/CommandLine/VersionCommand.cs | 2 |
8 files changed, 267 insertions, 113 deletions
diff --git a/src/WixToolset.Core/CommandLine/BuildCommand.cs b/src/WixToolset.Core/CommandLine/BuildCommand.cs index 92aa3343..5653afca 100644 --- a/src/WixToolset.Core/CommandLine/BuildCommand.cs +++ b/src/WixToolset.Core/CommandLine/BuildCommand.cs | |||
@@ -1,6 +1,6 @@ | |||
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 | ||
3 | namespace WixToolset.Core | 3 | namespace WixToolset.Core.CommandLine |
4 | { | 4 | { |
5 | using System; | 5 | using System; |
6 | using System.Collections.Generic; | 6 | using System.Collections.Generic; |
@@ -13,7 +13,7 @@ namespace WixToolset.Core | |||
13 | 13 | ||
14 | internal class BuildCommand : ICommandLineCommand | 14 | internal class BuildCommand : ICommandLineCommand |
15 | { | 15 | { |
16 | public BuildCommand(IServiceProvider serviceProvider, IMessaging messaging, 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 | public BuildCommand(IServiceProvider serviceProvider, IMessaging messaging, 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) |
17 | { | 17 | { |
18 | this.ServiceProvider = serviceProvider; | 18 | this.ServiceProvider = serviceProvider; |
19 | this.Messaging = messaging; | 19 | this.Messaging = messaging; |
@@ -34,7 +34,6 @@ namespace WixToolset.Core | |||
34 | this.ContentsFile = contentsFile; | 34 | this.ContentsFile = contentsFile; |
35 | this.OutputsFile = outputsFile; | 35 | this.OutputsFile = outputsFile; |
36 | this.BuiltOutputsFile = builtOutputsFile; | 36 | this.BuiltOutputsFile = builtOutputsFile; |
37 | this.WixProjectFile = wixProjectFile; | ||
38 | } | 37 | } |
39 | 38 | ||
40 | public IServiceProvider ServiceProvider { get; } | 39 | public IServiceProvider ServiceProvider { get; } |
@@ -73,8 +72,6 @@ namespace WixToolset.Core | |||
73 | 72 | ||
74 | public string BuiltOutputsFile { get; } | 73 | public string BuiltOutputsFile { get; } |
75 | 74 | ||
76 | public string WixProjectFile { get; } | ||
77 | |||
78 | public int Execute() | 75 | public int Execute() |
79 | { | 76 | { |
80 | var intermediates = this.CompilePhase(); | 77 | var intermediates = this.CompilePhase(); |
@@ -207,7 +204,12 @@ namespace WixToolset.Core | |||
207 | 204 | ||
208 | ResolveResult resolveResult; | 205 | ResolveResult resolveResult; |
209 | { | 206 | { |
210 | var resolver = new Resolver(this.ServiceProvider, this.BindPaths, output, this.IntermediateFolder, localizations); | 207 | var resolver = new Resolver(this.ServiceProvider); |
208 | resolver.BindPaths = this.BindPaths; | ||
209 | resolver.IntermediateFolder = this.IntermediateFolder; | ||
210 | resolver.IntermediateRepresentation = output; | ||
211 | resolver.Localizations = localizations; | ||
212 | |||
211 | resolveResult = resolver.Execute(); | 213 | resolveResult = resolver.Execute(); |
212 | } | 214 | } |
213 | 215 | ||
@@ -224,28 +226,22 @@ namespace WixToolset.Core | |||
224 | intermediateFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); | 226 | intermediateFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); |
225 | } | 227 | } |
226 | 228 | ||
227 | var context = this.ServiceProvider.GetService<IBindContext>(); | 229 | var binder = new Binder(this.ServiceProvider); |
228 | context.Messaging = this.Messaging; | 230 | //binder.CabbingThreadCount = this.CabbingThreadCount; |
229 | //context.CabbingThreadCount = this.CabbingThreadCount; | 231 | binder.CabCachePath = this.CabCachePath; |
230 | context.CabCachePath = this.CabCachePath; | 232 | binder.Codepage = resolveResult.Codepage; |
231 | context.Codepage = resolveResult.Codepage; | 233 | //binder.DefaultCompressionLevel = this.DefaultCompressionLevel; |
232 | //context.DefaultCompressionLevel = this.DefaultCompressionLevel; | 234 | binder.DelayedFields = resolveResult.DelayedFields; |
233 | context.DelayedFields = resolveResult.DelayedFields; | 235 | binder.ExpectedEmbeddedFiles = resolveResult.ExpectedEmbeddedFiles; |
234 | context.ExpectedEmbeddedFiles = resolveResult.ExpectedEmbeddedFiles; | 236 | binder.Ices = Array.Empty<string>(); // TODO: set this correctly |
235 | //context.Ices = this.Ices; | 237 | binder.IntermediateFolder = intermediateFolder; |
236 | context.IntermediateFolder = intermediateFolder; | 238 | binder.IntermediateRepresentation = resolveResult.IntermediateRepresentation; |
237 | context.IntermediateRepresentation = resolveResult.IntermediateRepresentation; | 239 | binder.OutputPath = this.OutputPath; |
238 | context.OutputPath = this.OutputPath; | 240 | binder.OutputPdbPath = Path.ChangeExtension(this.OutputPath, ".wixpdb"); |
239 | context.OutputPdbPath = Path.ChangeExtension(this.OutputPath, ".wixpdb"); | 241 | binder.SuppressIces = Array.Empty<string>(); // TODO: set this correctly |
240 | //context.SuppressIces = this.SuppressIces; | 242 | binder.SuppressValidation = true; // TODO: set this correctly |
241 | context.SuppressValidation = true; // TODO: set this correctly | 243 | |
242 | context.ContentsFile = this.ContentsFile; | 244 | bindResult = binder.Execute(); |
243 | context.OutputsFile = this.OutputsFile; | ||
244 | context.BuiltOutputsFile = this.BuiltOutputsFile; | ||
245 | context.WixprojectFile = this.WixProjectFile; | ||
246 | |||
247 | var binder = new Binder(); | ||
248 | bindResult = binder.Bind(context); | ||
249 | } | 245 | } |
250 | 246 | ||
251 | if (this.Messaging.EncounteredError) | 247 | if (this.Messaging.EncounteredError) |
@@ -254,8 +250,14 @@ namespace WixToolset.Core | |||
254 | } | 250 | } |
255 | 251 | ||
256 | { | 252 | { |
257 | // TODO: correctly set SuppressAclReset bool at the end. | 253 | var layout = new Layout(this.ServiceProvider); |
258 | var layout = new Layout(this.ServiceProvider, bindResult.FileTransfers, bindResult.ContentFilePaths, this.ContentsFile, this.OutputsFile, this.BuiltOutputsFile, false); | 254 | layout.FileTransfers = bindResult.FileTransfers; |
255 | layout.ContentFilePaths = bindResult.ContentFilePaths; | ||
256 | layout.ContentsFile = this.ContentsFile; | ||
257 | layout.OutputsFile = this.OutputsFile; | ||
258 | layout.BuiltOutputsFile = this.BuiltOutputsFile; | ||
259 | layout.SuppressAclReset = false; // TODO: correctly set SuppressAclReset | ||
260 | |||
259 | layout.Execute(); | 261 | layout.Execute(); |
260 | } | 262 | } |
261 | } | 263 | } |
diff --git a/src/WixToolset.Core/CommandLine/CommandLineContext.cs b/src/WixToolset.Core/CommandLine/CommandLineContext.cs index cbb9af53..2ff2c1fd 100644 --- a/src/WixToolset.Core/CommandLine/CommandLineContext.cs +++ b/src/WixToolset.Core/CommandLine/CommandLineContext.cs | |||
@@ -1,6 +1,6 @@ | |||
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 | ||
3 | namespace WixToolset.Core | 3 | namespace WixToolset.Core.CommandLine |
4 | { | 4 | { |
5 | using System; | 5 | using System; |
6 | using WixToolset.Extensibility.Services; | 6 | using WixToolset.Extensibility.Services; |
diff --git a/src/WixToolset.Core/CommandLine/CommandLineHelper.cs b/src/WixToolset.Core/CommandLine/CommandLineHelper.cs new file mode 100644 index 00000000..51ece0f7 --- /dev/null +++ b/src/WixToolset.Core/CommandLine/CommandLineHelper.cs | |||
@@ -0,0 +1,216 @@ | |||
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 | |||
3 | namespace WixToolset.Core.CommandLine | ||
4 | { | ||
5 | using System; | ||
6 | using System.IO; | ||
7 | using WixToolset.Data; | ||
8 | using WixToolset.Extensibility.Services; | ||
9 | |||
10 | public class CommandLineHelper | ||
11 | { | ||
12 | /// <summary> | ||
13 | /// Validates that a string is a valid directory name, and throws appropriate warnings/errors if not | ||
14 | /// </summary> | ||
15 | /// <param name="commandlineSwitch">The commandline switch we're parsing (for error display purposes).</param> | ||
16 | /// <param name="messageHandler">The messagehandler to report warnings/errors to.</param> | ||
17 | /// <param name="args">The list of strings to check.</param> | ||
18 | /// <param name="index">The index (in args) of the commandline parameter to be parsed.</param> | ||
19 | /// <returns>The string if it is valid, null if it is invalid.</returns> | ||
20 | public static string GetDirectory(string commandlineSwitch, IMessaging messageHandler, string[] args, int index) | ||
21 | { | ||
22 | return GetDirectory(commandlineSwitch, messageHandler, args, index, false); | ||
23 | } | ||
24 | |||
25 | /// <summary> | ||
26 | /// Validates that a string is a valid directory name, and throws appropriate warnings/errors if not | ||
27 | /// </summary> | ||
28 | /// <param name="commandlineSwitch">The commandline switch we're parsing (for error display purposes).</param> | ||
29 | /// <param name="messageHandler">The messagehandler to report warnings/errors to.</param> | ||
30 | /// <param name="args">The list of strings to check.</param> | ||
31 | /// <param name="index">The index (in args) of the commandline parameter to be parsed.</param> | ||
32 | /// <param name="allowPrefix">Indicates if a colon-delimited prefix is allowed.</param> | ||
33 | /// <returns>The string if it is valid, null if it is invalid.</returns> | ||
34 | public static string GetDirectory(string commandlineSwitch, IMessaging messageHandler, string[] args, int index, bool allowPrefix) | ||
35 | { | ||
36 | commandlineSwitch = String.Concat("-", commandlineSwitch); | ||
37 | |||
38 | if (!IsValidArg(args, index)) | ||
39 | { | ||
40 | messageHandler.Write(ErrorMessages.DirectoryPathRequired(commandlineSwitch)); | ||
41 | return null; | ||
42 | } | ||
43 | |||
44 | if (File.Exists(args[index])) | ||
45 | { | ||
46 | messageHandler.Write(ErrorMessages.ExpectedDirectoryGotFile(commandlineSwitch, args[index])); | ||
47 | return null; | ||
48 | } | ||
49 | |||
50 | return VerifyPath(messageHandler, args[index], allowPrefix); | ||
51 | } | ||
52 | |||
53 | /// <summary> | ||
54 | /// Validates that a string is a valid filename, and throws appropriate warnings/errors if not | ||
55 | /// </summary> | ||
56 | /// <param name="commandlineSwitch">The commandline switch we're parsing (for error display purposes).</param> | ||
57 | /// <param name="messageHandler">The messagehandler to report warnings/errors to.</param> | ||
58 | /// <param name="args">The list of strings to check.</param> | ||
59 | /// <param name="index">The index (in args) of the commandline parameter to be parsed.</param> | ||
60 | /// <returns>The string if it is valid, null if it is invalid.</returns> | ||
61 | public static string GetFile(string commandlineSwitch, IMessaging messageHandler, string[] args, int index) | ||
62 | { | ||
63 | commandlineSwitch = String.Concat("-", commandlineSwitch); | ||
64 | |||
65 | if (!IsValidArg(args, index)) | ||
66 | { | ||
67 | messageHandler.Write(ErrorMessages.FilePathRequired(commandlineSwitch)); | ||
68 | return null; | ||
69 | } | ||
70 | |||
71 | if (Directory.Exists(args[index])) | ||
72 | { | ||
73 | messageHandler.Write(ErrorMessages.ExpectedFileGotDirectory(commandlineSwitch, args[index])); | ||
74 | return null; | ||
75 | } | ||
76 | |||
77 | return VerifyPath(messageHandler, args[index]); | ||
78 | } | ||
79 | |||
80 | /// <summary> | ||
81 | /// Get a set of files that possibly have a search pattern in the path (such as '*'). | ||
82 | /// </summary> | ||
83 | /// <param name="searchPath">Search path to find files in.</param> | ||
84 | /// <param name="fileType">Type of file; typically "Source".</param> | ||
85 | /// <returns>An array of files matching the search path.</returns> | ||
86 | /// <remarks> | ||
87 | /// This method is written in this verbose way because it needs to support ".." in the path. | ||
88 | /// It needs the directory path isolated from the file name in order to use Directory.GetFiles | ||
89 | /// or DirectoryInfo.GetFiles. The only way to get this directory path is manually since | ||
90 | /// Path.GetDirectoryName does not support ".." in the path. | ||
91 | /// </remarks> | ||
92 | /// <exception cref="WixFileNotFoundException">Throws WixFileNotFoundException if no file matching the pattern can be found.</exception> | ||
93 | public static string[] GetFiles(string searchPath, string fileType) | ||
94 | { | ||
95 | if (null == searchPath) | ||
96 | { | ||
97 | throw new ArgumentNullException(nameof(searchPath)); | ||
98 | } | ||
99 | |||
100 | // Convert alternate directory separators to the standard one. | ||
101 | string filePath = searchPath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); | ||
102 | int lastSeparator = filePath.LastIndexOf(Path.DirectorySeparatorChar); | ||
103 | string[] files = null; | ||
104 | |||
105 | try | ||
106 | { | ||
107 | if (0 > lastSeparator) | ||
108 | { | ||
109 | files = Directory.GetFiles(".", filePath); | ||
110 | } | ||
111 | else // found directory separator | ||
112 | { | ||
113 | files = Directory.GetFiles(filePath.Substring(0, lastSeparator + 1), filePath.Substring(lastSeparator + 1)); | ||
114 | } | ||
115 | } | ||
116 | catch (DirectoryNotFoundException) | ||
117 | { | ||
118 | // Don't let this function throw the DirectoryNotFoundException. This exception | ||
119 | // occurs for non-existant directories and invalid characters in the searchPattern. | ||
120 | } | ||
121 | catch (ArgumentException) | ||
122 | { | ||
123 | // Don't let this function throw the ArgumentException. This exception | ||
124 | // occurs in certain situations such as when passing a malformed UNC path. | ||
125 | } | ||
126 | catch (IOException) | ||
127 | { | ||
128 | throw new WixFileNotFoundException(searchPath, fileType); | ||
129 | } | ||
130 | |||
131 | if (null == files || 0 == files.Length) | ||
132 | { | ||
133 | throw new WixFileNotFoundException(searchPath, fileType); | ||
134 | } | ||
135 | |||
136 | return files; | ||
137 | } | ||
138 | |||
139 | /// <summary> | ||
140 | /// Validates that a valid string parameter (without "/" or "-"), and returns a bool indicating its validity | ||
141 | /// </summary> | ||
142 | /// <param name="args">The list of strings to check.</param> | ||
143 | /// <param name="index">The index (in args) of the commandline parameter to be validated.</param> | ||
144 | /// <returns>True if a valid string parameter exists there, false if not.</returns> | ||
145 | public static bool IsValidArg(string[] args, int index) | ||
146 | { | ||
147 | if (args.Length <= index || String.IsNullOrEmpty(args[index]) || '/' == args[index][0] || '-' == args[index][0]) | ||
148 | { | ||
149 | return false; | ||
150 | } | ||
151 | else | ||
152 | { | ||
153 | return true; | ||
154 | } | ||
155 | } | ||
156 | |||
157 | /// <summary> | ||
158 | /// Validates that a commandline parameter is a valid file or directory name, and throws appropriate warnings/errors if not | ||
159 | /// </summary> | ||
160 | /// <param name="messageHandler">The messagehandler to report warnings/errors to.</param> | ||
161 | /// <param name="path">The path to test.</param> | ||
162 | /// <returns>The string if it is valid, null if it is invalid.</returns> | ||
163 | public static string VerifyPath(IMessaging messageHandler, string path) | ||
164 | { | ||
165 | return VerifyPath(messageHandler, path, false); | ||
166 | } | ||
167 | |||
168 | /// <summary> | ||
169 | /// Validates that a commandline parameter is a valid file or directory name, and throws appropriate warnings/errors if not | ||
170 | /// </summary> | ||
171 | /// <param name="messageHandler">The messagehandler to report warnings/errors to.</param> | ||
172 | /// <param name="path">The path to test.</param> | ||
173 | /// <param name="allowPrefix">Indicates if a colon-delimited prefix is allowed.</param> | ||
174 | /// <returns>The full path if it is valid, null if it is invalid.</returns> | ||
175 | public static string VerifyPath(IMessaging messageHandler, string path, bool allowPrefix) | ||
176 | { | ||
177 | string fullPath; | ||
178 | |||
179 | if (0 <= path.IndexOf('\"')) | ||
180 | { | ||
181 | messageHandler.Write(ErrorMessages.PathCannotContainQuote(path)); | ||
182 | return null; | ||
183 | } | ||
184 | |||
185 | try | ||
186 | { | ||
187 | string prefix = null; | ||
188 | if (allowPrefix) | ||
189 | { | ||
190 | int prefixLength = path.IndexOf('=') + 1; | ||
191 | if (0 != prefixLength) | ||
192 | { | ||
193 | prefix = path.Substring(0, prefixLength); | ||
194 | path = path.Substring(prefixLength); | ||
195 | } | ||
196 | } | ||
197 | |||
198 | if (String.IsNullOrEmpty(prefix)) | ||
199 | { | ||
200 | fullPath = Path.GetFullPath(path); | ||
201 | } | ||
202 | else | ||
203 | { | ||
204 | fullPath = String.Concat(prefix, Path.GetFullPath(path)); | ||
205 | } | ||
206 | } | ||
207 | catch (Exception e) | ||
208 | { | ||
209 | messageHandler.Write(ErrorMessages.InvalidCommandLineFileName(path, e.Message)); | ||
210 | return null; | ||
211 | } | ||
212 | |||
213 | return fullPath; | ||
214 | } | ||
215 | } | ||
216 | } | ||
diff --git a/src/WixToolset.Core/CommandLine/CommandLine.cs b/src/WixToolset.Core/CommandLine/CommandLineParser.cs index 97f79755..0e7da42a 100644 --- a/src/WixToolset.Core/CommandLine/CommandLine.cs +++ b/src/WixToolset.Core/CommandLine/CommandLineParser.cs | |||
@@ -1,6 +1,6 @@ | |||
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 | ||
3 | namespace WixToolset.Core | 3 | namespace WixToolset.Core.CommandLine |
4 | { | 4 | { |
5 | using System; | 5 | using System; |
6 | using System.Collections.Generic; | 6 | using System.Collections.Generic; |
@@ -22,7 +22,7 @@ namespace WixToolset.Core | |||
22 | Bind, | 22 | Bind, |
23 | } | 23 | } |
24 | 24 | ||
25 | internal class CommandLine : ICommandLine, IParseCommandLine | 25 | internal class CommandLineParser : ICommandLine, IParseCommandLine |
26 | { | 26 | { |
27 | private IServiceProvider ServiceProvider { get; set; } | 27 | private IServiceProvider ServiceProvider { get; set; } |
28 | 28 | ||
@@ -54,7 +54,7 @@ namespace WixToolset.Core | |||
54 | 54 | ||
55 | if (!String.IsNullOrEmpty(context.Arguments)) | 55 | if (!String.IsNullOrEmpty(context.Arguments)) |
56 | { | 56 | { |
57 | args = CommandLine.ParseArgumentsToArray(context.Arguments).Union(args).ToArray(); | 57 | args = CommandLineParser.ParseArgumentsToArray(context.Arguments).Union(args).ToArray(); |
58 | } | 58 | } |
59 | 59 | ||
60 | return this.ParseStandardCommandLine(context, args); | 60 | return this.ParseStandardCommandLine(context, args); |
@@ -88,13 +88,12 @@ namespace WixToolset.Core | |||
88 | var contentsFile = String.Empty; | 88 | var contentsFile = String.Empty; |
89 | var outputsFile = String.Empty; | 89 | var outputsFile = String.Empty; |
90 | var builtOutputsFile = String.Empty; | 90 | var builtOutputsFile = String.Empty; |
91 | var wixProjectFile = String.Empty; | ||
92 | 91 | ||
93 | this.Parse(context, args, (cmdline, arg) => Enum.TryParse(arg, true, out command), (cmdline, arg) => | 92 | this.Parse(context, args, (cmdline, arg) => Enum.TryParse(arg, true, out command), (cmdline, arg) => |
94 | { | 93 | { |
95 | if (cmdline.IsSwitch(arg)) | 94 | if (cmdline.IsSwitch(arg)) |
96 | { | 95 | { |
97 | var parameter = arg.TrimStart(new[] { '-', '/' }); | 96 | var parameter = arg.Substring(1); |
98 | switch (parameter.ToLowerInvariant()) | 97 | switch (parameter.ToLowerInvariant()) |
99 | { | 98 | { |
100 | case "?": | 99 | case "?": |
@@ -127,9 +126,6 @@ namespace WixToolset.Core | |||
127 | case "builtoutputsfile": | 126 | case "builtoutputsfile": |
128 | cmdline.GetNextArgumentOrError(ref builtOutputsFile); | 127 | cmdline.GetNextArgumentOrError(ref builtOutputsFile); |
129 | return true; | 128 | return true; |
130 | case "wixprojectfile": | ||
131 | cmdline.GetNextArgumentOrError(ref wixProjectFile); | ||
132 | return true; | ||
133 | 129 | ||
134 | case "d": | 130 | case "d": |
135 | case "define": | 131 | case "define": |
@@ -181,7 +177,7 @@ namespace WixToolset.Core | |||
181 | } | 177 | } |
182 | else | 178 | else |
183 | { | 179 | { |
184 | files.AddRange(cmdline.GetFiles(arg, "source code")); | 180 | files.AddRange(CommandLineHelper.GetFiles(arg, "source code")); |
185 | return true; | 181 | return true; |
186 | } | 182 | } |
187 | }); | 183 | }); |
@@ -211,7 +207,7 @@ namespace WixToolset.Core | |||
211 | var variables = this.GatherPreprocessorVariables(defines); | 207 | var variables = this.GatherPreprocessorVariables(defines); |
212 | var bindPathList = this.GatherBindPaths(bindPaths); | 208 | var bindPathList = this.GatherBindPaths(bindPaths); |
213 | var type = CalculateOutputType(outputType, outputFile); | 209 | var type = CalculateOutputType(outputType, outputFile); |
214 | return new BuildCommand(this.ServiceProvider, this.Messaging, this.ExtensionManager, sourceFiles, variables, locFiles, libraryFiles, outputFile, type, cabCachePath, cultures, bindFiles, bindPathList, intermediateFolder, contentsFile, outputsFile, builtOutputsFile, wixProjectFile); | 210 | return new BuildCommand(this.ServiceProvider, this.Messaging, this.ExtensionManager, sourceFiles, variables, locFiles, libraryFiles, outputFile, type, cabCachePath, cultures, bindFiles, bindPathList, intermediateFolder, contentsFile, outputsFile, builtOutputsFile); |
215 | } | 211 | } |
216 | 212 | ||
217 | case Commands.Compile: | 213 | case Commands.Compile: |
@@ -283,7 +279,7 @@ namespace WixToolset.Core | |||
283 | } | 279 | } |
284 | #endif | 280 | #endif |
285 | 281 | ||
286 | private ICommandLine Parse(ICommandLineContext context, string[] commandLineArguments, Func<CommandLine, string, bool> parseCommand, Func<CommandLine, string, bool> parseArgument) | 282 | private ICommandLine Parse(ICommandLineContext context, string[] commandLineArguments, Func<CommandLineParser, string, bool> parseCommand, Func<CommandLineParser, string, bool> parseArgument) |
287 | { | 283 | { |
288 | this.FlattenArgumentsWithResponseFilesIntoOriginalArguments(commandLineArguments); | 284 | this.FlattenArgumentsWithResponseFilesIntoOriginalArguments(commandLineArguments); |
289 | 285 | ||
@@ -335,7 +331,7 @@ namespace WixToolset.Core | |||
335 | 331 | ||
336 | foreach (var bindPath in bindPaths) | 332 | foreach (var bindPath in bindPaths) |
337 | { | 333 | { |
338 | BindPath bp = BindPath.Parse(bindPath); | 334 | var bp = BindPath.Parse(bindPath); |
339 | 335 | ||
340 | if (Directory.Exists(bp.Path)) | 336 | if (Directory.Exists(bp.Path)) |
341 | { | 337 | { |
@@ -351,65 +347,6 @@ namespace WixToolset.Core | |||
351 | } | 347 | } |
352 | 348 | ||
353 | /// <summary> | 349 | /// <summary> |
354 | /// Get a set of files that possibly have a search pattern in the path (such as '*'). | ||
355 | /// </summary> | ||
356 | /// <param name="searchPath">Search path to find files in.</param> | ||
357 | /// <param name="fileType">Type of file; typically "Source".</param> | ||
358 | /// <returns>An array of files matching the search path.</returns> | ||
359 | /// <remarks> | ||
360 | /// This method is written in this verbose way because it needs to support ".." in the path. | ||
361 | /// It needs the directory path isolated from the file name in order to use Directory.GetFiles | ||
362 | /// or DirectoryInfo.GetFiles. The only way to get this directory path is manually since | ||
363 | /// Path.GetDirectoryName does not support ".." in the path. | ||
364 | /// </remarks> | ||
365 | /// <exception cref="WixFileNotFoundException">Throws WixFileNotFoundException if no file matching the pattern can be found.</exception> | ||
366 | public string[] GetFiles(string searchPath, string fileType) | ||
367 | { | ||
368 | if (null == searchPath) | ||
369 | { | ||
370 | throw new ArgumentNullException(nameof(searchPath)); | ||
371 | } | ||
372 | |||
373 | // Convert alternate directory separators to the standard one. | ||
374 | string filePath = searchPath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); | ||
375 | int lastSeparator = filePath.LastIndexOf(Path.DirectorySeparatorChar); | ||
376 | string[] files = null; | ||
377 | |||
378 | try | ||
379 | { | ||
380 | if (0 > lastSeparator) | ||
381 | { | ||
382 | files = Directory.GetFiles(".", filePath); | ||
383 | } | ||
384 | else // found directory separator | ||
385 | { | ||
386 | files = Directory.GetFiles(filePath.Substring(0, lastSeparator + 1), filePath.Substring(lastSeparator + 1)); | ||
387 | } | ||
388 | } | ||
389 | catch (DirectoryNotFoundException) | ||
390 | { | ||
391 | // Don't let this function throw the DirectoryNotFoundException. This exception | ||
392 | // occurs for non-existant directories and invalid characters in the searchPattern. | ||
393 | } | ||
394 | catch (ArgumentException) | ||
395 | { | ||
396 | // Don't let this function throw the ArgumentException. This exception | ||
397 | // occurs in certain situations such as when passing a malformed UNC path. | ||
398 | } | ||
399 | catch (IOException) | ||
400 | { | ||
401 | throw new WixFileNotFoundException(searchPath, fileType); | ||
402 | } | ||
403 | |||
404 | if (null == files || 0 == files.Length) | ||
405 | { | ||
406 | throw new WixFileNotFoundException(searchPath, fileType); | ||
407 | } | ||
408 | |||
409 | return files; | ||
410 | } | ||
411 | |||
412 | /// <summary> | ||
413 | /// Validates that a valid switch (starts with "/" or "-"), and returns a bool indicating its validity | 350 | /// Validates that a valid switch (starts with "/" or "-"), and returns a bool indicating its validity |
414 | /// </summary> | 351 | /// </summary> |
415 | /// <param name="args">The list of strings to check.</param> | 352 | /// <param name="args">The list of strings to check.</param> |
@@ -449,7 +386,7 @@ namespace WixToolset.Core | |||
449 | { | 386 | { |
450 | if (this.TryGetNextArgumentOrError(out var arg)) | 387 | if (this.TryGetNextArgumentOrError(out var arg)) |
451 | { | 388 | { |
452 | foreach (var path in this.GetFiles(arg, fileType)) | 389 | foreach (var path in CommandLineHelper.GetFiles(arg, fileType)) |
453 | { | 390 | { |
454 | args.Add(path); | 391 | args.Add(path); |
455 | } | 392 | } |
@@ -458,13 +395,12 @@ namespace WixToolset.Core | |||
458 | 395 | ||
459 | public bool TryGetNextArgumentOrError(out string arg) | 396 | public bool TryGetNextArgumentOrError(out string arg) |
460 | { | 397 | { |
461 | //if (this.RemainingArguments.TryDequeue(out arg) && !this.IsSwitch(arg)) | ||
462 | if (TryDequeue(this.RemainingArguments, out arg) && !this.IsSwitch(arg)) | 398 | if (TryDequeue(this.RemainingArguments, out arg) && !this.IsSwitch(arg)) |
463 | { | 399 | { |
464 | return true; | 400 | return true; |
465 | } | 401 | } |
466 | 402 | ||
467 | this.ErrorArgument = arg ?? CommandLine.ExpectedArgument; | 403 | this.ErrorArgument = arg ?? CommandLineParser.ExpectedArgument; |
468 | 404 | ||
469 | return false; | 405 | return false; |
470 | } | 406 | } |
@@ -489,7 +425,7 @@ namespace WixToolset.Core | |||
489 | { | 425 | { |
490 | if ('@' == arg[0]) | 426 | if ('@' == arg[0]) |
491 | { | 427 | { |
492 | var responseFileArguments = CommandLine.ParseResponseFile(arg.Substring(1)); | 428 | var responseFileArguments = CommandLineParser.ParseResponseFile(arg.Substring(1)); |
493 | args.AddRange(responseFileArguments); | 429 | args.AddRange(responseFileArguments); |
494 | } | 430 | } |
495 | else | 431 | else |
@@ -526,7 +462,7 @@ namespace WixToolset.Core | |||
526 | } | 462 | } |
527 | } | 463 | } |
528 | 464 | ||
529 | private void ProcessRemainingArguments(ICommandLineContext context, Func<CommandLine, string, bool> parseArgument, Func<CommandLine, string, bool> parseCommand) | 465 | private void ProcessRemainingArguments(ICommandLineContext context, Func<CommandLineParser, string, bool> parseArgument, Func<CommandLineParser, string, bool> parseCommand) |
530 | { | 466 | { |
531 | var extensions = this.ExtensionManager.Create<IExtensionCommandLine>(); | 467 | var extensions = this.ExtensionManager.Create<IExtensionCommandLine>(); |
532 | 468 | ||
@@ -593,7 +529,7 @@ namespace WixToolset.Core | |||
593 | arguments = reader.ReadToEnd(); | 529 | arguments = reader.ReadToEnd(); |
594 | } | 530 | } |
595 | 531 | ||
596 | return CommandLine.ParseArgumentsToArray(arguments); | 532 | return CommandLineParser.ParseArgumentsToArray(arguments); |
597 | } | 533 | } |
598 | 534 | ||
599 | private static List<string> ParseArgumentsToArray(string arguments) | 535 | private static List<string> ParseArgumentsToArray(string arguments) |
@@ -631,7 +567,7 @@ namespace WixToolset.Core | |||
631 | // Add the argument to the list if it's not empty. | 567 | // Add the argument to the list if it's not empty. |
632 | if (arg.Length > 0) | 568 | if (arg.Length > 0) |
633 | { | 569 | { |
634 | argsList.Add(CommandLine.ExpandEnvironmentVariables(arg.ToString())); | 570 | argsList.Add(CommandLineParser.ExpandEnvironmentVariables(arg.ToString())); |
635 | arg.Length = 0; | 571 | arg.Length = 0; |
636 | } | 572 | } |
637 | } | 573 | } |
diff --git a/src/WixToolset.Core/CommandLine/CommandLineResponseFile.cs b/src/WixToolset.Core/CommandLine/CommandLineResponseFile.cs index 578c3b22..6922b246 100644 --- a/src/WixToolset.Core/CommandLine/CommandLineResponseFile.cs +++ b/src/WixToolset.Core/CommandLine/CommandLineResponseFile.cs | |||
@@ -1,6 +1,6 @@ | |||
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 | ||
3 | namespace WixToolset | 3 | namespace WixToolset.Core.CommandLine |
4 | { | 4 | { |
5 | using System; | 5 | using System; |
6 | using System.Collections; | 6 | using System.Collections; |
diff --git a/src/WixToolset.Core/CommandLine/CompileCommand.cs b/src/WixToolset.Core/CommandLine/CompileCommand.cs index 856dd29f..f0ff5b1a 100644 --- a/src/WixToolset.Core/CommandLine/CompileCommand.cs +++ b/src/WixToolset.Core/CommandLine/CompileCommand.cs | |||
@@ -1,6 +1,6 @@ | |||
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 | ||
3 | namespace WixToolset.Core | 3 | namespace WixToolset.Core.CommandLine |
4 | { | 4 | { |
5 | using System; | 5 | using System; |
6 | using System.Collections.Generic; | 6 | using System.Collections.Generic; |
diff --git a/src/WixToolset.Core/CommandLine/HelpCommand.cs b/src/WixToolset.Core/CommandLine/HelpCommand.cs index 2a2eab24..6e547d60 100644 --- a/src/WixToolset.Core/CommandLine/HelpCommand.cs +++ b/src/WixToolset.Core/CommandLine/HelpCommand.cs | |||
@@ -1,6 +1,6 @@ | |||
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 | ||
3 | namespace WixToolset.Core | 3 | namespace WixToolset.Core.CommandLine |
4 | { | 4 | { |
5 | using System; | 5 | using System; |
6 | using WixToolset.Extensibility.Services; | 6 | using WixToolset.Extensibility.Services; |
diff --git a/src/WixToolset.Core/CommandLine/VersionCommand.cs b/src/WixToolset.Core/CommandLine/VersionCommand.cs index 12941bdc..a04aac31 100644 --- a/src/WixToolset.Core/CommandLine/VersionCommand.cs +++ b/src/WixToolset.Core/CommandLine/VersionCommand.cs | |||
@@ -1,6 +1,6 @@ | |||
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 | ||
3 | namespace WixToolset.Core | 3 | namespace WixToolset.Core.CommandLine |
4 | { | 4 | { |
5 | using System; | 5 | using System; |
6 | using WixToolset.Extensibility.Services; | 6 | using WixToolset.Extensibility.Services; |