2019-10-01 18:16:45 +02:00
|
|
|
ALL_PKGS := $(shell GO111MODULE=on go list ./...)
|
|
|
|
|
|
|
|
export GO111MODULE=on
|
2019-07-03 01:21:24 +02:00
|
|
|
|
2019-09-19 18:16:09 +02:00
|
|
|
EXAMPLES := \
|
|
|
|
./example/basic \
|
|
|
|
./example/http/client \
|
2019-09-23 23:39:10 +02:00
|
|
|
./example/http/server \
|
|
|
|
./experimental/streaming/example/basic
|
2019-09-19 18:16:09 +02:00
|
|
|
|
2019-08-02 19:44:32 +02:00
|
|
|
# All source code and documents. Used in spell check.
|
|
|
|
ALL_DOCS := $(shell find . -name '*.md' -type f | sort)
|
2019-09-19 18:16:09 +02:00
|
|
|
# All directories with go.mod files. Used in go mod tidy.
|
2019-09-23 20:04:55 +02:00
|
|
|
ALL_GO_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | sort)
|
2019-08-02 19:44:32 +02:00
|
|
|
|
2019-07-03 01:21:24 +02:00
|
|
|
GOTEST=go test
|
|
|
|
GOTEST_OPT?=-v -race -timeout 30s
|
|
|
|
GOTEST_OPT_WITH_COVERAGE = $(GOTEST_OPT) -coverprofile=coverage.txt -covermode=atomic
|
|
|
|
|
|
|
|
.DEFAULT_GOAL := precommit
|
|
|
|
|
2019-06-19 02:09:49 +02:00
|
|
|
.PHONY: precommit
|
|
|
|
|
|
|
|
TOOLS_DIR := ./.tools
|
|
|
|
|
|
|
|
$(TOOLS_DIR)/golangci-lint: go.mod go.sum tools.go
|
|
|
|
go build -o $(TOOLS_DIR)/golangci-lint github.com/golangci/golangci-lint/cmd/golangci-lint
|
|
|
|
|
2019-08-02 19:44:32 +02:00
|
|
|
$(TOOLS_DIR)/misspell: go.mod go.sum tools.go
|
|
|
|
go build -o $(TOOLS_DIR)/misspell github.com/client9/misspell/cmd/misspell
|
|
|
|
|
2019-08-22 20:16:51 +02:00
|
|
|
$(TOOLS_DIR)/stringer: go.mod go.sum tools.go
|
|
|
|
go build -o $(TOOLS_DIR)/stringer golang.org/x/tools/cmd/stringer
|
|
|
|
|
|
|
|
precommit: $(TOOLS_DIR)/golangci-lint $(TOOLS_DIR)/misspell $(TOOLS_DIR)/stringer
|
|
|
|
PATH="$(abspath $(TOOLS_DIR)):$${PATH}" go generate ./...
|
2019-09-25 18:38:55 +02:00
|
|
|
# TODO: Fix this on windows.
|
|
|
|
set -e; for dir in $(ALL_GO_MOD_DIRS); do \
|
|
|
|
echo "golangci-lint in $${dir}"; \
|
|
|
|
(cd "$${dir}" && $(abspath $(TOOLS_DIR))/golangci-lint run --fix); \
|
|
|
|
done
|
2019-08-05 22:58:24 +02:00
|
|
|
$(TOOLS_DIR)/misspell -w $(ALL_DOCS)
|
2019-09-25 18:38:55 +02:00
|
|
|
set -e; for dir in $(ALL_GO_MOD_DIRS); do \
|
2019-09-19 18:16:09 +02:00
|
|
|
echo "go mod tidy in $${dir}"; \
|
|
|
|
(cd "$${dir}" && go mod tidy); \
|
|
|
|
done
|
2019-07-03 01:21:24 +02:00
|
|
|
|
|
|
|
.PHONY: test-with-coverage
|
|
|
|
test-with-coverage:
|
|
|
|
$(GOTEST) $(GOTEST_OPT_WITH_COVERAGE) $(ALL_PKGS)
|
|
|
|
go tool cover -html=coverage.txt -o coverage.html
|
|
|
|
|
|
|
|
.PHONY: circle-ci
|
2019-09-19 18:16:09 +02:00
|
|
|
circle-ci: precommit test-clean-work-tree test-with-coverage test-386 examples
|
2019-08-22 20:16:51 +02:00
|
|
|
|
|
|
|
.PHONY: test-clean-work-tree
|
|
|
|
test-clean-work-tree:
|
|
|
|
@if ! git diff --quiet; then \
|
|
|
|
echo; \
|
2019-10-01 18:16:45 +02:00
|
|
|
echo 'Working tree is not clean, did you forget to run "make precommit"?'; \
|
2019-08-22 20:16:51 +02:00
|
|
|
echo; \
|
|
|
|
git status; \
|
|
|
|
exit 1; \
|
|
|
|
fi
|
2019-07-03 01:21:24 +02:00
|
|
|
|
|
|
|
.PHONY: test
|
2019-09-19 18:16:09 +02:00
|
|
|
test: examples
|
2019-07-03 01:21:24 +02:00
|
|
|
$(GOTEST) $(GOTEST_OPT) $(ALL_PKGS)
|
|
|
|
|
|
|
|
.PHONY: test-386
|
|
|
|
test-386:
|
|
|
|
GOARCH=386 $(GOTEST) -v -timeout 30s $(ALL_PKGS)
|
|
|
|
|
2019-09-19 18:16:09 +02:00
|
|
|
.PHONY: examples
|
|
|
|
examples:
|
2019-09-25 18:38:55 +02:00
|
|
|
@set -e; for ex in $(EXAMPLES); do \
|
2019-09-19 18:16:09 +02:00
|
|
|
echo "Building $${ex}"; \
|
|
|
|
(cd "$${ex}" && go build .); \
|
|
|
|
done
|
|
|
|
|
2019-07-03 01:21:24 +02:00
|
|
|
all-pkgs:
|
|
|
|
@echo $(ALL_PKGS) | tr ' ' '\n' | sort
|
|
|
|
|
2019-08-05 22:58:24 +02:00
|
|
|
all-docs:
|
2019-08-22 20:16:51 +02:00
|
|
|
@echo $(ALL_DOCS) | tr ' ' '\n' | sort
|