From c8c73ccddedcb64f9989e3d5a9f15240b476b551 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Fri, 27 Jul 2018 00:35:52 -0700 Subject: Remove WixFileNotFoundException, report checked paths and improve bind path command-line parsing --- src/WixToolset.Core/Bind/FileResolver.cs | 36 ++++++++++++++++------ src/WixToolset.Core/Bind/ResolveFieldsCommand.cs | 5 ++- src/WixToolset.Core/Bind/TransferFilesCommand.cs | 2 +- .../CommandLine/CommandLineParser.cs | 18 ++++++++--- src/WixToolset.Core/Preprocessor.cs | 2 +- 5 files changed, 43 insertions(+), 20 deletions(-) (limited to 'src/WixToolset.Core') diff --git a/src/WixToolset.Core/Bind/FileResolver.cs b/src/WixToolset.Core/Bind/FileResolver.cs index 86075e46..01dfe36c 100644 --- a/src/WixToolset.Core/Bind/FileResolver.cs +++ b/src/WixToolset.Core/Bind/FileResolver.cs @@ -43,17 +43,24 @@ namespace WixToolset.Core.Bind public string Resolve(SourceLineNumber sourceLineNumbers, IntermediateTupleDefinition tupleDefinition, string source) { + var checkedPaths = new List(); + foreach (var extension in this.LibrarianExtensions) { - var resolved = extension.Resolve(sourceLineNumbers, tupleDefinition, source); + var resolved = extension.ResolveFile(sourceLineNumbers, tupleDefinition, source); + + if (resolved?.CheckedPaths != null) + { + checkedPaths.AddRange(resolved.CheckedPaths); + } - if (null != resolved) + if (!String.IsNullOrEmpty(resolved?.Path)) { - return resolved; + return resolved?.Path; } } - return this.ResolveUsingBindPaths(source, tupleDefinition, sourceLineNumbers, BindStage.Normal); + return this.MustResolveUsingBindPaths(source, tupleDefinition, sourceLineNumbers, BindStage.Normal, checkedPaths); } /// @@ -66,24 +73,32 @@ namespace WixToolset.Core.Bind /// Should return a valid path for the stream to be imported. public string ResolveFile(string source, IntermediateTupleDefinition tupleDefinition, SourceLineNumber sourceLineNumbers, BindStage bindStage) { + var checkedPaths = new List(); + foreach (var extension in this.ResolverExtensions) { var resolved = extension.ResolveFile(source, tupleDefinition, sourceLineNumbers, bindStage); - if (null != resolved) + if (resolved?.CheckedPaths != null) + { + checkedPaths.AddRange(resolved.CheckedPaths); + } + + if (!String.IsNullOrEmpty(resolved?.Path)) { - return resolved; + return resolved?.Path; } } - return this.ResolveUsingBindPaths(source, tupleDefinition, sourceLineNumbers, bindStage); + return this.MustResolveUsingBindPaths(source, tupleDefinition, sourceLineNumbers, bindStage, checkedPaths); } - private string ResolveUsingBindPaths(string source, IntermediateTupleDefinition tupleDefinition, SourceLineNumber sourceLineNumbers, BindStage bindStage) + private string MustResolveUsingBindPaths(string source, IntermediateTupleDefinition tupleDefinition, SourceLineNumber sourceLineNumbers, BindStage bindStage, List checkedPaths) { string resolved = null; // If the file exists, we're good to go. + checkedPaths.Add(source); if (CheckFileExists(source)) { resolved = source; @@ -121,6 +136,7 @@ namespace WixToolset.Core.Bind { var filePath = Path.Combine(bindPath.Path, pathWithoutSourceDir); + checkedPaths.Add(filePath); if (CheckFileExists(filePath)) { resolved = filePath; @@ -131,6 +147,7 @@ namespace WixToolset.Core.Bind { var filePath = Path.Combine(bindPath.Path, path); + checkedPaths.Add(filePath); if (CheckFileExists(filePath)) { resolved = filePath; @@ -141,10 +158,9 @@ namespace WixToolset.Core.Bind if (null == resolved) { - throw new WixFileNotFoundException(sourceLineNumbers, source, tupleDefinition.Name); + throw new WixException(ErrorMessages.FileNotFound(sourceLineNumbers, source, tupleDefinition.Name, checkedPaths)); } - // Didn't find the file. return resolved; } diff --git a/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs b/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs index 0d5c3142..b7ed8a18 100644 --- a/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs +++ b/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs @@ -152,10 +152,9 @@ namespace WixToolset.Core.Bind } #endif } - catch (WixFileNotFoundException) + catch (WixException e) { - // display the error with source line information - this.Messaging.Write(ErrorMessages.FileNotFound(row.SourceLineNumbers, objectField.Path)); + this.Messaging.Write(e.Error); } } diff --git a/src/WixToolset.Core/Bind/TransferFilesCommand.cs b/src/WixToolset.Core/Bind/TransferFilesCommand.cs index b89d3d03..b9c54a14 100644 --- a/src/WixToolset.Core/Bind/TransferFilesCommand.cs +++ b/src/WixToolset.Core/Bind/TransferFilesCommand.cs @@ -63,7 +63,7 @@ namespace WixToolset.Core.Bind } catch (FileNotFoundException e) { - throw new WixFileNotFoundException(fileTransfer.SourceLineNumbers, e.FileName); + throw new WixException(ErrorMessages.FileNotFound(fileTransfer.SourceLineNumbers, e.FileName)); } catch (DirectoryNotFoundException) { diff --git a/src/WixToolset.Core/CommandLine/CommandLineParser.cs b/src/WixToolset.Core/CommandLine/CommandLineParser.cs index 92944ab2..d518931a 100644 --- a/src/WixToolset.Core/CommandLine/CommandLineParser.cs +++ b/src/WixToolset.Core/CommandLine/CommandLineParser.cs @@ -22,6 +22,8 @@ namespace WixToolset.Core.CommandLine internal class CommandLineParser : ICommandLineParser { + private static readonly char[] BindPathSplit = { '=' }; + public CommandLineParser(IServiceProvider serviceProvider) { this.ServiceProvider = serviceProvider; @@ -380,15 +382,15 @@ namespace WixToolset.Core.CommandLine foreach (var bindPath in bindPaths) { - var bp = BindPath.Parse(bindPath); + var bp = ParseBindPath(bindPath); - if (Directory.Exists(bp.Path)) + if (File.Exists(bp.Path)) { - result.Add(bp); + this.Messaging.Write(ErrorMessages.ExpectedDirectoryGotFile("-bindpath", bp.Path)); } - else if (File.Exists(bp.Path)) + else { - this.Messaging.Write(ErrorMessages.ExpectedDirectoryGotFile("-bindpath", bp.Path)); + result.Add(bp); } } @@ -407,5 +409,11 @@ namespace WixToolset.Core.CommandLine return false; } + + public static BindPath ParseBindPath(string bindPath) + { + string[] namedPath = bindPath.Split(BindPathSplit, 2); + return (1 == namedPath.Length) ? new BindPath(namedPath[0]) : new BindPath(namedPath[0], namedPath[1]); + } } } diff --git a/src/WixToolset.Core/Preprocessor.cs b/src/WixToolset.Core/Preprocessor.cs index ac8cefe3..aca954bd 100644 --- a/src/WixToolset.Core/Preprocessor.cs +++ b/src/WixToolset.Core/Preprocessor.cs @@ -649,7 +649,7 @@ namespace WixToolset.Core if (null == includeFile) { - throw new WixFileNotFoundException(sourceLineNumbers, includePath, "include"); + throw new WixException(ErrorMessages.FileNotFound(sourceLineNumbers, includePath, "include")); } using (XmlReader reader = XmlReader.Create(includeFile, DocumentXmlReaderSettings)) -- cgit v1.2.3-55-g6feb