-
Notifications
You must be signed in to change notification settings - Fork 13
/
Makefile
82 lines (69 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
export GOPRIVATE := code.cfops.it
IMPORT_PATH := github.com/cloudflare/slirpnetstack
VERSION := $(shell git describe --tags --always --dirty="-dev")
DATE := $(shell date -u '+%Y-%m-%d-%H:%MUTC')
GOFLAGS := -ldflags='-compressdwarf=false -X "$(IMPORT_PATH)/ext.Version=$(VERSION)" -X "$(IMPORT_PATH)/ext.BuildTime=$(DATE)"'
bin/slirpnetstack: *.go go.mod
go build \
$(GOFLAGS) \
-o $@ \
$(IMPORT_PATH)
bin/slirpnetstack.cover: *.go go.mod
go test \
$(GOFLAGS) \
-coverpkg="$(IMPORT_PATH)" \
-c \
-o $@ \
-tags testrunmain \
$(IMPORT_PATH)
bin/gocovmerge:
go build -o $@ github.com/wadey/gocovmerge
.PHONY: format
format:
go fmt *go
ifdef COVER
PWD:=$(CURDIR)
SLIRPNETSTACKDEP:=./bin/slirpnetstack.cover
SLIRPNETSTACKBIN:= "./bin/slirpnetstack.cover -test.coverprofile=$(PWD)/.cover/%(nr)s.out"
else
SLIRPNETSTACKDEP:=./bin/slirpnetstack
SLIRPNETSTACKBIN:= "./bin/slirpnetstack"
endif
.PHONY: test
test: $(SLIRPNETSTACKDEP)
go test ./...
SLIRPNETSTACKBIN=$(SLIRPNETSTACKBIN) \
PYTHONPATH=. \
PYTHONIOENCODING=utf-8 \
unshare -Ur python3 -m tests.runner tests
cover: bin/gocovmerge
@-mkdir -p .cover
@rm -f .cover/*.out .cover/all.merged
@$(MAKE) test COVER=1
@./bin/gocovmerge .cover/*.out > .cover/all.merged
@echo "[*] Total test coverage:"
@./tests/cover.py .cover/all.merged
ifdef CI
go tool cover -html .cover/all.merged -o .cover/all.html
endif
ifdef HTML
go tool cover -html .cover/all.merged
endif
clean:
rm -f bin/* .cover/*out
GOTESTTARGETS = \
bin/mocktcpecho \
bin/mockudpecho \
bin/mockdns
test: $(GOTESTTARGETS)
$(GOTESTTARGETS): $(wildcard tests/*/*.go)
go build \
-o $@ \
$(IMPORT_PATH)/tests/$(subst bin/,,$@)
update-gomod:
# Use something like that if you want to pin to specific commit:
# go get -u gvisor.dev/gvisor@2f6429be86f927058392a85dcb6512bebb836d9d
# otherwise this fetches tip
go get -u gvisor.dev/gvisor@go all
go mod tidy
$(MAKE) bin/gocovmerge bin/slirpnetstack bin/slirpnetstack.cover