...
1# TODO: Fix this on windows.
2ALL_SRC := $(shell find . -name '*.go' \
3 -not -path './vendor/*' \
4 -not -path '*/gen-go/*' \
5 -type f | sort)
6ALL_PKGS := $(shell go list $(sort $(dir $(ALL_SRC))))
7
8GOTEST_OPT?=-v -race -timeout 30s
9GOTEST_OPT_WITH_COVERAGE = $(GOTEST_OPT) -coverprofile=coverage.txt -covermode=atomic
10GOTEST=go test
11GOIMPORTS=goimports
12GOLINT=golint
13GOVET=go vet
14EMBEDMD=embedmd
15# TODO decide if we need to change these names.
16TRACE_ID_LINT_EXCEPTION="type name will be used as trace.TraceID by other packages"
17TRACE_OPTION_LINT_EXCEPTION="type name will be used as trace.TraceOptions by other packages"
18README_FILES := $(shell find . -name '*README.md' | sort | tr '\n' ' ')
19
20.DEFAULT_GOAL := imports-lint-vet-embedmd-test
21
22.PHONY: imports-lint-vet-embedmd-test
23imports-lint-vet-embedmd-test: imports lint vet embedmd test
24
25# TODO enable test-with-coverage in tavis
26.PHONY: travis-ci
27travis-ci: imports lint vet embedmd test test-386
28
29all-pkgs:
30 @echo $(ALL_PKGS) | tr ' ' '\n' | sort
31
32all-srcs:
33 @echo $(ALL_SRC) | tr ' ' '\n' | sort
34
35.PHONY: test
36test:
37 $(GOTEST) $(GOTEST_OPT) $(ALL_PKGS)
38
39.PHONY: test-386
40test-386:
41 GOARCH=386 $(GOTEST) -v -timeout 30s $(ALL_PKGS)
42
43.PHONY: test-with-coverage
44test-with-coverage:
45 $(GOTEST) $(GOTEST_OPT_WITH_COVERAGE) $(ALL_PKGS)
46
47.PHONY: imports
48imports:
49 @IMPORTSOUT=`$(GOIMPORTS) -l $(ALL_SRC) 2>&1`; \
50 if [ "$$IMPORTSOUT" ]; then \
51 echo "$(GOIMPORTS) FAILED => goimports the following files:\n"; \
52 echo "$$IMPORTSOUT\n"; \
53 exit 1; \
54 else \
55 echo "Imports finished successfully"; \
56 fi
57
58.PHONY: lint
59lint:
60 @LINTOUT=`$(GOLINT) $(ALL_PKGS) | grep -v $(TRACE_ID_LINT_EXCEPTION) | grep -v $(TRACE_OPTION_LINT_EXCEPTION) 2>&1`; \
61 if [ "$$LINTOUT" ]; then \
62 echo "$(GOLINT) FAILED => clean the following lint errors:\n"; \
63 echo "$$LINTOUT\n"; \
64 exit 1; \
65 else \
66 echo "Lint finished successfully"; \
67 fi
68
69.PHONY: vet
70vet:
71 # TODO: Understand why go vet downloads "github.com/google/go-cmp v0.2.0"
72 @VETOUT=`$(GOVET) ./... | grep -v "go: downloading" 2>&1`; \
73 if [ "$$VETOUT" ]; then \
74 echo "$(GOVET) FAILED => go vet the following files:\n"; \
75 echo "$$VETOUT\n"; \
76 exit 1; \
77 else \
78 echo "Vet finished successfully"; \
79 fi
80
81.PHONY: embedmd
82embedmd:
83 @EMBEDMDOUT=`$(EMBEDMD) -d $(README_FILES) 2>&1`; \
84 if [ "$$EMBEDMDOUT" ]; then \
85 echo "$(EMBEDMD) FAILED => embedmd the following files:\n"; \
86 echo "$$EMBEDMDOUT\n"; \
87 exit 1; \
88 else \
89 echo "Embedmd finished successfully"; \
90 fi
91
92.PHONY: install-tools
93install-tools:
94 go install golang.org/x/lint/golint@latest
95 go install golang.org/x/tools/cmd/cover@latest
96 go install golang.org/x/tools/cmd/goimports@latest
97 go install github.com/rakyll/embedmd@latest
View as plain text