-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathMakefile
More file actions
115 lines (93 loc) · 3.44 KB
/
Makefile
File metadata and controls
115 lines (93 loc) · 3.44 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
#!/usr/bin/make
# Copyright (c) 2017 Arista Networks, Inc. All rights reserved.
########################################################
# Makefile for go-cvprac
#
# useful targets:
# make coverage -- go coverage tool
# make fmtcheck -- formate check
# make vet -- go vet
# make lint -- go lint
# make deadcode -- deadcode checker
# make test -- run tests
# make clean -- clean
#
########################################################
# Supply defaults if not provided
GOOS ?= linux
GOARCH ?= 386
GOTEST_FLAGS ?= -v -cover -timeout=240s
RACE_FLAGS ?= -race -timeout=60s
GOLDFLAGS := -ldflags="-s -w"
DEFAULT_GOPATH := $${GOPATH%%:*}
GO := go
GOFMT := goimports
GOLINT := golint
GO_DEADCODE := deadcode
GOFILES := find . -name '*.go' ! -path './Godeps/*' ! -path './vendor/*'
GOFOLDERS := $(GO) list ./... | sed 's:^github.com/aristanetworks/go-cvprac:.:' | grep -vw -e './vendor'
VERSION_FILE = version.go
GOPKGVERSION := $(shell git describe --tags --always --match "v[0-9]*" --abbrev=7 HEAD)
ifndef GOPKGVERSION
$(error unable to determine git version)
endif
# External Tools
EXTERNAL_TOOLS=\
github.com/golang/lint/golint \
github.com/remyoudompheng/go-misc/deadcode \
golang.org/x/tools/cmd/godoc \
golang.org/x/tools/cmd/goimports
check: fmtcheck vet lint deadcode unittest
deadcode:
@if ! which $(GO_DEADCODE) >/dev/null; then echo Please install $(GO_DEADCODE); exit 1; fi
$(GOFOLDERS) | xargs $(GO_DEADCODE)
lint:
lint=`$(GOFOLDERS) | xargs -L 1 $(GOLINT)`; if test -n "$$lint"; then echo "$$lint"; exit 1; fi
# The above is ugly, but unfortunately golint doesn't exit 1 when it finds
# lint. See https://github.com/golang/lint/issues/65
fmtcheck:
@if ! which $(GOFMT) >/dev/null; then echo Please install $(GOFMT); exit 1; fi
goimports=`$(GOFILES) | xargs $(GOFMT) -l 2>&1`; \
if test -n "$$goimports"; then echo Check the following files for coding style AND USE goimports; echo "$$goimports"; \
if test "$(shell $(GO) version | awk '{ print $$3 }')" != "devel"; then exit 1; fi; \
fi
$(GOFILES) -exec ./check_line_len.awk {} +
fmt:
$(GOFOLDERS) | xargs $(GO) fmt
vet:
$(GOFOLDERS) | xargs $(GO) vet
test:
$(GOFOLDERS) | xargs $(GO) test $(GOTEST_FLAGS)
systest:
$(GOFOLDERS) | xargs $(GO) test $(GOTEST_FLAGS) -tags=systest -run SystemTest$
unittest:
$(GOFOLDERS) | xargs $(GO) test $(GOTEST_FLAGS) -run UnitTest$
doc:
godoc -http="localhost:6060" -play=true
COVER_PKGS := `find . -name '*_test.go' ! -path "./.git/*" ! -path "./Godeps/*" ! -path "./vendor/*" | xargs -I{} dirname {} | sort -u`
COVER_MODE := count
COVER_TMPFILE := coverage.out
coverdata:
echo 'mode: $(COVER_MODE)' > $(COVER_TMPFILE) ;\
for dir in $(COVER_PKGS); do \
$(GO) test -covermode=$(COVER_MODE) -coverprofile=$(COVER_TMPFILE).tmp $$dir || exit; \
tail -n +2 $(COVER_TMPFILE).tmp >> $(COVER_TMPFILE) && \
rm $(COVER_TMPFILE).tmp; \
done;
coverage: coverdata
$(GO) tool cover -html=$(COVER_TMPFILE)
rm -f $(COVER_TMPFILE)
bootstrap:
@for tool in $(EXTERNAL_TOOLS) ; do \
echo "Installing $$tool" ; \
go get $$tool; \
done
version: $(VERSION_FILE)
$(VERSION_FILE): $(VERSION_FILE).in .git/HEAD .git/index
sed -e 's/@VERSION@/$(GOPKGVERSION)/' $(VERSION_FILE).in >$(VERSION_FILE)-t
mv $(VERSION_FILE)-t $(VERSION_FILE)
clean:
rm -rf $(COVER_TMPFILE).tmp $(COVER_TMPFILE) $(VERSION_FILE){,-t}
$(GO) clean ./...
.PHONY: all fmtcheck test vet check doc lint deadcode
.PHONY: clean coverage coverdata version