forked from influxdata/influx-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
98 lines (73 loc) · 2.46 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
# TOP is the directory where Makefile lives (i.e. top-level project).
# This must be before any includes.
TOP := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
include $(TOP)/support.mk
### Environment setup
export GOPATH=$(shell go env GOPATH)
export GOOS=$(shell go env GOOS)
export GOARCH=$(shell go env GOARCH)
export GOVERSION=$(shell go list -m -f '{{.GoVersion}}')
ifeq ($(GOOS),windows)
GOTAGS += timetzdata,
endif
LDFLAGS := $(LDFLAGS) -X main.date=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
ifdef VERSION
LDFLAGS += -X main.version=$(VERSION)
endif
ifdef COMMIT
LDFLAGS += -X main.commit=$(COMMIT)
endif
# Use default flags, but allow adding -gcflags "..." if desired. Eg, for debug
# builds, may want to use GCFLAGS="all=-N -l" in the build environment.
GCFLAGS ?=
ifneq ($(GCFLAGS),)
GCFLAGS := -gcflags "$(GCFLAGS)"
endif
export GO_BUILD=go build $(call with-param,-tags ,$(GOTAGS)) $(GCFLAGS) -ldflags "$(LDFLAGS)"
# SOURCES are the files that affect building the main binary.
SOURCES := $(shell find . -name '*.go' -not -name '*_test.go') go.mod go.sum
# FMT_FILES are all files that should be formatted according to our rules.
FMT_FILES := $(shell find . -path ./vendor -prune -o -name "*.go" -print)
# Allow for `go test` to be swapped out by other tooling, i.e. `gotestsum`
export GO_TEST=go test
# Allow for a subset of tests to be specified.
GO_TEST_PATHS=./...
### Build / dependency management
openapi:
./etc/generate-openapi.sh
fmt: $(FMT_FILES)
# Format everything, but the import-format doesn't match our desired pattern.
gofmt -w -s $^
# Remove unused imports.
go run golang.org/x/tools/cmd/goimports -w $^
# Format imports.
go run github.com/daixiang0/gci -w $^
bin/$(GOOS)/$(GOARCH)/influx: $(SOURCES)
CGO_ENABLED=0 $(GO_BUILD) -o bin/$(GOOS)/$(GOARCH)/ ./cmd/$(shell basename "$@")
.DEFAULT_GOAL := influx
influx: bin/$(GOOS)/$(GOARCH)/influx
clean:
$(RM) -r bin
### Linters
checkfmt:
./etc/checkfmt.sh
checktidy:
./etc/checktidy.sh
checkopenapi:
./etc/checkopenapi.sh
checkgenerate:
./etc/checkgenerate.sh
staticcheck: $(SOURCES)
go run honnef.co/go/tools/cmd/staticcheck -go $(GOVERSION) ./...
vet:
go vet ./...
# Testing
mock: ./internal/mock/gen.go
go generate ./internal/mock/
test:
CGO_ENABLED=0 $(GO_TEST) $(GO_TEST_PATHS)
test-race:
# Race-checking requires CGO.
$(GO_TEST) -v -race -count=1 $(GO_TEST_PATHS)
### List of all targets that don't produce a file
.PHONY: influx openapi fmt checkfmt checktidy staticcheck vet mock test test-race