github.com/decred/dcrlnd@v0.7.6/mobile/gen_bindings.sh (about)

     1  #!/bin/sh
     2  
     3  mkdir -p build
     4  
     5  # Check falafel version.
     6  falafelVersion=$1
     7  if [ -z $falafelVersion ]
     8  then
     9          echo "falafel version not set"
    10          exit 1
    11  fi
    12  
    13  falafel=$(which falafel)
    14  if [ $falafel ]
    15  then
    16          version="v$($falafel -v)"
    17          if [ $version != $falafelVersion ]
    18          then
    19                  echo "falafel version $falafelVersion required, had $version"
    20                  exit 1
    21          fi
    22          echo "Using plugin $falafel $version"
    23  else
    24          echo "falafel not found"
    25          exit 1
    26  fi
    27  
    28  # Name of the package for the generated APIs.
    29  pkg="dcrlndmobile"
    30  
    31  # The package where the protobuf definitions originally are found.
    32  target_pkg="github.com/decred/dcrlnd/lnrpc"
    33  
    34  # A mapping from grpc service to name of the custom listeners. The grpc server
    35  # must be configured to listen on these.
    36  listeners="lightning=lightningLis walletunlocker=lightningLis state=lightningLis"
    37  
    38  # Set to 1 to create boiler plate grpc client code and listeners. If more than
    39  # one proto file is being parsed, it should only be done once.
    40  mem_rpc=1
    41  
    42  PROTOS="lightning.proto walletunlocker.proto stateservice.proto"
    43  
    44  opts="package_name=$pkg,target_package=$target_pkg,listeners=$listeners,mem_rpc=$mem_rpc"
    45  
    46  for file in $PROTOS; do
    47    echo "Generating mobile protos from ${file}"
    48  
    49    protoc -I/usr/local/include -I. \
    50           --plugin=protoc-gen-custom=$falafel\
    51           --custom_out=./build \
    52           --custom_opt="$opts" \
    53           --proto_path=../lnrpc \
    54           "${file}"
    55  done
    56  
    57  # If prefix=1 is specified, prefix the generated methods with subserver name.
    58  # This must be enabled to support subservers with name conflicts.
    59  use_prefix="0"
    60  if [ "$SUBSERVER_PREFIX" = "1" ]
    61  then
    62      echo "Prefixing methods with subserver name"
    63      use_prefix="1"
    64  fi
    65  
    66  # Find all subservers.
    67  for file in ../lnrpc/**/*.proto
    68  do
    69      DIRECTORY=$(dirname ${file})
    70      tag=$(basename ${DIRECTORY})
    71      build_tags="// +build $tag"
    72      lis="lightningLis"
    73  
    74      opts="package_name=$pkg,target_package=$target_pkg/$tag,build_tags=$build_tags,api_prefix=$use_prefix,defaultlistener=$lis"
    75  
    76      echo "Generating mobile protos from ${file}, with build tag ${tag}"
    77  
    78      protoc -I/usr/local/include -I. \
    79             -I../lnrpc \
    80             --plugin=protoc-gen-custom=$falafel \
    81             --custom_out=./build \
    82             --custom_opt="$opts" \
    83             --proto_path=${DIRECTORY} \
    84             ${file}
    85  done
    86  
    87  # Run goimports to resolve any dependencies among the sub-servers.
    88  goimports -w ./*_generated.go