forked from stellar/stellar-core
-
Notifications
You must be signed in to change notification settings - Fork 1
/
hash-xdrs.sh
executable file
·35 lines (29 loc) · 1.11 KB
/
hash-xdrs.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
#!/bin/bash
#
# This file generates a C++ file which contains (filename, hash) pairs for XDR
# files included in the build. These are included in the stellar-core build to
# be checked against similar hashes produced by xdrgen when it is compiling XDR
# definitions for Rust code.
#
# The goal is to detect the (unfortunately easy) condition of C++ and Rust code
# communicating with each other using different XDR definitions.
set -o errexit
set -o pipefail
if [ ! -d $1/xdr ]; then
echo "usage: $0 XDR_PROTOCOL_DIR"
exit 1
fi
cat <<EOF
// DO NOT EDIT: this file is automatically generated from $0
#include <string>
#include <vector>
#include <filesystem>
namespace stellar {
extern const std::vector<std::pair<std::filesystem::path, std::string>> XDR_FILES_SHA256 = {
EOF
# Hashes to ignore
IGNORE="Stellar-internal\|Stellar-overlay\|Stellar-contract-spec\|Stellar-contract-meta\|Stellar-contract-env-meta"
sha256sum -b $1/xdr/*.x | grep -v "${IGNORE}" | perl -pe 's/([a-f0-9]+)[ \*]+(.*)/{"$2", "$1"},/'
# Add empty entries for the 5 skipped files
echo '{"", ""}, {"", ""}, {"", ""}, {"", ""}, {"", ""}};'
echo '}'