浏览文件
protoc.sh
29 行 · 970 B历史下载| 1 | |
| 2 | |
| 3 | # SPDX-FileCopyrightText: Copyright The Lima Authors |
| 4 | # SPDX-License-Identifier: Apache-2.0 |
| 5 | |
| 6 | # Generate Go code from a .proto file. |
| 7 | # Expected to be called from `//go:generate` directive. |
| 8 | |
| 9 | set -eu |
| 10 | if [ "$#" -ne 1 ]; then |
| 11 | echo >&2 "Usage: $0 FILE" |
| 12 | exit 1 |
| 13 | fi |
| 14 | |
| 15 | PROTO="$1" ## a.proto |
| 16 | BASE="$(basename "$PROTO" .proto)" ## a |
| 17 | PB_DESC="${BASE}.pb.desc" ## a.pb.desc |
| 18 | PB_GO="${BASE}.pb.go" ## a.pb.go |
| 19 | GRPC_PB_GO="${BASE}_grpc.pb.go" ## a_grpc.pb.go |
| 20 | |
| 21 | set -x |
| 22 | |
| 23 | protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative "$PROTO" --descriptor_set_out="$PB_DESC" |
| 24 | |
| 25 | # -// - protoc v6.32.0 |
| 26 | # +// - protoc version [omitted for reproducibility] |
| 27 | # |
| 28 | # perl is used because `sed -i` is not portable across BSD (macOS) and GNU. |
| 29 | perl -pi -E 's@(^//.*protoc.*)[[:blank:]]+v[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+@\1 [version omitted for reproducibility]@g' "$PB_GO" "$GRPC_PB_GO" |

