diff --git a/tools/codegen/core/gen_nano_proto.sh b/tools/codegen/core/gen_nano_proto.sh index 81b91229709..db69d28ae78 100755 --- a/tools/codegen/core/gen_nano_proto.sh +++ b/tools/codegen/core/gen_nano_proto.sh @@ -33,7 +33,7 @@ # Example usage: # tools/codegen/core/gen_nano_proto.sh \ # src/proto/grpc/lb/v0/load_balancer.proto -# src/core/ext/lb_policy/grpclb/proto/grpc/lb/v0 +# $PWD/src/core/ext/lb_policy/grpclb/proto/grpc/lb/v0 read -r -d '' COPYRIGHT <<'EOF' /* @@ -76,15 +76,15 @@ COPYRIGHT_FILE=$(mktemp) echo "${COPYRIGHT//$CURRENT_YEAR}" > $COPYRIGHT_FILE set -ex -if [ $# -ne 2 ]; then - echo "Usage: $0 " +if [ $# -lt 2 ]; then + echo "Usage: $0 [grpc path]" exit 1 fi -readonly GRPC_ROOT=$PWD +readonly GRPC_ROOT="$PWD" readonly INPUT_PROTO="$1" -readonly REL_OUTPUT_DIR="$2" -readonly ABS_OUTPUT_DIR="$GRPC_ROOT/$2" +readonly OUTPUT_DIR="$2" +readonly GRPC_OUTPUT_DIR="${3:-$OUTPUT_DIR}" readonly EXPECTED_OPTIONS_FILE_PATH="${1%.*}.options" if [[ ! -f "$INPUT_PROTO" ]]; then @@ -96,9 +96,14 @@ if [[ ! -f "${EXPECTED_OPTIONS_FILE_PATH}" ]]; then exit 4 fi -mkdir -p "$ABS_OUTPUT_DIR" +if [[ "${OUTPUT_DIR:0:1}" != '/' ]]; then + echo "The output directory must be an absolute path. Got '$OUTPUT_DIR'" + exit 5 +fi + +mkdir -p "$OUTPUT_DIR" if [ $? != 0 ]; then - echo "Error creating output directory $ABS_OUTPUT_DIR" + echo "Error creating output directory $OUTPUT_DIR" exit 2 fi @@ -117,19 +122,19 @@ pushd "$(dirname $INPUT_PROTO)" > /dev/null protoc \ --plugin=protoc-gen-nanopb="$GRPC_ROOT/third_party/nanopb/generator/protoc-gen-nanopb" \ ---nanopb_out='-T -L#include\ \"third_party/nanopb/pb.h\"'":$ABS_OUTPUT_DIR" \ +--nanopb_out='-T -L#include\ \"third_party/nanopb/pb.h\"'":$OUTPUT_DIR" \ "$(basename $INPUT_PROTO)" readonly PROTO_BASENAME=$(basename $INPUT_PROTO .proto) -sed -i "s:$PROTO_BASENAME.pb.h:$REL_OUTPUT_DIR/$PROTO_BASENAME.pb.h:g" \ - "$ABS_OUTPUT_DIR/$PROTO_BASENAME.pb.c" +sed -i "s:$PROTO_BASENAME.pb.h:${GRPC_OUTPUT_DIR}/$PROTO_BASENAME.pb.h:g" \ + "$OUTPUT_DIR/$PROTO_BASENAME.pb.c" # prepend copyright TMPFILE=$(mktemp) -cat $COPYRIGHT_FILE "$ABS_OUTPUT_DIR/$PROTO_BASENAME.pb.c" > $TMPFILE -mv -v $TMPFILE "$ABS_OUTPUT_DIR/$PROTO_BASENAME.pb.c" -cat $COPYRIGHT_FILE "$ABS_OUTPUT_DIR/$PROTO_BASENAME.pb.h" > $TMPFILE -mv -v $TMPFILE "$ABS_OUTPUT_DIR/$PROTO_BASENAME.pb.h" +cat $COPYRIGHT_FILE "$OUTPUT_DIR/$PROTO_BASENAME.pb.c" > $TMPFILE +mv -v $TMPFILE "$OUTPUT_DIR/$PROTO_BASENAME.pb.c" +cat $COPYRIGHT_FILE "$OUTPUT_DIR/$PROTO_BASENAME.pb.h" > $TMPFILE +mv -v $TMPFILE "$OUTPUT_DIR/$PROTO_BASENAME.pb.h" deactivate rm -rf $VENV_DIR diff --git a/tools/distrib/check_nanopb_output.sh b/tools/distrib/check_nanopb_output.sh index f299d74638b..92cb8ecbb49 100755 --- a/tools/distrib/check_nanopb_output.sh +++ b/tools/distrib/check_nanopb_output.sh @@ -31,36 +31,42 @@ set -ex readonly NANOPB_TMP_OUTPUT="$(mktemp -d)" +readonly PROTOBUF_INSTALL_PREFIX="$(mktemp -d)" # install protoc version 3 pushd third_party/protobuf ./autogen.sh -./configure +./configure --prefix="$PROTOBUF_INSTALL_PREFIX" make make install -ldconfig +#ldconfig popd -if [ ! -x "/usr/local/bin/protoc" ]; then - echo "Error: protoc not found in path" +readonly PROTOC_BIN_PATH="$PROTOBUF_INSTALL_PREFIX/bin" +if [ ! -x "$PROTOBUF_INSTALL_PREFIX/bin/protoc" ]; then + echo "Error: protoc not found in temp install dir '$PROTOBUF_INSTALL_PREFIX'" exit 1 fi -readonly PROTOC_PATH='/usr/local/bin' + # stack up and change to nanopb's proto generator directory pushd third_party/nanopb/generator/proto -PATH="$PROTOC_PATH:$PATH" make - +export PATH="$PROTOC_BIN_PATH:$PATH" +make # back to the root directory popd - +# +# Checks for load_balancer.proto +# +readonly LOAD_BALANCER_GRPC_OUTPUT_PATH='src/core/ext/lb_policy/grpclb/proto/grpc/lb/v0' # nanopb-compile the proto to a temp location -PATH="$PROTOC_PATH:$PATH" ./tools/codegen/core/gen_nano_proto.sh \ +./tools/codegen/core/gen_nano_proto.sh \ src/proto/grpc/lb/v0/load_balancer.proto \ - $NANOPB_TMP_OUTPUT + "$NANOPB_TMP_OUTPUT" \ + "$LOAD_BALANCER_GRPC_OUTPUT_PATH" # compare outputs to checked compiled code if ! diff -r $NANOPB_TMP_OUTPUT src/core/ext/lb_policy/grpclb/proto/grpc/lb/v0; then - echo "Outputs differ: $NANOPB_TMP_OUTPUT vs src/core/ext/lb_policy/grpclb/proto/grpc/lb/v0" + echo "Outputs differ: $NANOPB_TMP_OUTPUT vs $LOAD_BALANCER_GRPC_OUTPUT_PATH" exit 2 fi