1

我有几个嵌套目录,每个都包含 proto 文件,并且许多 proto 文件依赖于位于根目录中某处的其他 proto。我正在使用这个脚本来尝试编译它们,并从一个目录中执行它,该目录包含带有 protos 的文件夹和我希望编译的 proto 类所在的文件夹。我现在遇到的问题之一是我遇到了protoc: command not found错误。

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

关于如何最好地做到这一点的任何想法?

4

1 回答 1

2

忘记发布我是如何解决这个问题的。这成功了(基本上只是用 -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
于 2017-12-14T01:41:40.387 回答