2019-10-29 17:45:48 +02:00
|
|
|
EXAMPLES := $(shell ./get_main_pkgs.sh ./example)
|
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-12-03 09:58:53 +02:00
|
|
|
ALL_COVERAGE_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | egrep -v '^./example' | sort)
|
2019-08-02 19:44:32 +02:00
|
|
|
|
2019-11-27 21:27:41 +02:00
|
|
|
GOTEST_MIN = go test -v -timeout 30s
|
|
|
|
GOTEST = $(GOTEST_MIN) -race
|
|
|
|
GOTEST_WITH_COVERAGE = $(GOTEST) -coverprofile=coverage.txt -covermode=atomic
|
2019-07-03 01:21:24 +02:00
|
|
|
|
|
|
|
.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
|
|
|
|
|
2020-01-24 22:06:24 +02:00
|
|
|
precommit: generate build lint examples test
|
2019-07-03 01:21:24 +02:00
|
|
|
|
|
|
|
.PHONY: test-with-coverage
|
|
|
|
test-with-coverage:
|
2019-12-03 09:58:53 +02:00
|
|
|
set -e; for dir in $(ALL_COVERAGE_MOD_DIRS); do \
|
2019-10-30 19:09:18 +02:00
|
|
|
echo "go test ./... + coverage in $${dir}"; \
|
|
|
|
(cd "$${dir}" && \
|
2019-11-27 21:27:41 +02:00
|
|
|
$(GOTEST_WITH_COVERAGE) ./... && \
|
2019-10-30 19:09:18 +02:00
|
|
|
go tool cover -html=coverage.txt -o coverage.html); \
|
|
|
|
done
|
2019-07-03 01:21:24 +02:00
|
|
|
|
2019-11-27 21:27:41 +02:00
|
|
|
.PHONY: ci
|
|
|
|
ci: precommit check-clean-work-tree test-with-coverage test-386
|
2019-08-22 20:16:51 +02:00
|
|
|
|
2019-11-27 21:27:41 +02:00
|
|
|
.PHONY: check-clean-work-tree
|
|
|
|
check-clean-work-tree:
|
2019-08-22 20:16:51 +02:00
|
|
|
@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
|
|
|
|
2019-11-27 21:27:41 +02:00
|
|
|
.PHONY: build
|
|
|
|
build:
|
|
|
|
# TODO: Fix this on windows.
|
2019-10-30 19:09:18 +02:00
|
|
|
set -e; for dir in $(ALL_GO_MOD_DIRS); do \
|
2019-11-27 21:27:41 +02:00
|
|
|
echo "compiling all packages in $${dir}"; \
|
2019-10-30 19:09:18 +02:00
|
|
|
(cd "$${dir}" && \
|
2019-11-27 21:27:41 +02:00
|
|
|
go build ./... && \
|
|
|
|
go test -run xxxxxMatchNothingxxxxx ./... >/dev/null); \
|
2019-10-30 19:09:18 +02:00
|
|
|
done
|
2019-07-03 01:21:24 +02:00
|
|
|
|
2019-11-27 21:27:41 +02:00
|
|
|
.PHONY: test
|
|
|
|
test:
|
2019-11-22 20:48:53 +02:00
|
|
|
set -e; for dir in $(ALL_GO_MOD_DIRS); do \
|
2019-11-27 21:27:41 +02:00
|
|
|
echo "go test ./... + race in $${dir}"; \
|
2019-11-22 20:48:53 +02:00
|
|
|
(cd "$${dir}" && \
|
2019-11-27 21:27:41 +02:00
|
|
|
$(GOTEST) ./...); \
|
2019-11-22 20:48:53 +02:00
|
|
|
done
|
|
|
|
|
2019-07-03 01:21:24 +02:00
|
|
|
.PHONY: test-386
|
|
|
|
test-386:
|
2019-10-30 19:09:18 +02:00
|
|
|
set -e; for dir in $(ALL_GO_MOD_DIRS); do \
|
|
|
|
echo "go test ./... GOARCH 386 in $${dir}"; \
|
|
|
|
(cd "$${dir}" && \
|
2019-11-27 21:27:41 +02:00
|
|
|
GOARCH=386 $(GOTEST_MIN) ./...); \
|
2019-10-30 19:09:18 +02:00
|
|
|
done
|
2019-07-03 01:21:24 +02:00
|
|
|
|
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}"; \
|
2019-10-30 19:09:18 +02:00
|
|
|
(cd "$${ex}" && \
|
|
|
|
go build .); \
|
2019-09-19 18:16:09 +02:00
|
|
|
done
|
2019-11-27 21:27:41 +02:00
|
|
|
|
|
|
|
.PHONY: lint
|
2020-01-24 22:06:24 +02:00
|
|
|
lint: $(TOOLS_DIR)/golangci-lint $(TOOLS_DIR)/misspell
|
2019-11-27 21:27:41 +02:00
|
|
|
set -e; for dir in $(ALL_GO_MOD_DIRS); do \
|
|
|
|
echo "golangci-lint in $${dir}"; \
|
|
|
|
(cd "$${dir}" && \
|
2019-11-28 09:20:34 +02:00
|
|
|
$(abspath $(TOOLS_DIR))/golangci-lint run --fix && \
|
|
|
|
$(abspath $(TOOLS_DIR))/golangci-lint run); \
|
2019-11-27 21:27:41 +02:00
|
|
|
done
|
|
|
|
$(TOOLS_DIR)/misspell -w $(ALL_DOCS)
|
|
|
|
set -e; for dir in $(ALL_GO_MOD_DIRS); do \
|
|
|
|
echo "go mod tidy in $${dir}"; \
|
|
|
|
(cd "$${dir}" && \
|
|
|
|
go mod tidy); \
|
|
|
|
done
|
|
|
|
|
2020-01-24 22:06:24 +02:00
|
|
|
generate: $(TOOLS_DIR)/stringer
|
2019-11-27 21:27:41 +02:00
|
|
|
PATH="$(abspath $(TOOLS_DIR)):$${PATH}" go generate ./...
|