1#!/bin/bash 2# Copyright 2015 gRPC authors. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16set -ex 17 18readonly NANOPB_ALTS_TMP_OUTPUT="$(mktemp -d)" 19readonly NANOPB_TMP_OUTPUT="$(mktemp -d)" 20readonly PROTOBUF_INSTALL_PREFIX="$(mktemp -d)" 21 22# install protoc version 3 23pushd third_party/protobuf 24./autogen.sh 25./configure --prefix="$PROTOBUF_INSTALL_PREFIX" 26make -j 8 27make install 28#ldconfig 29popd 30 31readonly PROTOC_BIN_PATH="$PROTOBUF_INSTALL_PREFIX/bin" 32if [ ! -x "$PROTOBUF_INSTALL_PREFIX/bin/protoc" ]; then 33 echo "Error: protoc not found in temp install dir '$PROTOBUF_INSTALL_PREFIX'" 34 exit 1 35fi 36 37# stack up and change to nanopb's proto generator directory 38pushd third_party/nanopb/generator/proto 39export PATH="$PROTOC_BIN_PATH:$PATH" 40make -j 8 41# back to the root directory 42popd 43 44# 45# Checks for load_balancer.proto 46# 47readonly LOAD_BALANCER_GRPC_OUTPUT_PATH='src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1' 48# nanopb-compile the proto to a temp location 49./tools/codegen/core/gen_nano_proto.sh \ 50 src/proto/grpc/lb/v1/load_balancer.proto \ 51 "$NANOPB_TMP_OUTPUT" \ 52 "$LOAD_BALANCER_GRPC_OUTPUT_PATH" 53 54./tools/codegen/core/gen_nano_proto.sh \ 55 third_party/protobuf/src/google/protobuf/duration.proto \ 56 "$NANOPB_TMP_OUTPUT/google/protobuf" \ 57 "$LOAD_BALANCER_GRPC_OUTPUT_PATH/google/protobuf" 58 59./tools/codegen/core/gen_nano_proto.sh \ 60 third_party/protobuf/src/google/protobuf/timestamp.proto \ 61 "$NANOPB_TMP_OUTPUT/google/protobuf" \ 62 "$LOAD_BALANCER_GRPC_OUTPUT_PATH/google/protobuf" 63 64# compare outputs to checked compiled code 65if ! diff -r "$NANOPB_TMP_OUTPUT" src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1; then 66 echo "Outputs differ: $NANOPB_TMP_OUTPUT vs $LOAD_BALANCER_GRPC_OUTPUT_PATH" 67 exit 2 68fi 69 70# 71# Checks for handshaker.proto and transport_security_common.proto 72# 73readonly HANDSHAKER_GRPC_OUTPUT_PATH='src/core/tsi/alts/handshaker' 74# nanopb-compile the proto to a temp location 75./tools/codegen/core/gen_nano_proto.sh \ 76 src/core/tsi/alts/handshaker/proto/handshaker.proto \ 77 "$NANOPB_ALTS_TMP_OUTPUT" \ 78 "$HANDSHAKER_GRPC_OUTPUT_PATH" 79./tools/codegen/core/gen_nano_proto.sh \ 80 src/core/tsi/alts/handshaker/proto/transport_security_common.proto \ 81 "$NANOPB_ALTS_TMP_OUTPUT" \ 82 "$HANDSHAKER_GRPC_OUTPUT_PATH" 83./tools/codegen/core/gen_nano_proto.sh \ 84 src/core/tsi/alts/handshaker/proto/altscontext.proto \ 85 "$NANOPB_ALTS_TMP_OUTPUT" \ 86 "$HANDSHAKER_GRPC_OUTPUT_PATH" 87 88# compare outputs to checked compiled code 89for NANOPB_OUTPUT_FILE in $NANOPB_ALTS_TMP_OUTPUT/*.pb.*; do 90 if ! diff "$NANOPB_OUTPUT_FILE" "src/core/tsi/alts/handshaker/$(basename $NANOPB_OUTPUT_FILE)"; then 91 echo "Outputs differ: $NANOPB_ALTS_TMP_OUTPUT vs $HANDSHAKER_GRPC_OUTPUT_PATH" 92 exit 2 93 fi 94done 95