From 6bea9e25b1a3a362c0f5f09f5b64af0365604400 Mon Sep 17 00:00:00 2001 From: csharptest Date: Wed, 10 Oct 2012 16:44:31 -0500 Subject: Issue 40: import doesn't work / proto_path does not work for command-line file names --- src/ProtoGen/ProgramPreprocess.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/ProtoGen') diff --git a/src/ProtoGen/ProgramPreprocess.cs b/src/ProtoGen/ProgramPreprocess.cs index 011035eb..110bdff0 100644 --- a/src/ProtoGen/ProgramPreprocess.cs +++ b/src/ProtoGen/ProgramPreprocess.cs @@ -84,6 +84,15 @@ namespace Google.ProtocolBuffers.ProtoGen return 0; } + string pathRoot = Environment.CurrentDirectory; + foreach(string arg in args) + { + if (arg.StartsWith("--proto_path=", StringComparison.InvariantCultureIgnoreCase)) + { + pathRoot = arg.Substring(13); + } + } + foreach (string arg in args) { if (arg.StartsWith(ProtocDirectoryArg)) @@ -95,7 +104,7 @@ namespace Google.ProtocolBuffers.ProtoGen { protocArgs.Add(arg); } - else if (File.Exists(arg) && + else if ((File.Exists(arg) || File.Exists(Path.Combine(pathRoot, arg))) && StringComparer.OrdinalIgnoreCase.Equals(".proto", Path.GetExtension(arg))) { if (tempFile == null) @@ -105,7 +114,13 @@ namespace Google.ProtocolBuffers.ProtoGen protocArgs.Add(String.Format("--descriptor_set_out={0}", tempFile)); protoGenArgs.Add(tempFile); } - protocArgs.Add(arg); + string patharg = arg; + if (!File.Exists(patharg)) + { + patharg = Path.Combine(pathRoot, arg); + } + + protocArgs.Add(patharg); } else { -- cgit v1.2.3