forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_fastcrypto.sh
executable file
·85 lines (72 loc) · 2.17 KB
/
update_fastcrypto.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
# Copyright (c) Mysten Labs, Inc.
# SPDX-License-Identifier: Apache-2.0
# shellcheck disable=SC2181
# This script attempts to update the Fastcrypto pointer in Sui
# It is expected to fail in some cases, notably when those updates require code changes
set -e
set -eo pipefail
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
TOPLEVEL="${DIR}/../"
GREP=${GREP:=grep}
# Crutch for old bash versions
# Very minimal readarray implementation using read. Does NOT work with lines that contain double-quotes due to eval()
readarray() {
while IFS= read -r var; do
MAPFILE+=("$var")
done
}
# check for the presence of needed executables:
# - we use GNU grep in perl re mode
# - we use cargo-hakari
function check_gnu_grep() {
GNUSTRING=$($GREP --version|head -n1| grep 'GNU grep')
if [[ -z $GNUSTRING ]];
then
echo "Could not find GNU grep. This requires GNU grep 3.7 with PCRE expressions"; exit 1
else
return 0
fi
}
function check_cargo_hakari() {
cargo hakari --version > /dev/null 2>&1
if [[ $? -ne 0 ]]; then
echo "Could not find cargo hakari. Please install"; exit 1
else
return 0
fi
}
function latest_fc_revision() {
FC_CHECKOUT=$(mktemp -d)
cd "$FC_CHECKOUT"
git clone --depth 1 https://github.com/mystenlabs/fastcrypto
cd fastcrypto
git rev-parse HEAD
}
function current_fc_revision() {
cd "$TOPLEVEL"
readarray -t <<< "$(find ./ -iname '*.toml' -exec $GREP -oPe 'git = "https://github.com/MystenLabs/fastcrypto", *rev *= *\"\K[0-9a-fA-F]+' '{}' \;)"
watermark=${MAPFILE[0]}
for i in "${MAPFILE[@]}"; do
if [[ "$watermark" != "$i" ]]; then
not_equal=true
break
fi
done
[[ -n "$not_equal" ]] && echo "Different values found for the current Fastcrypto revision in Sui, aborting" && exit 1
echo "$watermark"
}
# Check for tooling
check_gnu_grep
check_cargo_hakari
# Debug prints
CURRENT_FC=$(current_fc_revision)
LATEST_FC=$(latest_fc_revision)
if [[ "$CURRENT_FC" != "$LATEST_FC" ]]; then
echo "About to replace $CURRENT_FC with $LATEST_FC as the Narwhal pointer in Sui"
else
exit 0
fi
# Edit the source & run hakari
find ./ -iname "*.toml" -execdir sed -i '' -re "s/$CURRENT_FC/$LATEST_FC/" '{}' \;
cargo hakari generate