-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbazel.sh
executable file
·105 lines (86 loc) · 2.42 KB
/
bazel.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
set -euo pipefail
BAZEL='bzl' # or bazelisk
write_workspace() {
cat << EOF > WORKSPACE
workspace(name = "com_github_stackb_protoreflecthash")
EOF
}
write_modulebazel() {
cat << EOF > MODULE.bazel
module(
name = "protoreflecthash",
version = "0.1.0",
repo_name = "com_github_stackb_protoreflecthash",
)
bazel_dep(name = "protobuf", version = "21.7", repo_name = "com_google_protobuf")
bazel_dep(name = "rules_proto", version = "4.0.0")
bazel_dep(name = "rules_go", version = "0.39.1")
bazel_dep(name = "gazelle", version = "0.31.1")
EOF
}
write_bazelversion() {
cat << EOF > .bazelversion
6.2.1
EOF
}
write_bazelrc() {
cat << EOF > .bazelrc
build --experimental_enable_bzlmod
EOF
}
write_bazelbuild() {
cat << EOF > BUILD.bazel
load("@rules_go//go:def.bzl", "go_library", "go_test")
load("@rules_proto//proto:defs.bzl", "proto_descriptor_set")
load("@gazelle//:def.bzl", "gazelle")
# gazelle:prefix github.com/stackb/protoreflecthash
# gazelle:resolve go go github.com/stackb/protoreflecthash/test_protos/generated/latest/proto2 @com_github_stackb_protoreflecthash//test_protos/generated/latest/proto2
# gazelle:resolve go go github.com/stackb/protoreflecthash/test_protos/generated/latest/proto3 @com_github_stackb_protoreflecthash//test_protos/generated/latest/proto3
gazelle(name = "gazelle")
proto_descriptor_set(
name = "protoset",
deps = [
"//test_protos/schema/proto2:proto2_proto",
"//test_protos/schema/proto3:proto3_proto",
],
)
EOF
}
run_gazelle() {
"${BAZEL}" run gazelle
}
build_targets() {
"${BAZEL}" build \
//test_protos/schema/proto3:proto3_go_proto \
//test_protos/schema/proto2:proto2_go_proto \
//:protoset
}
copy_pb_go() {
cp -f bazel-bin/test_protos/schema/proto3/proto3_go_proto_/github.com/stackb/protoreflecthash/test_protos/generated/latest/proto3/*.pb.go \
test_protos/generated/latest/proto3
cp -f bazel-bin/test_protos/schema/proto2/proto2_go_proto_/github.com/stackb/protoreflecthash/test_protos/generated/latest/proto2/*.pb.go \
test_protos/generated/latest/proto2
}
copy_protoset() {
cp -f bazel-bin/protoset.pb \
testdata/
}
clean() {
"${BAZEL}" clean
rm .bazelversion .bazelrc MODULE.bazel WORKSPACE
find . -name 'BUILD.bazel' | xargs rm
}
main() {
write_workspace
write_modulebazel
write_bazelversion
write_bazelrc
write_bazelbuild
run_gazelle
build_targets
copy_pb_go
copy_protoset
}
main
# clean