-
Notifications
You must be signed in to change notification settings - Fork 146
/
Makefile
181 lines (145 loc) · 7 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
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
current_dir := $(patsubst %/,%,$(dir $(mkfile_path)))
MESOS_API_VERSION := v1
API_PKG := ./api/${MESOS_API_VERSION}/lib
API_VENDOR := ${current_dir}/api/${MESOS_API_VERSION}/vendor
CMD_PKG := ./api/${MESOS_API_VERSION}/cmd
CMD_VENDOR := ./api/${MESOS_API_VERSION}/cmd/vendor
PROTO_PATH := ${GOPATH}/src/:${API_VENDOR}/:.
PROTO_PATH := ${PROTO_PATH}:${API_VENDOR}/github.com/gogo/protobuf/protobuf
PROTO_PATH := ${PROTO_PATH}:${API_VENDOR}/github.com/gogo/protobuf/gogoproto
PACKAGES ?= $(shell go list ${API_PKG}/...|grep -v vendor)
TEST_DIRS ?= $(sort $(dir $(shell find ${API_PKG} -name '*_test.go' | grep -v vendor)))
BINARIES ?= $(shell go list -f "{{.Name}} {{.ImportPath}}" ${CMD_PKG}/...|grep -v -e vendor|grep -e ^main|cut -f2 -d' ')
# NOTE: set this to non-"true" to disable reservation refinement for the resource math in api/v1/lib.
# See api/v1/lib.CapabilityReservationRefinement.
CAP_RESERVATION_REFINEMENT ?= true
TEST_LDFLAGS ?=
TEST_FLAGS ?= -race
INSTALL_LDFLAGS ?=
INSTALL_FLAGS ?=
CAP_RESERVATION_REFINEMENT_STR = 1
ifeq ($(CAP_RESERVATION_REFINEMENT),true)
else
CAP_RESERVATION_REFINEMENT_STR = 0
endif
INSTALL_LDFLAGS += -X github.com/mesos/mesos-go/api/v1/lib.CapabilityReservationRefinement=$(CAP_RESERVATION_REFINEMENT_STR)
TEST_LDFLAGS += -X github.com/mesos/mesos-go/api/v1/lib.CapabilityReservationRefinement=$(CAP_RESERVATION_REFINEMENT_STR)
ifeq ($(INSTALL_LDFLAGS),)
else
INSTALL_FLAGS += -ldflags "$(INSTALL_LDFLAGS)"
endif
ifeq ($(TEST_LDFLAGS),)
else
TEST_FLAGS += -ldflags "$(TEST_LDFLAGS)"
endif
COVERAGE_TARGETS = ${TEST_DIRS:%/=%.cover}
GO_VERSION := $(shell go version|cut -f3 -d' '|dd bs=1 count=6 2>/dev/null)
.PHONY: all
all: test
.PHONY: install
install: INSTALL_FLAGS +=
install:
go install $(INSTALL_FLAGS) $(BINARIES)
.PHONY: test
test:
$(MAKE) _test CAP_RESERVATION_REFINEMENT=false
$(MAKE) _test CAP_RESERVATION_REFINEMENT=true
.PHONY: _test
_test:
go test $(TEST_FLAGS) $(TEST_DIRS)
.PHONY: test-verbose
test-verbose: TEST_FLAGS += -v
test-verbose: test
# TODO(jdef) simplify test coverage target now that ./... (almost) works as expected.
# TODO(jdef) test coverage w/ and w/out CapabilityReservationRefinement.
.PHONY: coverage $(COVERAGE_TARGETS)
coverage: REPORT=_output/coverage.out
coverage: COVER_PACKAGE = $(shell go list ${API_PKG}/...|egrep -v 'vendor|cmd'|tr '\n' ','|sed -e 's/,$$//')
coverage: TEST_FLAGS = -v -cover -coverpkg=$(COVER_PACKAGE)
coverage: $(COVERAGE_TARGETS)
echo "mode: set" >$(REPORT) && cat _output/*.cover | grep -v mode: | sort -r | \
awk '{if($$1 != last) {print $$0;last=$$1}}' >> $(REPORT)
$(COVERAGE_TARGETS): %.cover :
mkdir -p _output && go test ./$* $(TEST_FLAGS) -coverprofile=_output/$(subst /,___,$@)
.PHONY: vet
vet:
go $@ $(PACKAGES) $(BINARIES)
.PHONY: codecs
codecs: protobufs ffjson
.PHONY: protobufs-requirements
protobufs-requirements: REQUIRED_PROTOC_BINARIES = protoc-gen-gogo
protobufs-requirements:
@for i in ${REQUIRED_PROTOC_BINARIES}; do which $$i >/dev/null || { echo "failed to locate binary: $$i"; exit 1; }; done
.PHONY: protobufs
protobufs: GOGO_OUT=Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types:.
protobufs: protobufs-requirements clean-protobufs
(cd ${API_PKG}; protoc --proto_path="${PROTO_PATH}" --gogo_out=${GOGO_OUT} *.proto)
(cd ${API_PKG}; protoc --proto_path="${PROTO_PATH}" --gogo_out=${GOGO_OUT} ./scheduler/*.proto)
(cd ${API_PKG}; protoc --proto_path="${PROTO_PATH}" --gogo_out=${GOGO_OUT} ./executor/*.proto)
(cd ${API_PKG}; protoc --proto_path="${PROTO_PATH}" --gogo_out=${GOGO_OUT} ./agent/*.proto)
(cd ${API_PKG}; protoc --proto_path="${PROTO_PATH}" --gogo_out=${GOGO_OUT} ./quota/*.proto)
(cd ${API_PKG}; protoc --proto_path="${PROTO_PATH}" --gogo_out=${GOGO_OUT} ./allocator/*.proto)
(cd ${API_PKG}; protoc --proto_path="${PROTO_PATH}" --gogo_out=${GOGO_OUT} ./maintenance/*.proto)
(cd ${API_PKG}; protoc --proto_path="${PROTO_PATH}" --gogo_out=${GOGO_OUT} ./master/*.proto)
.PHONY: clean-protobufs
clean-protobufs:
(cd ${API_PKG}; rm -f *.pb.go */*.pb.go)
.PHONY: ffjson
ffjson: clean-ffjson
(cd ${API_PKG}; ffjson *.pb.go)
(cd ${API_PKG}; ffjson scheduler/*.pb.go)
(cd ${API_PKG}; ffjson executor/*.pb.go)
(cd ${API_PKG}; ffjson agent/*.pb.go)
(cd ${API_PKG}; ffjson quota/*.pb.go)
(cd ${API_PKG}; ffjson allocator/*.pb.go)
(cd ${API_PKG}; ffjson maintenance/*.pb.go)
(cd ${API_PKG}; ffjson master/*.pb.go)
.PHONY: clean-ffjson
clean-ffjson:
(cd ${API_PKG}; rm -f *ffjson.go */*ffjson.go)
.PHONY: sync
sync:
@which govendor >/dev/null || { echo "govendor not found in $$PATH"; exit 1; }
(cd ${API_VENDOR}; govendor sync)
(cd ${CMD_VENDOR}; govendor sync)
.PHONY: generate
generate: GENERATE_PACKAGES = ./api/v1/lib/extras/executor/eventrules ./api/v1/lib/extras/executor/callrules ./api/v1/lib/extras/scheduler/eventrules ./api/v1/lib/extras/scheduler/callrules ./api/v1/lib/executor/events ./api/v1/lib/executor/calls ./api/v1/lib/scheduler/events ./api/v1/lib/scheduler/calls ./api/v1/lib/agent/calls ./api/v1/lib/master/calls ./api/v1/lib/httpcli/httpagent ./api/v1/lib/httpcli/httpmaster ./api/v1/lib/httpcli/httpexec
generate:
go generate -x ${GENERATE_PACKAGES}
GOPKG := github.com/mesos/mesos-go
GOPKG_DIRNAME := $(shell dirname $(GOPKG))
UID ?= $(shell id -u $$USER)
GID ?= $(shell id -g $$USER)
DOCKER_IMAGE_REPO ?= jdef
DOCKER_IMAGE_NAME ?= example-scheduler-httpv1
DOCKER_IMAGE_VERSION ?= latest
DOCKER_IMAGE_TAG ?= $(DOCKER_IMAGE_REPO)/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_VERSION)
GOLDFLAGS = -X $(GOPKG)/api/${MESOS_API_VERSION}/cmd.DockerImageTag=$(DOCKER_IMAGE_TAG)
BUILD_STEP := 'ln -s /src /go/src/$(GOPKG) && cd /go/src/$(GOPKG) && go install -ldflags "$(GOLDFLAGS)" $(BINARIES)'
COPY_STEP := 'cp /go/bin/* /src/_output/ && chown $(UID):$(GID) /src/_output/*'
# required for docker/Makefile
export DOCKER_IMAGE_TAG
.PHONY: docker
docker:
mkdir -p _output
test -n "$(UID)" || (echo 'ERROR: $$UID is undefined'; exit 1)
test -n "$(GID)" || (echo 'ERROR: $$GID is undefined'; exit 1)
docker run --rm -v "$$PWD":/src -w /go/src/$(GOPKG_DIRNAME) golang:1.11.5-alpine sh -c $(BUILD_STEP)' && '$(COPY_STEP)
make -C api/${MESOS_API_VERSION}/docker
.PHONY: coveralls
coveralls: IGNORE_FILES = $(shell { find api/v1/cmd -type d ; ls api/v1/lib{,/scheduler,/executor,/agent,/quota,/allocator,/maintenance,/master}/*.pb{,_ffjson}.go ; find api/v0 -type d; } | tr '\n' ,)
coveralls: SHELL := /bin/bash
coveralls:
test "$(TRAVIS)" = "" || rm -rf $$HOME/gopath/pkg
$(MAKE) coverage
$$HOME/gopath/bin/goveralls -service=travis-ci -coverprofile=_output/coverage.out -ignore=$(IGNORE_FILES)
# re-generate protobuf and json code, check that there are no differences w/ respect to what's been checked in
.PHONY: validate-protobufs
ifeq ($(GO_VERSION),go1.11)
validate-protobufs: SHELL := /bin/bash
validate-protobufs:
(cd api/v1; govendor install +vendor,program) && $(MAKE) -s protobufs ffjson && [[ `{ git status --porcelain || echo "failed"; } | tee /tmp/status | wc -l` = "0" ]] || { cat /tmp/status; git diff; false; }
else
validate-protobufs:
endif