@@ -22,14 +22,29 @@ KARMADA_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
22
22
23
23
# Use `hack/generate-proto.sh` to generate proto files.
24
24
25
- export GOPATH=$( go env GOPATH | awk -F ' :' ' {print $1}' )
25
+ DEFAULT_GOPATH=$( go env GOPATH | awk -F ' :' ' {print $1}' )
26
+ export GOPATH=${DEFAULT_GOPATH}
26
27
export PATH=$PATH :$GOPATH /bin
27
28
28
29
GO111MODULE=on go install golang.org/x/tools/cmd/goimports
29
30
GO111MODULE=on go install k8s.io/code-generator/cmd/go-to-protobuf
30
31
GO111MODULE=on go install github.com/gogo/protobuf/protoc-gen-gogo
31
32
GO111MODULE=on go install github.com/vektra/mockery/v2
32
33
34
+ # Make dummy GOPATH for go-to-protobuf to generate the files to repo root.
35
+ # It is useful for case that karmada repo not in the real GOPATH.
36
+ go_path=" ${KARMADA_ROOT} /_go"
37
+ cleanup () {
38
+ rm -rf " ${go_path} "
39
+ }
40
+ trap " cleanup" EXIT SIGINT
41
+
42
+ cleanup
43
+
44
+ source " ${KARMADA_ROOT} " /hack/util.sh
45
+ util:create_gopath_tree " ${KARMADA_ROOT} " " ${go_path} "
46
+ export GOPATH=" ${go_path} "
47
+
33
48
# ref https://github.com/kubernetes/kubernetes/blob/master/hack/update-generated-protobuf-dockerized.sh
34
49
if [[ -z " $( which protoc) " || $( protoc --version | sed -r " s/libprotoc ([0-9]+).*/\1/g" ) -lt 3 ]]; then
35
50
echo " Generating protobuf requires protoc 3.0.0-beta1 or newer. Please download and"
@@ -54,7 +69,7 @@ APIMACHINERY_PKGS=(
54
69
k8s.io/api/core/v1
55
70
)
56
71
57
- ${GOPATH} /bin/ go-to-protobuf \
72
+ go-to-protobuf \
58
73
--go-header-file=./hack/boilerplate/boilerplate.go.txt \
59
74
--apimachinery-packages=$( IFS=, ; echo " ${APIMACHINERY_PKGS[*]} " ) \
60
75
--packages=$( IFS=, ; echo " ${PACKAGES[*]} " ) \
@@ -64,4 +79,5 @@ ${GOPATH}/bin/go-to-protobuf \
64
79
go generate ./pkg/estimator/service
65
80
66
81
# The `go-to-protobuf` tool will modify all import proto files in vendor, so we should use go mod vendor to prevent.
82
+ export GOPATH=${DEFAULT_GOPATH}
67
83
go mod vendor
0 commit comments