2
0
mirror of https://github.com/lightninglabs/loop synced 2024-11-17 21:25:56 +00:00
loop/looprpc/gen_protos.sh
carla dad103530f
multi: move server proto files to their own directory
Protobuf does not allow naming conflicts for files within the same
process, because all proto messages register themselves in a global
registry.

This is problematic because the server's itests import the client's
looprpc package to make rpc queries to the loopd client, thus importing
duplicate common.proto and server.proto from the client's looprc package
(since they're both in there as well).

This change moves the server's proto files into their own directory so
that they are not imported when we want to use the client's files. We
cannot change the package name for the server, because that would be
a breaking change (the package name is included in URIS). Fortunately,
we have the go_package option which allows us to place generated files
in a different location.
2021-12-13 13:56:40 +02:00

53 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
set -e
# generate compiles the *.pb.go stubs from the *.proto files.
function generate() {
# Generate the gRPC bindings for all proto files.
for file in ./*.proto
do
protoc -I/usr/local/include -I. -I.. \
--go_out . --go_opt paths=source_relative \
--go-grpc_out . --go-grpc_opt paths=source_relative \
"${file}"
done
# Generate the REST reverse proxy for the client only.
protoc -I/usr/local/include -I. -I.. \
--grpc-gateway_out . \
--grpc-gateway_opt logtostderr=true \
--grpc-gateway_opt paths=source_relative \
--grpc-gateway_opt grpc_api_configuration=client.yaml \
client.proto
# Finally, generate the swagger file which describes the REST API in detail.
protoc -I/usr/local/include -I. -I.. \
--openapiv2_out . \
--openapiv2_opt logtostderr=true \
--openapiv2_opt grpc_api_configuration=client.yaml \
--openapiv2_opt json_names_for_fields=false \
client.proto
# Generate the JSON/WASM client stubs.
falafel=$(which falafel)
pkg="looprpc"
opts="package_name=$pkg,js_stubs=1,build_tags=// +build js"
protoc -I/usr/local/include -I. -I.. \
--plugin=protoc-gen-custom=$falafel\
--custom_out=. \
--custom_opt="$opts" \
client.proto
}
# format formats the *.proto files with the clang-format utility.
function format() {
find . -name "*.proto" -print0 | xargs -0 clang-format --style=file -i
}
# Compile and format the looprpc package.
pushd looprpc
format
generate
popd