ligo/scripts/archive_protocol.sh

88 lines
2.7 KiB
Bash
Raw Normal View History

2018-07-19 18:37:11 +04:00
#! /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}
2018-07-19 23:34:49 +04:00
dir_name=${3:-$name}
lib_name=`echo $dir_name | tr -- _ -`
2018-07-19 18:37:11 +04:00
if [ -z "$version" ] ; then
2018-07-19 23:34:49 +04:00
echo "Usage: $0 NNN alpha [proto_dir]"
2018-07-19 18:37:11 +04:00
exit 1
fi
2018-07-19 23:34:49 +04:00
current_hash_alpha=`jq '.hash' < src/proto_$dir_name/lib_protocol/src/TEZOS_PROTOCOL | tr -d '"'`
2018-07-19 18:37:11 +04:00
echo "Computing the protocol hash..."
2018-07-19 23:34:49 +04:00
sed -i --follow-symlink \
-e 's/let version_value = "[^"]*"/let version_value = "'${name}'_'${version}'"/' \
src/proto_${dir_name}/lib_protocol/src/raw_context.ml
long_hash=`./tezos-protocol-compiler -hash-only src/proto_${dir_name}/lib_protocol/src`
2018-07-19 18:37:11 +04:00
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
2018-07-19 23:34:49 +04:00
git mv src/proto_${dir_name}/ src/proto_${version}_${short_hash}
git commit -m "Archive_protocol: rename proto_${dir_name} into proto_${version}_${short_hash}"
2018-07-19 18:37:11 +04:00
sed -i --follow-symlink \
2018-07-19 23:34:49 +04:00
-e s/_${dir_name}/_${version}_${short_hash}/g \
-e s/-${lib_name}/-${version}-${short_hash}/g \
2018-11-22 03:59:06 +04:00
dune $(find src vendors docs -name dune -or -name \*.opam)
2018-07-19 18:37:11 +04:00
2018-07-19 23:34:49 +04:00
if ls src/proto_000_*/lib_protocol/src/TEZOS_PROTOCOL | grep proto_000_ > /dev/null ; then
proto_genesis_dir="proto_000_`ls src | grep proto_000_ | cut -f3 -d_`"
else
proto_genesis_dir="proto_genesis"
fi
2018-07-19 18:37:11 +04:00
cd "src/proto_${version}_${short_hash}"
2018-07-19 23:34:49 +04:00
rename s/${lib_name}/${version}-${short_hash}/ $(find -name \*.opam)
rename s/_${dir_name}/_${version}_${short_hash}/ $(find -name main_\*.ml -or -name main_\*.mli)
2018-07-19 18:37:11 +04:00
sed -i --follow-symlink \
2018-07-19 23:34:49 +04:00
-e s/Tezos_protocol_${dir_name}/Tezos_protocol_${version}_${short_hash}/ \
2018-07-19 18:37:11 +04:00
$(find -name \*.ml -or -name \*.mli) \
2018-07-19 23:34:49 +04:00
../$proto_genesis_dir/lib_client/proto_alpha.ml \
2018-07-19 18:37:11 +04:00
../lib_shell/bench/helpers/proto_alpha.ml
2018-07-19 23:34:49 +04:00
sed -i --follow-symlink \
-e 's/let version_value = "[^"]*"/let version_value = "'${name}'_'${version}'"/' \
lib_protocol/src/raw_context.ml
2018-07-19 18:37:11 +04:00
sed -i --follow-symlink \
-e 's/"hash": "[^"]*",/"hash": "'$long_hash'",/' \
lib_protocol/src/TEZOS_PROTOCOL
2018-11-22 03:59:06 +04:00
sed -i --follow-symlink \
-e "s/-genesis/-000-Ps9mPmXa/" \
-e "s/_genesis/_000_Ps9mPmXa/" \
$(find lib_delegate/test -type f)
2018-07-19 23:34:49 +04:00
2018-07-19 18:37:11 +04:00
cd ../..
sed -i --follow-symlink \
2018-07-19 23:34:49 +04:00
-e "s/${lib_name}/${version}-${short_hash}/" \
2018-07-19 18:37:11 +04:00
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}"