Skip to content

Commit a54908f

Browse files
alarso16maru-ava
andauthored
chore: Use go 1.24's 'go tool' support for CLI tooling (#1843)
Co-authored-by: maru <maru.newby@avalabs.org>
1 parent 49fa955 commit a54908f

File tree

20 files changed

+2601
-56
lines changed

20 files changed

+2601
-56
lines changed

.github/CONTRIBUTING.md

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,22 @@ Mocks are auto-generated using [mockgen](https://pkg.go.dev/go.uber.org/mock/moc
3434
- To **re-generate all mocks**, use the command below from the root of the project:
3535

3636
```sh
37-
go generate -run "go.uber.org/mock/mockgen" ./...
37+
go generate -run mockgen ./...
3838
```
3939

40-
- To **add** an interface that needs a corresponding mock generated:
41-
- if the file `mocks_generate_test.go` exists in the package where the interface is located, either:
42-
- modify its `//go:generate go run go.uber.org/mock/mockgen` to generate a mock for your interface (preferred); or
43-
- add another `//go:generate go run go.uber.org/mock/mockgen` to generate a mock for your interface according to specific mock generation settings
44-
- if the file `mocks_generate_test.go` does not exist in the package where the interface is located, create it with content (adapt as needed):
40+
* To **add** an interface that needs a corresponding mock generated:
41+
* if the file `mocks_generate_test.go` exists in the package where the interface is located, either:
42+
* modify its `//go:generate go tool -modfile=tools/go.mod mockgen` to generate a mock for your interface (preferred); or
43+
* add another `//go:generate go tool -modfile=tools/go.mod mockgen` to generate a mock for your interface according to specific mock generation settings
44+
* if the file `mocks_generate_test.go` does not exist in the package where the interface is located, create it with content (adapt as needed):
4545

4646
```go
4747
// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved.
4848
// See the file LICENSE for licensing terms.
4949
5050
package mypackage
5151
52-
//go:generate go run go.uber.org/mock/mockgen -package=${GOPACKAGE} -destination=mocks_test.go . YourInterface
52+
//go:generate go tool -modfile=tools/go.mod mockgen -package=${GOPACKAGE} -destination=mocks_test.go . YourInterface
5353
```
5454

5555
Notes:
@@ -58,22 +58,28 @@ Mocks are auto-generated using [mockgen](https://pkg.go.dev/go.uber.org/mock/moc
5858
- To **remove** an interface from having a corresponding mock generated:
5959
1. Edit the `mocks_generate_test.go` file in the directory where the interface is defined
6060
1. If the `//go:generate` mockgen command line:
61-
- generates a mock file for multiple interfaces, remove your interface from the line
62-
- generates a mock file only for the interface, remove the entire line. If the file is empty, remove `mocks_generate_test.go` as well.
61+
* generates a mock file for multiple interfaces, remove your interface from the line
62+
* generates a mock file only for the interface, remove the entire line. If the file is empty, remove `mocks_generate_test.go` as well.
6363

64-
## Documentation guidelines
64+
## Tool Dependencies
6565

66-
- Code should be well commented, so it is easier to read and maintain.
67-
Any complex sections or invariants should be documented explicitly.
68-
- Code must be documented adhering to the official Go
69-
[commentary](https://go.dev/doc/effective_go#commentary) guidelines.
70-
- Changes with user facing impact (e.g., addition or modification of flags and
71-
options) should be accompanied by a link to a pull request to the [avalanche-docs](https://github.com/ava-labs/avalanche-docs)
72-
repository. [example](https://github.com/ava-labs/avalanche-docs/pull/1119/files).
73-
- Changes that modify a package significantly or add new features should
74-
either update the existing or include a new `README.md` file in that package.
66+
This project uses `go tool` to manage development tool dependencies in `tools/go.mod`. This isolates tool dependencies from the main application dependencies and provides consistent, version-locked tools across the team.
7567

76-
## Can I have feature X
68+
### Managing Tools
7769

78-
Before you submit a feature request, please check and make sure that it isn't
79-
possible through some other means.
70+
* To **add a new tool**:
71+
```sh
72+
go get -tool -modfile=tools/go.mod example.com/tool/cmd/toolname@version
73+
```
74+
75+
* To **upgrade a tool**:
76+
```sh
77+
go get -tool -modfile=tools/go.mod example.com/tool/cmd/toolname@newversion
78+
```
79+
80+
* To **run a tool manually**:
81+
```sh
82+
go tool -modfile=tools/go.mod toolname [args...]
83+
```
84+
85+
Note: `ginkgo` remains in the main `go.mod` as it is used directly in e2e test code.

.github/workflows/ci.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ jobs:
1919
- uses: actions/setup-go@v5
2020
with:
2121
go-version-file: "go.mod"
22+
cache-dependency-path: |
23+
go.sum
24+
tools/go.sum
25+
tools/legacy-golangci-lint.sum
2226
- name: Run all lint checks
2327
run: ./scripts/run_task.sh lint-all-ci
2428
- name: Check go.mod and go.sum are up-to-date
@@ -40,6 +44,9 @@ jobs:
4044
- uses: actions/setup-go@v5
4145
with:
4246
go-version-file: "go.mod"
47+
cache-dependency-path: |
48+
go.sum
49+
tools/go.sum
4350
- run: go mod download
4451
- name: Check generated codec files are up to date
4552
run: ./scripts/run_task.sh check-generate-codec
@@ -60,10 +67,6 @@ jobs:
6067
with:
6168
fetch-depth: 0
6269
submodules: recursive
63-
- name: Set up Go
64-
uses: actions/setup-go@v5
65-
with:
66-
go-version-file: "go.mod"
6770
- name: Set up solc
6871
uses: ARR4N/setup-solc@v0.2.0
6972
with:

Taskfile.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,14 @@ tasks:
6767
- task: check-clean-branch
6868

6969
check-go-mod-tidy:
70-
desc: Checks that go.mod and go.sum are up-to-date (requires a clean git working tree)
70+
desc: Checks that all go.mod and go.sum files are up-to-date (requires a clean git working tree)
7171
cmds:
7272
- cmd: go mod tidy
7373
- task: check-clean-branch
74+
- cmd: cd tools && go mod tidy
75+
- task: check-clean-branch
76+
- cmd: cd tools && go mod tidy -modfile=legacy-golangci-lint.mod
77+
- task: check-clean-branch
7478

7579
coverage:
7680
desc: Display test coverage statistics from coverage.out file
@@ -80,19 +84,19 @@ tasks:
8084
desc: Generates fjl/gencodec files
8185
cmds:
8286
- cmd: grep -lr -E '^// Code generated by github\.com\/fjl\/gencodec\. DO NOT EDIT\.$' . | xargs -r rm
83-
- cmd: go generate -run "github.com/fjl/gencodec" ./...
87+
- cmd: go generate -run gencodec ./...
8488

8589
generate-mocks:
8690
desc: Generates testing mocks
8791
cmds:
8892
- cmd: grep -lr -E '^// Code generated by MockGen\. DO NOT EDIT\.$' . | xargs -r rm
89-
- cmd: go generate -run "go.uber.org/mock/mockgen" ./...
90-
93+
- cmd: go generate -run mockgen ./...
94+
9195
generate-rlp:
9296
desc: Generates rlp files
9397
cmds:
9498
- cmd: grep -lr -E '^// Code generated by rlpgen\. DO NOT EDIT.\.$' . | xargs -r rm
95-
- cmd: go generate -run "github.com/ava-labs/libevm/rlp/rlpgen" ./...
99+
- cmd: go generate -run rlpgen ./...
96100

97101
install-avalanchego-release:
98102
desc: Download and install AvalancheGo release binary for testing, with fallback to building from source

bin/ginkgo

Lines changed: 0 additions & 10 deletions
This file was deleted.

bin/ginkgo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../scripts/run_ginkgo.sh

core/genesis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ import (
5757
"github.com/holiman/uint256"
5858
)
5959

60-
//go:generate go run github.com/fjl/gencodec -type Genesis -field-override genesisSpecMarshaling -out gen_genesis.go
60+
//go:generate go tool -modfile=../tools/go.mod gencodec -type Genesis -field-override genesisSpecMarshaling -out gen_genesis.go
6161

6262
var errGenesisNoConfig = errors.New("genesis has no chain configuration")
6363

eth/ethconfig/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func NewDefaultConfig() Config {
7474
}
7575
}
7676

77-
//go:generate go run github.com/fjl/gencodec -type Config -formats toml -out gen_config.go
77+
//go:generate go tool -modfile=../../tools/go.mod gencodec -type Config -formats toml -out gen_config.go
7878

7979
// Config contains configuration options for ETH and LES protocols.
8080
type Config struct {

go.mod

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
module github.com/ava-labs/subnet-evm
22

3+
// CLI tools intended for invocation with `go tool` should be added to
4+
// tools/go.mod to avoid polluting the main module's dependencies. See
5+
// CONTRIBUTING.md for more details.
6+
7+
// - Changes to the minimum golang version must also be replicated in:
8+
// - go.mod (here)
9+
// - tools/go.mod
10+
// - tools/legacy-golangci-lint.mod
11+
//
12+
// - If updating between minor versions (e.g. 1.24.x -> 1.25.x):
13+
// - Consider updating the version of golangci-lint (see tools/go.mod)
314
go 1.24.9
415

516
require (
@@ -189,3 +200,10 @@ require (
189200
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
190201
sigs.k8s.io/yaml v1.3.0 // indirect
191202
)
203+
204+
// The following tools are managed here instead of in tools/go.mod
205+
// because they are already direct dependencies of the main module.
206+
tool (
207+
github.com/ava-labs/libevm/rlp/rlpgen
208+
github.com/onsi/ginkgo/v2/ginkgo
209+
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package ethapi
22

3-
//go:generate go run go.uber.org/mock/mockgen -package=$GOPACKAGE -destination=mocks_test.go . Backend
3+
//go:generate go tool -modfile=../../tools/go.mod mockgen -package=$GOPACKAGE -destination=mocks_test.go . Backend

plugin/evm/customtypes/header_ext.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ func (h *HeaderSerializable) updateToExtras(extras *HeaderExtra) {
178178
// NOTE: both generators currently do not support type aliases.
179179
// We are using custom versions of these programs for now to support type aliases,
180180
// see https://github.com/ava-labs/coreth/pull/746#discussion_r1969673252
181-
//go:generate go run github.com/fjl/gencodec -type HeaderSerializable -field-override headerMarshaling -out gen_header_serializable_json.go
182-
//go:generate go run github.com/ava-labs/libevm/rlp/rlpgen -type HeaderSerializable -out gen_header_serializable_rlp.go
181+
//go:generate go tool -modfile=../../../tools/go.mod gencodec -type HeaderSerializable -field-override headerMarshaling -out gen_header_serializable_json.go
182+
//go:generate go tool rlpgen -type HeaderSerializable -out gen_header_serializable_rlp.go
183183

184184
// HeaderSerializable defines the header of a block in the Ethereum blockchain,
185185
// as it is to be serialized into RLP and JSON. Note it must be exported so that

0 commit comments

Comments
 (0)