github.com/matrixorigin/matrixone@v0.7.0/proto/gen.sh (about)

     1  #!/bin/bash
     2  #
     3  # Generate all MatrixOne protobuf bindings. Run from repository root.
     4  #
     5  set -ex
     6  
     7  program_exists() {
     8    if command -v "${1}" > /dev/null 2>&1; then
     9      echo "ok"
    10    else
    11      echo "fail"
    12    fi
    13  }
    14  
    15  VENDOR_DIR="$PWD/vendor"
    16  PB_DIR="$PWD/pkg/pb"
    17  PROTOC_DIR="$PWD/proto"
    18  PROTO_SYNTAX_VERSION='3'
    19  PROTOC_VERSION='21.1'
    20  GOGOPROTOBUF_VERSION='1.'
    21  
    22  if [ "${GOPATH}" == "" ];then
    23    GOPATH=`go env GOPATH`
    24  fi
    25  echo "GOPATH: ${GOPATH}"
    26  
    27  res=$(program_exists goimports)
    28  echo "res: ${res}"
    29  if [ "${res}" == "ok" ];then
    30    echo "goimports exits"
    31  else
    32    echo "install goimports"
    33    go install golang.org/x/tools/cmd/goimports@latest
    34  fi
    35  
    36  res=$(program_exists protoc)
    37  echo "res: ${res}"
    38  if [ "${res}" == "ok" ];then
    39    echo "protoc exits"
    40    version=$(protoc --version)
    41    if [[ "${version}" == *"${PROTO_SYNTAX_VERSION}.${PROTOC_VERSION}"* ]];then
    42      echo "protoc version matches ${PROTOC_VERSION}"
    43    else
    44      echo "protoc version does not match"
    45    fi
    46    if [ -f ${GOPATH}/bin/protoc ]; then
    47      ${GOPATH}/bin/protoc --version
    48    else
    49      ln -s $(which protoc) ${GOPATH}/bin/protoc
    50      ${GOPATH}/bin/protoc --version
    51    fi
    52  
    53  else
    54    echo "install protoc"
    55    if [ "$(uname)" == "Darwin" ];then
    56      OS='osx'
    57    elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ];then
    58      OS='linux'
    59    else
    60      echo "unsupported os, failed"
    61      exit 1
    62    fi
    63    if [[ "$(uname -m)" == *"x86"* ]];then
    64      ARCH='x86'
    65    elif [[ "$(uname -m)" == *"arm"* ]];then
    66      ARCH='aarch'
    67    elif [[ "$(uname -m)" == *"aarch"* ]];then
    68      ARCH='aarch'
    69    else
    70      echo "unsupported arch, failed"
    71      exit 1
    72    fi
    73    if [[ "$(getconf LONG_BIT)" == "64" ]];then
    74      SYSTEM_BIT='64'
    75    elif [[ "$(getconf LONG_BIT)" == "32" ]];then
    76      SYSTEM_BIT='32'
    77    else
    78      echo "unsupported system bit, failed"
    79      exit 1
    80    fi
    81    PROTOC_ZIP="protoc-${PROTOC_VERSION}-${OS}-${ARCH}_${SYSTEM_BIT}.zip"
    82    curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/${PROTOC_ZIP}
    83    unzip -o $PROTOC_ZIP -d "${GOPATH}/" bin/protoc
    84    unzip -o $PROTOC_ZIP -d "${GOPATH}/" 'include/*'
    85    ${GOPATH}/bin/protoc --version
    86  fi
    87  
    88  res=$(program_exists protoc-gen-gogofast)
    89  echo "res: ${res}"
    90  if [ "${res}" == "ok" ];then
    91    echo "protoc-gen-gogofast exits"
    92  else
    93    echo "install protoc-gen-gogofast"
    94    if [ -f protobuf/ ];then rm -rf protobuf/;fi
    95    git clone https://github.com/gogo/protobuf.git
    96    cd protobuf
    97    git checkout v1.3.2
    98    cd protoc-gen-gogofast
    99    go build -o $GOPATH/bin/protoc-gen-gogofast
   100    cd ../..
   101  fi
   102  
   103  
   104  for file in `ls $PROTOC_DIR/*.proto`
   105  do
   106  	dir=$(basename $file .proto)
   107  	mkdir -p $PB_DIR/$dir
   108  	${GOPATH}/bin/protoc -I=.:$PROTOC_DIR:$VENDOR_DIR --gogofast_out=paths=source_relative:./pkg/pb/$dir  $file
   109      goimports -w $PB_DIR/$dir/*pb.go
   110  done
   111  
   112  if [ -f protobuf/ ];then rm -rf protobuf/;fi