forked from Velocidex/velociraptor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_proto.sh
executable file
·89 lines (70 loc) · 3.06 KB
/
make_proto.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
#!/bin/bash
# Used to regenrate proto bindings. This script should be run if any
# of the .proto files are modified.
# This script requires protoc 3.6 +
set -e
CWD=$PWD
PROTOC=${PROTOC:-"protoc"}
QUIET=${QUIET:-}
PROTOC=protoc
if [ -z "$GOPATH" ]; then
GOPATH="$HOME/go"
fi
function debug() {
if [ -z "$QUIET" ]; then
echo "$@"
fi
}
#GOOGLEAPIS_PATH=$CWD/googleapis/
#GOOGLEAPIS_COMMIT="82a542279"
#if [ ! -d "$GOOGLEAPIS_PATH" ]; then
# git clone --shallow-since 2021-12-15 https://github.com/googleapis/googleapis/ $GOOGLEAPIS_PATH
# (cd googleapis && git checkout $GOOGLEAPIS_COMMIT)
#fi
# Instead of checking out the latest git project, we just manually
# copy the few files we actually need into third party.
GOOGLEAPIS_PATH=$CWD/third_party/googleapis/
if ! command -v protoc-gen-go > /dev/null; then
go install google.golang.org/protobuf/cmd/protoc-gen-go
fi
if ! command -v protoc-gen-go-grpc > /dev/null; then
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc
fi
if ! command -v protoc-gen-grpc-gateway > /dev/null; then
go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway
fi
PROTO_DIRECTORIES="$CWD/proto/ $CWD/crypto/proto/ \
$CWD/artifacts/proto/ \
$CWD/actions/proto/ \
$CWD/services/frontend/proto/ \
$CWD/config/proto/ \
$CWD/timelines/proto/ \
$CWD/acls/proto/ \
$CWD/flows/proto/"
for i in $PROTO_DIRECTORIES ; do
debug Building protos in $i
debug $PROTOC -I$i -I$GOPATH/src/ -I/usr/include/ -I/usr/local/include/ -I$GOOGLEAPIS_PATH -I$CWD --go_out=paths=source_relative:$i $i/*.proto
$PROTOC -I$i -I$GOPATH/src/ -I/usr/include/ -I/usr/local/include/ -I$GOOGLEAPIS_PATH -I$CWD --go_out=paths=source_relative:$i $i/*.proto
# Clean up extra version information the proto compiler adds to
# the files.
sed -i -e '1h;2,$H;$!d;g' -re 's|// versions.+// source:|// source:|' $i/*.pb.go
done
# Build GRPC servers.
for i in $CWD/api/proto/ ; do
debug Building protos in $i
debug $PROTOC -I$i -I. -I$GOPATH/src/ -I/usr/local/include/ \
-I$GOOGLEAPIS_PATH -I/usr/include/ \
-I$CWD $i/*.proto --go-grpc_out=paths=source_relative:$i --go_out=paths=source_relative:$i
$PROTOC -I$i -I. -I$GOPATH/src/ -I/usr/local/include/ \
-I$GOOGLEAPIS_PATH -I/usr/include/ \
-I$CWD $i/*.proto --go-grpc_out=paths=source_relative:$i --go_out=paths=source_relative:$i
debug $PROTOC -I$i -I. -I$GOPATH/src/ -I/usr/local/include/ \
-I$GOOGLEAPIS_PATH -I/usr/include/ \
--grpc-gateway_out=paths=source_relative,logtostderr=true:$i $i/*.proto
$PROTOC -I$i -I. -I$GOPATH/src/ -I/usr/local/include/ \
-I$GOOGLEAPIS_PATH -I/usr/include/ \
--grpc-gateway_out=paths=source_relative,logtostderr=true:$i $i/*.proto
# Clean up extra version information the proto compiler adds to
# the files.
sed -i -e '1h;2,$H;$!d;g' -re 's|// versions.+// source|// source|' $i/*.pb.go
done