Skip to content

Commit

Permalink
chore(scripts): simplify mock.gen.sh to use go generate commands
Browse files Browse the repository at this point in the history
- Add missing license headers
- Localized mockgen commands in the package where they are needed
- Less shell scripting needed
- Remove unneeded `source` commands for constants.sh and versions.sh
  • Loading branch information
qdm12 committed Dec 27, 2024
1 parent b465ad5 commit d6746f8
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 37 deletions.
25 changes: 25 additions & 0 deletions license_header
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
(c) 2024, Ava Labs, Inc.

This file is a derived work, based on the go-ethereum library whose original
notices appear below.

It is distributed under a license compatible with the licensing terms of the
original code from which it is derived.

Much love to the original authors for their work.
**********
Copyright 2014 The go-ethereum Authors
This file is part of the go-ethereum library.

The go-ethereum library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

The go-ethereum library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
28 changes: 27 additions & 1 deletion plugin/evm/validators/state/interfaces/mock_listener.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions plugin/evm/validators/state/interfaces/mocks_generate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package interfaces

//go:generate mockgen -package=$GOPACKAGE -copyright_file=../../../../../license_header -destination=mock_listener.go . StateCallbackListener
28 changes: 27 additions & 1 deletion precompile/contract/mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions precompile/contract/mocks_generate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package contract

//go:generate mockgen -package=$GOPACKAGE -copyright_file=../../license_header -destination=mocks.go . BlockContext,AccessibleState,StateDB
28 changes: 27 additions & 1 deletion precompile/precompileconfig/mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions precompile/precompileconfig/mocks_generate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package precompileconfig

//go:generate mockgen -package=$GOPACKAGE -copyright_file=../../license_header -destination=mocks.go . Predicater,Config,ChainConfig,Accepter
35 changes: 1 addition & 34 deletions scripts/mock.gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,7 @@

set -euo pipefail

# Root directory
SUBNET_EVM_PATH=$(
cd "$(dirname "${BASH_SOURCE[0]}")"
cd .. && pwd
)

if ! [[ "$0" =~ scripts/mock.gen.sh ]]; then
echo "must be run from repository root"
exit 255
fi

# https://github.com/uber-go/mock
go install -v go.uber.org/mock/mockgen@v0.4.0

if ! command -v go-license &>/dev/null; then
echo "go-license not found, installing..."
# https://github.com/palantir/go-license
go install -v github.com/palantir/go-license@v1.25.0
fi

# Load the constants
source "$SUBNET_EVM_PATH"/scripts/constants.sh

# tuples of (source interface import path, comma-separated interface names, output file path)
input="scripts/mocks.mockgen.txt"
while IFS= read -r line; do
IFS='=' read -r src_import_path interface_name output_path <<<"${line}"
package_name=$(basename "$(dirname "$output_path")")
echo "Generating ${output_path}..."
mockgen -package="${package_name}" -destination="${output_path}" "${src_import_path}" "${interface_name}"

go-license \
--config=./header.yml \
"${output_path}"
done <"$input"

echo "SUCCESS"
go generate -run "mockgen.+license_header" ./...

0 comments on commit d6746f8

Please sign in to comment.