grpc / grpc

The C based gRPC (C++, Python, Ruby, Objective-C, PHP, C#)

Home Page:https://grpc.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Python compiler behaving unexpectedly for --descriptor_set_in flag

jasonbrown-alis opened this issue · comments

What version of gRPC and what language are you using?

Python 3.8.9

What operating system (Linux, Windows,...) and version?

macOS Monterey version 12.4

What runtime / compiler are you using (e.g. python version or version of gcc)

Python 3.8.9, Apple clang version 13.1.6 (clang-1316.0.21.2)
Target: arm64-apple-darwin21.5.0
Thread model: posix

What did you do?

When trying to run the grpc_tools.protoc command with the following:
arch -x86_64 python3 -m grpc_tools.protoc --python_out=outDir --grpc_python_out=outDir -I=google/proto -I=mine/proto --descriptor_set_in=mine/proto/descriptor.pb

I get the output: "Missing input file", but upon providing the proto files at the end of the command (i.e. arch -x86_64 python3 -m grpc_tools.protoc --python_out=outDir --grpc_python_out=outDir -I=google/proto -I=mine/proto --descriptor_set_in=mine/proto/descriptor.pb mine/proto/service.proto) it works as expected.

What did you expect to see?

When trying to run the grpc_tools.protoc command with the --descriptor-set-in flag, one would expect this to be sufficient input to generate the protobufs (as it contains the entire definition of the .proto file and it's imports if the --include_imports flag was used when generating the file descriptor set). For the go protobuf compiler, this would work fine.

What did you see instead?

Error message: "Missing input file."

See TROUBLESHOOTING.md for how to diagnose problems better.

Anything else we should know about your project / environment?

the protoc command requires PROTO_FILES, even though you don't have the files locally, you need to get the list of files from the file descriptor set.

Here is a go example used for the javascripts version:

...
// The protoc command requires a set of PROTO_FILES
// Since we are using the --descriptor_set_in= parameter and not the original .proto files, we need to pass the list
// of files on which the FDS object was created.
var protoFiles []string
for _, file := range req.GetFileDescriptorSet().GetFile() {
    protoFiles = append(protoFiles, file.GetName())
}

cmds := "protoc --js_out=import_style=commonjs:" + workDir + " --grpc-web_out=import_style=commonjs,mode=grpcwebtext:" + workDir + " --descriptor_set_in=" + descriptorPath + " " + strings.Join(protoFiles, " ")
out, err := exec.CommandContext(ctx, "bash", cmds).CombinedOutput()
if err != nil {
    return nil, status.Errorf(codes.Internal, "%s : %s", err, out)
}
_ = cmds
...