|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +function import_path() { |
| 4 | + local pkg=$1 |
| 5 | + # Find out what version of pool to use for the imported auctioneer.proto by |
| 6 | + # parsing the go.mod file. |
| 7 | + LAST_LINE=$(grep "$pkg" ../go.mod | tail -n 1) |
| 8 | + PKG_PATH="" |
| 9 | + if [[ $LAST_LINE =~ "replace" ]] |
| 10 | + then |
| 11 | + # There is a replace directive. Use awk to split by spaces then extract field |
| 12 | + # 4 and 5 and stitch them together with an @ which will resolve into |
| 13 | + # github.com/lightninglabs/[email protected]. |
| 14 | + PKG_PATH=$(echo $LAST_LINE | awk -F " " '{ print $4"@"$5 }') |
| 15 | + else |
| 16 | + # This is a normal directive, just combine field 1 and 2 with an @. |
| 17 | + PKG_PATH=$(echo $LAST_LINE | awk -F " " '{ print $1"@"$2 }') |
| 18 | + fi |
| 19 | + echo "$GOPATH/pkg/mod/$PKG_PATH" |
| 20 | +} |
| 21 | + |
| 22 | +falafel=$(which falafel) |
| 23 | + |
| 24 | +# Name of the package for the generated APIs. |
| 25 | +pkg="main" |
| 26 | + |
| 27 | +# The package where the protobuf definitions originally are found. |
| 28 | +target_pkg="github.com/lightningnetwork/lnd/lnrpc" |
| 29 | + |
| 30 | +lnd_src=$(import_path "github.com/lightningnetwork/lnd ") |
| 31 | +opts="package_name=$pkg,target_package=$target_pkg,api_prefix=1,js_stubs=1,build_tags=// +build js" |
| 32 | +protoc -I/usr/local/include -I. -I"$lnd_src/lnrpc" \ |
| 33 | + --plugin=protoc-gen-custom=$falafel\ |
| 34 | + --custom_out=. \ |
| 35 | + --custom_opt="$opts" \ |
| 36 | + --proto_path="$1" \ |
| 37 | + rpc.proto stateservice.proto |
| 38 | + |
| 39 | +target_pkg="github.com/lightningnetwork/lnd/lnrpc/verrpc" |
| 40 | +opts="package_name=$pkg,target_package=$target_pkg,api_prefix=1,js_stubs=1,build_tags=// +build js" |
| 41 | +protoc -I/usr/local/include -I. -I"$lnd_src/lnrpc" \ |
| 42 | + --plugin=protoc-gen-custom=$falafel\ |
| 43 | + --custom_out=. \ |
| 44 | + --custom_opt="$opts" \ |
| 45 | + --proto_path="$1" \ |
| 46 | + verrpc/verrpc.proto |
| 47 | + |
| 48 | +# TODO(guggero): Fix import problem with auctioneerrpc package. |
| 49 | +# When uncommenting the following lines, there will be errors in the generated |
| 50 | +# code. You'll need to manually add the auctioneerrpc package import and change |
| 51 | +# the batch snapshot messages from poolrpc to auctioneerrpc. |
| 52 | +# This will be fixed by generating the stubs directly in the repo where the |
| 53 | +# proto lives. |
| 54 | +# |
| 55 | +#target_pkg="github.com/lightninglabs/pool/poolrpc" |
| 56 | +#opts="package_name=$pkg,target_package=$target_pkg,api_prefix=1,js_stubs=1,build_tags=// +build js" |
| 57 | +#protoc -Iproto \ |
| 58 | +# --plugin=protoc-gen-custom=$falafel\ |
| 59 | +# --custom_out=. \ |
| 60 | +# --custom_opt="$opts" \ |
| 61 | +# --proto_path="$1" \ |
| 62 | +# trader.proto |
| 63 | + |
| 64 | +target_pkg="github.com/lightninglabs/loop/looprpc" |
| 65 | +opts="package_name=$pkg,target_package=$target_pkg,api_prefix=1,js_stubs=1,build_tags=// +build js" |
| 66 | +protoc -Iproto \ |
| 67 | + --plugin=protoc-gen-custom=$falafel\ |
| 68 | + --custom_out=. \ |
| 69 | + --custom_opt="$opts" \ |
| 70 | + --proto_path="$1" \ |
| 71 | + loop.proto |
0 commit comments