File: pb-rs-gen.sh

package info (click to toggle)
rust-rust-unixfs 0.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 652 kB
  • sloc: sh: 17; makefile: 2
file content (32 lines) | stat: -rwxr-xr-x 894 bytes parent folder | download | duplicates (2)
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
#!/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"
	pb-rs --single-mod --output "$output" "$tmpfile" || retval=$?
	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