-
Notifications
You must be signed in to change notification settings - Fork 1
/
build_protos.sh
executable file
·90 lines (83 loc) · 2.06 KB
/
build_protos.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
86
87
88
89
90
#!/bin/sh
set -eu
outdir_name="genproto"
usage() {
printf 'usage: %s --boostrap|PATH_TO_TENSORBOARD_REPO\n' "$0"
printf '\n'
printf 'With --bootstrap, defines Go modules so that go.mod parses.\n'
printf 'With TensorBoard repository, replaces directory "%s" with\n' \
"${outdir_name}"
printf 'Go bindings for proto definitions.\n'
}
needs() {
failed=
for arg; do
if ! command -v "${arg}" >/dev/null 2>&1; then
failed=1
printf 'error: %s: command not found\n' "${arg}"
fi
done
if [ -n "${failed}" ]; then
printf >&2 'fatal: install dependencies and try again\n'
exit 1
fi
}
main() {
if [ $# -ne 1 ]; then
usage >&2
exit 1
fi
outdir="$PWD/${outdir_name}"
case "$1" in
--help) usage ;;
--bootstrap) bootstrap ;;
--*)
usage >&2
exit 1
;;
*)
if ! [ -d "$1" ]; then
usage >&2
exit 1
fi
compile "$1"
;;
esac
}
bootstrap() (
mkdir -p "${outdir}"
cd "${outdir}"
for module in \
github.com/tensorflow/tensorflow \
github.com/wchargin/tensorboard-data-server/proto \
; do
mkdir -p "${module}"
if ! [ -f "${module}/go.mod" ]; then
(cd "${module}" && go mod init "${module}")
fi
done
)
compile() {
needs protoc protoc-gen-go protoc-gen-go-grpc
case "$1" in
/*) tensorboard_repo="$1" ;;
*) tensorboard_repo="$PWD/$1" ;;
esac
rm -rf "${outdir}"
mkdir -p "${outdir}"
(
cd "${tensorboard_repo}"
find tensorboard/compat/proto/ -name '*.proto' \
-exec protoc --go_out="${outdir}" --go_opt=paths=import {} +
)
(
cd ./proto
find . -name '*.proto' -exec protoc \
-I"${tensorboard_repo}" -I. \
--go_out="${outdir}" --go-grpc_out="${outdir}" \
--go_opt=paths=import --go-grpc_opt=paths=import \
{} +
)
bootstrap
}
main "$@"