From ed7879a89ed5c5f1ffe5105ca404976d769281a8 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 12 Aug 2020 12:49:11 +0300 Subject: [PATCH] Add script to prepare multiversion structure --- Makefile | 2 +- prepare.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100755 prepare.sh diff --git a/Makefile b/Makefile index 600586ec..0847abe4 100644 --- a/Makefile +++ b/Makefile @@ -47,7 +47,7 @@ docgen: deps done # Regenerate proto files: -protoc: deps +protoc: @echo "${B}${G}⇒ Cleanup old files ${R}" @find . -type f -name '*.pb.go' -not -path './vendor/*' -exec rm {} \; diff --git a/prepare.sh b/prepare.sh new file mode 100755 index 00000000..75af3e34 --- /dev/null +++ b/prepare.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +prefix=v2 + +if [ -z "$1" ]; then + echo "usage: ./prepare.sh path/to/neofs-api" + exit 1 +fi + +API_GO_PATH=$(pwd) +API_PATH=$1 + +# MOVE FILES FROM API REPO +cd $API_PATH +ARGS=$(find ./ -name '*.proto') +for file in $ARGS; do + dir=$(dirname $file) + cp -r $dir $API_GO_PATH +done +cd $API_GO_PATH + +# MODIFY FILES +for file in $ARGS; do + TYPES=$(grep '^import' $file | sed 's/import\ \"\(.*\)\/.*/\1/' | sort | uniq) + PKG=$(grep '^package' $file | sed 's/package\ \(.*\);/\1/') + + TYPES=( "${TYPES[@]}" "${PKG[@]}") # merge two arrays + TYPES=$(printf "%s\n" "${TYPES[@]}" | sort | uniq) # left only uniq elemetns + + for t in $TYPES; do + sed -i "s/$t\./$t\.$prefix\./" $file + sed -i "s/$t\//$t\/$prefix\//" $file + done + + sed -i "s/^package\(.*\);/package\1.$prefix;/" $file + sed -i "s/go_package\(.*\)\";$/go_package\1\/$prefix\";/" $file + + dir=$(dirname $file) + mkdir $dir/v2 2>/dev/null + mv $file $dir/v2 +done + +# COMPILE +make protoc + +# REMOVE PROTO FILES +# TO BE DONE AS NEOFS-API WILL BE STABLE