我有这个shell脚本:
#!/usr/bin/env bash
dir_name="$(cd "$(dirname "${BASH_SOURCE}")" && PWD)"
protoc --go_out="$dir_name" --go-grpc_out="$dir_name" "${dir_name}/myservice.proto"
我收到这个奇怪的错误消息:
alex@alex yoda % /Users/alex/codes/yoda/yoda.ores.int/src/proto/generate.sh
/Users/alex/codes/yoda/yoda.ores.int/src/proto
/Users/alex/codes/yoda/yoda.ores.int/src/proto/myservice.proto: File does not reside within any path specified using --proto_path (or -I). You must specify a --proto_path which encompasses this file. Note that the proto_path must be an exact prefix of the .proto file names -- protoc is too dumb to figure out when two paths (e.g. absolute and relative) are equivalent (it's harder than you think).
这是更清晰的错误:
文件不驻留在使用 --proto_path (或 -我)。您必须指定包含此文件的 --proto_path。请注意,proto_path 必须是 .proto 文件的精确前缀 名称 - protoc 太笨了,无法弄清楚何时有两条路径(例如 绝对和相对)是等价的(比你想象的要难)。
输入文件、输出文件和生成脚本都位于同一文件夹中。 有人可以帮我找出我做错了什么吗?
单个输入文件当前如下所示:
// myservice.proto
syntax = "proto3";
package myservice;
// Define your gRPC service.
service MyService {
rpc SendMessage (MessageRequest) returns (MessageResponse);
}
// Define your request and response message types.
message MessageRequest {
string message_data = 1;
// Add more fields as needed
}
message MessageResponse {
string status = 1;
// Add more fields as needed
}
protoc
在导入路径方面具有挑战性。
因为(!)您引用带有
myservice.proto
前缀的 ${dir_name}
,所以您也必须包含 --proto_path=${dir_name}
:
protoc \
--proto_path="$dir_name" \
--go_out="$dir_name" \
--go-grpc_out="$dir_name" \
"${dir_name}/myservice.proto"