rust-ipfs/unixfs/pb-rs-gen.sh

33 lines
894 B
Bash
Raw Normal View History

2020-06-03 17:15:42 +03:00
#!/usr/bin/env bash
# don't really use this as the files do have local modifications:
# - removal of the broken owned container
# - fixing of clippy warnings
# - added lifetime
# - fix the lint ignore
#
set -eu
gen() {
# strip the packages as apparently there is a bug with single-mod 0.8.2
local tmpfile="$(mktemp).proto"
grep -v '^package ' "$1" > "$tmpfile";
retval=0
local filename="$(basename "$1")"
local output="$(dirname "$1")/${filename%.*}.rs"
2020-06-05 23:32:57 +03:00
pb-rs --single-mod --output "$output" "$tmpfile" || retval=$?
2020-06-03 17:15:42 +03:00
rm "$tmpfile"
if [[ "$retval" -ne 0 ]]; then
return $retval;
fi
# strip out the empty lines and fix the automatically generated comment
# empty lines seem to be a problem for cargo fmt
sed -i -Ee '/^\s*$/d' -e "s/'$(basename "$tmpfile")'/'$filename'/g" "$output"
cargo fmt -- "$output"
}
gen src/pb/merkledag.proto src/pb
gen src/pb/unixfs.proto src/pb