Skip to content

Commit 8d59289

Browse files
ucwongfjl
authored andcommitted
build: add imports for go generate tools (ethereum#24682)
This adds a tools.go file to import all command packages used for go:generate. Doing so makes it possible to execute go-based code generators using 'go run', locking in the tool version using go.mod. Co-authored-by: Felix Lange <[email protected]>
1 parent ebcc775 commit 8d59289

File tree

24 files changed

+77
-30
lines changed

24 files changed

+77
-30
lines changed

build/ci.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,11 +1133,7 @@ func doXCodeFramework(cmdline []string) {
11331133
tc := new(build.GoToolchain)
11341134

11351135
// Build gomobile.
1136-
build.MustRun(tc.Install(GOBIN, "golang.org/x/mobile/cmd/gomobile@latest", "golang.org/x/mobile/cmd/gobind@latest"))
1137-
1138-
// Ensure all dependencies are available. This is required to make
1139-
// gomobile bind work because it expects go.sum to contain all checksums.
1140-
build.MustRun(tc.Go("mod", "download"))
1136+
build.MustRun(tc.Install(GOBIN, "golang.org/x/mobile/cmd/gomobile", "golang.org/x/mobile/cmd/gobind"))
11411137

11421138
// Build the iOS XCode framework
11431139
bind := gomobileTool("bind", "-ldflags", "-s -w", "--target", "ios", "-v", "github.com/ethereum/go-ethereum/mobile")

build/tools/tools.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2019 The go-ethereum Authors
2+
// This file is part of the go-ethereum library.
3+
//
4+
// The go-ethereum library is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Lesser General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// The go-ethereum library is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Lesser General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Lesser General Public License
15+
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
16+
17+
//go:build tools
18+
// +build tools
19+
20+
package tools
21+
22+
import (
23+
// Tool imports for go:generate.
24+
_ "github.com/fjl/gencodec"
25+
_ "github.com/golang/protobuf/protoc-gen-go"
26+
_ "github.com/kevinburke/go-bindata/go-bindata"
27+
_ "golang.org/x/tools/cmd/stringer"
28+
29+
// Tool imports for mobile build.
30+
_ "golang.org/x/mobile/cmd/gobind"
31+
_ "golang.org/x/mobile/cmd/gomobile"
32+
)

cmd/evm/internal/t8ntool/block.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636
"gopkg.in/urfave/cli.v1"
3737
)
3838

39-
//go:generate gencodec -type header -field-override headerMarshaling -out gen_header.go
39+
//go:generate go run github.com/fjl/gencodec -type header -field-override headerMarshaling -out gen_header.go
4040
type header struct {
4141
ParentHash common.Hash `json:"parentHash"`
4242
OmmerHash *common.Hash `json:"sha3Uncles"`

cmd/evm/internal/t8ntool/execution.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ type ommer struct {
6363
Address common.Address `json:"address"`
6464
}
6565

66-
//go:generate gencodec -type stEnv -field-override stEnvMarshaling -out gen_stenv.go
66+
//go:generate go run github.com/fjl/gencodec -type stEnv -field-override stEnvMarshaling -out gen_stenv.go
6767
type stEnv struct {
6868
Coinbase common.Address `json:"currentCoinbase" gencodec:"required"`
6969
Difficulty *big.Int `json:"currentDifficulty"`

cmd/faucet/faucet.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// faucet is an Ether faucet backed by a light client.
1818
package main
1919

20-
//go:generate go-bindata -nometadata -o website.go faucet.html
20+
//go:generate go run github.com/kevinburke/go-bindata/go-bindata -nometadata -o website.go faucet.html
2121
//go:generate gofmt -w -s website.go
2222

2323
import (

cmd/faucet/website.go

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contracts/checkpointoracle/oracle.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// Package checkpointoracle is a an on-chain light client checkpoint oracle.
1818
package checkpointoracle
1919

20-
//go:generate abigen --sol contract/oracle.sol --pkg contract --out contract/oracle.go
20+
//go:generate go run ../../cmd/abigen --sol contract/oracle.sol --pkg contract --out contract/oracle.go
2121

2222
import (
2323
"errors"

core/genesis.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ import (
3939
"github.com/ethereum/go-ethereum/trie"
4040
)
4141

42-
//go:generate gencodec -type Genesis -field-override genesisSpecMarshaling -out gen_genesis.go
43-
//go:generate gencodec -type GenesisAccount -field-override genesisAccountMarshaling -out gen_genesis_account.go
42+
//go:generate go run github.com/fjl/gencodec -type Genesis -field-override genesisSpecMarshaling -out gen_genesis.go
43+
//go:generate go run github.com/fjl/gencodec -type GenesisAccount -field-override genesisAccountMarshaling -out gen_genesis_account.go
4444

4545
var errGenesisNoConfig = errors.New("genesis has no chain configuration")
4646

core/types/access_list_tx.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"github.com/ethereum/go-ethereum/common"
2323
)
2424

25-
//go:generate go run github.com/fjl/gencodec@latest -type AccessTuple -out gen_access_tuple.go
25+
//go:generate go run github.com/fjl/gencodec -type AccessTuple -out gen_access_tuple.go
2626

2727
// AccessList is an EIP-2930 access list.
2828
type AccessList []AccessTuple

core/types/block.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (n *BlockNonce) UnmarshalText(input []byte) error {
6363
return hexutil.UnmarshalFixedText("BlockNonce", input, n[:])
6464
}
6565

66-
//go:generate go run github.com/fjl/gencodec@latest -type Header -field-override headerMarshaling -out gen_header_json.go
66+
//go:generate go run github.com/fjl/gencodec -type Header -field-override headerMarshaling -out gen_header_json.go
6767
//go:generate go run ../../rlp/rlpgen -type Header -out gen_header_rlp.go
6868

6969
// Header represents a block header in the Ethereum blockchain.

0 commit comments

Comments
 (0)