Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build(v2): fix usage by moving code to a v2 subfolder #927

Merged
merged 8 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 7 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ jobs:
command: go version
- run:
name: Core and drivers tests
command: go test -v -coverprofile=coverage.txt -covermode=atomic . ./drivers/...
command: |
cd ./v2
go test -v -coverprofile=coverage.txt -covermode=atomic . ./drivers/...
- run:
name: Code coverage
command: |
Expand All @@ -39,7 +41,9 @@ jobs:
- run:
# digispark needs libusb, joystick needs sdl2, opencv needs opencv
name: Platform tests (except digispark, joystick, opencv)
command: go test -v $(go list ./platforms/... | grep -v platforms/digispark | grep -v platforms/joystick | grep -v platforms/opencv)
command: |
cd ./v2
go test -v $(go list ./platforms/... | grep -v platforms/digispark | grep -v platforms/joystick | grep -v platforms/opencv)

"check_examples":
docker:
Expand All @@ -53,6 +57,7 @@ jobs:
# digispark needs libusb, joystick needs sdl2, opencv needs opencv
name: Check examples (except digispark, joystick, opencv)
command: |
cd ./v2
ALL=$(grep -l -r --include "*.go" 'build example' ./)
SOME=$(grep -L 'digispark' $(grep -L 'joystick' $(grep -L 'gocv' ${ALL})))
for e in ${SOME} ; do go vet "${e}" ; done
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
version: v1.52.2

# Optional: working directory, useful for monorepos
# working-directory: somedir
working-directory: v2

# Optional: golangci-lint command line arguments.
# mostly there is no problem locally, but on server: "could not import C (cgo preprocessing failed) (typecheck)"
Expand Down
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# note: GolangCI-Lint also searches for config files in all directories from the directory of the first analyzed path up to the root.
run:
# Timeout for analysis, e.g. 30s, 5m.
# gobot is very expensive, on a machine with heavy load it takes some minutes
Expand Down
78 changes: 9 additions & 69 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,76 +1,16 @@
# 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))
# prevent examples with joystick (sdl2) dependencies
EXAMPLES_NO_JOYSTICK := $(shell grep -L 'joystick' $(ALL_EXAMPLES))
# prevent examples with joystick (sdl2) and gocv (opencv) dependencies
EXAMPLES_NO_GOCV_JOYSTICK := $(shell grep -L 'joystick' $$(grep -L 'gocv' $(EXAMPLES_NO_GOCV)))
# used examples
EXAMPLES := $(EXAMPLES_NO_GOCV_JOYSTICK)
# this file is just a forwarder to the folder with go.mod for common use cases
# it is working since Go 1.18 is installed locally

.PHONY: test test_race test_cover robeaux version_check fmt_check fmt_fix examples examples_check $(EXAMPLES)
gomoddir := $(shell go list -f '{{.Dir}}' -m)

# opencv platform currently skipped to prevent install of preconditions
including_except := $(shell go list ./... | grep -v platforms/opencv)

# Run tests on nearly all directories without test cache
test:
go test -count=1 -v $(including_except)

# Run tests with race detection
test_race:
go test -race $(including_except)

# 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 ; \
.PHONY: test fmt_check examples_check

# 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 ; \
test:
cd $(gomoddir) && make test && cd ..

# Check for bad code style and other issues
fmt_check:
gofmt -l ./
golangci-lint run -v

# Fix bad code style (will only be executed, on version match)
fmt_fix: version_check
go fmt ./...

examples: $(EXAMPLES)

examples_check:
$(MAKE) CHECK=ON examples
cd $(gomoddir) && make fmt_check && cd ..

$(EXAMPLES):
ifeq ($(CHECK),ON)
go vet ./$@
else
go build -o /tmp/gobot_examples/$@ ./$@
endif
examples_check:
cd $(gomoddir) && make examples_check && cd ..
2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ before_test:
- go env

build_script:
- cd ./v2
- go test -v -cpu=2 .
- go test -v -cpu=2 ./drivers/aio/...
- go test -v -cpu=2 ./drivers/i2c/...
- go test -v -cpu=2 ./platforms/firmata/...
- go test -v -cpu=2 ./platforms/ble/...
- cd ..
5 changes: 5 additions & 0 deletions go.work
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
go 1.17

// this helps go tools and golangci-lint to find the subfolder
// it is working since Go 1.18 is installed
use ./v2
76 changes: 76 additions & 0 deletions v2/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# 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))
# prevent examples with joystick (sdl2) dependencies
EXAMPLES_NO_JOYSTICK := $(shell grep -L 'joystick' $(ALL_EXAMPLES))
# prevent examples with joystick (sdl2) and gocv (opencv) dependencies
EXAMPLES_NO_GOCV_JOYSTICK := $(shell grep -L 'joystick' $$(grep -L 'gocv' $(EXAMPLES_NO_GOCV)))
# used examples
EXAMPLES := $(EXAMPLES_NO_GOCV_JOYSTICK)

.PHONY: test test_race test_cover robeaux version_check fmt_check fmt_fix examples examples_check $(EXAMPLES)

# opencv platform currently skipped to prevent install of preconditions
including_except := $(shell go list ./... | grep -v platforms/opencv)

# Run tests on nearly all directories without test cache
test:
go test -count=1 -v $(including_except)

# Run tests with race detection
test_race:
go test -race $(including_except)

# 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 ; \

# 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 ; \

# Check for bad code style and other issues
fmt_check:
gofmt -l ./
golangci-lint run -v

# Fix bad code style (will only be executed, on version match)
fmt_fix: version_check
go fmt ./...

examples: $(EXAMPLES)

examples_check:
$(MAKE) CHECK=ON examples

$(EXAMPLES):
ifeq ($(CHECK),ON)
go vet ./$@
else
go build -o /tmp/gobot_examples/$@ ./$@
endif
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading