Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

go-modularize packages (part I) #1622

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions btcec/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module github.com/btcsuite/btcd/btcec

go 1.14

require (
github.com/btcsuite/btcd/chaincfg/chainhash v0.1.0
github.com/davecgh/go-spew v1.1.1
)

replace github.com/btcsuite/btcd/chaincfg/chainhash => ../chaincfg/chainhash
2 changes: 2 additions & 0 deletions btcec/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
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=
3 changes: 3 additions & 0 deletions chaincfg/chainhash/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/btcsuite/btcd/chaincfg/chainhash

go 1.14
14 changes: 14 additions & 0 deletions chaincfg/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module github.com/btcsuite/btcd/chaincfg

go 1.14

require (
github.com/btcsuite/btcd/chaincfg/chainhash v0.1.0
github.com/btcsuite/btcd/wire v0.1.0
github.com/davecgh/go-spew v1.1.1
)

replace (
github.com/btcsuite/btcd/chaincfg/chainhash => ./chainhash
github.com/btcsuite/btcd/wire => ../wire
)
2 changes: 2 additions & 0 deletions chaincfg/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
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=
11 changes: 11 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module github.com/btcsuite/btcd

require (
github.com/btcsuite/btcd/btcec v0.1.0
github.com/btcsuite/btcd/chaincfg v0.1.0
github.com/btcsuite/btcd/chaincfg/chainhash v0.1.0
github.com/btcsuite/btcd/wire v0.1.0
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
github.com/btcsuite/btcutil v1.0.2
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd
Expand All @@ -14,4 +18,11 @@ require (
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37
)

replace (
github.com/btcsuite/btcd/btcec => ./btcec
github.com/btcsuite/btcd/chaincfg => ./chaincfg
github.com/btcsuite/btcd/chaincfg/chainhash => ./chaincfg/chainhash
github.com/btcsuite/btcd/wire => ./wire
)

go 1.14
50 changes: 42 additions & 8 deletions goclean.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,53 @@
#!/bin/bash
# The script does automatic checking on a Go package and its sub-packages, including:
# 1. gofmt (http://golang.org/cmd/gofmt/)
# 2. goimports (https://godoc.org/golang.org/x/tools/cmd/goimports)
# 3. go vet (http://golang.org/cmd/vet)
# 4. gosimple (https://github.com/dominikh/go-simple)
# 5. unconvert (https://github.com/mdempsky/unconvert)
# 6. race detector (http://blog.golang.org/race-detector)
# 7. test coverage (http://blog.golang.org/cover)

set -ex
# Automatic checks
for i in $(find . -name go.mod -type f -print); do
module=$(dirname ${i})
echo "==> ${module}"

env GORACE="halt_on_error=1" go test -race -tags="rpctest" -covermode atomic -coverprofile=profile.cov ./...
MODNAME=$(echo $module | sed -E -e "s/^$ROOTPATHPATTERN//" \
-e 's,^/,,' -e 's,/v[0-9]+$,,')
if [ -z "$MODNAME" ]; then
MODNAME=.
fi

# Automatic checks
golangci-lint run --deadline=10m --disable-all \
--enable=gofmt \
--enable=vet \
--enable=gosimple \
--enable=unconvert
# run tests
(cd $MODNAME && env GORACE=halt_on_error=1 go test -tags="rpctest" -race ./...) || exit 1

# check linters
(cd $MODNAME && \
go mod download && \
golangci-lint run --deadline=10m --disable-all \
--enable=gofmt \
--enable=goimports \
--enable=govet \
--enable=gosimple \
--enable=unconvert
)
done

# Run test coverage on each subdirectories and merge the coverage profile.

echo "mode: count" > profile.cov

# Standard go tooling behavior is to ignore dirs with leading underscores.
for dir in $(find . -maxdepth 10 -not -path './.git*' -not -path '*/_*' -type d);
do
if ls $dir/*.go &> /dev/null; then
go test -covermode=count -coverprofile=$dir/profile.tmp $dir
if [ -f $dir/profile.tmp ]; then
cat $dir/profile.tmp | tail -n +2 >> profile.cov
rm $dir/profile.tmp
fi
fi
done

go tool cover -func profile.cov
10 changes: 10 additions & 0 deletions wire/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module github.com/btcsuite/btcd/wire

go 1.14

require (
github.com/btcsuite/btcd/chaincfg/chainhash v0.1.0
github.com/davecgh/go-spew v1.1.1
)

replace github.com/btcsuite/btcd/chaincfg/chainhash => ../chaincfg/chainhash
2 changes: 2 additions & 0 deletions wire/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
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=