Debian Codegraph @

Makefile

raw
1 # Define directories
2 ROOT_DIR ?= ${CURDIR}
3 TOOLS_DIR ?= ${ROOT_DIR}/tools
4
5 # Set a local GOBIN, since the default value can't be trusted
6 # (See https://github.com/golang/go/issues/23439)
7 export GOBIN ?= ${TOOLS_DIR}/bin
8
9 # Set the mode for code-coverage
10 GO_TEST_COVERAGE_MODE ?= count
11 GO_TEST_COVERAGE_FILE_NAME ?= coverage.out
12
13 # Set flags for `gofmt`
14 GOFMT_FLAGS ?= -s
15
16 # Set a default `min_confidence` value for `golint`
17 GOLINT_MIN_CONFIDENCE ?= 0.1
18
19
20 all: build
21
22 clean:
23 go clean -i -x ./...
24
25 build:
26 go build -v ./...
27
28 install-deps:
29 go mod download
30
31 tools install-deps-dev:
32 cd tools && go install \
33 golang.org/x/lint/golint \
34 golang.org/x/tools/cmd/goimports \
35 honnef.co/go/tools/cmd/staticcheck
36
37 update-deps:
38 go get ./...
39
40 test:
41 go test -v ./...
42
43 test-with-coverage:
44 go test -cover -covermode ${GO_TEST_COVERAGE_MODE} ./...
45
46 test-with-coverage-formatted:
47 go test -cover -covermode ${GO_TEST_COVERAGE_MODE} ./... | column -t | sort -r
48
49 test-with-coverage-profile:
50 go test -covermode ${GO_TEST_COVERAGE_MODE} -coverprofile ${GO_TEST_COVERAGE_FILE_NAME} ./...
51
52 format-lint:
53 errors=$$(gofmt -l ${GOFMT_FLAGS} .); if [ "$${errors}" != "" ]; then echo "$${errors}"; exit 1; fi
54
55 import-lint: install-deps-dev
56 errors=$$(${GOBIN}/goimports -l .); if [ "$${errors}" != "" ]; then echo "$${errors}"; exit 1; fi
57
58 style-lint: install-deps-dev
59 ${GOBIN}/golint -min_confidence=${GOLINT_MIN_CONFIDENCE} -set_exit_status ./...
60 ${GOBIN}/staticcheck ./...
61
62 lint: install-deps-dev format-lint import-lint style-lint
63
64 vet:
65 go vet ./...
66
67 format-fix:
68 gofmt -w ${GOFMT_FLAGS} .
69
70 import-fix:
71 goimports -w .
72
73
74 .PHONY: all clean build install-deps tools install-deps-dev update-deps test test-with-coverage test-with-coverage-formatted test-with-coverage-profile format-lint import-lint style-lint lint vet format-fix import-fix