-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathMakefile
63 lines (49 loc) · 1.94 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
# Package related
PACKAGE := sriovnet
BIN_DIR := $(CURDIR)/bin
GOFILES := $(shell find . -name "*.go" | grep -vE "(\/vendor\/)|(_test.go)")
PKGS := $(or $(PKG),$(shell go list ./... | grep -v "^$(PACKAGE)/vendor/"))
TESTPKGS := $(shell go list -f '{{ if or .TestGoFiles .XTestGoFiles }}{{ .ImportPath }}{{ end }}' $(PKGS))
# Go tools
GOLANGCI_LINT := $(BIN_DIR)/golangci-lint
GCOV2LCOV := $(BIN_DIR)/gcov2lcov
# 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
Q = $(if $(filter 1,$V),,@)
.PHONY: all
all: lint test build
$(BIN_DIR):
@mkdir -p $@
build: $(GOFILES) ;@ ## build sriovnet
@CGO_ENABLED=0 go build -v
# Tests
.PHONY: lint
lint: | $(GOLANGCI_LINT) ; $(info running golangci-lint...) @ ## Run lint tests
$Q $(GOLANGCI_LINT) run
.PHONY: test tests
test: ; $(info running unit tests...) ## Run unit tests
$Q go test -race ./...
tests: test lint ; ## Run all tests
COVERAGE_MODE = count
.PHONY: test-coverage test-coverage-tools
test-coverage-tools: $(GCOV2LCOV)
test-coverage: | test-coverage-tools; $(info running coverage tests...) @ ## Run coverage tests
$Q go test -covermode=$(COVERAGE_MODE) -coverprofile=sriovnet.cover ./...
$Q $(GCOV2LCOV) -infile sriovnet.cover -outfile sriovnet.lcov
# Tools
$(GOLANGCI_LINT): | $(BIN_DIR) ; $(info building golangci-lint...)
$Q GOBIN=$(BIN_DIR) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VER)
$(GCOV2LCOV): | $(BIN_DIR) ; $(info building gocov2lcov...)
$Q GOBIN=$(BIN_DIR) go install github.com/jandelgado/[email protected]
# Misc
.PHONY: clean
clean: ; $(info Cleaning...) @ ## Cleanup everything
@rm -rf $(BIN_DIR)
@rm sriovnet.cover
@rm sriovnet.lcov
.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}'