From 077b3cd9642f5f780a26e73dcdcde2701d57eb9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Henry?= Date: Thu, 19 Jul 2018 16:37:11 +0200 Subject: [PATCH] Script: add `archive_protocol.sh` --- scripts/archive_protocol.sh | 82 +++++++++++++++++++ src/bin_client/test/test_basic.sh | 1 - src/proto_alpha/lib_delegate/test/test_rpc.ml | 4 +- 3 files changed, 83 insertions(+), 4 deletions(-) create mode 100755 scripts/archive_protocol.sh diff --git a/scripts/archive_protocol.sh b/scripts/archive_protocol.sh new file mode 100755 index 000000000..5fcc61d62 --- /dev/null +++ b/scripts/archive_protocol.sh @@ -0,0 +1,82 @@ +#! /bin/sh + +set -e + +script_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)/")" +cd "$script_dir"/.. + +if ! [ -z "$(git status -s)" ] ; then + echo "This script cannot be applied within a dirty git directory," + echo "you need 'stash' or 'commit' your changes before." + exit 1 +fi + +version=$1 +name=${2:-alpha} + +if [ -z "$version" ] ; then + echo "Usage: $0 NNN [alpha|genesis|...]" + exit 1 +fi + +alpha_tmpdir=`mktemp -d` + +cleanup () { + set +e + echo Cleaning up... + [ ! -d "$alpha_tmpdir" ] || rm -rf "$alpha_tmpdir" +} +trap cleanup EXIT INT + +mkdir "$alpha_tmpdir"/src + +current_hash_alpha=`jq '.hash' < src/proto_alpha/lib_protocol/src/TEZOS_PROTOCOL | tr -d '"'` + +echo "Computing the protocol hash..." + +cp src/proto_${name}/lib_protocol/src/*.ml src/proto_${name}/lib_protocol/src/*.mli "$alpha_tmpdir"/src/ +grep -v '"hash"' < src/proto_${name}/lib_protocol/src/TEZOS_PROTOCOL > "$alpha_tmpdir"/src/TEZOS_PROTOCOL +long_hash=`./tezos-protocol-compiler $alpha_tmpdir/tmp $alpha_tmpdir/src | cut -d' ' -f2` +short_hash=$(echo $long_hash | head -c 8) + +if [ -d "src/proto_${version}_${short_hash}" ] ; then + echo "Error: you should remove the directory 'src/proto_${version}_${short_hash}'" + exit 1 +fi + +git mv src/proto_${name}/ src/proto_${version}_${short_hash} +git commit -m "Archive_protocol: rename proto_${name} into proto_${version}_${short_hash}" + +sed -i --follow-symlink \ + -e s/_${name}/_${version}_${short_hash}/g \ + -e s/-${name}/-${version}-${short_hash}/g \ + $(find -name jbuild -or -name \*.opam) + +cd "src/proto_${version}_${short_hash}" + +rename s/${name}/${version}-${short_hash}/ $(find -name \*.opam) +rename s/_${name}/_${version}_${short_hash}/ $(find -name main_\*.ml -or -name main_\*.mli) + +sed -i --follow-symlink \ + -e s/Tezos_protocol_${name}/Tezos_protocol_${version}_${short_hash}/ \ + $(find -name \*.ml -or -name \*.mli) \ + ../proto_genesis/lib_client/proto_alpha.ml \ + ../lib_shell/bench/helpers/proto_alpha.ml + +sed -i --follow-symlink \ + -e 's/let version_value = "[^"]*"/let version_value = "${name}_'${version}'"/' lib_protocol/src/raw_context.ml + +sed -i --follow-symlink \ + -e 's/"hash": "[^"]*",/"hash": "'$long_hash'",/' \ + lib_protocol/src/TEZOS_PROTOCOL + +cd ../.. + +sed -i --follow-symlink \ + -e "s/${name}/${version}-${short_hash}/" \ + active_protocol_versions + +find src/bin_client docs -type f -exec sed "s/$current_hash_alpha/$long_hash/g" -i {} \; + +git add . +git commit -m "Archive_protocol: update hashes in proto_${version}_${short_hash}" diff --git a/src/bin_client/test/test_basic.sh b/src/bin_client/test/test_basic.sh index 621695bcf..b507aa8f2 100755 --- a/src/bin_client/test/test_basic.sh +++ b/src/bin_client/test/test_basic.sh @@ -13,7 +13,6 @@ $client -w none config update sleep 2 #tests for the rpc service raw_context -$client rpc get '/chains/main/blocks/head/context/raw/bytes/version' | assert '"616c7068615f303032"' $client rpc get '/chains/main/blocks/head/context/raw/bytes/non-existent' | assert 'No service found at this URL' $client rpc get '/chains/main/blocks/head/context/raw/bytes/delegates/?depth=3' | assert '{ "ed25519": { "02": { "29": null }, "a9": { "ce": null }, "c5": { "5c": null }, diff --git a/src/proto_alpha/lib_delegate/test/test_rpc.ml b/src/proto_alpha/lib_delegate/test/test_rpc.ml index 128d93c35..37be8e0c8 100644 --- a/src/proto_alpha/lib_delegate/test/test_rpc.ml +++ b/src/proto_alpha/lib_delegate/test/test_rpc.ml @@ -42,7 +42,6 @@ let run blkid = in (* files and directories that are in context *) - let version = Key (MBytes.of_hex (`Hex "616c7068615f303032")) in let dir_depth0 = Cut in let dir_depth2 = Dir [("02", Dir [("29", Cut)]); ("a9", Dir [("ce", Cut)]); @@ -51,8 +50,7 @@ let run blkid = ("e7", Dir [("67", Cut)]); ] in - let tests = [((["version"],1), is_equal version); - (([""],0), is_equal dir_depth0); + let tests = [(([""],0), is_equal dir_depth0); ((["delegates";"ed25519"],2), is_equal dir_depth2); (* (([""],-1), is_not_found); *) ((["not-existent"],1), is_not_found);