2018-10-14 04:39:16 +00:00
|
|
|
GO ?= go
|
2017-06-13 02:50:42 +00:00
|
|
|
GOFMT ?= gofmt "-s"
|
2021-06-23 05:10:49 +00:00
|
|
|
GO_VERSION=$(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
|
2019-11-25 07:42:23 +00:00
|
|
|
PACKAGES ?= $(shell $(GO) list ./...)
|
|
|
|
VETPACKAGES ?= $(shell $(GO) list ./... | grep -v /examples/)
|
|
|
|
GOFILES := $(shell find . -name "*.go")
|
2018-10-14 04:39:16 +00:00
|
|
|
TESTFOLDER := $(shell $(GO) list ./... | grep -E 'gin$$|binding$$|render$$' | grep -v examples)
|
2020-01-07 03:31:10 +00:00
|
|
|
TESTTAGS ?= ""
|
2017-06-13 02:50:42 +00:00
|
|
|
|
|
|
|
.PHONY: test
|
2024-05-13 01:29:21 +00:00
|
|
|
# Run tests to verify code functionality.
|
2017-06-13 02:50:42 +00:00
|
|
|
test:
|
2018-10-14 04:39:16 +00:00
|
|
|
echo "mode: count" > coverage.out
|
|
|
|
for d in $(TESTFOLDER); do \
|
2022-08-02 02:20:59 +00:00
|
|
|
$(GO) test $(TESTTAGS) -v -covermode=count -coverprofile=profile.out $$d > tmp.out; \
|
2018-12-05 05:49:03 +00:00
|
|
|
cat tmp.out; \
|
|
|
|
if grep -q "^--- FAIL" tmp.out; then \
|
|
|
|
rm tmp.out; \
|
2018-12-25 16:27:46 +00:00
|
|
|
exit 1; \
|
|
|
|
elif grep -q "build failed" tmp.out; then \
|
|
|
|
rm tmp.out; \
|
2019-02-21 12:32:55 +00:00
|
|
|
exit 1; \
|
|
|
|
elif grep -q "setup failed" tmp.out; then \
|
|
|
|
rm tmp.out; \
|
|
|
|
exit 1; \
|
2018-12-05 05:49:03 +00:00
|
|
|
fi; \
|
2018-10-14 04:39:16 +00:00
|
|
|
if [ -f profile.out ]; then \
|
|
|
|
cat profile.out | grep -v "mode:" >> coverage.out; \
|
|
|
|
rm profile.out; \
|
|
|
|
fi; \
|
|
|
|
done
|
2017-06-13 02:50:42 +00:00
|
|
|
|
|
|
|
.PHONY: fmt
|
2024-05-13 01:29:21 +00:00
|
|
|
# Ensure consistent code formatting.
|
2017-06-13 02:50:42 +00:00
|
|
|
fmt:
|
|
|
|
$(GOFMT) -w $(GOFILES)
|
|
|
|
|
|
|
|
.PHONY: fmt-check
|
2024-05-13 01:29:21 +00:00
|
|
|
# format (check only).
|
2017-06-13 02:50:42 +00:00
|
|
|
fmt-check:
|
|
|
|
@diff=$$($(GOFMT) -d $(GOFILES)); \
|
|
|
|
if [ -n "$$diff" ]; then \
|
|
|
|
echo "Please run 'make fmt' and commit the result:"; \
|
|
|
|
echo "$${diff}"; \
|
|
|
|
exit 1; \
|
|
|
|
fi;
|
|
|
|
|
2024-04-02 03:58:00 +00:00
|
|
|
.PHONY: vet
|
2024-05-13 01:29:21 +00:00
|
|
|
# Examine packages and report suspicious constructs if any.
|
2017-06-13 02:50:42 +00:00
|
|
|
vet:
|
2018-10-14 04:39:16 +00:00
|
|
|
$(GO) vet $(VETPACKAGES)
|
2017-06-13 02:50:42 +00:00
|
|
|
|
|
|
|
.PHONY: lint
|
2024-05-13 01:29:21 +00:00
|
|
|
# Inspect source code for stylistic errors or potential bugs.
|
2017-06-13 02:50:42 +00:00
|
|
|
lint:
|
|
|
|
@hash golint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
2018-10-14 04:39:16 +00:00
|
|
|
$(GO) get -u golang.org/x/lint/golint; \
|
2017-06-13 02:50:42 +00:00
|
|
|
fi
|
|
|
|
for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
|
|
|
|
|
2024-05-13 01:29:21 +00:00
|
|
|
.PHONY: misspell
|
|
|
|
# Correct commonly misspelled English words in source code.
|
|
|
|
misspell:
|
2017-06-13 02:50:42 +00:00
|
|
|
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
2018-10-14 04:39:16 +00:00
|
|
|
$(GO) get -u github.com/client9/misspell/cmd/misspell; \
|
2017-06-13 02:50:42 +00:00
|
|
|
fi
|
2024-05-13 01:29:21 +00:00
|
|
|
misspell -w $(GOFILES)
|
2017-06-13 02:50:42 +00:00
|
|
|
|
2024-05-13 01:29:21 +00:00
|
|
|
.PHONY: misspell-check
|
|
|
|
# misspell (check only).
|
|
|
|
misspell-check:
|
2017-06-13 02:50:42 +00:00
|
|
|
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
|
2018-10-14 04:39:16 +00:00
|
|
|
$(GO) get -u github.com/client9/misspell/cmd/misspell; \
|
2017-06-13 02:50:42 +00:00
|
|
|
fi
|
2024-05-13 01:29:21 +00:00
|
|
|
misspell -error $(GOFILES)
|
2018-10-15 04:52:51 +00:00
|
|
|
|
|
|
|
.PHONY: tools
|
2024-05-13 01:29:21 +00:00
|
|
|
# Install tools (golint and misspell).
|
2018-10-15 04:52:51 +00:00
|
|
|
tools:
|
2021-06-23 05:10:49 +00:00
|
|
|
@if [ $(GO_VERSION) -gt 15 ]; then \
|
|
|
|
$(GO) install golang.org/x/lint/golint@latest; \
|
|
|
|
$(GO) install github.com/client9/misspell/cmd/misspell@latest; \
|
|
|
|
elif [ $(GO_VERSION) -lt 16 ]; then \
|
|
|
|
$(GO) install golang.org/x/lint/golint; \
|
|
|
|
$(GO) install github.com/client9/misspell/cmd/misspell; \
|
|
|
|
fi
|
2024-05-13 01:29:21 +00:00
|
|
|
|
|
|
|
.PHONY: help
|
|
|
|
# Help.
|
|
|
|
help:
|
|
|
|
@echo ''
|
|
|
|
@echo 'Usage:'
|
|
|
|
@echo ' make [target]'
|
|
|
|
@echo ''
|
|
|
|
@echo 'Targets:'
|
|
|
|
@awk '/^[a-zA-Z\-\0-9]+:/ { \
|
|
|
|
helpMessage = match(lastLine, /^# (.*)/); \
|
|
|
|
if (helpMessage) { \
|
|
|
|
helpCommand = substr($$1, 0, index($$1, ":")-1); \
|
|
|
|
helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \
|
|
|
|
printf " - \033[36m%-20s\033[0m %s\n", helpCommand, helpMessage; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
{ lastLine = $$0 }' $(MAKEFILE_LIST)
|
|
|
|
|
|
|
|
.DEFAULT_GOAL := help
|