github.com/thanos-io/thanos@v0.32.5/scripts/genproto.sh (about)

     1  #!/usr/bin/env bash
     2  #
     3  # Generate all protobuf bindings.
     4  # Run from repository root.
     5  set -e
     6  set -u
     7  
     8  PROTOC_VERSION=${PROTOC_VERSION:-3.20.1}
     9  PROTOC_BIN=${PROTOC_BIN:-protoc}
    10  GOIMPORTS_BIN=${GOIMPORTS_BIN:-goimports}
    11  PROTOC_GEN_GOGOFAST_BIN=${PROTOC_GEN_GOGOFAST_BIN:-protoc-gen-gogofast}
    12  
    13  if ! [[ "scripts/genproto.sh" =~ $0 ]]; then
    14    echo "must be run from repository root"
    15    exit 255
    16  fi
    17  
    18  if ! [[ $(${PROTOC_BIN} --version) == *"${PROTOC_VERSION}"* ]]; then
    19    echo "could not find protoc ${PROTOC_VERSION}, is it installed + in PATH?"
    20    exit 255
    21  fi
    22  
    23  mkdir -p /tmp/protobin/
    24  cp ${PROTOC_GEN_GOGOFAST_BIN} /tmp/protobin/protoc-gen-gogofast
    25  PATH=${PATH}:/tmp/protobin
    26  GOGOPROTO_ROOT="$(GO111MODULE=on go list -modfile=.bingo/protoc-gen-gogofast.mod -f '{{ .Dir }}' -m github.com/gogo/protobuf)"
    27  GOGOPROTO_PATH="${GOGOPROTO_ROOT}:${GOGOPROTO_ROOT}/protobuf"
    28  
    29  DIRS="store/storepb/ store/storepb/prompb/ store/labelpb rules/rulespb targets/targetspb store/hintspb queryfrontend metadata/metadatapb exemplars/exemplarspb info/infopb api/query/querypb"
    30  echo "generating code"
    31  pushd "pkg"
    32  for dir in ${DIRS}; do
    33    ${PROTOC_BIN} --gogofast_out=Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types,plugins=grpc:. \
    34      -I=. \
    35      -I="${GOGOPROTO_PATH}" \
    36      ${dir}/*.proto
    37  
    38    pushd ${dir}
    39    sed -i.bak -E 's/import _ \"gogoproto\"//g' *.pb.go
    40    sed -i.bak -E 's/_ \"google\/protobuf\"//g' *.pb.go
    41    # We cannot do Mstore/storepb/types.proto=github.com/thanos-io/thanos/pkg/store/storepb,\ due to protobuf v1 bug.
    42    # TODO(bwplotka): Consider removing in v2.
    43    sed -i.bak -E 's/\"store\/storepb\"/\"github.com\/thanos-io\/thanos\/pkg\/store\/storepb\"/g' *.pb.go
    44    sed -i.bak -E 's/\"store\/labelpb\"/\"github.com\/thanos-io\/thanos\/pkg\/store\/labelpb\"/g' *.pb.go
    45    sed -i.bak -E 's/\"store\/storepb\/prompb\"/\"github.com\/thanos-io\/thanos\/pkg\/store\/storepb\/prompb\"/g' *.pb.go
    46    rm -f *.bak
    47    ${GOIMPORTS_BIN} -w *.pb.go
    48    popd
    49  done
    50  popd
    51  
    52  # Generate vendored Cortex protobufs.
    53  CORTEX_DIRS="cortex/querier/queryrange/"
    54  pushd "internal"
    55  for dir in ${CORTEX_DIRS}; do
    56    ${PROTOC_BIN} --gogofast_out=Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types,plugins=grpc:. \
    57      -I=../pkg \
    58      -I="${GOGOPROTO_PATH}" \
    59      -I=. \
    60      ${dir}/*.proto
    61  
    62    pushd ${dir}
    63    sed -i.bak -E 's/import _ \"gogoproto\"//g' *.pb.go
    64    sed -i.bak -E 's/_ \"google\/protobuf\"//g' *.pb.go
    65    sed -i.bak -E 's/\"cortex\/cortexpb\"/\"github.com\/thanos-io\/thanos\/internal\/cortex\/cortexpb\"/g' *.pb.go
    66    rm -f *.bak
    67    ${GOIMPORTS_BIN} -w *.pb.go
    68    popd
    69  done
    70  popd