2023-05-30 01:23:28 +08:00
|
|
|
# include also examples in other than ./examples folder
|
|
|
|
ALL_EXAMPLES := $(shell grep -l -r --include "*.go" 'build example' ./)
|
|
|
|
# prevent examples with gocv (opencv) dependencies
|
|
|
|
EXAMPLES_NO_GOCV := $(shell grep -L 'gocv' $(ALL_EXAMPLES))
|
|
|
|
# used examples
|
2023-09-23 18:32:31 +08:00
|
|
|
EXAMPLES := $(EXAMPLES_NO_GOCV)
|
2022-09-27 18:18:07 +08:00
|
|
|
|
2024-02-11 22:34:50 +08:00
|
|
|
.PHONY: test test_race test_cover robeaux version_check fmt_check fmt_fix examples examples_check examples_fmt_fix $(EXAMPLES)
|
2014-07-11 02:13:32 +08:00
|
|
|
|
2023-05-30 01:23:28 +08:00
|
|
|
# opencv platform currently skipped to prevent install of preconditions
|
|
|
|
including_except := $(shell go list ./... | grep -v platforms/opencv)
|
2017-11-05 06:26:01 +08:00
|
|
|
|
2023-11-12 03:18:44 +08:00
|
|
|
# Run tests on nearly all directories without test cache, with race detection
|
|
|
|
test_race:
|
2024-02-05 01:50:43 +08:00
|
|
|
go test -failfast -count=1 -race $(including_except)
|
2023-11-12 03:18:44 +08:00
|
|
|
|
2023-05-30 01:23:28 +08:00
|
|
|
# Run tests on nearly all directories without test cache
|
2023-05-23 01:35:36 +08:00
|
|
|
test:
|
2023-11-12 03:18:44 +08:00
|
|
|
go test -failfast -count=1 $(including_except)
|
2023-05-30 01:23:28 +08:00
|
|
|
|
|
|
|
# Test, generate and show coverage in browser
|
|
|
|
test_cover:
|
|
|
|
go test -v $(including_except) -coverprofile=coverage.txt ; \
|
|
|
|
go tool cover -html=coverage.txt ; \
|
|
|
|
|
|
|
|
robeaux:
|
|
|
|
ifeq (,$(shell which go-bindata))
|
|
|
|
$(error robeaux not built! https://github.com/jteeuwen/go-bindata is required to build robeaux assets )
|
|
|
|
endif
|
|
|
|
cd api ; \
|
|
|
|
npm install robeaux ; \
|
|
|
|
cp -r node_modules/robeaux robeaux-tmp ; \
|
|
|
|
cd robeaux-tmp ; \
|
|
|
|
rm Makefile package.json README.markdown ; \
|
|
|
|
touch css/fonts.css ; \
|
|
|
|
echo "Updating robeaux..." ; \
|
|
|
|
go-bindata -pkg="robeaux" -o robeaux.go -ignore=\\.git ./... ; \
|
|
|
|
mv robeaux.go ../robeaux ; \
|
|
|
|
cd .. ; \
|
|
|
|
rm -rf robeaux-tmp/ ; \
|
|
|
|
rm -rf node_modules/ ; \
|
|
|
|
go fmt ./robeaux/robeaux.go ; \
|
2022-09-28 00:14:14 +08:00
|
|
|
|
2023-05-30 01:23:28 +08:00
|
|
|
# Check for installed and module version match. Will exit with code 50 if not match.
|
|
|
|
# There is nothing bad in general, if you program with a higher version.
|
|
|
|
# At least the recipe "fmt_fix" will not work in that case.
|
|
|
|
version_check:
|
|
|
|
@gv=$$(echo $$(go version) | sed "s/^.* go\([0-9].[0-9]*\).*/\1/") ; \
|
|
|
|
mv=$$(grep -m 1 'go 1.' ./go.mod | sed "s/^go \([0-9].[0-9]*\).*/\1/") ; \
|
|
|
|
echo "go: $${gv}.*, go.mod: $${mv}" ; \
|
|
|
|
if [ "$${gv}" != "$${mv}" ]; then exit 50; fi ; \
|
|
|
|
|
2023-10-21 02:50:42 +08:00
|
|
|
# Check for bad code style and other issues (gofumpt and gofmt check is activated for the linter)
|
2022-09-28 00:14:14 +08:00
|
|
|
fmt_check:
|
2023-05-30 01:23:28 +08:00
|
|
|
golangci-lint run -v
|
|
|
|
|
2023-10-21 02:50:42 +08:00
|
|
|
# Fix bad code style (the go version will be automatically obtained from go.mod)
|
|
|
|
fmt_fix:
|
|
|
|
$(MAKE) version_check || true
|
|
|
|
gofumpt -l -w .
|
2023-11-10 03:31:18 +08:00
|
|
|
golangci-lint run -v --fix
|
2023-05-30 01:23:28 +08:00
|
|
|
|
|
|
|
examples: $(EXAMPLES)
|
|
|
|
|
|
|
|
examples_check:
|
|
|
|
$(MAKE) CHECK=ON examples
|
2022-10-11 14:32:14 +08:00
|
|
|
|
2024-02-11 22:34:50 +08:00
|
|
|
examples_fmt_fix:
|
|
|
|
$(MAKE) CHECK=FMT examples
|
|
|
|
|
2023-05-30 01:23:28 +08:00
|
|
|
$(EXAMPLES):
|
|
|
|
ifeq ($(CHECK),ON)
|
|
|
|
go vet ./$@
|
2024-02-11 22:34:50 +08:00
|
|
|
else ifeq ($(CHECK),FMT)
|
|
|
|
gofumpt -l -w ./$@
|
|
|
|
golangci-lint run ./$@ --fix --build-tags example --disable forcetypeassert --disable noctx
|
2023-05-30 01:23:28 +08:00
|
|
|
else
|
|
|
|
go build -o /tmp/gobot_examples/$@ ./$@
|
|
|
|
endif
|