Open wangming1993 opened 6 years ago
#!/bin/bash #function walk_dir(){ # for element in `ls $1` # do # dir_or_file=$1"/"$element # if [ -d $dir_or_file ] # then # walk_dir $dir_or_file # else # echo $dir_or_file # fi # done #} BASE_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) REPO_PATH="${GOPATH}/src/github.com/bzy-ai/rpc-mesh" PROTO_PACKAGE="github.com/bzy-ai/rpc-mesh/proto" PROTO_PATH="${GOPATH}/src/${PROTO_PACKAGE}" PROTO_IMPORTS="" function get_proto_imports(){ for file in `ls $1` do dir_or_file=$1"/"$file if [ -d $dir_or_file ] then get_proto_imports $dir_or_file else path="$1" len=${#path} # 计算文件名字符串长度 pkg=${path:2:len} #去掉文件名开头部分的 ./ abs_pkg="${PROTO_PACKAGE}" if [[ -n $pkg ]];then file="$pkg/${file}" # 文件路径+文件名 abs_pkg="${PROTO_PACKAGE}/${pkg}" fi if [[ "${file##*.}"x = "proto"x ]] \ && [[ ${file} != google* ]] \ && [[ ${file} != protoc-gen-swagger* ]]; then PROTO_IMPORTS="${PROTO_IMPORTS},M${file}=${abs_pkg}"; fi fi done } cd "${PROTO_PATH}/definition" get_proto_imports "." echo $PROTO_IMPORTS;