forked from gravitational/teleport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenproto.sh
executable file
·79 lines (69 loc) · 2.55 KB
/
genproto.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
#!/usr/bin/env bash
#
# Generates protos for Teleport and Teleport API.
set -eu
echoed() {
echo "$*" >&2
"$@"
}
main() {
cd "$(dirname "$0")" # ./build-assets/
cd ../ # teleport root
# Parse optional args.
local skip_js=0 # skips Javascript and Typescript protogen
local skip_rm=0 # skips removal of old protos
while [[ $# -gt 0 ]]; do
case "$1" in
--skip-js)
skip_js=1
;;
--skip-rm)
skip_rm=1
;;
*)
echo "Unknown argument $1" >&2
exit 1
;;
esac
shift
done
# Clean gen/proto directories before regenerating them. Legacy protos are
# generated all over the directory tree, so they won't get cleaned up
# automatically if the proto is deleted.
[[ $skip_rm -eq 0 ]] && echoed rm -fr api/gen/proto gen/proto
# Generate Gogo protos. Generated protos are written to
# gogogen/github.com/gravitational/teleport/..., so we copy them to the
# correct relative path. This is in lieu of the module= option, which would do
# this for us (and which is what we use for the non-gogo protogen).
rm -fr gogogen
trap 'rm -fr gogogen' EXIT # don't leave files behind
echoed buf generate --template=buf-gogo.gen.yaml \
--path=api/proto/teleport/legacy/ \
--path=api/proto/teleport/attestation/ \
--path=api/proto/teleport/usageevents/ \
--path=proto/teleport/lib/web/envelope.proto \
--exclude-path=api/proto/teleport/legacy/client/proto/event.proto
cp -r gogogen/github.com/gravitational/teleport/. .
# error out if there's anything outside of github.com/gravitational/teleport
rm -fr gogogen/github.com/gravitational/teleport
rmdir gogogen/github.com/gravitational gogogen/github.com gogogen
# Generate protoc-gen-go protos (preferred).
echoed buf generate --template=buf-go.gen.yaml \
--exclude-path=api/proto/teleport/legacy/ \
--exclude-path=api/proto/teleport/attestation/ \
--exclude-path=api/proto/teleport/usageevents/ \
--exclude-path=proto/teleport/lib/web/envelope.proto \
--exclude-path=proto/prehog/
# Generate event.proto separately because we only want to run it on this
# one particular file in legacy.
echoed buf generate --template=buf-go.gen.yaml \
--path=api/proto/teleport/legacy/client/proto/event.proto
# Generate connect-go protos.
echoed buf generate --template=buf-connect-go.gen.yaml \
--path=proto/prehog/
# Generate JS protos.
[[ $skip_js -eq 0 ]] && echoed buf generate --template=buf-js.gen.yaml \
--path=proto/prehog/ \
--path=proto/teleport/lib/teleterm/
}
main "$@"