2019-01-24 16:51:05 +03:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
mkdir -p build
|
|
|
|
|
|
|
|
# Check falafel version.
|
2020-07-16 14:18:57 +03:00
|
|
|
falafelVersion=$1
|
|
|
|
if [ -z $falafelVersion ]
|
|
|
|
then
|
|
|
|
echo "falafel version not set"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-01-24 16:51:05 +03:00
|
|
|
falafel=$(which falafel)
|
|
|
|
if [ $falafel ]
|
|
|
|
then
|
2020-07-16 14:18:57 +03:00
|
|
|
version="v$($falafel -v)"
|
2019-01-24 16:51:05 +03:00
|
|
|
if [ $version != $falafelVersion ]
|
|
|
|
then
|
|
|
|
echo "falafel version $falafelVersion required"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo "Using plugin $falafel $version"
|
|
|
|
else
|
|
|
|
echo "falafel not found"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-11-21 14:33:48 +03:00
|
|
|
# Name of the package for the generated APIs.
|
2019-01-24 16:51:05 +03:00
|
|
|
pkg="lndmobile"
|
2019-11-21 14:33:48 +03:00
|
|
|
|
|
|
|
# The package where the protobuf definitions originally are found.
|
2019-01-24 16:51:05 +03:00
|
|
|
target_pkg="github.com/lightningnetwork/lnd/lnrpc"
|
|
|
|
|
2019-11-21 14:33:48 +03:00
|
|
|
# A mapping from grpc service to name of the custom listeners. The grpc server
|
|
|
|
# must be configured to listen on these.
|
|
|
|
listeners="lightning=lightningLis walletunlocker=walletUnlockerLis"
|
|
|
|
|
|
|
|
# Set to 1 to create boiler plate grpc client code and listeners. If more than
|
|
|
|
# one proto file is being parsed, it should only be done once.
|
|
|
|
mem_rpc=1
|
|
|
|
|
2020-08-04 15:43:08 +03:00
|
|
|
PROTOS="rpc.proto walletunlocker.proto"
|
|
|
|
|
2019-11-21 14:33:48 +03:00
|
|
|
opts="package_name=$pkg,target_package=$target_pkg,listeners=$listeners,mem_rpc=$mem_rpc"
|
2020-08-04 15:43:08 +03:00
|
|
|
|
|
|
|
for file in $PROTOS; do
|
|
|
|
echo "Generating mobile protos from ${file}"
|
|
|
|
|
|
|
|
protoc -I/usr/local/include -I. \
|
|
|
|
--plugin=protoc-gen-custom=$falafel\
|
|
|
|
--custom_out=./build \
|
|
|
|
--custom_opt="$opts" \
|
|
|
|
--proto_path=../lnrpc \
|
|
|
|
"${file}"
|
|
|
|
done
|
2019-01-24 16:51:05 +03:00
|
|
|
|
|
|
|
# If prefix=1 is specified, prefix the generated methods with subserver name.
|
|
|
|
# This must be enabled to support subservers with name conflicts.
|
|
|
|
use_prefix="0"
|
2020-07-16 13:59:07 +03:00
|
|
|
if [ "$prefix" = "1" ]
|
2019-01-24 16:51:05 +03:00
|
|
|
then
|
|
|
|
echo "Prefixing methods with subserver name"
|
|
|
|
use_prefix="1"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Find all subservers.
|
|
|
|
for file in ../lnrpc/**/*.proto
|
|
|
|
do
|
|
|
|
DIRECTORY=$(dirname ${file})
|
|
|
|
tag=$(basename ${DIRECTORY})
|
|
|
|
build_tags="// +build $tag"
|
|
|
|
lis="lightningLis"
|
|
|
|
|
|
|
|
opts="package_name=$pkg,target_package=$target_pkg/$tag,build_tags=$build_tags,api_prefix=$use_prefix,defaultlistener=$lis"
|
|
|
|
|
|
|
|
echo "Generating mobile protos from ${file}, with build tag ${tag}"
|
|
|
|
|
|
|
|
protoc -I/usr/local/include -I. \
|
|
|
|
-I../lnrpc \
|
|
|
|
--plugin=protoc-gen-custom=$falafel \
|
|
|
|
--custom_out=./build \
|
|
|
|
--custom_opt="$opts" \
|
|
|
|
--proto_path=${DIRECTORY} \
|
|
|
|
${file}
|
|
|
|
done
|
2019-11-26 16:57:17 +03:00
|
|
|
|
|
|
|
# Run goimports to resolve any dependencies among the sub-servers.
|
|
|
|
goimports -w ./*_generated.go
|