forked from vmware/vic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
326 lines (259 loc) · 11.3 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
# Copyright 2016 VMware, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
GO ?= go
GOVERSION ?= go1.6.2
OS := $(shell uname | tr '[:upper:]' '[:lower:]')
ifeq (vagrant, $(filter vagrant,$(USER) $(SUDO_USER)))
# assuming we are in a shared directory where host arch is different from the guest
BIN_ARCH := -$(OS)
endif
BASE_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
BASE_PKG := github.com/vmware/vic/
BIN ?= bin
IGNORE := $(shell mkdir -p $(BIN))
export GOPATH ?= $(shell echo $(CURDIR) | sed -e 's,/src/.*,,')
SWAGGER ?= $(GOPATH)/bin/swagger$(BIN_ARCH)
GOIMPORTS ?= $(GOPATH)/bin/goimports$(BIN_ARCH)
GOLINT ?= $(GOPATH)/bin/golint$(BIN_ARCH)
GVT ?= $(GOPATH)/bin/gvt$(BIN_ARCH)
GOVC ?= $(GOPATH)/bin/govc$(BIN_ARCH)
.PHONY: all tools clean test check \
goversion goimports gvt gopath govet \
isos tethers apiservers copyright
.DEFAULT_GOAL := all
ifeq ($(ENABLE_RACE_DETECTOR),true)
RACE := -race
else
RACE :=
endif
# utility function to dynamically generate go dependencies
define godeps
$(wildcard $1) $(shell $(BASE_DIR)/infra/scripts/go-deps.sh $(dir $1) $(MAKEFLAGS))
endef
# target aliases - environment variable definition
docker-engine-api := $(BIN)/docker-engine-server
portlayerapi := $(BIN)/port-layer-server
portlayerapi-client := lib/apiservers/portlayer/client/port_layer_client.go
portlayerapi-server := lib/apiservers/portlayer/restapi/server.go
imagec := $(BIN)/imagec
vicadmin := $(BIN)/vicadmin
rpctool := $(BIN)/rpctool
vic-machine := $(BIN)/vic-machine
tether-linux := $(BIN)/tether-linux
tether-windows := $(BIN)/tether-windows.exe
tether-darwin := $(BIN)/tether-darwin
appliance := $(BIN)/appliance.iso
appliance-staging := $(BIN)/appliance-staging.tgz
bootstrap := $(BIN)/bootstrap.iso
bootstrap-staging := $(BIN)/bootstrap-staging.tgz
bootstrap-staging-debug := $(BIN)/bootstrap-staging-debug.tgz
bootstrap-debug := $(BIN)/bootstrap-debug.iso
iso-base := $(BIN)/iso-base.tgz
go-lint := $(BIN)/.golint
go-imports := $(BIN)/.goimports
# target aliases - target mapping
docker-engine-api: $(docker-engine-api)
portlayerapi: $(portlayerapi)
portlayerapi-client: $(portlayerapi-client)
portlayerapi-server: $(portlayerapi-server)
imagec: $(imagec)
vicadmin: $(vicadmin)
rpctool: $(rpctool)
tether-linux: $(tether-linux)
tether-windows: $(tether-windows)
tether-darwin: $(tether-darwin)
appliance: $(appliance)
appliance-staging: $(appliance-staging)
bootstrap: $(bootstrap)
bootstrap-staging: $(bootstrap-staging)
bootstrap-debug: $(bootstrap-debug)
bootstrap-staging-debug: $(bootstrap-staging-debug)
iso-base: $(iso-base)
vic-machine: $(vic-machine)
swagger: $(SWAGGER)
golint: $(go-lint)
goimports: $(go-imports)
# convenience targets
all: components tethers isos vic-machine
tools: $(GOIMPORTS) $(GVT) $(GOLINT) $(SWAGGER) goversion
check: goversion goimports govet golint copyright whitespace
apiservers: $(portlayerapi) $(docker-engine-api)
components: check apiservers $(imagec) $(vicadmin) $(rpctool)
isos: $(appliance) $(bootstrap)
tethers: $(tether-linux) $(tether-windows) $(tether-darwin)
# utility targets
goversion:
@echo checking go version...
@( $(GO) version | grep -q $(GOVERSION) ) || ( echo "Please install $(GOVERSION) (found: $$($(GO) version))" && exit 1 )
$(GOIMPORTS): vendor/manifest
@echo building $(GOIMPORTS)...
@$(GO) build $(RACE) -o $(GOIMPORTS) ./vendor/golang.org/x/tools/cmd/goimports
$(GVT):
@echo getting gvt
@$(GO) get -u github.com/FiloSottile/gvt
$(GOLINT): vendor/manifest
@echo building $(GOLINT)...
@$(GO) build $(RACE) -o $(GOLINT) ./vendor/github.com/golang/lint/golint
$(SWAGGER): vendor/manifest
@echo building $(SWAGGER)...
@$(GO) build $(RACE) -o $(SWAGGER) ./vendor/github.com/go-swagger/go-swagger/cmd/swagger
$(GOVC): vendor/manifest
@echo building $(GOVC)...
@$(GO) build $(RACE) -o $(GOVC) ./vendor/github.com/vmware/govmomi/govc
copyright:
@echo "checking copyright in header..."
@infra/scripts/header-check.sh
whitespace:
@echo "checking whitespace..."
@infra/scripts/whitespace-check.sh
# exit 1 if golint complains about anything other than comments
golintf = $(GOLINT) $(1) | sh -c "! grep -v 'should have comment'" | sh -c "! grep -v 'comment on exported'"
$(go-lint): $(GOLINT)
@echo checking go lint...
@$(call golintf,github.com/vmware/vic/cmd/...)
@$(call golintf,github.com/vmware/vic/pkg/...)
@$(call golintf,github.com/vmware/vic/lib/install/...)
@$(call golintf,github.com/vmware/vic/lib/portlayer/...)
@$(call golintf,github.com/vmware/vic/lib/apiservers/portlayer/restapi/handlers/...)
@$(call golintf,github.com/vmware/vic/lib/apiservers/engine/backends/...)
@touch $@
# For use by external tools such as emacs or for example:
# GOPATH=$(make gopath) go get ...
gopath:
@echo -n $(GOPATH)
$(go-imports): $(GOIMPORTS) $(find . -type f -name '*.go' -not -path "./vendor/*" -not -path "lib/apiservers/portlayer") $(PORTLAYER_DEPS)
@echo checking go imports...
@! $(GOIMPORTS) -d $$(find . -type f -name '*.go' -not -path "./vendor/*") 2>&1 | egrep -v '^$$'
@touch $@
govet:
@echo checking go vet...
@$(GO) tool vet -all $$(find . -mindepth 1 -maxdepth 1 -type d -not -name vendor)
vendor: $(GVT)
@echo restoring vendor
$(GOPATH)/bin/gvt restore
integration-tests: $(GOVC) components isos vic-machine
@echo Running integration tests
@GOVC=$(GOVC) ./tests/vendor/github.com/sstephenson/bats/libexec/bats -t tests
TEST_DIRS=github.com/vmware/vic/cmd/tether
TEST_DIRS+=github.com/vmware/vic/cmd/imagec
TEST_DIRS+=github.com/vmware/vic/cmd/vicadmin
TEST_DIRS+=github.com/vmware/vic/cmd/rpctool
TEST_DIRS+=github.com/vmware/vic/cmd/vic-machine
TEST_DIRS+=github.com/vmware/vic/lib/apiservers/portlayer
TEST_DIRS+=github.com/vmware/vic/lib/install
TEST_DIRS+=github.com/vmware/vic/lib/portlayer
TEST_DIRS+=github.com/vmware/vic/pkg
test:
@echo Running unit tests
# test everything but vendor
ifdef DRONE
@echo Generating coverage data
@infra/scripts/coverage.sh $(TEST_DIRS)
else
@echo Generating local html coverage report
@infra/scripts/coverage.sh --html $(TEST_DIRS)
endif
docker-integration-tests:
@echo Running Docker integration tests
@tests/docker-tests/run-tests.sh
$(tether-linux): $(call godeps,cmd/tether/*.go)
@echo building tether-linux
@CGO_ENABLED=1 GOOS=linux GOARCH=amd64 $(GO) build $(RACE) -tags netgo -installsuffix netgo --ldflags '-extldflags "-static"' -o ./$@ ./$(dir $<)
$(tether-windows): $(call godeps,cmd/tether/*.go)
@echo building tether-windows
@CGO_ENABLED=1 GOOS=windows GOARCH=amd64 $(GO) build $(RACE) -tags netgo -installsuffix netgo --ldflags '-extldflags "-static"' -o ./$@ ./$(dir $<)
# CGO is disabled for darwin otherwise build fails with "gcc: error: unrecognized command line option '-mmacosx-version-min=10.6'"
$(tether-darwin): $(call godeps,cmd/tether/*.go)
@echo building tether-darwin
@CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GO) build $(RACE) -tags netgo -installsuffix netgo --ldflags '-extldflags "-static"' -o ./$@ ./$(dir $<)
$(rpctool): $(call godeps,cmd/rpctool/*.go)
ifeq ($(OS),linux)
@echo building rpctool
@GOARCH=amd64 GOOS=linux $(GO) build $(RACE) -o ./$@ --ldflags '-extldflags "-static"' ./$(dir $<)
else
@echo skipping rpctool, cannot cross compile cgo
endif
$(vicadmin): $(call godeps,cmd/vicadmin/*.go)
@echo building vicadmin
@GOARCH=amd64 GOOS=linux $(GO) build $(RACE) -o ./$@ --ldflags '-extldflags "-static"' ./$(dir $<)
$(imagec): $(call godeps,cmd/imagec/*.go) $(portlayerapi-client)
@echo building imagec...
@$(GO) build $(RACE) -o ./$@ ./$(dir $<)
$(docker-engine-api): $(call godeps,cmd/docker/*.go) $(portlayerapi-client)
ifeq ($(OS),linux)
@echo Building docker-engine-api server...
@$(GO) build $(RACE) -o $@ ./cmd/docker
else
@echo skipping docker-engine-api server, cannot build on non-linux
endif
# Common portlayer dependencies between client and server
PORTLAYER_DEPS ?= lib/apiservers/portlayer/swagger.yml \
lib/apiservers/portlayer/restapi/configure_port_layer.go \
lib/apiservers/portlayer/restapi/options/*.go \
lib/apiservers/portlayer/restapi/handlers/*.go
$(portlayerapi-client): $(PORTLAYER_DEPS) $(SWAGGER)
@echo regenerating swagger models and operations for Portlayer API client...
@$(SWAGGER) generate client -A PortLayer --template-dir lib/apiservers/templates -t $(realpath $(dir $<)) -f $<
$(portlayerapi-server): $(PORTLAYER_DEPS) $(SWAGGER)
@echo regenerating swagger models and operations for Portlayer API server...
@$(SWAGGER) generate server -A PortLayer --template-dir lib/apiservers/templates -t $(realpath $(dir $<)) -f $<
$(portlayerapi): $(call godeps,lib/apiservers/portlayer/cmd/port-layer-server/*.go) $(portlayerapi-server) $(portlayerapi-client)
@echo building Portlayer API server...
@$(GO) build $(RACE) -o $@ ./lib/apiservers/portlayer/cmd/port-layer-server
$(iso-base): isos/base.sh isos/base/*.repo isos/base/isolinux/** isos/base/xorriso-options.cfg
@echo building iso-base docker image
@$< -c $(BIN)/yum-cache.tgz -p $@
# appliance staging - allows for caching of package install
$(appliance-staging): isos/appliance-staging.sh $(iso-base)
@echo staging for VCH appliance
@$< -c $(BIN)/yum-cache.tgz -p $(iso-base) -o $@
# main appliance target - depends on all top level component targets
$(appliance): isos/appliance.sh isos/appliance/* $(rpctool) $(vicadmin) $(imagec) $(portlayerapi) $(docker-engine-api) $(appliance-staging)
@echo building VCH appliance ISO
@$< -p $(appliance-staging) -b $(BIN)
# main bootstrap target
$(bootstrap): isos/bootstrap.sh $(tether-linux) $(rpctool) $(bootstrap-staging) isos/bootstrap/*
@echo "Making bootstrap iso"
@$< -p $(bootstrap-staging) -b $(BIN)
$(bootstrap-debug): isos/bootstrap.sh $(tether-linux) $(rpctool) $(bootstrap-staging-debug) isos/bootstrap/*
@echo "Making bootstrap-debug iso"
@$< -p $(bootstrap-staging-debug) -b $(BIN) -d true
$(bootstrap-staging): isos/bootstrap-staging.sh $(iso-base)
@echo staging for bootstrap
@$< -c $(BIN)/yum-cache.tgz -p $(iso-base) -o $@
$(bootstrap-staging-debug): isos/bootstrap-staging.sh $(iso-base)
@echo staging debug for bootstrap
@$< -c $(BIN)/yum-cache.tgz -p $(iso-base) -o $@ -d true
$(vic-machine): $(call godeps,cmd/vic-machine/*.go)
@echo building vic-machine...
@$(GO) build $(RACE) -o ./$@ ./$(dir $<)
clean:
rm -rf $(BIN)
@echo removing swagger generated files...
rm -f ./lib/apiservers/portlayer/restapi/doc.go
rm -f ./lib/apiservers/portlayer/restapi/embedded_spec.go
rm -f ./lib/apiservers/portlayer/restapi/server.go
rm -rf ./lib/apiservers/portlayer/client/
rm -rf ./lib/apiservers/portlayer/cmd/
rm -rf ./lib/apiservers/portlayer/models/
rm -rf ./lib/apiservers/portlayer/restapi/operations/
rm -f lib/apiservers/docker/restapi/doc.go
rm -f lib/apiservers/docker/restapi/embedded_spec.go
rm -f lib/apiservers/docker/restapi/server.go
rm -fr lib/apiservers/docker/cmd
rm -fr lib/apiservers/docker/models
rm -fr lib/apiservers/docker/restapi/operations
rm -fr ./tests/helpers/bats-assert/
rm -fr ./tests/helpers/bats-support/
@tests/docker-tests/run-tests.sh clean