Issue running the protobuf compiler on nested directories of proto files

3.4k views Asked by At

I have several nested directories, each containing proto files, and many of the proto files have dependencies on the other protos located somewhere within the root directory. I'm using this script to try to compile them, and executing it from a directory that contains both the folder with the protos and the folder where I want my compiled proto classes to go. One of the issues I'm having now is that I'm getting a protoc: command not found error.

set -e

BASEDIR="$(greadlink -f $(dirname $0))"
PROTO_DIR="$BASEDIR/new-protos-aug/"
SWIFTPROTO_DIR="$BASEDIR/new-swift-protos-aug/"
echo "Converting files from $PROTO_DIR to $SWIFTPROTO_DIR"

FILES=$(find new-protos-aug -type f -name "*.proto")

for proto in $FILES; do
    PATH=${proto///[^ ]*\.proto/};
    PROTO_DIR="$BASEDIR/$PATH/"
    protoc -I=$PROTO_DIR --swift_out=$SWIFTPROTO_DIR $proto;
done

Any ideas on how best to do this?

1

There are 1 answers

0
Eden On BEST ANSWER

Forgot to post how I resolved this. This did the trick (basically just listing every possible subdirectory with -I)

#!/bin/bash
set -e

BASEDIR="$(greadlink -f $(dirname $0))"
PROTO_DIR="$BASEDIR/new-protos-aug/"
SWIFTPROTO_DIR="$BASEDIR/new-swift-protos-aug/"
echo "Converting files from $PROTO_DIR to $SWIFTPROTO_DIR"

FILES=$(find new-protos-aug -type f -name "*.proto")

for proto in $FILES; do
    echo $proto;
    echo "Running in $PROTO_DIR"
    protoc -I="new-protos-aug" -I="new-protos-aug/bgs/low/pb/client" -I="new-protos-aug/bgs/low/pb/client/client" -I="new-protos-aug/bgs/low/pb/client/global_extensions" -I="new-protos-aug/bgs/low/pb/client/client/v1" -I="new-protos-aug/bgs/low/pb/client/client/v2" -I="new-protos-aug/google/protobuf" --swift_out="$SWIFTPROTO_DIR" "$proto";
done