-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
216 lines (197 loc) · 6.65 KB
/
Makefile
File metadata and controls
216 lines (197 loc) · 6.65 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
GOHOSTOS:=$(shell go env GOHOSTOS)
VERSION=$(shell git describe --tags --always)
BUILD_TIME=$(shell date '+%Y-%m-%dT%H:%M:%SZ')
AUTHOR=$(shell git log -1 --format='%an')
AUTHOR_EMAIL=$(shell git log -1 --format='%ae')
REPO=$(shell git config remote.origin.url)
ifeq ($(GOHOSTOS), windows)
#the `find.exe` is different from `find` in bash/shell.
#to see https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/find.
#changed to use git-bash.exe to run find cli or other cli friendly, caused of every developer has a Git.
Git_Bash=$(subst \,/,$(subst cmd\,bin\bash.exe,$(dir $(shell where git))))
API_PROTO_FILES=$(shell $(Git_Bash) -c "find proto/rabbit/api -name *.proto")
# Use mkdir -p equivalent for Windows
MKDIR=mkdir
RM=del /f /q
else
API_PROTO_FILES=$(shell find proto/rabbit/api -name *.proto)
MKDIR=mkdir -p
RM=rm -f
endif
.PHONY: init
# initialize the moon environment
init:
@echo "Initializing moon environment"
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.36.3
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.5.1
go install github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2@latest
go install github.com/go-kratos/kratos/cmd/protoc-gen-go-errors/v2@latest
go install github.com/google/gnostic/cmd/protoc-gen-openapi@latest
go install github.com/google/wire/cmd/wire@latest
go install github.com/aide-family/stringer@v1.1.3
go install github.com/protoc-gen/i18n-gen@latest
go install golang.org/x/tools/gopls@latest
go install github.com/go-kratos/kratos/cmd/kratos/v2@latest
.PHONY: conf
# generate the conf files
conf: config
@echo "Generating conf files"
protoc --proto_path=./internal/conf \
--proto_path=./proto/rabbit \
--proto_path=./proto/third_party \
--go_out=paths=source_relative:./internal/conf \
--experimental_allow_proto3_optional \
./internal/conf/*.proto
.PHONY: config
# generate the config files
config:
@echo "Generating config files"
@if [ "$(GOHOSTOS)" = "windows" ]; then \
$(Git_Bash) -c "rm -rf ./pkg/config/*.pb.go"; \
if [ ! -d "./pkg/config" ]; then $(MKDIR) ./pkg/config; fi \
else \
rm -rf ./pkg/config/*.pb.go; \
if [ ! -d "./pkg/config" ]; then $(MKDIR) ./pkg/config; fi \
fi
protoc --proto_path=./proto/rabbit/config \
--proto_path=./proto/rabbit \
--proto_path=./proto/third_party \
--go_out=paths=source_relative:./pkg/config \
--experimental_allow_proto3_optional \
./proto/rabbit/config/*.proto
.PHONY: enum
# generate the enum files
enum:
@echo "Generating enum files"
@if [ "$(GOHOSTOS)" = "windows" ]; then \
$(Git_Bash) -c "rm -rf ./pkg/enum/*.pb.go"; \
if [ ! -d "./pkg/enum" ]; then $(MKDIR) ./pkg/enum; fi \
else \
rm -rf ./pkg/enum/*.pb.go; \
if [ ! -d "./pkg/enum" ]; then $(MKDIR) ./pkg/enum; fi \
fi
protoc --proto_path=./proto/rabbit/enum \
--proto_path=./proto/third_party \
--go_out=paths=source_relative:./pkg/enum \
--experimental_allow_proto3_optional \
./proto/rabbit/enum/*.proto
.PHONY: api
# generate the api files
api: enum
@echo "Generating api files"
@if [ "$(GOHOSTOS)" = "windows" ]; then \
$(Git_Bash) -c "rm -rf ./pkg/api/*.pb.go"; \
if [ ! -d "./pkg/api" ]; then $(MKDIR) ./pkg/api; fi \
else \
rm -rf ./pkg/api/*.pb.go; \
if [ ! -d "./pkg/api" ]; then $(MKDIR) ./pkg/api; fi \
fi
protoc --proto_path=./proto/rabbit/api \
--proto_path=./proto/rabbit \
--proto_path=./proto/third_party \
--go_out=paths=source_relative:./pkg/api \
--go-http_out=paths=source_relative:./pkg/api \
--go-grpc_out=paths=source_relative:./pkg/api \
--openapi_out=fq_schema_naming=true,default_response=false:./internal/server/swagger \
--experimental_allow_proto3_optional \
$(API_PROTO_FILES)
.PHONY: i18n
# i18n generate the i18n files
i18n:
i18n-gen -O ./i18n/ -P ./proto/rabbit/**.proto -L en,zh -suffix Error
.PHONY: errors
# generate errors
errors:
@echo "Generating errors"
@if [ "$(GOHOSTOS)" = "windows" ]; then \
$(Git_Bash) -c "rm -rf ./pkg/merr/*.pb.go"; \
if [ ! -d "./pkg/merr" ]; then $(MKDIR) ./pkg/merr; fi \
else \
rm -rf ./pkg/merr/*.pb.go; \
if [ ! -d "./pkg/merr" ]; then $(MKDIR) ./pkg/merr; fi \
fi
protoc --proto_path=./proto/rabbit/merr \
--proto_path=./proto/third_party \
--go_out=paths=source_relative:./pkg/merr \
--go-errors_out=paths=source_relative:./pkg/merr \
./proto/rabbit/merr/*.proto
make i18n
.PHONY: wire
# generate the wire files
wire:
@echo "Generating wire files"
wire ./...
.PHONY: vobj
# generate the vobj files
vobj:
@echo "Generating vobj files"
cd internal/biz/vobj && go generate .
.PHONY: gorm-gen
# generate the gorm files
gorm-gen:
@echo "Generating gorm files"
go run ./cmd/gorm gorm gen
.PHONY: gorm-migrate
# migrate the gorm files
gorm-migrate:
@echo "Migrating gorm files"
go run ./cmd/gorm gorm migrate
.PHONY: all
# generate all files
all:
@git log -1 --format='%B' > description.txt
make clean errors api conf vobj gorm-gen wire
.PHONY: build
# build the rabbit binary
build: all
@echo "Building rabbit"
@echo "VERSION: $(VERSION)"
@echo "BUILD_TIME: $(BUILD_TIME)"
@echo "AUTHOR: $(AUTHOR)"
@echo "AUTHOR_EMAIL: $(AUTHOR_EMAIL)"
@git log -1 --format='%B' > description.txt
go build -ldflags "-X main.Version=$(VERSION) -X main.BuildTime=$(BUILD_TIME) -X main.Author=$(AUTHOR) -X main.Email=$(AUTHOR_EMAIL) -X main.Repo=$(REPO)" -o bin/rabbit main.go
.PHONY: dev
# run the rabbit binary in development mode
dev:
@echo "Running rabbit in development mode"
go run . run all --use-database=true --main-use-system-logger=false --main-debug=true
.PHONY: test
# run the tests
test: all
@echo "Running tests"
go test ./...
.PHONY: clean
# clean the binary
clean:
@echo "Cleaning up"
rm -rf bin
rm -rf internal/biz/do/query
ifeq ($(GOHOSTOS), windows)
@echo "Cleaning generated files (Windows)"
$(Git_Bash) -c "find . -name '*__string.go' -type f -delete"
$(Git_Bash) -c "find . -name '*.pb.go' -type f -delete"
$(Git_Bash) -c "find . -name '*.pb.gw.go' -type f -delete"
else
@echo "Cleaning generated files"
find . -name '*__string.go' -type f -delete
find . -name '*.pb.go' -type f -delete
find . -name '*.pb.gw.go' -type f -delete
endif
# show help
help:
@echo ''
@echo 'Usage:'
@echo ' make [target]'
@echo ''
@echo 'Targets:'
@awk '/^[a-zA-Z\-\_0-9]+:/ { \
helpMessage = match(lastLine, /^# (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")); \
helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \
printf "\033[36m%-22s\033[0m %s\n", helpCommand,helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
.DEFAULT_GOAL := help