diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 0e0b0a1..8a8bb11 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -4,9 +4,14 @@ updates: - package-ecosystem: github-actions directory: / schedule: - interval: daily + interval: weekly - package-ecosystem: gomod directory: / schedule: - interval: daily + interval: weekly + + - package-ecosystem: gomod + directory: .sage + schedule: + interval: weekly diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index acdfbc3..3ffdead 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,24 +12,16 @@ jobs: make: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Setup Go - uses: actions/setup-go@v3 - with: - go-version: 1.16 - - - name: Setup Node - uses: actions/setup-node@v3 + - name: Setup Sage + uses: einride/sage/actions/setup@master with: - node-version: 16 + go-version: 1.19 - name: Make run: make - name: Report Code Coverage - uses: codecov/codecov-action@v2.1.0 + uses: codecov/codecov-action@v3.1.1 with: file: ./build/coverage/go-test.txt fail_ci_if_error: true @@ -39,26 +31,19 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Setup Go - uses: actions/setup-go@v3 + - name: Setup Sage + uses: einride/sage/actions/setup@master with: - go-version: ^1.16 + go-version: 1.19 - - name: Setup Node - uses: actions/setup-node@v3 + - name: Create Release + uses: go-semantic-release/action@v1.19 with: - node-version: 16 - - - name: Run semantic-release - run: make semantic-release - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + github-token: ${{ secrets.GITHUB_TOKEN }} + allow-initial-development-versions: true - name: Run goreleaser - uses: goreleaser/goreleaser-action@v2.9.1 + uses: goreleaser/goreleaser-action@v3.2.0 with: version: latest args: release --rm-dist diff --git a/.golangci.yml b/.golangci.yml deleted file mode 100644 index 26b7041..0000000 --- a/.golangci.yml +++ /dev/null @@ -1,29 +0,0 @@ -run: - timeout: 5m - skip-dirs: - - gen - -linters: - enable-all: true - disable: - - dupl # allow duplication - - funlen # allow long functions - - gomnd # allow some magic numbers - - wsl # unwanted amount of whitespace - - godox # allow TODOs - - interfacer # deprecated by the author for having too many false positives - - gocognit # allow higher cognitive complexity - - testpackage # unwanted convention - - nestif # allow deep nesting - - unparam # allow constant parameters - - goerr113 # allow "dynamic" errors - - dogsled # allow blank identifiers - - cyclop # allow complex functions - - nlreturn # allow return/break without whitespace - - exhaustive # TODO: make switches exhaustive and enable - - noctx # TODO: update http calls and enable - - wrapcheck # TODO: don't require error wrapping - - paralleltest # TODO: make tests parallel and enable - - forbidigo # TODO: remove Printf from CLI tools and enable - - exhaustivestruct # don't require exhaustive structs - - ifshort # has false positives in 1.37.0 diff --git a/.sage/go.mod b/.sage/go.mod new file mode 100644 index 0000000..fb18b2b --- /dev/null +++ b/.sage/go.mod @@ -0,0 +1,5 @@ +module go.einride.tech/can/.sage + +go 1.19 + +require go.einride.tech/sage v0.184.1 diff --git a/.sage/go.sum b/.sage/go.sum new file mode 100644 index 0000000..c1de077 --- /dev/null +++ b/.sage/go.sum @@ -0,0 +1,2 @@ +go.einride.tech/sage v0.184.1 h1:ZQPFz+TMzHZ9n6OVMv3GQwj3qlE2H2lMfWVMER/MGi8= +go.einride.tech/sage v0.184.1/go.mod h1:EzV5uciFX7/2ho8EKB5K9JghOfXIxlzs694b+Tkl5GQ= diff --git a/.sage/main.go b/.sage/main.go new file mode 100644 index 0000000..cd98e57 --- /dev/null +++ b/.sage/main.go @@ -0,0 +1,128 @@ +package main + +import ( + "context" + "fmt" + "os" + "path/filepath" + + "go.einride.tech/sage/sg" + "go.einride.tech/sage/sgtool" + "go.einride.tech/sage/tools/sgconvco" + "go.einride.tech/sage/tools/sggit" + "go.einride.tech/sage/tools/sggolangcilint" + "go.einride.tech/sage/tools/sggolicenses" + "go.einride.tech/sage/tools/sggoreview" + "go.einride.tech/sage/tools/sgmarkdownfmt" + "go.einride.tech/sage/tools/sgyamlfmt" +) + +func main() { + sg.GenerateMakefiles( + sg.Makefile{ + Path: sg.FromGitRoot("Makefile"), + DefaultTarget: Default, + }, + ) +} + +func Default(ctx context.Context) error { + sg.Deps(ctx, ConvcoCheck, FormatMarkdown, FormatYaml, GoGenerate, GenerateTestdata) + sg.Deps(ctx, GoLint, GoReview) + sg.Deps(ctx, GoTest) + sg.Deps(ctx, GoModTidy) + sg.Deps(ctx, GoLicenses, GitVerifyNoDiff) + return nil +} + +func GoModTidy(ctx context.Context) error { + sg.Logger(ctx).Println("tidying Go module files...") + return sg.Command(ctx, "go", "mod", "tidy", "-v").Run() +} + +func GoTest(ctx context.Context) error { + sg.Logger(ctx).Println("running Go tests...") + coverageDir := sg.FromGitRoot("build", "coverage") + if err := os.MkdirAll(coverageDir, 0o775); err != nil { + return err + } + return sg.Command( + ctx, + "go", + "test", + "-short", + "-race", + fmt.Sprintf("-coverprofile=%s", filepath.Join(coverageDir, "go-test.txt")), + "-covermode=atomic", + "./...", + ).Run() +} + +func GoReview(ctx context.Context) error { + sg.Logger(ctx).Println("reviewing Go files...") + return sggoreview.Run(ctx) +} + +func GoLint(ctx context.Context) error { + sg.Logger(ctx).Println("linting Go files...") + return sggolangcilint.Run(ctx) +} + +func GoLicenses(ctx context.Context) error { + sg.Logger(ctx).Println("checking Go licenses...") + return sggolicenses.Check(ctx) +} + +func FormatMarkdown(ctx context.Context) error { + sg.Logger(ctx).Println("formatting Markdown files...") + return sgmarkdownfmt.Command(ctx, "-w", ".").Run() +} + +func FormatYaml(ctx context.Context) error { + sg.Logger(ctx).Println("formatting Yaml files...") + return sgyamlfmt.Run(ctx) +} + +func ConvcoCheck(ctx context.Context) error { + sg.Logger(ctx).Println("checking git commits...") + return sgconvco.Command(ctx, "check", "origin/master..HEAD").Run() +} + +func GitVerifyNoDiff(ctx context.Context) error { + sg.Logger(ctx).Println("verifying that git has no diff...") + return sggit.VerifyNoDiff(ctx) +} + +func GoGenerate(ctx context.Context) error { + sg.Deps(ctx, Mockgen, Stringer) + sg.Logger(ctx).Println("generating Go code...") + return sg.Command(ctx, "go", "generate", "./...").Run() +} + +func Mockgen(ctx context.Context) error { + sg.Logger(ctx).Println("installing mockgen...") + _, err := sgtool.GoInstallWithModfile(ctx, "github.com/golang/mock/mockgen", sg.FromGitRoot("go.mod")) + return err +} + +func Stringer(ctx context.Context) error { + sg.Logger(ctx).Println("installing stringer...") + _, err := sgtool.GoInstallWithModfile(ctx, "golang.org/x/tools/cmd/stringer", sg.FromGitRoot("go.mod")) + return err +} + +func GenerateTestdata(ctx context.Context) error { + sg.Logger(ctx).Println("generating testdata...") + // don't use "sg.FromGitRoot" in paths to avoid embedding user paths in generated files + cmd := sg.Command( + ctx, + "go", + "run", + "cmd/cantool/main.go", + "generate", + "testdata/dbc", + "testdata/gen/go", + ) + cmd.Dir = sg.FromGitRoot() + return cmd.Run() +} diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index a899c5e..41edeea 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,129 +1,87 @@ -# Contributor Covenant Code of Conduct +Contributor Covenant Code of Conduct +==================================== -## Our Pledge +Our Pledge +---------- -We as members, contributors, and leaders pledge to make participation in our -community a harassment-free experience for everyone, regardless of age, body -size, visible or invisible disability, ethnicity, sex characteristics, gender -identity and expression, level of experience, education, socio-economic status, -nationality, personal appearance, race, religion, or sexual identity -and orientation. +We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. -We pledge to act and interact in ways that contribute to an open, welcoming, -diverse, inclusive, and healthy community. +We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. -## Our Standards +Our Standards +------------- -Examples of behavior that contributes to a positive environment for our -community include: +Examples of behavior that contributes to a positive environment for our community include: -- Demonstrating empathy and kindness toward other people -- Being respectful of differing opinions, viewpoints, and experiences -- Giving and gracefully accepting constructive feedback -- Accepting responsibility and apologizing to those affected by our mistakes, - and learning from the experience -- Focusing on what is best not just for us as individuals, but for the - overall community +- Demonstrating empathy and kindness toward other people +- Being respectful of differing opinions, viewpoints, and experiences +- Giving and gracefully accepting constructive feedback +- Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience +- Focusing on what is best not just for us as individuals, but for the overall community Examples of unacceptable behavior include: -- The use of sexualized language or imagery, and sexual attention or - advances of any kind -- Trolling, insulting or derogatory comments, and personal or political attacks -- Public or private harassment -- Publishing others' private information, such as a physical or email - address, without their explicit permission -- Other conduct which could reasonably be considered inappropriate in a - professional setting +- The use of sexualized language or imagery, and sexual attention or advances of any kind +- Trolling, insulting or derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information, such as a physical or email address, without their explicit permission +- Other conduct which could reasonably be considered inappropriate in a professional setting -## Enforcement Responsibilities +Enforcement Responsibilities +---------------------------- -Community leaders are responsible for clarifying and enforcing our standards of -acceptable behavior and will take appropriate and fair corrective action in -response to any behavior that they deem inappropriate, threatening, offensive, -or harmful. +Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. -Community leaders have the right and responsibility to remove, edit, or reject -comments, commits, code, wiki edits, issues, and other contributions that are -not aligned to this Code of Conduct, and will communicate reasons for moderation -decisions when appropriate. +Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. -## Scope +Scope +----- -This Code of Conduct applies within all community spaces, and also applies when -an individual is officially representing the community in public spaces. -Examples of representing our community include using an official e-mail address, -posting via an official social media account, or acting as an appointed -representative at an online or offline event. +This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. -## Enforcement +Enforcement +----------- -Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported to the community leaders responsible for enforcement at -. +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at open-source@einride.tech. All complaints will be reviewed and investigated promptly and fairly. -All community leaders are obligated to respect the privacy and security of the -reporter of any incident. +All community leaders are obligated to respect the privacy and security of the reporter of any incident. -## Enforcement Guidelines +Enforcement Guidelines +---------------------- -Community leaders will follow these Community Impact Guidelines in determining -the consequences for any action they deem in violation of this Code of Conduct: +Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: ### 1. Correction -**Community Impact**: Use of inappropriate language or other behavior deemed -unprofessional or unwelcome in the community. +**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. -**Consequence**: A private, written warning from community leaders, providing -clarity around the nature of the violation and an explanation of why the -behavior was inappropriate. A public apology may be requested. +**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. ### 2. Warning -**Community Impact**: A violation through a single incident or series -of actions. +**Community Impact**: A violation through a single incident or series of actions. -**Consequence**: A warning with consequences for continued behavior. No -interaction with the people involved, including unsolicited interaction with -those enforcing the Code of Conduct, for a specified period of time. This -includes avoiding interactions in community spaces as well as external channels -like social media. Violating these terms may lead to a temporary or -permanent ban. +**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. ### 3. Temporary Ban -**Community Impact**: A serious violation of community standards, including -sustained inappropriate behavior. +**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. -**Consequence**: A temporary ban from any sort of interaction or public -communication with the community for a specified period of time. No public or -private interaction with the people involved, including unsolicited interaction -with those enforcing the Code of Conduct, is allowed during this period. -Violating these terms may lead to a permanent ban. +**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. ### 4. Permanent Ban -**Community Impact**: Demonstrating a pattern of violation of community -standards, including sustained inappropriate behavior, harassment of an -individual, or aggression toward or disparagement of classes of individuals. +**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. -**Consequence**: A permanent ban from any sort of public interaction within -the community. +**Consequence**: A permanent ban from any sort of public interaction within the community. -## Attribution +Attribution +----------- -This Code of Conduct is adapted from the [Contributor Covenant][homepage], -version 2.0, available at -https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. +This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org), version 2.0, available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. -Community Impact Guidelines were inspired by [Mozilla's code of conduct -enforcement ladder](https://github.com/mozilla/diversity). +Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). -[homepage]: https://www.contributor-covenant.org - -For answers to common questions about this code of conduct, see the FAQ at -https://www.contributor-covenant.org/faq. Translations are available at -https://www.contributor-covenant.org/translations. +For answers to common questions about this code of conduct, see the FAQ at https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations. diff --git a/Makefile b/Makefile index bdc95d3..2cccf8f 100644 --- a/Makefile +++ b/Makefile @@ -1,70 +1,100 @@ -SHELL := /bin/bash - -all: \ - commitlint \ - stringer-generate \ - mockgen-generate \ - testdata \ - go-lint \ - go-review \ - go-test \ - go-mod-tidy \ - git-verify-nodiff - -include tools/commitlint/rules.mk -include tools/git-verify-nodiff/rules.mk -include tools/golangci-lint/rules.mk -include tools/goreview/rules.mk -include tools/semantic-release/rules.mk -include tools/stringer/rules.mk - -.PHONY: clean -clean: - $(info [$@] removing build files...) - @rm -rf tools/*/*/ build - -.PHONY: mockgen-generate -mockgen-generate: \ - internal/gen/mock/mockcanrunner/mocks.go \ - internal/gen/mock/mockclock/mocks.go \ - internal/gen/mock/mocksocketcan/mocks.go - -internal/gen/mock/mockcanrunner/mocks.go: pkg/canrunner/run.go go.mod - go run github.com/golang/mock/mockgen \ - -destination $@ -package mockcanrunner go.einride.tech/can/pkg/canrunner \ - Node,TransmittedMessage,ReceivedMessage,FrameTransmitter,FrameReceiver - -internal/gen/mock/mockclock/mocks.go: internal/clock/clock.go go.mod - go run github.com/golang/mock/mockgen \ - -destination $@ -package mockclock go.einride.tech/can/internal/clock \ - Clock,Ticker - -internal/gen/mock/mocksocketcan/mocks.go: pkg/socketcan/fileconn.go go.mod - go run github.com/golang/mock/mockgen \ - -destination $@ -package mocksocketcan -source $< - -.PHONY: stringer-generate -stringer-generate: \ - pkg/descriptor/sendtype_string.go \ - pkg/socketcan/errorclass_string.go \ - pkg/socketcan/protocolviolationerrorlocation_string.go \ - pkg/socketcan/protocolviolationerror_string.go \ - pkg/socketcan/controllererror_string.go \ - pkg/socketcan/transceivererror_string.go - -%_string.go: %.go $(stringer) - go generate $< - -.PHONY: testdata -testdata: - go run cmd/cantool/main.go generate testdata/dbc testdata/gen/go +# Code generated by go.einride.tech/sage. DO NOT EDIT. +# To learn more, see .sage/main.go and https://github.com/einride/sage. -.PHONY: go-test -go-test: - $(info [$@] running Go tests...) - @mkdir -p build/coverage - @go test -short -race -coverprofile=build/coverage/$@.txt -covermode=atomic ./... +.DEFAULT_GOAL := default + +cwd := $(dir $(realpath $(firstword $(MAKEFILE_LIST)))) +sagefile := $(abspath $(cwd)/.sage/bin/sagefile) + +# Setup Go. +go := $(shell command -v go 2>/dev/null) +export GOWORK ?= off +ifndef go +SAGE_GO_VERSION ?= 1.18.4 +export GOROOT := $(abspath $(cwd)/.sage/tools/go/$(SAGE_GO_VERSION)/go) +export PATH := $(PATH):$(GOROOT)/bin +go := $(GOROOT)/bin/go +os := $(shell uname | tr '[:upper:]' '[:lower:]') +arch := $(shell uname -m) +ifeq ($(arch),x86_64) +arch := amd64 +endif +$(go): + $(info installing Go $(SAGE_GO_VERSION)...) + @mkdir -p $(dir $(GOROOT)) + @curl -sSL https://go.dev/dl/go$(SAGE_GO_VERSION).$(os)-$(arch).tar.gz | tar xz -C $(dir $(GOROOT)) + @touch $(GOROOT)/go.mod + @chmod +x $(go) +endif + +.PHONY: $(sagefile) +$(sagefile): $(go) + @cd .sage && $(go) mod tidy && $(go) run . + +.PHONY: sage +sage: + @$(MAKE) $(sagefile) + +.PHONY: update-sage +update-sage: $(go) + @cd .sage && $(go) get -d go.einride.tech/sage@latest && $(go) mod tidy && $(go) run . + +.PHONY: clean-sage +clean-sage: + @git clean -fdx .sage/tools .sage/bin .sage/build + +.PHONY: convco-check +convco-check: $(sagefile) + @$(sagefile) ConvcoCheck + +.PHONY: default +default: $(sagefile) + @$(sagefile) Default + +.PHONY: format-markdown +format-markdown: $(sagefile) + @$(sagefile) FormatMarkdown + +.PHONY: format-yaml +format-yaml: $(sagefile) + @$(sagefile) FormatYaml + +.PHONY: generate-testdata +generate-testdata: $(sagefile) + @$(sagefile) GenerateTestdata + +.PHONY: git-verify-no-diff +git-verify-no-diff: $(sagefile) + @$(sagefile) GitVerifyNoDiff + +.PHONY: go-generate +go-generate: $(sagefile) + @$(sagefile) GoGenerate + +.PHONY: go-licenses +go-licenses: $(sagefile) + @$(sagefile) GoLicenses + +.PHONY: go-lint +go-lint: $(sagefile) + @$(sagefile) GoLint .PHONY: go-mod-tidy -go-mod-tidy: - go mod tidy -v +go-mod-tidy: $(sagefile) + @$(sagefile) GoModTidy + +.PHONY: go-review +go-review: $(sagefile) + @$(sagefile) GoReview + +.PHONY: go-test +go-test: $(sagefile) + @$(sagefile) GoTest + +.PHONY: mockgen +mockgen: $(sagefile) + @$(sagefile) Mockgen + +.PHONY: stringer +stringer: $(sagefile) + @$(sagefile) Stringer diff --git a/README.md b/README.md index 7fb58c8..1a68db7 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,14 @@ -# :electric_plug: CAN Go +:electric_plug: CAN Go +====================== -[![PkgGoDev][pkg-badge]][pkg] -[![GoReportCard][report-badge]][report] -[![Codecov][codecov-badge]][codecov] - -[pkg-badge]: https://pkg.go.dev/badge/go.einride.tech/can -[pkg]: https://pkg.go.dev/go.einride.tech/can -[report-badge]: https://goreportcard.com/badge/go.einride.tech/can -[report]: https://goreportcard.com/report/go.einride.tech/can -[codecov-badge]: https://codecov.io/gh/einride/can-go/branch/master/graph/badge.svg -[codecov]: https://codecov.io/gh/einride/can-go +[![PkgGoDev](https://pkg.go.dev/badge/go.einride.tech/can)](https://pkg.go.dev/go.einride.tech/can) [![GoReportCard](https://goreportcard.com/badge/go.einride.tech/can)](https://goreportcard.com/report/go.einride.tech/can) [![Codecov](https://codecov.io/gh/einride/can-go/branch/master/graph/badge.svg)](https://codecov.io/gh/einride/can-go) CAN toolkit for Go programmers. -can-go makes use of the Linux SocketCAN abstraction for CAN communication. -(See the [SocketCAN][socketcan] documentation for more details). - -[socketcan]: https://www.kernel.org/doc/Documentation/networking/can.txt +can-go makes use of the Linux SocketCAN abstraction for CAN communication. (See the [SocketCAN](https://www.kernel.org/doc/Documentation/networking/can.txt) documentation for more details). -## Examples +Examples +-------- ### Receiving CAN frames @@ -26,14 +16,14 @@ Receiving CAN frames from a socketcan interface. ```go func main() { - // Error handling omitted to keep example simple - conn, _ := socketcan.DialContext(context.Background(), "can", "can0") - - recv := socketcan.NewReceiver(conn) - for recv.Receive() { - frame := recv.Frame() - fmt.Println(frame.String()) - } + // Error handling omitted to keep example simple + conn, _ := socketcan.DialContext(context.Background(), "can", "can0") + + recv := socketcan.NewReceiver(conn) + for recv.Receive() { + frame := recv.Frame() + fmt.Println(frame.String()) + } } ``` @@ -49,7 +39,7 @@ func main() { frame := can.Frame{} tx := socketcan.NewTransmitter(conn) - _ = tx.TransmitFrame(context.Background(), frame) + _ = tx.TransmitFrame(context.Background(), frame) } ``` @@ -61,9 +51,7 @@ It is possible to generate Go code from a `.dbc` file. $ go run go.einride.tech/can/cmd/cantool generate ``` -In order to generate Go code that makes sense, we currently perform some -validations when parsing the DBC file so there may need to be some changes -on the DBC file to make it work +In order to generate Go code that makes sense, we currently perform some validations when parsing the DBC file so there may need to be some changes on the DBC file to make it work After generating Go code we can marshal a message to a frame: diff --git a/cmd/cantool/main.go b/cmd/cantool/main.go index 3422bd7..f687c48 100644 --- a/cmd/cantool/main.go +++ b/cmd/cantool/main.go @@ -3,7 +3,7 @@ package main import ( "errors" "fmt" - "io/ioutil" + "io" "os" "path/filepath" "strings" @@ -87,7 +87,7 @@ func lintCommand(app *kingpin.Application) { if err != nil { return err } - source, err := ioutil.ReadAll(f) + source, err := io.ReadAll(f) if err != nil { return err } @@ -145,7 +145,7 @@ func genGo(inputFile, outputFile string) error { if err := os.MkdirAll(filepath.Dir(outputFile), 0o755); err != nil { return err } - input, err := ioutil.ReadFile(inputFile) + input, err := os.ReadFile(inputFile) if err != nil { return err } @@ -160,7 +160,7 @@ func genGo(inputFile, outputFile string) error { if err != nil { return err } - if err := ioutil.WriteFile(outputFile, output, 0o600); err != nil { + if err := os.WriteFile(outputFile, output, 0o600); err != nil { return err } fmt.Println("wrote:", outputFile) diff --git a/data.go b/data.go index d1b5d2f..9701746 100644 --- a/data.go +++ b/data.go @@ -10,91 +10,91 @@ const MaxDataLength = 8 // Data holds the data in a CAN frame. // -// Layout +// # Layout // // Individual bits in the data are numbered according to the following scheme: // -// BIT -// NUMBER -// +------+------+------+------+------+------+------+------+ -// | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | -// BYTE +------+------+------+------+------+------+------+------+ -// NUMBER -// +-----+ +------+------+------+------+------+------+------+------+ -// | 0 | | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | -// +-----+ +------+------+------+------+------+------+------+------+ -// | 1 | | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | -// +-----+ +------+------+------+------+------+------+------+------+ -// | 2 | | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | -// +-----+ +------+------+------+------+------+------+------+------+ -// | 3 | | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | -// +-----+ +------+------+------+------+------+------+------+------+ -// | 4 | | 39 | 38 | 37 | 36 | 35 | 34 | 33 | 32 | -// +-----+ +------+------+------+------+------+------+------+------+ -// | 5 | | 47 | 46 | 45 | 44 | 43 | 42 | 41 | 40 | -// +-----+ +------+------+------+------+------+------+------+------+ -// | 6 | | 55 | 54 | 53 | 52 | 51 | 50 | 49 | 48 | -// +-----+ +------+------+------+------+------+------+------+------+ -// | 7 | | 63 | 62 | 61 | 60 | 59 | 58 | 57 | 56 | -// +-----+ +------+------+------+------+------+------+------+------+ +// BIT +// NUMBER +// +------+------+------+------+------+------+------+------+ +// | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | +// BYTE +------+------+------+------+------+------+------+------+ +// NUMBER +// +-----+ +------+------+------+------+------+------+------+------+ +// | 0 | | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | +// +-----+ +------+------+------+------+------+------+------+------+ +// | 1 | | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | +// +-----+ +------+------+------+------+------+------+------+------+ +// | 2 | | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | +// +-----+ +------+------+------+------+------+------+------+------+ +// | 3 | | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | +// +-----+ +------+------+------+------+------+------+------+------+ +// | 4 | | 39 | 38 | 37 | 36 | 35 | 34 | 33 | 32 | +// +-----+ +------+------+------+------+------+------+------+------+ +// | 5 | | 47 | 46 | 45 | 44 | 43 | 42 | 41 | 40 | +// +-----+ +------+------+------+------+------+------+------+------+ +// | 6 | | 55 | 54 | 53 | 52 | 51 | 50 | 49 | 48 | +// +-----+ +------+------+------+------+------+------+------+------+ +// | 7 | | 63 | 62 | 61 | 60 | 59 | 58 | 57 | 56 | +// +-----+ +------+------+------+------+------+------+------+------+ // // Bit ranges can be manipulated using little-endian and big-endian bit ordering. // -// Little-endian bit ranges +// # Little-endian bit ranges // // Example range of length 32 starting at bit 29: // -// BIT -// NUMBER -// +------+------+------+------+------+------+------+------+ -// | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | -// BYTE +------+------+------+------+------+------+------+------+ -// NUMBER -// +-----+ +------+------+------+------+------+------+------+------+ -// | 0 | | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | -// +-----+ +------+------+------+------+------+------+------+------+ -// | 1 | | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | -// +-----+ +------+------+------+------+------+------+------+------+ -// | 2 | | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | -// +-----+ +------+------+------+------+------+------+------+------+ -// | 3 | | <-------------LSb | 28 | 27 | 26 | 25 | 24 | -// +-----+ +------+------+------+------+------+------+------+------+ -// | 4 | | <-------------------------------------------------- | -// +-----+ +------+------+------+------+------+------+------+------+ -// | 5 | | <-------------------------------------------------- | -// +-----+ +------+------+------+------+------+------+------+------+ -// | 6 | | <-------------------------------------------------- | -// +-----+ +------+------+------+------+------+------+------+------+ -// | 7 | | 63 | 62 | 61 | <-MSb--------------------------- | -// +-----+ +------+------+------+------+------+------+------+------+ +// BIT +// NUMBER +// +------+------+------+------+------+------+------+------+ +// | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | +// BYTE +------+------+------+------+------+------+------+------+ +// NUMBER +// +-----+ +------+------+------+------+------+------+------+------+ +// | 0 | | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | +// +-----+ +------+------+------+------+------+------+------+------+ +// | 1 | | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | +// +-----+ +------+------+------+------+------+------+------+------+ +// | 2 | | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | +// +-----+ +------+------+------+------+------+------+------+------+ +// | 3 | | <-------------LSb | 28 | 27 | 26 | 25 | 24 | +// +-----+ +------+------+------+------+------+------+------+------+ +// | 4 | | <-------------------------------------------------- | +// +-----+ +------+------+------+------+------+------+------+------+ +// | 5 | | <-------------------------------------------------- | +// +-----+ +------+------+------+------+------+------+------+------+ +// | 6 | | <-------------------------------------------------- | +// +-----+ +------+------+------+------+------+------+------+------+ +// | 7 | | 63 | 62 | 61 | <-MSb--------------------------- | +// +-----+ +------+------+------+------+------+------+------+------+ // -// Big-endian bit ranges +// # Big-endian bit ranges // // Example range of length 32 starting at bit 29: // -// BIT -// NUMBER -// +------+------+------+------+------+------+------+------+ -// | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | -// BYTE +------+------+------+------+------+------+------+------+ -// NUMBER -// +-----+ +------+------+------+------+------+------+------+------+ -// | 0 | | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | -// +-----+ +------+------+------+------+------+------+------+------+ -// | 1 | | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | -// +-----+ +------+------+------+------+------+------+------+------+ -// | 2 | | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | -// +-----+ +------+------+------+------+------+------+------+------+ -// | 3 | | 31 | 30 | <-MSb--------------------------------- | -// +-----+ +------+------+------+------+------+------+------+------+ -// | 4 | | <-------------------------------------------------- | -// +-----+ +------+------+------+------+------+------+------+------+ -// | 5 | | <-------------------------------------------------- | -// +-----+ +------+------+------+------+------+------+------+------+ -// | 6 | | <-------------------------------------------------- | -// +-----+ +------+------+------+------+------+------+------+------+ -// | 7 | | <------LSb | 61 | 60 | 59 | 58 | 57 | 56 | -// +-----+ +------+------+------+------+------+------+------+------+ +// BIT +// NUMBER +// +------+------+------+------+------+------+------+------+ +// | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | +// BYTE +------+------+------+------+------+------+------+------+ +// NUMBER +// +-----+ +------+------+------+------+------+------+------+------+ +// | 0 | | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | +// +-----+ +------+------+------+------+------+------+------+------+ +// | 1 | | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | +// +-----+ +------+------+------+------+------+------+------+------+ +// | 2 | | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | +// +-----+ +------+------+------+------+------+------+------+------+ +// | 3 | | 31 | 30 | <-MSb--------------------------------- | +// +-----+ +------+------+------+------+------+------+------+------+ +// | 4 | | <-------------------------------------------------- | +// +-----+ +------+------+------+------+------+------+------+------+ +// | 5 | | <-------------------------------------------------- | +// +-----+ +------+------+------+------+------+------+------+------+ +// | 6 | | <-------------------------------------------------- | +// +-----+ +------+------+------+------+------+------+------+------+ +// | 7 | | <------LSb | 61 | 60 | 59 | 58 | 57 | 56 | +// +-----+ +------+------+------+------+------+------+------+------+ type Data [MaxDataLength]byte // UnsignedBitsLittleEndian returns the little-endian bit range [start, start+length) as an unsigned value. diff --git a/frame.go b/frame.go index 86309e2..65873d0 100644 --- a/frame.go +++ b/frame.go @@ -62,7 +62,7 @@ func (f *Frame) Validate() error { // // Format: // -// ([0-9A-F]{3}|[0-9A-F]{3})#(R[0-8]?|[0-9A-F]{0,16}) +// ([0-9A-F]{3}|[0-9A-F]{3})#(R[0-8]?|[0-9A-F]{0,16}) // // The format is compatible with the candump(1) log file format. func (f Frame) String() string { diff --git a/frame_json.go b/frame_json.go index a96efca..e14ced6 100644 --- a/frame_json.go +++ b/frame_json.go @@ -19,8 +19,8 @@ type jsonFrame struct { // // Examples: // -// {"id":32,"data":"0102030405060708"} -// {"id":32,"extended":true,"remote":true,"length":4} +// {"id":32,"data":"0102030405060708"} +// {"id":32,"extended":true,"remote":true,"length":4} func (f Frame) JSON() string { switch { case f.IsRemote && f.IsExtended: diff --git a/go.mod b/go.mod index 43d1652..9f8cb5b 100644 --- a/go.mod +++ b/go.mod @@ -1,20 +1,28 @@ module go.einride.tech/can -go 1.13 +go 1.19 require ( - github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect - github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect github.com/davecgh/go-spew v1.1.1 github.com/fatih/color v1.13.0 - github.com/golang/mock v1.4.4-0.20200519145626-92f53b0a566c - github.com/shurcooL/go v0.0.0-20190704215121-7189cc372560 // indirect + github.com/golang/mock v1.6.0 github.com/shurcooL/go-goon v0.0.0-20170922171312-37c2f522c041 go.uber.org/goleak v1.1.12 - golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f - golang.org/x/sync v0.0.0-20210220032951-036812b2e83c - golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 + golang.org/x/net v0.0.0-20220923203811-8be639271d50 + golang.org/x/sync v0.0.0-20220923202941-7f9b1623fab7 + golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec golang.org/x/tools v0.1.10 gopkg.in/alecthomas/kingpin.v2 v2.2.6 - gotest.tools/v3 v3.1.0 + gotest.tools/v3 v3.4.0 +) + +require ( + github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect + github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect + github.com/google/go-cmp v0.5.5 // indirect + github.com/mattn/go-colorable v0.1.9 // indirect + github.com/mattn/go-isatty v0.0.14 // indirect + github.com/shurcooL/go v0.0.0-20190704215121-7189cc372560 // indirect + golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect + golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect ) diff --git a/go.sum b/go.sum index 2c09fa4..d6f89b4 100644 --- a/go.sum +++ b/go.sum @@ -7,42 +7,35 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= -github.com/golang/mock v1.4.4-0.20200519145626-92f53b0a566c h1:SP2mbHeyu1pCO5i8Xv6e3xgoKKMEhm6DJNVnflRaim0= -github.com/golang/mock v1.4.4-0.20200519145626-92f53b0a566c/go.mod h1:Va/jHywg6k5sXNOWdWbM806eUNOSiXznot/rTG4olf0= +github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= +github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/shurcooL/go v0.0.0-20190704215121-7189cc372560 h1:SpaoQDTgpo2YZkvmr2mtgloFFfPTjtLMlZkQtNAPQik= github.com/shurcooL/go v0.0.0-20190704215121-7189cc372560/go.mod h1:TDJrrUr11Vxrven61rcy3hJMUqaf/CLWYhHNPmT14Lk= github.com/shurcooL/go-goon v0.0.0-20170922171312-37c2f522c041 h1:llrF3Fs4018ePo4+G/HV/uQUqEI1HMDjCeOf2V6puPc= github.com/shurcooL/go-goon v0.0.0-20170922171312-37c2f522c041/go.mod h1:N5mDOmsrJOB+vfqUK+7DmDyjhSLIIBnXo9lvZJj3MWQ= -github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA= go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= @@ -53,14 +46,14 @@ golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f h1:OfiFi4JbukWwe3lzw+xunroH1mnC1e2Gy5cxNJApiSY= -golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220923203811-8be639271d50 h1:vKyz8L3zkd+xrMeIaBsQ/MNVPVFSffdaU3ZyYlBGFnI= +golang.org/x/net v0.0.0-20220923203811-8be639271d50/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220923202941-7f9b1623fab7 h1:ZrnxWX62AgTKOSagEqxvb3ffipvEDX2pl7E1TdqLqIc= +golang.org/x/sync v0.0.0-20220923202941-7f9b1623fab7/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -69,22 +62,18 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0= -golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec h1:BkDtF2Ih9xZ7le9ndzTA7KJow28VbQW3odyk/8drmuI= +golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= +golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20= golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= @@ -96,12 +85,9 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8T gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gotest.tools/v3 v3.1.0 h1:rVV8Tcg/8jHUkPUorwjaMTtemIMVXfIPKiOqnhEhakk= -gotest.tools/v3 v3.1.0/go.mod h1:fHy7eyTmJFO5bQbUsEGQ1v4m2J3Jz9eWL54TP2/ZuYQ= -rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= -rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= +gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o= +gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g= diff --git a/internal/generate/compile_test.go b/internal/generate/compile_test.go index ffd423c..6aa4592 100644 --- a/internal/generate/compile_test.go +++ b/internal/generate/compile_test.go @@ -1,7 +1,7 @@ package generate import ( - "io/ioutil" + "os" "testing" "time" @@ -295,7 +295,7 @@ func TestCompile_ExampleDBC(t *testing.T) { }, }, } - input, err := ioutil.ReadFile(exampleDBCFile) + input, err := os.ReadFile(exampleDBCFile) assert.NilError(t, err) result, err := Compile(exampleDBCFile, input) if err != nil { diff --git a/internal/mocks/gen.go b/internal/mocks/gen.go new file mode 100644 index 0000000..7d67ade --- /dev/null +++ b/internal/mocks/gen.go @@ -0,0 +1,6 @@ +package mocks + +//nolint:lll +//go:generate mockgen -destination gen/mockclock/mocks.go -package mockclock go.einride.tech/can/internal/clock Clock,Ticker +//go:generate mockgen -destination gen/mocksocketcan/mocks.go -package mocksocketcan -source ../../pkg/socketcan/fileconn.go +//go:generate mockgen -destination gen/mockcanrunner/mocks.go -package mockcanrunner go.einride.tech/can/pkg/canrunner Node,TransmittedMessage,ReceivedMessage,FrameTransmitter,FrameReceiver diff --git a/internal/gen/mock/mockcanrunner/mocks.go b/internal/mocks/gen/mockcanrunner/mocks.go similarity index 99% rename from internal/gen/mock/mockcanrunner/mocks.go rename to internal/mocks/gen/mockcanrunner/mocks.go index 4c47727..119bf39 100644 --- a/internal/gen/mock/mockcanrunner/mocks.go +++ b/internal/mocks/gen/mockcanrunner/mocks.go @@ -6,13 +6,14 @@ package mockcanrunner import ( context "context" + net "net" + reflect "reflect" + time "time" + gomock "github.com/golang/mock/gomock" can "go.einride.tech/can" canrunner "go.einride.tech/can/pkg/canrunner" descriptor "go.einride.tech/can/pkg/descriptor" - net "net" - reflect "reflect" - time "time" ) // MockNode is a mock of Node interface. diff --git a/internal/gen/mock/mockclock/mocks.go b/internal/mocks/gen/mockclock/mocks.go similarity index 99% rename from internal/gen/mock/mockclock/mocks.go rename to internal/mocks/gen/mockclock/mocks.go index 5ef1cf2..6e8dfaa 100644 --- a/internal/gen/mock/mockclock/mocks.go +++ b/internal/mocks/gen/mockclock/mocks.go @@ -5,10 +5,11 @@ package mockclock import ( - gomock "github.com/golang/mock/gomock" - clock "go.einride.tech/can/internal/clock" reflect "reflect" time "time" + + gomock "github.com/golang/mock/gomock" + clock "go.einride.tech/can/internal/clock" ) // MockClock is a mock of Clock interface. diff --git a/internal/gen/mock/mocksocketcan/mocks.go b/internal/mocks/gen/mocksocketcan/mocks.go similarity index 98% rename from internal/gen/mock/mocksocketcan/mocks.go rename to internal/mocks/gen/mocksocketcan/mocks.go index f8cabad..81da53e 100644 --- a/internal/gen/mock/mocksocketcan/mocks.go +++ b/internal/mocks/gen/mocksocketcan/mocks.go @@ -1,13 +1,14 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: pkg/socketcan/fileconn.go +// Source: ../../pkg/socketcan/fileconn.go // Package mocksocketcan is a generated GoMock package. package mocksocketcan import ( - gomock "github.com/golang/mock/gomock" reflect "reflect" time "time" + + gomock "github.com/golang/mock/gomock" ) // Mockfile is a mock of file interface. @@ -33,34 +34,33 @@ func (m *Mockfile) EXPECT() *MockfileMockRecorder { return m.recorder } -// Read mocks base method. -func (m *Mockfile) Read(arg0 []byte) (int, error) { +// Close mocks base method. +func (m *Mockfile) Close() error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Read", arg0) - ret0, _ := ret[0].(int) - ret1, _ := ret[1].(error) - return ret0, ret1 + ret := m.ctrl.Call(m, "Close") + ret0, _ := ret[0].(error) + return ret0 } -// Read indicates an expected call of Read. -func (mr *MockfileMockRecorder) Read(arg0 interface{}) *gomock.Call { +// Close indicates an expected call of Close. +func (mr *MockfileMockRecorder) Close() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Read", reflect.TypeOf((*Mockfile)(nil).Read), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Close", reflect.TypeOf((*Mockfile)(nil).Close)) } -// Write mocks base method. -func (m *Mockfile) Write(arg0 []byte) (int, error) { +// Read mocks base method. +func (m *Mockfile) Read(arg0 []byte) (int, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Write", arg0) + ret := m.ctrl.Call(m, "Read", arg0) ret0, _ := ret[0].(int) ret1, _ := ret[1].(error) return ret0, ret1 } -// Write indicates an expected call of Write. -func (mr *MockfileMockRecorder) Write(arg0 interface{}) *gomock.Call { +// Read indicates an expected call of Read. +func (mr *MockfileMockRecorder) Read(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Write", reflect.TypeOf((*Mockfile)(nil).Write), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Read", reflect.TypeOf((*Mockfile)(nil).Read), arg0) } // SetDeadline mocks base method. @@ -105,16 +105,17 @@ func (mr *MockfileMockRecorder) SetWriteDeadline(arg0 interface{}) *gomock.Call return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetWriteDeadline", reflect.TypeOf((*Mockfile)(nil).SetWriteDeadline), arg0) } -// Close mocks base method. -func (m *Mockfile) Close() error { +// Write mocks base method. +func (m *Mockfile) Write(arg0 []byte) (int, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Close") - ret0, _ := ret[0].(error) - return ret0 + ret := m.ctrl.Call(m, "Write", arg0) + ret0, _ := ret[0].(int) + ret1, _ := ret[1].(error) + return ret0, ret1 } -// Close indicates an expected call of Close. -func (mr *MockfileMockRecorder) Close() *gomock.Call { +// Write indicates an expected call of Write. +func (mr *MockfileMockRecorder) Write(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Close", reflect.TypeOf((*Mockfile)(nil).Close)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Write", reflect.TypeOf((*Mockfile)(nil).Write), arg0) } diff --git a/pkg/candebug/http_test.go b/pkg/candebug/http_test.go index 3453489..f963165 100644 --- a/pkg/candebug/http_test.go +++ b/pkg/candebug/http_test.go @@ -1,7 +1,8 @@ package candebug import ( - "io/ioutil" + "context" + "io" "net/http" "net/http/httptest" "strings" @@ -23,9 +24,13 @@ func TestServeMessagesHTTP_Single(t *testing.T) { }, }) })) - res, err := http.Get(ts.URL) + c := http.DefaultClient + ctx := context.Background() + req, err := http.NewRequestWithContext(ctx, http.MethodGet, ts.URL, nil) assert.NilError(t, err) - response, err := ioutil.ReadAll(res.Body) + res, err := c.Do(req) + assert.NilError(t, err) + response, err := io.ReadAll(res.Body) assert.NilError(t, err) assert.NilError(t, res.Body.Close()) const expected = ` @@ -55,9 +60,13 @@ func TestServeMessagesHTTP_Multi(t *testing.T) { }, }) })) - res, err := http.Get(ts.URL) + c := http.DefaultClient + ctx := context.Background() + req, err := http.NewRequestWithContext(ctx, http.MethodGet, ts.URL, nil) + assert.NilError(t, err) + res, err := c.Do(req) assert.NilError(t, err) - response, err := ioutil.ReadAll(res.Body) + response, err := io.ReadAll(res.Body) assert.NilError(t, err) assert.NilError(t, res.Body.Close()) const expected = ` diff --git a/pkg/canrunner/run_test.go b/pkg/canrunner/run_test.go index 608956e..2b7ea57 100644 --- a/pkg/canrunner/run_test.go +++ b/pkg/canrunner/run_test.go @@ -9,8 +9,8 @@ import ( "github.com/golang/mock/gomock" "go.einride.tech/can" - "go.einride.tech/can/internal/gen/mock/mockcanrunner" - "go.einride.tech/can/internal/gen/mock/mockclock" + "go.einride.tech/can/internal/mocks/gen/mockcanrunner" + "go.einride.tech/can/internal/mocks/gen/mockclock" "go.einride.tech/can/pkg/canrunner" "go.einride.tech/can/pkg/descriptor" "golang.org/x/sync/errgroup" @@ -82,7 +82,6 @@ func TestRunMessageTransmitter_TransmitEventMessage(t *testing.T) { } transmitEventChan := make(chan struct{}) wakeUpChan := make(chan struct{}) - ctx := context.Background() msg.EXPECT().Descriptor().AnyTimes().Return(desc) msg.EXPECT().TransmitEventChan().Return(transmitEventChan) msg.EXPECT().WakeUpChan().Return(wakeUpChan) diff --git a/pkg/cantext/encode.go b/pkg/cantext/encode.go index e7ba323..a634ffd 100644 --- a/pkg/cantext/encode.go +++ b/pkg/cantext/encode.go @@ -119,7 +119,7 @@ func AppendFrame(buf []byte, f can.Frame) []byte { return appendAttributeString(buf, "Frame", f.String()) } -func appendAttributeString(buf []byte, name string, s string) []byte { +func appendAttributeString(buf []byte, name, s string) []byte { buf = append(buf, name...) buf = append(buf, ": "...) buf = append(buf, s...) diff --git a/pkg/dbc/analysis/passes/signalnames/analyzer_test.go b/pkg/dbc/analysis/passes/signalnames/analyzer_test.go index d36d1d0..37babd6 100644 --- a/pkg/dbc/analysis/passes/signalnames/analyzer_test.go +++ b/pkg/dbc/analysis/passes/signalnames/analyzer_test.go @@ -26,7 +26,10 @@ BO_ 400 MOTOR_STATUS: 3 MOTOR `, Diagnostics: []*analysis.Diagnostic{ { - Pos: scanner.Position{Line: 2, Column: 2}, + Pos: scanner.Position{ + Line: 2, + Column: 2, + }, Message: "signal names must be CamelCase", }, }, diff --git a/pkg/dbc/parser_test.go b/pkg/dbc/parser_test.go index e63bd40..5f7d1a4 100644 --- a/pkg/dbc/parser_test.go +++ b/pkg/dbc/parser_test.go @@ -1,7 +1,6 @@ package dbc import ( - "io/ioutil" "os" "strings" "testing" @@ -18,14 +17,14 @@ func shouldUpdateGoldenFiles() bool { func TestParse_ExampleDBC(t *testing.T) { const inputFile = "../../testdata/dbc/example/example.dbc" const goldenFile = "../../testdata/dbc/example/example.dbc.golden" - data, err := ioutil.ReadFile(inputFile) + data, err := os.ReadFile(inputFile) assert.NilError(t, err) p := NewParser(inputFile, data) assert.NilError(t, p.Parse()) if shouldUpdateGoldenFiles() { - assert.NilError(t, ioutil.WriteFile(goldenFile, []byte(dump(p.Defs())), 0600)) + assert.NilError(t, os.WriteFile(goldenFile, []byte(dump(p.Defs())), 0o600)) } - goldenFileData, err := ioutil.ReadFile(goldenFile) + goldenFileData, err := os.ReadFile(goldenFile) assert.NilError(t, err) assert.Equal(t, string(goldenFileData), dump(p.Defs())) } diff --git a/pkg/socketcan/dialraw_linux.go b/pkg/socketcan/dialraw_linux.go index 939366f..ca0f179 100644 --- a/pkg/socketcan/dialraw_linux.go +++ b/pkg/socketcan/dialraw_linux.go @@ -1,5 +1,4 @@ -// +build linux -// +build go1.12 +//go:build linux && go1.12 package socketcan diff --git a/pkg/socketcan/dialraw_linux_test.go b/pkg/socketcan/dialraw_linux_test.go index 289ffa9..291efde 100644 --- a/pkg/socketcan/dialraw_linux_test.go +++ b/pkg/socketcan/dialraw_linux_test.go @@ -1,5 +1,4 @@ -// +build linux -// +build go1.12 +//go:build linux && go1.12 package socketcan diff --git a/pkg/socketcan/dialraw_others.go b/pkg/socketcan/dialraw_others.go index 0e18ce6..ec655ee 100644 --- a/pkg/socketcan/dialraw_others.go +++ b/pkg/socketcan/dialraw_others.go @@ -1,4 +1,4 @@ -// +build !linux !go1.12 +//go:build !linux || !go1.12 package socketcan diff --git a/pkg/socketcan/emulator.go b/pkg/socketcan/emulator.go index cb8fc34..7990b99 100644 --- a/pkg/socketcan/emulator.go +++ b/pkg/socketcan/emulator.go @@ -32,7 +32,7 @@ type EmulatorOption func(*emulatorCfg) // WithMulticastAddress sets the address for the multicast group that the Emulator should listen on. // A multicast address starts with 239.x.x.x, and using an address that does not conform to this -// will lead to undefined behaviour. +// will lead to undefined behavior. func WithMulticastAddress(address string) EmulatorOption { return func(cfg *emulatorCfg) { cfg.address = address diff --git a/pkg/socketcan/emulator_test.go b/pkg/socketcan/emulator_test.go index c94a5d8..75e043e 100644 --- a/pkg/socketcan/emulator_test.go +++ b/pkg/socketcan/emulator_test.go @@ -245,13 +245,13 @@ func TestEmulate_SendReceive(t *testing.T) { func TestEmulator_Isolation(t *testing.T) { // Given 5 separate emulators const nEmulators = 5 - var emulators []*Emulator + emulators := make([]*Emulator, nEmulators) ctx, cancel := context.WithCancel(context.Background()) eg, eCtx := errgroup.WithContext(ctx) for i := 0; i < nEmulators; i++ { e, err := NewEmulator() assert.NilError(t, err) - emulators = append(emulators, e) + emulators[i] = e eg.Go(func() error { return e.Run(eCtx) }) diff --git a/pkg/socketcan/fileconn_test.go b/pkg/socketcan/fileconn_test.go index db17a6d..3626b93 100644 --- a/pkg/socketcan/fileconn_test.go +++ b/pkg/socketcan/fileconn_test.go @@ -8,7 +8,7 @@ import ( "time" "github.com/golang/mock/gomock" - "go.einride.tech/can/internal/gen/mock/mocksocketcan" + "go.einride.tech/can/internal/mocks/gen/mocksocketcan" "gotest.tools/v3/assert" ) diff --git a/pkg/socketcan/frame.go b/pkg/socketcan/frame.go index b565256..327d44e 100644 --- a/pkg/socketcan/frame.go +++ b/pkg/socketcan/frame.go @@ -64,14 +64,14 @@ type FrameInterceptor func(fr can.Frame) // // The format specified in the Linux SocketCAN kernel module: // -// struct can_frame { -// canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */ -// __u8 can_dlc; /* frame payload length in byte (0 .. 8) */ -// __u8 __pad; /* padding */ -// __u8 __res0; /* reserved / padding */ -// __u8 __res1; /* reserved / padding */ -// __u8 data[8] __attribute__((aligned(8))); -// }; +// struct can_frame { +// canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */ +// __u8 can_dlc; /* frame payload length in byte (0 .. 8) */ +// __u8 __pad; /* padding */ +// __u8 __res0; /* reserved / padding */ +// __u8 __res1; /* reserved / padding */ +// __u8 data[8] __attribute__((aligned(8))); +// }; type frame struct { // idAndFlags is the combined CAN ID and flags. idAndFlags uint32 diff --git a/pkg/socketcan/receiver_test.go b/pkg/socketcan/receiver_test.go index e68de9f..487d969 100644 --- a/pkg/socketcan/receiver_test.go +++ b/pkg/socketcan/receiver_test.go @@ -2,7 +2,7 @@ package socketcan import ( "bytes" - "io/ioutil" + "io" "testing" "go.einride.tech/can" @@ -16,7 +16,7 @@ func TestReceiver_ReceiveFrames_Options(t *testing.T) { 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x12, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, } expected := can.Frame{ID: 0x01, Length: 2, Data: can.Data{0x12, 0x34}} - receiver := NewReceiver(ioutil.NopCloser(bytes.NewReader(input)), opt) + receiver := NewReceiver(io.NopCloser(bytes.NewReader(input)), opt) assert.Assert(t, receiver.Receive(), "expecting 1 CAN frames") assert.NilError(t, receiver.Err()) assert.Assert(t, !receiver.HasErrorFrame()) @@ -92,7 +92,7 @@ func TestReceiver_ReceiveFrames(t *testing.T) { } { tt := tt t.Run(tt.msg, func(t *testing.T) { - receiver := NewReceiver(ioutil.NopCloser(bytes.NewReader(tt.input))) + receiver := NewReceiver(io.NopCloser(bytes.NewReader(tt.input))) for i, expected := range tt.expectedFrames { assert.Assert(t, receiver.Receive(), "expecting %d CAN frames", i+1) assert.NilError(t, receiver.Err()) @@ -117,7 +117,7 @@ func TestReceiver_ReceiveErrorFrame(t *testing.T) { // id---------------> | dlc | padding-------> | data----------------------------------------> | 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x12, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, } - receiver := NewReceiver(ioutil.NopCloser(bytes.NewReader(input))) + receiver := NewReceiver(io.NopCloser(bytes.NewReader(input))) // expect frame assert.Assert(t, receiver.Receive()) assert.Assert(t, !receiver.HasErrorFrame()) diff --git a/pkg/socketcan/tools.go b/pkg/socketcan/tools.go deleted file mode 100644 index 79e0973..0000000 --- a/pkg/socketcan/tools.go +++ /dev/null @@ -1,5 +0,0 @@ -// +build tools - -package socketcan - -import _ "github.com/golang/mock/mockgen" diff --git a/tools.go b/tools.go index 3c324cb..9565ace 100644 --- a/tools.go +++ b/tools.go @@ -1,4 +1,4 @@ -// +build tools +//go:build tools package tools diff --git a/tools/commitlint/.commitlintrc.js b/tools/commitlint/.commitlintrc.js deleted file mode 100644 index 92e3aec..0000000 --- a/tools/commitlint/.commitlintrc.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - extends: ['@commitlint/config-conventional'], - rules: { - // Treat as warning until Dependabot supports commitlint. - // https://github.com/dependabot/dependabot-core/issues/2445 - "body-max-line-length": [1, "always", 100], - } -}; diff --git a/tools/commitlint/package.json b/tools/commitlint/package.json deleted file mode 100644 index 2f66822..0000000 --- a/tools/commitlint/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "devDependencies": { - "@commitlint/cli": "^11.0.0", - "@commitlint/config-conventional": "^11.0.0" - } -} diff --git a/tools/commitlint/rules.mk b/tools/commitlint/rules.mk deleted file mode 100644 index 0d3eb3b..0000000 --- a/tools/commitlint/rules.mk +++ /dev/null @@ -1,16 +0,0 @@ -commitlint_cwd := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) -commitlint := $(commitlint_cwd)/node_modules/.bin/commitlint - -$(commitlint): $(commitlint_cwd)/package.json - $(info [commitlint] installing package...) - @cd $(commitlint_cwd) && npm install --no-save --no-audit &> /dev/null - @touch $@ - -.PHONY: commitlint -commitlint: $(commitlint_cwd)/.commitlintrc.js $(commitlint) - $(info [$@] linting commit messages...) - @git fetch --tags - @NODE_PATH=$(commitlint_cwd)/node_modules $(commitlint) \ - --config $< \ - --from origin/master \ - --to HEAD diff --git a/tools/git-verify-nodiff/git-verify-nodiff.bash b/tools/git-verify-nodiff/git-verify-nodiff.bash deleted file mode 100755 index 0dd1f0c..0000000 --- a/tools/git-verify-nodiff/git-verify-nodiff.bash +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -set -euo pipefail - -if [[ -n $(git status --porcelain) ]]; then - echo "Staging area is dirty, please add all files created by the build to .gitignore" - git diff --patch - exit 1 -fi diff --git a/tools/git-verify-nodiff/rules.mk b/tools/git-verify-nodiff/rules.mk deleted file mode 100644 index 9e3cf98..0000000 --- a/tools/git-verify-nodiff/rules.mk +++ /dev/null @@ -1,7 +0,0 @@ -git_verify_nodiff_cwd := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) -git_verify_nodiff := $(git_verify_nodiff_cwd)/git-verify-nodiff.bash - -.PHONY: git-verify-nodiff -git-verify-nodiff: - @echo verifying that git has no diff... - @$(git_verify_nodiff) diff --git a/tools/golangci-lint/rules.mk b/tools/golangci-lint/rules.mk deleted file mode 100644 index dd539a3..0000000 --- a/tools/golangci-lint/rules.mk +++ /dev/null @@ -1,24 +0,0 @@ -golangci_lint_cwd := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) -golangci_lint_version := 1.37.0 -golangci_lint := $(golangci_lint_cwd)/$(golangci_lint_version)/golangci-lint - -ifeq ($(shell uname),Linux) -golangci_lint_archive_url := https://github.com/golangci/golangci-lint/releases/download/v${golangci_lint_version}/golangci-lint-${golangci_lint_version}-linux-amd64.tar.gz -else ifeq ($(shell uname),Darwin) -golangci_lint_archive_url := https://github.com/golangci/golangci-lint/releases/download/v${golangci_lint_version}/golangci-lint-${golangci_lint_version}-darwin-amd64.tar.gz -else -$(error unsupported OS: $(shell uname)) -endif - -$(golangci_lint): - $(info building golangci-lint...) - @mkdir -p $(dir $@) - @curl -sSL $(golangci_lint_archive_url) -o - | \ - tar -xz --directory $(dir $@) --strip-components 1 - @chmod +x $@ - @touch $@ - -.PHONY: go-lint -go-lint: $(golangci_lint) - $(info linting Go code with golangci-lint...) - @$(golangci_lint) run diff --git a/tools/goreview/rules.mk b/tools/goreview/rules.mk deleted file mode 100644 index 426850e..0000000 --- a/tools/goreview/rules.mk +++ /dev/null @@ -1,18 +0,0 @@ -goreview_cwd := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) -goreview_version := 0.15.0 -goreview := $(goreview_cwd)/$(goreview_version)/goreview - -goreview_archive_url := https://github.com/einride/goreview/releases/download/v$(goreview_version)/goreview_$(goreview_version)_$(shell uname)_$(shell uname -m).tar.gz - -$(goreview): $(goreview_cwd)/rules.mk - $(info [goreview] fetching $(goreview_version) binary...) - @mkdir -p $(dir $@) - @curl -sSL $(goreview_archive_url) -o - | tar -xz --directory $(dir $@) - @chmod +x $@ - @touch $@ - -# go-review: review Go code for Einride-specific conventions -.PHONY: go-review -go-review: $(goreview) - $(info [$@] reviewing Go code for Einride-specific conventions...) - @$(goreview) -c 1 ./... diff --git a/tools/semantic-release/.releaserc.yaml b/tools/semantic-release/.releaserc.yaml deleted file mode 100644 index 1a68877..0000000 --- a/tools/semantic-release/.releaserc.yaml +++ /dev/null @@ -1,19 +0,0 @@ -plugins: - - - "@semantic-release/commit-analyzer" - - preset: "conventionalcommits" - releaseRules: - # Given Go v2+ conventions we disable major releases on - # breaking changes and leave it up to the developer - # to make major releases - - breaking: true - release: "minor" - - "@semantic-release/release-notes-generator" - - "@semantic-release/github" - -branches: ["master"] -# github plugin is the only one running this step and we're not interested -# in its updates to PR and issues -success: false -# github plugin is the only one running this step and we're not interested -# the issues it creates due to failed releases -fail: false diff --git a/tools/semantic-release/package.json b/tools/semantic-release/package.json deleted file mode 100644 index 3069fdc..0000000 --- a/tools/semantic-release/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "devDependencies": { - "semantic-release": "^17.3.0", - "@semantic-release/github": "^7.2.0", - "@semantic-release/release-notes-generator": "^9.0.1", - "conventional-changelog-conventionalcommits": "^4.5.0" - } -} diff --git a/tools/semantic-release/rules.mk b/tools/semantic-release/rules.mk deleted file mode 100644 index 2992c1a..0000000 --- a/tools/semantic-release/rules.mk +++ /dev/null @@ -1,12 +0,0 @@ -semantic_release_cwd := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) -semantic_release := $(semantic_release_cwd)/node_modules/.bin/semantic-release - -$(semantic_release): $(semantic_release_cwd)/package.json - $(info [semantic-release] installing packages...) - @cd $(semantic_release_cwd) && npm install --no-save --no-audit --ignore-scripts &> /dev/null - @touch $@ - -.PHONY: semantic-release -semantic-release: $(semantic_release_cwd)/.releaserc.yaml $(semantic_release) - $(info [$@] creating release...) - @cd $(semantic_release_cwd) && $(semantic_release) diff --git a/tools/stringer/go.mod b/tools/stringer/go.mod deleted file mode 100644 index ecf3e25..0000000 --- a/tools/stringer/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module tools/stringer - -go 1.13 - -require golang.org/x/tools v0.0.0-20200609164405-eb789aa7ce50 diff --git a/tools/stringer/go.sum b/tools/stringer/go.sum deleted file mode 100644 index 070ed99..0000000 --- a/tools/stringer/go.sum +++ /dev/null @@ -1,20 +0,0 @@ -github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/mod v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ= -golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20200609164405-eb789aa7ce50 h1:59syOWj4+Fl+op4LL8fX1kO7HmbdEWfxlw4tcGvH+y0= -golang.org/x/tools v0.0.0-20200609164405-eb789aa7ce50/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/tools/stringer/rules.mk b/tools/stringer/rules.mk deleted file mode 100644 index 8a75030..0000000 --- a/tools/stringer/rules.mk +++ /dev/null @@ -1,8 +0,0 @@ -stringer_cwd := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) -stringer := $(stringer_cwd)/bin/stringer -PATH := $(PATH):$(dir $(stringer)) - -$(stringer): $(stringer_cwd)/go.mod - @echo building stringer... - @cd $(stringer_cwd) && go build -o $@ golang.org/x/tools/cmd/stringer - @cd $(stringer_cwd) && go mod tidy diff --git a/tools/stringer/tool.go b/tools/stringer/tool.go deleted file mode 100644 index f836ab8..0000000 --- a/tools/stringer/tool.go +++ /dev/null @@ -1,5 +0,0 @@ -//+build tool - -package tool - -import _ "golang.org/x/tools/cmd/stringer"