From 6bcc37b07cb10d4882be3d3d707963ec39fbec43 Mon Sep 17 00:00:00 2001 From: "Kraemer, Benjamin" Date: Tue, 5 May 2020 14:41:40 +0200 Subject: [PATCH] Reverted GetDepFilenameForProto Otherwise it creates conflicts with non-standard $(Protobuf_DepFilesPath) --- .../Grpc.Tools.Tests/DepFileUtilTest.cs | 4 +- src/csharp/Grpc.Tools/DepFileUtil.cs | 52 ++++++++----------- 2 files changed, 23 insertions(+), 33 deletions(-) diff --git a/src/csharp/Grpc.Tools.Tests/DepFileUtilTest.cs b/src/csharp/Grpc.Tools.Tests/DepFileUtilTest.cs index 6b22e7f1a00..4da62f5773e 100644 --- a/src/csharp/Grpc.Tools.Tests/DepFileUtilTest.cs +++ b/src/csharp/Grpc.Tools.Tests/DepFileUtilTest.cs @@ -41,9 +41,9 @@ namespace Grpc.Tools.Tests [Test] public void GetDepFilenameForProto_IsSane() { - StringAssert.IsMatch(@"^out[\\/][a-f0-9]{16}[\\/]foo.protodep$", + StringAssert.IsMatch(@"^out[\\/][a-f0-9]{16}_foo.protodep$", DepFileUtil.GetDepFilenameForProto("out", "foo.proto")); - StringAssert.IsMatch(@"^[a-f0-9]{16}[\\/]foo.protodep$", + StringAssert.IsMatch(@"^[a-f0-9]{16}_foo.protodep$", DepFileUtil.GetDepFilenameForProto("", "foo.proto")); } diff --git a/src/csharp/Grpc.Tools/DepFileUtil.cs b/src/csharp/Grpc.Tools/DepFileUtil.cs index 15ffed24546..0c08fcb72e6 100644 --- a/src/csharp/Grpc.Tools/DepFileUtil.cs +++ b/src/csharp/Grpc.Tools/DepFileUtil.cs @@ -145,6 +145,21 @@ namespace Grpc.Tools /// /// Directory hash based on the file name, e. g. "deadbeef12345678" /// + /// + /// Since a project may contain proto files with the same filename but in different + /// directories, a unique directory for the generated files is constructed based on the + /// proto file names directory. The directory path can be arbitrary, for example, + /// it can be outside of the project, or an absolute path including a drive letter, + /// or a UNC network path. A name constructed from such a path by, for example, + /// replacing disallowed name characters with an underscore, may well be over + /// filesystem's allowed path length, since it will be located under the project + /// and solution directories, which are also some level deep from the root. + /// Instead of creating long and unwieldy names for these proto sources, we cache + /// the full path of the name without the filename, as in e. g. "foo/file.proto" + /// will yield the name "deadbeef12345678", where that is a presumed hash value + /// of the string "foo". This allows the path to be short, unique (up to a hash + /// collision), and still allowing the user to guess their provenance. + /// private static string GetDirectoryHash(string proto) { string dirname = Path.GetDirectoryName(proto); @@ -163,29 +178,16 @@ namespace Grpc.Tools /// Relative path to the proto item, e. g. "foo/file.proto" /// /// Full relative path to the dependency file, e. g. - /// "out/deadbeef12345678/file.protodep" + /// "out/deadbeef12345678_file.protodep" /// /// - /// Since a project may contain proto files with the same filename but in different - /// directories, a unique filename for the dependency file is constructed based on the - /// proto file name both name and directory. The directory path can be arbitrary, - /// for example, it can be outside of the project, or an absolute path including - /// a drive letter, or a UNC network path. A name constructed from such a path by, - /// for example, replacing disallowed name characters with an underscore, may well - /// be over filesystem's allowed path length, since it will be located under the - /// project and solution directories, which are also some level deep from the root. - /// Instead of creating long and unwieldy names for these proto sources, we cache - /// the full path of the name without the filename, and append the filename to it, - /// as in e. g. "foo/file.proto" will yield the name "deadbeef12345678/file", where - /// "deadbeef12345678" is a presumed hash value of the string "foo". This allows - /// the file names be short, unique (up to a hash collision), and still allowing - /// the user to guess their provenance. + /// See for notes on directory hash. /// public static string GetDepFilenameForProto(string protoDepDir, string proto) { - string outdir = GetOutputDirWithHash(protoDepDir, proto); + string dirhash = GetDirectoryHash(proto); string filename = Path.GetFileNameWithoutExtension(proto); - return Path.Combine(outdir, $"{filename}.protodep"); + return Path.Combine(protoDepDir, $"{dirhash}_{filename}.protodep"); } /// @@ -197,23 +199,11 @@ namespace Grpc.Tools /// Full relative path to the directory, e. g. "out/deadbeef12345678" /// /// - /// Since a project may contain proto files with the same filename but in different - /// directories, a unique directory for the generated files is constructed based on the - /// proto file names directory. The directory path can be arbitrary, for example, - /// it can be outside of the project, or an absolute path including a drive letter, - /// or a UNC network path. A name constructed from such a path by, for example, - /// replacing disallowed name characters with an underscore, may well be over - /// filesystem's allowed path length, since it will be located under the project - /// and solution directories, which are also some level deep from the root. - /// Instead of creating long and unwieldy names for these proto sources, we cache - /// the full path of the name without the filename, as in e. g. "foo/file.proto" - /// will yield the name "deadbeef12345678", where that is a presumed hash value - /// of the string "foo". This allows the path to be short, unique (up to a hash - /// collision), and still allowing the user to guess their provenance. + /// See for notes on directory hash. /// public static string GetOutputDirWithHash(string outputDir, string proto) { - var dirhash = GetDirectoryHash(proto); + string dirhash = GetDirectoryHash(proto); return Path.Combine(outputDir, dirhash); }