-
Notifications
You must be signed in to change notification settings - Fork 533
/
Makefile
361 lines (271 loc) · 9.48 KB
/
Makefile
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
#####################################################
REPO_PREFIX := yunion.io/x/onecloud
VERSION_PKG := yunion.io/x/pkg/util/version
ROOT_DIR := $(CURDIR)
BUILD_DIR := $(ROOT_DIR)/_output
BIN_DIR := $(BUILD_DIR)/bin
BUILD_SCRIPT := $(ROOT_DIR)/build/build.sh
DEB_BUILD_SCRIPT := $(ROOT_DIR)/build/build_deb.sh
ifeq ($(ONECLOUD_CI_BUILD),)
GIT_COMMIT := $(shell git rev-parse --short HEAD)
GIT_BRANCH := $(shell git branch -r --contains | head -1 | sed -E -e "s%(HEAD ->|origin|upstream)/?%%g" | xargs)
GIT_VERSION := $(shell git describe --always --tags --abbrev=14 $(GIT_COMMIT)^{commit})
GIT_TREE_STATE := $(shell s=`git status --porcelain 2>/dev/null`; if [ -z "$$s" ]; then echo "clean"; else echo "dirty"; fi)
BUILD_DATE := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
else
GIT_COMMIT:=x
GIT_BRANCH:=x
GIT_VERSION:=x
BUILD_TREE_STATE:=clean
BUILD_DATE=2099-07-01T07:11:09Z
endif
LDFLAGS := "-w \
-X $(VERSION_PKG).gitVersion=$(GIT_VERSION) \
-X $(VERSION_PKG).gitCommit=$(GIT_COMMIT) \
-X $(VERSION_PKG).gitBranch=$(GIT_BRANCH) \
-X $(VERSION_PKG).buildDate=$(BUILD_DATE) \
-X $(VERSION_PKG).gitTreeState=$(GIT_TREE_STATE) \
-X $(VERSION_PKG).gitMajor=0 \
-X $(VERSION_PKG).gitMinor=0"
#####################################################
ifneq ($(DLV),)
GO_BUILD_FLAGS += -gcflags "all=-N -l"
LDFLAGS = ""
endif
GO_BUILD_FLAGS+=-mod vendor -ldflags $(LDFLAGS)
GO_BUILD := go build $(GO_BUILD_FLAGS)
GO_INSTALL := go install -ldflags $(LDFLAGS)
GO_TEST := go test
PKGS := go list ./...
CGO_CFLAGS_ENV = $(shell go env CGO_CFLAGS)
CGO_LDFLAGS_ENV = $(shell go env CGO_LDFLAGS)
ifdef LIBQEMUIO_PATH
X_CGO_CFLAGS := ${CGO_CFLAGS_ENV} -I${LIBQEMUIO_PATH}/src -I${LIBQEMUIO_PATH}/src/include
X_CGO_LDFLAGS := ${CGO_LDFLAGS_ENV} -laio -lqemuio -lpthread -lgnutls -lnettle -L ${LIBQEMUIO_PATH}/src
endif
export GOOS ?= linux
export GO111MODULE:=on
export CGO_CFLAGS = ${X_CGO_CFLAGS}
export CGO_LDFLAGS = ${X_CGO_LDFLAGS}
UNAME := $(shell uname)
ifeq ($(UNAME), Linux)
XARGS_FLAGS = --no-run-if-empty
endif
cmdTargets:=$(filter-out cmd/host-image,$(wildcard cmd/*))
rpmTargets:=$(foreach b,$(patsubst cmd/%,%,$(cmdTargets)),$(if $(shell [ -f "$(CURDIR)/build/$(b)/vars" ] && echo 1),rpm/$(b)))
debTargets:=$(foreach b,$(patsubst cmd/%,%,$(cmdTargets)),$(if $(shell [ -f "$(CURDIR)/build/$(b)/vars" ] && echo 1),deb/$(b)))
all: build
install: prepare_dir
@for PKG in $$( $(PKGS) | grep -w "$(filter-out $@,$(MAKECMDGOALS))" ); do \
echo $$PKG; \
$(GO_INSTALL) $$PKG; \
done
gencopyright:
@bash scripts/gencopyright.sh pkg cmd
test:
@go test $(GO_BUILD_FLAGS) $(shell go list ./... | egrep -v 'host-image|hostimage|torrent')
vet:
go vet ./...
# cmd/esxi-agent: prepare_dir
# CGO_ENABLED=0 $(GO_BUILD) -o $(BIN_DIR)/$(shell basename $@) $(REPO_PREFIX)/$@
cmd/host: prepare_dir
CGO_ENABLED=1 $(GO_BUILD) -o $(BIN_DIR)/$(shell basename $@) $(REPO_PREFIX)/$@
cmd/host-image: prepare_dir
CGO_ENABLED=1 $(GO_BUILD) -o $(BIN_DIR)/$(shell basename $@) $(REPO_PREFIX)/$@
cmd/%: prepare_dir
CGO_ENABLED=0 $(GO_BUILD) -o $(BIN_DIR)/$(shell basename $@) $(REPO_PREFIX)/$@
rpm/%: cmd/%
$(BUILD_SCRIPT) $*
deb/%: cmd/%
$(DEB_BUILD_SCRIPT) $*
pkg/%: prepare_dir
$(GO_INSTALL) $(REPO_PREFIX)/$@
rpm/fetcherfs: cmd/fetcherfs
docker run --rm \
--name docker-centos-build-fetcherfs \
-v $(CURDIR):/data \
registry.cn-beijing.aliyuncs.com/yunionio/centos-build:1.1-4 \
/bin/bash -c "VERSION=3.6 /data/build/build.sh fetcherfs /opt/yunion/fetchclient/bin"
deb/fetcherfs: rpm/fetcherfs
#VERSION=3.6 $(DEB_BUILD_SCRIPT) fetcherfs /opt/yunion/fetchclient/bin
docker run --rm \
--name docker-debian-build-fetcherfs \
-v $(CURDIR):/data \
registry.cn-beijing.aliyuncs.com/yunionio/debian10-base:1.0 \
/data/build/convert_rpm2deb.sh
build:
$(MAKE) $(cmdTargets)
rpm:
$(MAKE) $(rpmTargets)
deb:
$(MAKE) $(debTargets)
rpmclean:
rm -fr $(BUILD_DIR)/rpms
prepare_dir: bin_dir
bin_dir: output_dir
@mkdir -p $(BUILD_DIR)/bin
output_dir:
@mkdir -p $(BUILD_DIR)
.PHONY: all build prepare_dir clean rpm
clean:
@rm -fr $(BUILD_DIR)
fmt:
@git ls-files --exclude '*' '*.go' \
| grep -v '^vendor/' \
| while read f; do \
if ! grep -m1 -q '^// Code generated .* DO NOT EDIT\.$$' "$$f"; then \
echo "$$f"; \
fi ; \
done \
| xargs $(XARGS_FLAGS) gofmt -w
fmt-check: fmt
@if git status --short | grep -E '^.M .*/[^.]+.go'; then \
git diff | cat; \
echo "$@: working tree modified (possibly by gofmt)" >&2 ; \
false ; \
fi
.PHONY: fmt fmt-check
gendocgo:
@sh build/gendoc.sh
adddocgo:
@git ls-files --others '*/doc.go' | xargs $(XARGS_FLAGS) -- git add
gendocgo-check: gendocgo
@n="$$(git ls-files --others '*/doc.go' | wc -l)"; \
if test "$$n" -gt 0; then \
git ls-files --others '*/doc.go' | sed -e 's/^/ /'; \
echo "$@: untracked doc.go file(s) exist in working directory" >&2 ; \
false ; \
fi
.PHONY: gendocgo adddocgo gendocgo-check
goimports-check:
@goimports -w -local "yunion.io/x/:yunion.io/x/onecloud" pkg cmd; \
if git status --short | grep -E '^.M .*/[^.]+.go'; then \
git diff | cat; \
echo "$@: working tree modified (possibly by goimports)" >&2 ; \
echo "$@: " >&2 ; \
echo "$@: import spec should be grouped in order: std, 3rd-party, yunion.io/x, yunion.io/x/onecloud" >&2 ; \
echo "$@: see \"yun\" branch at https://github.com/yousong/tools" >&2 ; \
false ; \
fi
.PHONY: goimports-check
vet-check:
./scripts/vet.sh gen
./scripts/vet.sh chk
.PHONY: vet-check
comma:=,
space:=$(space) $(space)
# NOTE: keep y18n-packages in alphabetical order
y18n-src-lang := en-US
y18n-lang := en-US,zh-CN
y18n-packages := \
yunion.io/x/onecloud/cmd/apigateway \
yunion.io/x/onecloud/cmd/keystone \
yunion.io/x/onecloud/cmd/monitor \
yunion.io/x/onecloud/cmd/region \
yunion.io/x/onecloud/cmd/yunionconf \
define y18n-gen
set -o errexit; \
set -o pipefail; \
export GO111MODULE=off; \
y18n \
-chdir $(CURDIR) \
-dir ./locales/ \
-out ./locales/locales.go \
-lang $(y18n-lang) \
$(y18n-packages) \
; \
$(foreach lang,$(filter-out $(y18n-src-lang),$(subst $(comma), ,$(y18n-lang))),cp ./locales/$(lang)/{out,messages}.gotext.json;) \
endef
y18n-gen:
$(y18n-gen)
$(y18n-gen)
.PHONY: y18n-gen
y18n-check:
$(y18n-gen)
if git status --short ./locales | sed 's/^/$@: /' | grep .; then \
echo "$@: Locales content needs care" >&2 ; \
false; \
fi
.PHONY: y18n-check
define hostdeployer-grpc-gen
set -o errexit; \
set -o pipefail; \
protoc -I pkg/hostman/hostdeployer/apis \
--go_out=pkg/hostman/hostdeployer/apis \
--go_opt=paths=source_relative \
--go-grpc_out=pkg/hostman/hostdeployer/apis \
--go-grpc_opt=paths=source_relative \
pkg/hostman/hostdeployer/apis/deploy.proto
endef
hostdeployer-grpc-gen:
$(hostdeployer-grpc-gen)
check: fmt-check
check: gendocgo-check
check: goimports-check
#check: vet-check
#check: y18n-check
.PHONY: check
define depDeprecated
OneCloud now requires using go-mod for dependency management. dep target,
vendor files will be removed in future versions
Follow the following link to find out more about go-mod
- https://blog.golang.org/using-go-modules
- https://github.com/golang/go/wiki/Modules
Switching to "make mod"...
endef
dep: export depDeprecated:=$(depDeprecated)
dep:
@echo "$$depDeprecated"
@$(MAKE) mod
RELEASE_BRANCH:=master
GOPROXY ?= direct
mod:
GOPROXY=$(GOPROXY) GONOSUMDB=yunion.io/x go get -d yunion.io/x/cloudmux@$(RELEASE_BRANCH)
GOPROXY=$(GOPROXY) GONOSUMDB=yunion.io/x go get -d $(patsubst %,%@master,$(shell GO111MODULE=on go mod edit -print | sed -n -e 's|.*\(yunion.io/x/[a-z].*\) v.*|\1|p' | grep -v '/cloudmux$$'))
GOPROXY=$(GOPROXY) GONOSUMDB=yunion.io/x go mod tidy
GOPROXY=$(GOPROXY) GONOSUMDB=yunion.io/x go mod vendor -v
define helpText
Build with docker
make docker-centos-build F='-j4'
make docker-centos-build F='-j4 cmd/region cmd/climc'
make docker-centos-build-stop
make docker-alpine-build F='-j4'
make docker-alpine-build F='-j4 cmd/host cmd/host-deployer'
make docker-alpine-build-stop
Tidy up go modules and vendor directory
make mod
endef
help: export helpText:=$(helpText)
help:
@echo "$$helpText"
.PHONY: help
gen-model-api-check:
which model-api-gen || (GO111MODULE=off go get -u yunion.io/x/code-generator/cmd/model-api-gen)
gen-model-api: gen-model-api-check
$(ROOT_DIR)/scripts/codegen.py model-api
gen-swagger-check:
which swagger || (GO111MODULE=off go get -u github.com/go-swagger/go-swagger/cmd/swagger)
which swagger-gen || (GO111MODULE=off go get -u yunion.io/x/code-generator/cmd/swagger-gen)
which swagger-serve || (GO111MODULE=off go get -u yunion.io/x/code-generator/cmd/swagger-serve)
gen-swagger: gen-swagger-check
$(ROOT_DIR)/scripts/codegen.py swagger-code
$(ROOT_DIR)/scripts/codegen.py swagger-yaml
swagger-serve-only:
$(ROOT_DIR)/scripts/codegen.py swagger-serve
swagger-serve: gen-model-api gen-swagger swagger-serve-only
swagger-site: gen-model-api gen-swagger
$(ROOT_DIR)/scripts/codegen.py swagger-site
.PHONY: gen-model-api-check gen-model-api gen-swagger-check gen-swagger swagger-serve swagger-site
REGISTRY ?= "registry.cn-beijing.aliyuncs.com/yunionio"
VERSION ?= $(shell git describe --exact-match 2> /dev/null || \
git describe --match=$(git rev-parse --short=8 HEAD) --always --dirty --abbrev=8)
image:
mkdir -p $(ROOT_DIR)/_output
DEBUG=$(DEBUG) ARCH=$(ARCH) TAG=$(VERSION) REGISTRY=$(REGISTRY) $(ROOT_DIR)/scripts/docker_push.sh $(filter-out $@,$(MAKECMDGOALS))
.PHONY: image
image-telegraf-raid-plugin:
VERSION=release-1.6.5 ARCH=all make image telegraf-raid-plugin
%:
@:
ModName:=yunion.io/x/onecloud
include $(CURDIR)/Makefile.common.mk