-
Notifications
You must be signed in to change notification settings - Fork 23
/
Makefile
80 lines (62 loc) · 2.38 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
# Package related
PACKAGE=rdmamap
ORG_PATH=github.com/Mellanox
REPO_PATH=$(ORG_PATH)/$(PACKAGE)
GOPATH=$(CURDIR)/.gopath
GOBIN =$(CURDIR)/bin
BASE=$(GOPATH)/src/$(REPO_PATH)
GOFILES=$(shell find . -name "*.go" | grep -vE "(\/vendor\/)|(_test.go)")
PKGS=$(or $(PKG),$(shell cd $(BASE) && env GOPATH=$(GOPATH) $(GO) list ./... | grep -v "^$(PACKAGE)/vendor/"))
TESTPKGS = $(shell env GOPATH=$(GOPATH) $(GO) list -f '{{ if or .TestGoFiles .XTestGoFiles }}{{ .ImportPath }}{{ end }}' $(PKGS))
export GOPATH
# Go tools
GO = go
GOLANGCI_LINT = $(GOBIN)/golangci-lint
# golangci-lint version should be updated periodically
# we keep it fixed to avoid it from unexpectedly failing on the project
# in case of a version bump
GOLANGCI_LINT_VER = v1.53.3
TIMEOUT = 15
Q = $(if $(filter 1,$V),,@)
.PHONY: all
all: lint test build
$(GOBIN):
@mkdir -p $@
$(BASE): ; $(info setting GOPATH...)
@mkdir -p $(dir $@)
@ln -sf $(CURDIR) $@
build: $(GOFILES)
@CGO_ENABLED=0 $(GO) build -v
# Tools
$(GOLANGCI_LINT): ; $(info building golangci-lint...)
$Q curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) $(GOLANGCI_LINT_VER)
GOVERALLS = $(GOBIN)/goveralls
$(GOBIN)/goveralls: $(BASE) $(GOBIN) ; $(info building goveralls...)
$Q go get github.com/mattn/goveralls
# Tests
.PHONY: lint
lint: $(BASE) $(GOLANGCI_LINT) ; $(info running golangci-lint...) @ ## Run golangci-lint
$Q mkdir -p $(BASE)/test
$Q cd $(BASE) && ret=0 && \
test -z "$$($(GOLANGCI_LINT) run | tee $(BASE)/test/lint.out)" || ret=1 ; \
cat $(BASE)/test/lint.out ; rm -rf $(BASE)/test ; \
exit $$ret
.PHONY: test tests
test: $(BASE) ; $(info running unit tests...) @ ## Run unit tests
$Q cd $(BASE) && $(GO) test -timeout $(TIMEOUT)s $(ARGS) ./...
tests: test lint ;
COVERAGE_MODE = count
.PHONY: test-coverage test-coverage-tools
test-coverage-tools: $(GOVERALLS)
test-coverage: COVERAGE_DIR := $(CURDIR)/test
test-coverage: test-coverage-tools $(BASE) ; $(info running coverage tests...) @ ## Run coverage tests
$Q cd $(BASE); $(GO) test -covermode=$(COVERAGE_MODE) -coverprofile=rdmamap.cover ./...
# Misc
.PHONY: clean
clean: ; $(info Cleaning...) @ ## Cleanup everything
@rm -rf $(GOPATH)
@rm -rf test
.PHONY: help
help: ## Show this message
@grep -E '^[ a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'