aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/CommandLine/CommandLineParser.cs
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2017-12-22 15:53:01 -0800
committerRob Mensching <rob@firegiant.com>2017-12-22 15:53:01 -0800
commitecf3a0cca5a424a91ab98557d963d2535963d582 (patch)
tree06355e906e5c404480dc6eac342b9b4d2ec9d122 /src/WixToolset.Core/CommandLine/CommandLineParser.cs
parentdc9f4c329e6f55ce7595970463e0caf148096f4b (diff)
downloadwix-ecf3a0cca5a424a91ab98557d963d2535963d582.tar.gz
wix-ecf3a0cca5a424a91ab98557d963d2535963d582.tar.bz2
wix-ecf3a0cca5a424a91ab98557d963d2535963d582.zip
Reintroduce binder extensions and light.exe for binding .wixouts
Diffstat (limited to '')
-rw-r--r--src/WixToolset.Core/CommandLine/CommandLineParser.cs (renamed from src/WixToolset.Core/CommandLine/CommandLine.cs)92
1 files changed, 14 insertions, 78 deletions
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
3namespace WixToolset.Core 3namespace 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 }