rules_buf icon indicating copy to clipboard operation
rules_buf copied to clipboard

[proto-lint] Could not find file in descriptor database - Bazel 7

Open joeljeske opened this issue 2 years ago • 2 comments

Under bazel 7.1, I am seeing the following error when running the buf proto lint tests. Under Bazel 6.4 the same test targets pass.

Could not find file in descriptor database: bazel-out/k8-fastbuild/bin/my/path/to.proto: No such file or directory

I think its related to https://github.com/bazelbuild/bazel/issues/21075

I can observe that the args params file that is passed to protoc has the following changes when changing bazel versions:

Bazel 6.4

--plugin=protoc-gen-buf-plugin=../rules_buf_toolchains/protoc-gen-buf-lint
--buf-plugin_opt={"error_format":"","input_config":"buf.yaml"}
--descriptor_set_in
../com_google_protobuf/descriptor_proto-descriptor-set.proto.bin
--buf-plugin_out=.
my/path/to.proto

Bazel 7.1

--plugin=protoc-gen-buf-plugin=../rules_buf_toolchains/protoc-gen-buf-lint
--buf-plugin_opt={"error_format":"","input_config":"buf.yaml"}
--descriptor_set_in
../com_google_protobuf/descriptor_proto-descriptor-set.proto.bin
--buf-plugin_out=.
bazel-out/k8-fastbuild/bin/my/path/to.proto

Note that the last argument has the bazel bin dir prefix whereas it previously did not have this.

joeljeske avatar Mar 26 '24 20:03 joeljeske

I've applied this patch to fix under bazel7

diff --git a/buf/internal/plugin.bzl b/buf/internal/plugin.bzl
index 45ee608..50e55a4 100755
--- a/buf/internal/plugin.bzl
+++ b/buf/internal/plugin.bzl
@@ -41,9 +41,14 @@ def protoc_plugin_test(ctx, proto_infos, protoc, plugin, config, files_to_includ
 
             # source is the argument passed to protoc. This is the import path "foo/foo.proto"
             # We have to trim the prefix if strip_import_prefix attr is used in proto_library.
-            sources.append(
-                f.path[len(pi.proto_source_root) + 1:] if f.path.startswith(pi.proto_source_root) else f.path,
-            )
+            file_path = f.path
+            if file_path.startswith(pi.proto_source_root):
+                file_path = file_path[len(pi.proto_source_root) + 1:]
+
+            if file_path.startswith(ctx.bin_dir.path):
+                file_path = file_path[len(ctx.bin_dir.path) + 1:]
+
+            sources.append(file_path)
 
     args = ctx.actions.args()
     args = args.set_param_file_format("multiline")

joeljeske avatar Mar 27 '24 19:03 joeljeske

@joeljeske Thank you for reporting this and for the patch, can you send a PR for this?

srikrsna-buf avatar Apr 01 '24 05:04 srikrsna-buf