-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
62 lines (48 loc) · 1.18 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
#
# Intro
go.modname := $(shell go list -m)
go.tidyflags = -go=1.18 -compat=1.18
help:
@echo 'Usage:'
@echo ' make help'
@echo ' make check'
@echo ' make $(notdir $(go.modname)).cov.html'
@echo ' make lint'
@echo ' make go-mod-tidy'
.PHONY: help
.SECONDARY:
.PHONY: FORCE
SHELL = bash
#
# Test suite
$(notdir $(go.modname)).cov: check
test -e $@
touch $@
check:
go test -count=1 -coverprofile=$(notdir $(go.modname)).cov -coverpkg=./... -race ./...
.PHONY: check
%.cov.html: %.cov
go tool cover -html=$< -o=$@
#
# Lint
lint: tools/bin/golangci-lint
tools/bin/golangci-lint run ./...
.PHONY: lint
#
# go mod tidy
go-mod-tidy:
.PHONY: go-mod-tidy
go-mod-tidy: go-mod-tidy/main
go-mod-tidy/main:
rm -f go.sum
GOFLAGS=-mod=mod go mod tidy $(go.tidyflags)
.PHONY: go-mod-tidy/main
#
# Tools
go-mod-tidy: $(patsubst tools/src/%/go.mod,go-mod-tidy/tools/%,$(wildcard tools/src/*/go.mod))
go-mod-tidy/tools/%:
rm -f tools/src/$*/go.sum
cd tools/src/$* && GOFLAGS=-mod=mod go mod tidy $(go.tidyflags)
.PHONY: go-mod-tidy/tools/%
tools/bin/%: tools/src/%/go.mod tools/src/%/pin.go
cd $(<D) && GOOS= GOARCH= go build -o $(abspath $@) $$(sed -En 's,^import "(.*)".*,\1,p' pin.go)