Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
122 lines (87 loc) · 3.64 KB
/
Copy pathMakefile
File metadata and controls
122 lines (87 loc) · 3.64 KB
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
# -----------------------------------------------------------------------------
# global
.DEFAULT_GOAL := help
# -----------------------------------------------------------------------------
# go
GO_BUILDTAGS = osusergo,netgo,static
GO_LDFLAGS = -s -w
ifeq ($(GO_OS),linux)
GO_LDFLAGS += "-extldflags=-static"
endif
GO_FLAGS ?= -tags='${GO_BUILDTAGS}' -ldflags='${GO_LDFLAGS}'
GOEXPERIMENT ?= simd,runtimesecret
export GOEXPERIMENT
TOOLS_BIN = ${CURDIR}/bin
TOOLS = $(shell go list tool)
GO_TEST ?= ${TOOLS_BIN}/gotestsum --
GO_TEST_PACKAGES = $(shell go list -f='{{if or .TestGoFiles .XTestGoFiles}}{{.ImportPath}}{{end}}' ./...)
GO_TEST_FLAGS ?= -race -count=1
GO_TEST_FUNC ?= .
GO_COVERAGE_JUNITFILE_DIR ?= _test_results
GO_BENCH_FLAGS ?= -benchmem
GO_BENCH_FUNC ?= .
GO_LINT_FLAGS ?=
# -----------------------------------------------------------------------------
# defines
define install_tool
for t in ${TOOLS}; do \
if [ -n '$1' ] && [ $$(basename $${t%%/v[0-9]*}) = '$1' ]; then \
echo "Install $$t ..." >&2; \
GOBIN=${TOOLS_BIN} CGO_ENABLED=0 go install -v -mod=readonly ${GO_FLAGS} "$${t}"; \
fi \
done
endef
# -----------------------------------------------------------------------------
# target
##@ test, bench, coverage
.PHONY: test
test: bin/gotestsum
test: ## Runs package test including race condition.
${GO_TEST} ${GO_TEST_FLAGS} -run=${GO_TEST_FUNC} $(strip ${GO_FLAGS}) ${GO_TEST_PACKAGES}
.PHONY: coverage
coverage: GO_TEST=${TOOLS_BIN}/gotestsum --junitfile=${GO_COVERAGE_JUNITFILE_DIR}/tests.$(@F).xml --
coverage: bin/gotestsum
coverage: ## Takes packages test coverage.
@mkdir -p ${GO_COVERAGE_JUNITFILE_DIR}
${GO_TEST} ${GO_TEST_FLAGS} -cover -covermode=atomic -coverpkg=./... -coverprofile=coverage.out $(strip ${GO_FLAGS}) ./...
##@ fmt, lint
.PHONY: fmt
fmt: bin/goimports-rereviser bin/gofumpt
fmt: ## Run goimports-rereviser and gofumpt.
@${TOOLS_BIN}/goimports-rereviser -project-name=go.lsp.dev/jsonrpc2 -use-cache -cache-fast-skip -format -rm-unused -set-alias -recursive .
@${TOOLS_BIN}/gofumpt -extra -w .
.PHONY: lint
lint: lint/golangci-lint ## Run all linters.
.PHONY: lint/golangci-lint
lint/golangci-lint: bin/golangci-lint
lint/golangci-lint: .golangci.yaml ## Run golangci-lint.
@${TOOLS_BIN}/golangci-lint run $(strip ${GO_LINT_FLAGS}) ./...
##@ generate
.PHONY: generate
generate: ## Regenerate the protocol package from metaModel.json and format it.
go run go.lsp.dev/protocol/internal/genlsp/cmd/genlsp -input internal/genlsp/testdata/metaModel.json -output . -pkg protocol
go tool gofumpt -extra -w .
##@ tools
.PHONY: tools
tools: bin/'' ## Install tools
tools/%: bin/% ## install an individual dependent tool
bin/%:
@$(call install_tool,$*)
##@ clean
.PHONY: clean
clean: ## Cleanups binaries and extra files in the package.
@rm -rf *.out *.test *.prof trace.txt ${TOOLS_BIN} ${GO_COVERAGE_JUNITFILE_DIR}
##@ miscellaneous
.PHONY: todo
TODO: ## Print the all of (TODO|BUG|XXX|FIXME|NOTE) in packages.
@grep -E '(TODO|BUG|XXX|FIXME)(\(.+\):|:)' $(shell find . -type f -name '*.go' -and -not -iwholename '*vendor*')
.PHONY: nolint
nolint: ## Print the all of //nolint:... pragma in packages.
@grep -E -C 3 '//nolint.+' $(shell find . -type f -name '*.go' -and -not -iwholename '*vendor*' -and -not -iwholename '*internal*')
.PHONY: env/%
env/%: ## Print the value of MAKEFILE_VARIABLE. Use `make env/GO_FLAGS` or etc.
@echo $($*)
##@ help
.PHONY: help
help: ## Show this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[33m<target>\033[0m\n"} /^[a-zA-Z_0-9\/%_-]+:.*?##/ { printf " \033[1;32m%-20s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)