From 7636622c1979e7f822f3c60dd691e9a7ac0535b7 Mon Sep 17 00:00:00 2001 From: Anirudha Bose Date: Mon, 31 Aug 2020 21:31:36 +0200 Subject: [PATCH 1/2] btcec, chaincfg, chaincfg/chainhash, wire: init go mod This initializes Go11 modules in the following packages: * btcec * chaincfg * chaincfg/chainhash * wire The primary motivation behind this step is to be able to introduce breaking changes to packages without doing a MAJOR semver bump to btcd. --- btcec/go.mod | 10 ++++++++++ btcec/go.sum | 2 ++ chaincfg/chainhash/go.mod | 3 +++ chaincfg/go.mod | 14 ++++++++++++++ chaincfg/go.sum | 2 ++ go.mod | 11 +++++++++++ wire/go.mod | 10 ++++++++++ wire/go.sum | 2 ++ 8 files changed, 54 insertions(+) create mode 100644 btcec/go.mod create mode 100644 btcec/go.sum create mode 100644 chaincfg/chainhash/go.mod create mode 100644 chaincfg/go.mod create mode 100644 chaincfg/go.sum create mode 100644 wire/go.mod create mode 100644 wire/go.sum diff --git a/btcec/go.mod b/btcec/go.mod new file mode 100644 index 0000000000..e6ab078327 --- /dev/null +++ b/btcec/go.mod @@ -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 diff --git a/btcec/go.sum b/btcec/go.sum new file mode 100644 index 0000000000..b5e2922e89 --- /dev/null +++ b/btcec/go.sum @@ -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= diff --git a/chaincfg/chainhash/go.mod b/chaincfg/chainhash/go.mod new file mode 100644 index 0000000000..662ecab165 --- /dev/null +++ b/chaincfg/chainhash/go.mod @@ -0,0 +1,3 @@ +module github.com/btcsuite/btcd/chaincfg/chainhash + +go 1.14 diff --git a/chaincfg/go.mod b/chaincfg/go.mod new file mode 100644 index 0000000000..2856252a85 --- /dev/null +++ b/chaincfg/go.mod @@ -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 +) diff --git a/chaincfg/go.sum b/chaincfg/go.sum new file mode 100644 index 0000000000..b5e2922e89 --- /dev/null +++ b/chaincfg/go.sum @@ -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= diff --git a/go.mod b/go.mod index c53b23d222..8366b02ff0 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/wire/go.mod b/wire/go.mod new file mode 100644 index 0000000000..01442eb65c --- /dev/null +++ b/wire/go.mod @@ -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 diff --git a/wire/go.sum b/wire/go.sum new file mode 100644 index 0000000000..b5e2922e89 --- /dev/null +++ b/wire/go.sum @@ -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= From 740a56acae3fe0cd3a387c1a20eb807893868f2e Mon Sep 17 00:00:00 2001 From: Anirudha Bose Date: Mon, 31 Aug 2020 22:01:33 +0200 Subject: [PATCH 2/2] build: adapt goclean.sh to work with module packages --- goclean.sh | 50 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/goclean.sh b/goclean.sh index dad9f8f1dc..86b37fd3bf 100755 --- a/goclean.sh +++ b/goclean.sh @@ -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