Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
joeljeske opened this issue Mar 26, 2024 · 2 comments
Open

Comments

@joeljeske
Copy link

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 bazelbuild/bazel#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
Copy link
Author

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")

@srikrsna-buf
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants