From 0755123ca319a64a0993519eb9baae41f3ef8f07 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Thu, 24 Jan 2019 19:54:46 -0800 Subject: [PATCH 01/16] s/gofmt/goimports/ goimports is a superset of gofmt. It does everything gofmt does, and also organizes package imports. --- CONTRIBUTING.md | 4 ++-- scripts/travis_checker.sh | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d01944135..1b5abab6b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -3,7 +3,7 @@ ## Coding Guidelines * In general, we follow [effective_go](https://golang.org/doc/effective_go.html) -* Code must adhere to the official [Go formatting guidelines](https://golang.org/doc/effective_go.html#formatting) (i.e. uses [gofmt](https://golang.org/cmd/gofmt/)). +* Code must adhere to the official [Go formatting guidelines](https://golang.org/doc/effective_go.html#formatting) (i.e. uses [goimports](https://godoc.org/golang.org/x/tools/cmd/goimports)). * Code must be documented adhering to the official Go [commentary](https://golang.org/doc/effective_go.html#commentary) guidelines. ## Pull Request (PR) @@ -13,7 +13,7 @@ This [github document](https://help.github.com/articles/creating-a-pull-request/ ## PR requirement To pursue engineering excellence, we have insisted on the highest stardard on the quality of each PR. -* For each PR, please run [golint](https://github.com/golang/lint), [gofmt](https://golang.org/cmd/gofmt/), to fix the basic issues/warnings. +* For each PR, please run [golint](https://github.com/golang/lint), [goimports](https://godoc.org/golang.org/x/tools/cmd/goimports), to fix the basic issues/warnings. * Make sure you understand [How to Write a Git Commit Message](https://chris.beams.io/posts/git-commit/). * Add a [Test] section in every PR detailing on your test process and results. If the test log is too long, please include a link to [gist](https://gist.github.com/) and add the link to the PR. diff --git a/scripts/travis_checker.sh b/scripts/travis_checker.sh index 13d546fe5..33b84c8e8 100755 --- a/scripts/travis_checker.sh +++ b/scripts/travis_checker.sh @@ -12,7 +12,7 @@ print_file() { echo "--- END ${2} ---" } -unset -v ok tmpdir go_files go_dirs gofmt_output golint_output +unset -v ok tmpdir go_files go_dirs goimports_output golint_output ok=true tmpdir= trap 'case "${tmpdir}" in ?*) rm -rf "${tmpdir}";; esac' EXIT @@ -56,16 +56,16 @@ else ok=false fi -echo "Running gofmt..." -gofmt_output="${tmpdir}/gofmt_output.txt" -xargs gofmt -d -e < "${go_files}" > "${gofmt_output}" 2>&1 -if [ -s "${gofmt_output}" ] +echo "Running goimports..." +goimports_output="${tmpdir}/goimports_output.txt" +xargs goimports -d -e < "${go_files}" > "${goimports_output}" 2>&1 +if [ -s "${goimports_output}" ] then - echo "gofmt FAILED!" - print_file "${gofmt_output}" "gofmt" + echo "goimports FAILED!" + print_file "${goimports_output}" "goimports" ok=false else - echo "gofmt passed." + echo "goimports passed." fi if ! ${ok} From fb4792bc9fe861c692999f7e443f4d3c6650145d Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Thu, 24 Jan 2019 19:57:06 -0800 Subject: [PATCH 02/16] goimports --- cmd/client/wallet/wallet_test.go | 5 +++-- consensus/consensus_leader.go | 1 + consensus/consensus_leader_test.go | 5 +++-- consensus/consensus_validator_test.go | 5 +++-- crypto/pki/utils_test.go | 3 ++- node/node_handler_test.go | 3 ++- test/crypto/bls/main.go | 3 ++- 7 files changed, 16 insertions(+), 9 deletions(-) diff --git a/cmd/client/wallet/wallet_test.go b/cmd/client/wallet/wallet_test.go index 5258bcac3..3257caa72 100644 --- a/cmd/client/wallet/wallet_test.go +++ b/cmd/client/wallet/wallet_test.go @@ -1,14 +1,15 @@ package main import ( + "testing" + "time" + "github.com/golang/mock/gomock" "github.com/harmony-one/harmony/api/client" "github.com/harmony-one/harmony/core/types" "github.com/harmony-one/harmony/node" "github.com/harmony-one/harmony/p2p" mock_host "github.com/harmony-one/harmony/p2p/host/mock" - "testing" - "time" ) func TestCreateWalletNode(test *testing.T) { diff --git a/consensus/consensus_leader.go b/consensus/consensus_leader.go index a39ded736..11907da59 100644 --- a/consensus/consensus_leader.go +++ b/consensus/consensus_leader.go @@ -11,6 +11,7 @@ import ( "github.com/dedis/kyber/sign/schnorr" "github.com/ethereum/go-ethereum/rlp" protobuf "github.com/golang/protobuf/proto" + consensus_proto "github.com/harmony-one/harmony/api/consensus" "github.com/harmony-one/harmony/api/services/explorer" "github.com/harmony-one/harmony/core/types" diff --git a/consensus/consensus_leader_test.go b/consensus/consensus_leader_test.go index 76d2c4e6c..26ea49448 100644 --- a/consensus/consensus_leader_test.go +++ b/consensus/consensus_leader_test.go @@ -3,13 +3,14 @@ package consensus import ( "fmt" + "testing" + "time" + "github.com/golang/mock/gomock" "github.com/harmony-one/harmony/crypto" "github.com/harmony-one/harmony/internal/utils" mock_host "github.com/harmony-one/harmony/p2p/host/mock" "github.com/stretchr/testify/assert" - "testing" - "time" "github.com/harmony-one/harmony/p2p/p2pimpl" diff --git a/consensus/consensus_validator_test.go b/consensus/consensus_validator_test.go index 5dcbddcbd..a88597ce8 100644 --- a/consensus/consensus_validator_test.go +++ b/consensus/consensus_validator_test.go @@ -2,13 +2,14 @@ package consensus import ( "encoding/hex" + "testing" + "time" + "github.com/golang/mock/gomock" "github.com/harmony-one/harmony/core/types" "github.com/harmony-one/harmony/internal/utils" mock_host "github.com/harmony-one/harmony/p2p/host/mock" "github.com/stretchr/testify/assert" - "testing" - "time" "github.com/harmony-one/harmony/p2p/p2pimpl" diff --git a/crypto/pki/utils_test.go b/crypto/pki/utils_test.go index c155e2698..4b4586525 100644 --- a/crypto/pki/utils_test.go +++ b/crypto/pki/utils_test.go @@ -1,10 +1,11 @@ package pki import ( - "github.com/harmony-one/harmony/crypto" "reflect" "testing" "time" + + "github.com/harmony-one/harmony/crypto" ) func TestGetAddressFromPublicKey(test *testing.T) { diff --git a/node/node_handler_test.go b/node/node_handler_test.go index a5106d257..f24a0e6cb 100644 --- a/node/node_handler_test.go +++ b/node/node_handler_test.go @@ -1,12 +1,13 @@ package node import ( + "testing" + "github.com/golang/mock/gomock" "github.com/harmony-one/harmony/consensus" "github.com/harmony-one/harmony/internal/utils" "github.com/harmony-one/harmony/p2p" "github.com/harmony-one/harmony/p2p/p2pimpl" - "testing" ) func TestNodeStreamHandler(t *testing.T) { diff --git a/test/crypto/bls/main.go b/test/crypto/bls/main.go index bdd7181a2..1d5611acf 100644 --- a/test/crypto/bls/main.go +++ b/test/crypto/bls/main.go @@ -1,9 +1,10 @@ package main import ( - "github.com/harmony-one/bls/ffi/go/bls" "log" "time" + + "github.com/harmony-one/bls/ffi/go/bls" ) func main() { From 5c8b8ea9b3af5d7bdc10eadc20c20da0d282f0d7 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Thu, 24 Jan 2019 21:49:11 -0800 Subject: [PATCH 03/16] Exempt generated files from golint/goimports --- scripts/travis_checker.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/travis_checker.sh b/scripts/travis_checker.sh index 33b84c8e8..c920f978a 100755 --- a/scripts/travis_checker.sh +++ b/scripts/travis_checker.sh @@ -19,7 +19,12 @@ trap 'case "${tmpdir}" in ?*) rm -rf "${tmpdir}";; esac' EXIT tmpdir=$(mktemp -d) go_files="${tmpdir}/go_files.txt" -git ls-files '*.go' | grep -v '^vendor/' > "${go_files}" +git ls-files '*.go' | grep -v \ + -e '^vendor/' \ + -e '\.pb\.go$' \ + -e '/mock_stream\.go' \ + -e '/host_mock\.go' \ + -e '/gen_[^/]*\.go' > "${go_files}" # Print dirname of each relative pathname from stdin (one per line). dirnames() { From dddd104b4f677adb8ed04bbc3048405218782c73 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Thu, 24 Jan 2019 21:53:23 -0800 Subject: [PATCH 04/16] Install goimports in Travis-CI --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index b2105d342..fc7fbffdb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,7 @@ install: - cd ../harmony - go get -t -v ./... - go get -u golang.org/x/lint/golint + - go get -u golang.org/x/tools/cmd/goimports - go get gopkg.in/check.v1 - ./scripts/travis_checker.sh - go build -v ./... From 887fdbc1a5d9405f30dcd64002d7c8070172b4d1 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Thu, 24 Jan 2019 23:32:46 -0800 Subject: [PATCH 05/16] Avail script dir in progdir and add it to PATH --- scripts/travis_checker.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/travis_checker.sh b/scripts/travis_checker.sh index c920f978a..7188d42d6 100755 --- a/scripts/travis_checker.sh +++ b/scripts/travis_checker.sh @@ -12,8 +12,16 @@ print_file() { echo "--- END ${2} ---" } -unset -v ok tmpdir go_files go_dirs goimports_output golint_output +unset -v ok tmpdir go_files go_dirs goimports_output golint_output progdir ok=true + +case "${0}" in +*/*) progdir="${0%/*}";; +*) progdir=.;; +esac +PATH="${PATH+"${PATH}:"}${progdir}" +export PATH + tmpdir= trap 'case "${tmpdir}" in ?*) rm -rf "${tmpdir}";; esac' EXIT tmpdir=$(mktemp -d) From fd45de0fd1e9a3e4a3f86b9aa1f66e14558c4dc8 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Thu, 24 Jan 2019 23:31:02 -0800 Subject: [PATCH 06/16] Factor Go source file listing into a script --- scripts/list_harmony_go_files.sh | 7 +++++++ scripts/travis_checker.sh | 7 +------ 2 files changed, 8 insertions(+), 6 deletions(-) create mode 100755 scripts/list_harmony_go_files.sh diff --git a/scripts/list_harmony_go_files.sh b/scripts/list_harmony_go_files.sh new file mode 100755 index 000000000..0ef0695e5 --- /dev/null +++ b/scripts/list_harmony_go_files.sh @@ -0,0 +1,7 @@ +#!/bin/sh +exec git ls-files '*.go' | grep -v \ + -e '^vendor/' \ + -e '\.pb\.go$' \ + -e '/mock_stream\.go' \ + -e '/host_mock\.go' \ + -e '/gen_[^/]*\.go' diff --git a/scripts/travis_checker.sh b/scripts/travis_checker.sh index 7188d42d6..dbf48d8eb 100755 --- a/scripts/travis_checker.sh +++ b/scripts/travis_checker.sh @@ -27,12 +27,7 @@ trap 'case "${tmpdir}" in ?*) rm -rf "${tmpdir}";; esac' EXIT tmpdir=$(mktemp -d) go_files="${tmpdir}/go_files.txt" -git ls-files '*.go' | grep -v \ - -e '^vendor/' \ - -e '\.pb\.go$' \ - -e '/mock_stream\.go' \ - -e '/host_mock\.go' \ - -e '/gen_[^/]*\.go' > "${go_files}" +"${progdir}/list_harmony_go_files.sh" > "${go_files}" # Print dirname of each relative pathname from stdin (one per line). dirnames() { From 02a42cdcbd8e5ef40d7248d313808b5c2b54faa6 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Thu, 24 Jan 2019 23:37:16 -0800 Subject: [PATCH 07/16] Factor print_file into a script --- scripts/print_file.sh | 4 ++++ scripts/travis_checker.sh | 16 ++-------------- 2 files changed, 6 insertions(+), 14 deletions(-) create mode 100755 scripts/print_file.sh diff --git a/scripts/print_file.sh b/scripts/print_file.sh new file mode 100755 index 000000000..6579ac0cb --- /dev/null +++ b/scripts/print_file.sh @@ -0,0 +1,4 @@ +#!/bin/sh +echo "--- BEGIN ${2} ---" +cat "${1}" +echo "--- END ${2} ---" diff --git a/scripts/travis_checker.sh b/scripts/travis_checker.sh index dbf48d8eb..28dc95baf 100755 --- a/scripts/travis_checker.sh +++ b/scripts/travis_checker.sh @@ -1,17 +1,5 @@ #!/bin/bash -# Print a file surrounded by BEGIN/END preamble, e.g.: -# -# --- BEGIN a.out output --- -# Hello world -# --- END a.out output --- -# -print_file() { - echo "--- BEGIN ${2} ---" - cat "${1}" - echo "--- END ${2} ---" -} - unset -v ok tmpdir go_files go_dirs goimports_output golint_output progdir ok=true @@ -60,7 +48,7 @@ then echo "golint passed." else echo "golint FAILED!" - print_file "${golint_output}" "golint" + "${progdir}/print_file.sh" "${golint_output}" "golint" ok=false fi @@ -70,7 +58,7 @@ xargs goimports -d -e < "${go_files}" > "${goimports_output}" 2>&1 if [ -s "${goimports_output}" ] then echo "goimports FAILED!" - print_file "${goimports_output}" "goimports" + "${progdir}/print_file.sh" "${goimports_output}" "goimports" ok=false else echo "goimports passed." From ecd1977c058be0ee3dc11adba12b47c135457832 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Thu, 24 Jan 2019 23:40:00 -0800 Subject: [PATCH 08/16] Factor dirnames into a script --- scripts/dirnames.sh | 12 ++++++++++++ scripts/travis_checker.sh | 14 +------------- 2 files changed, 13 insertions(+), 13 deletions(-) create mode 100755 scripts/dirnames.sh diff --git a/scripts/dirnames.sh b/scripts/dirnames.sh new file mode 100755 index 000000000..c6a6b741b --- /dev/null +++ b/scripts/dirnames.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +# Print dirname of each relative pathname from stdin (one per line). + +# pathname dirname +# ---------------------- +# a/b/c.go a/b +# c.go . +exec sed \ + -e 's:^:./:' \ + -e 's:/[^/]*$::' \ + -e 's:^\./::' diff --git a/scripts/travis_checker.sh b/scripts/travis_checker.sh index 28dc95baf..9ac5ade6a 100755 --- a/scripts/travis_checker.sh +++ b/scripts/travis_checker.sh @@ -17,20 +17,8 @@ tmpdir=$(mktemp -d) go_files="${tmpdir}/go_files.txt" "${progdir}/list_harmony_go_files.sh" > "${go_files}" -# Print dirname of each relative pathname from stdin (one per line). -dirnames() { - # pathname dirname - # ---------------------- - # a/b/c.go a/b - # c.go . - sed \ - -e 's:^:./:' \ - -e 's:/[^/]*$::' \ - -e 's:^\./::' -} - go_dirs="${tmpdir}/go_dirs.txt" -dirnames < "${go_files}" | sort -u -t/ > "${go_dirs}" +"${progdir}/dirnames.sh" < "${go_files}" | sort -u -t/ > "${go_dirs}" echo "Running go test..." if go test -v -count=1 ./... From 97809dd0dda322dbb86cee74d19c91d956142956 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Thu, 24 Jan 2019 23:46:03 -0800 Subject: [PATCH 09/16] Factor goimports validation into a script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This script (scripts/goimports.sh) handily exempts vendored and generated files. Sample usage: * “scripts/goimports.sh -d -e” → show full diff * “scripts/goimports.sh -w” → fix files in-place --- scripts/goimports.sh | 7 +++++++ scripts/travis_checker.sh | 8 +++----- 2 files changed, 10 insertions(+), 5 deletions(-) create mode 100755 scripts/goimports.sh diff --git a/scripts/goimports.sh b/scripts/goimports.sh new file mode 100755 index 000000000..97ee4ff5f --- /dev/null +++ b/scripts/goimports.sh @@ -0,0 +1,7 @@ +#!/bin/sh +unset -v progdir +case "${0}" in +*/*) progdir="${0%/*}";; +*) progdir=.;; +esac +"${progdir}/list_harmony_go_files.sh" | xargs goimports "$@" diff --git a/scripts/travis_checker.sh b/scripts/travis_checker.sh index 9ac5ade6a..240c20567 100755 --- a/scripts/travis_checker.sh +++ b/scripts/travis_checker.sh @@ -1,6 +1,6 @@ #!/bin/bash -unset -v ok tmpdir go_files go_dirs goimports_output golint_output progdir +unset -v ok tmpdir go_dirs goimports_output golint_output progdir ok=true case "${0}" in @@ -14,11 +14,9 @@ tmpdir= trap 'case "${tmpdir}" in ?*) rm -rf "${tmpdir}";; esac' EXIT tmpdir=$(mktemp -d) -go_files="${tmpdir}/go_files.txt" -"${progdir}/list_harmony_go_files.sh" > "${go_files}" go_dirs="${tmpdir}/go_dirs.txt" -"${progdir}/dirnames.sh" < "${go_files}" | sort -u -t/ > "${go_dirs}" +"${progdir}/list_harmony_go_files.sh" | "${progdir}/dirnames.sh" | sort -u -t/ > "${go_dirs}" echo "Running go test..." if go test -v -count=1 ./... @@ -42,7 +40,7 @@ fi echo "Running goimports..." goimports_output="${tmpdir}/goimports_output.txt" -xargs goimports -d -e < "${go_files}" > "${goimports_output}" 2>&1 +"${progdir}/goimports.sh" -d -e > "${goimports_output}" 2>&1 if [ -s "${goimports_output}" ] then echo "goimports FAILED!" From bb3d29f4765d3dd8eeb81dcc22ffd61c793ee0a5 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Thu, 24 Jan 2019 23:46:03 -0800 Subject: [PATCH 10/16] Factor golint validation into a script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This script (scripts/golint.sh) handily exempts vendored and generated files. Sample usage: * “scripts/goimports.sh -d -e” → show full diff * “scripts/goimports.sh -w” → fix files in-place --- scripts/golint.sh | 8 ++++++++ scripts/travis_checker.sh | 8 ++------ 2 files changed, 10 insertions(+), 6 deletions(-) create mode 100755 scripts/golint.sh diff --git a/scripts/golint.sh b/scripts/golint.sh new file mode 100755 index 000000000..f6327f173 --- /dev/null +++ b/scripts/golint.sh @@ -0,0 +1,8 @@ +#!/bin/sh +unset -v progdir +case "${0}" in +*/*) progdir="${0%/*}";; +*) progdir=.;; +esac +"${progdir}/list_harmony_go_files.sh" | "${progdir}/dirnames.sh" | \ + sort -u -t/ | xargs golint "$@" diff --git a/scripts/travis_checker.sh b/scripts/travis_checker.sh index 240c20567..9f6cda555 100755 --- a/scripts/travis_checker.sh +++ b/scripts/travis_checker.sh @@ -1,6 +1,6 @@ #!/bin/bash -unset -v ok tmpdir go_dirs goimports_output golint_output progdir +unset -v ok tmpdir goimports_output golint_output progdir ok=true case "${0}" in @@ -14,10 +14,6 @@ tmpdir= trap 'case "${tmpdir}" in ?*) rm -rf "${tmpdir}";; esac' EXIT tmpdir=$(mktemp -d) - -go_dirs="${tmpdir}/go_dirs.txt" -"${progdir}/list_harmony_go_files.sh" | "${progdir}/dirnames.sh" | sort -u -t/ > "${go_dirs}" - echo "Running go test..." if go test -v -count=1 ./... then @@ -29,7 +25,7 @@ fi echo "Running golint..." golint_output="${tmpdir}/golint_output.txt" -if xargs golint -set_exit_status < "${go_dirs}" > "${golint_output}" 2>&1 +if "${progdir}/golint.sh" -set_exit_status > "${golint_output}" 2>&1 then echo "golint passed." else From cf0486dbd38c1ddf998f81dad13f51afd651f388 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Fri, 25 Jan 2019 11:22:01 -0800 Subject: [PATCH 11/16] More goimports Recent version of goimports committed a few days ago now adds an explicit package name tag for imports whose last path component differ from the package name (see golang/go#28428 and https://go-review.googlesource.com/c/tools/+/152000). --- internal/beaconchain/libs/beaconchain.go | 2 +- p2p/host.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/beaconchain/libs/beaconchain.go b/internal/beaconchain/libs/beaconchain.go index 0e09a81be..ec3437b19 100644 --- a/internal/beaconchain/libs/beaconchain.go +++ b/internal/beaconchain/libs/beaconchain.go @@ -12,7 +12,7 @@ import ( proto_identity "github.com/harmony-one/harmony/api/proto/identity" "github.com/harmony-one/harmony/api/proto/node" "github.com/harmony-one/harmony/crypto/pki" - "github.com/harmony-one/harmony/internal/beaconchain/rpc" + beaconchain "github.com/harmony-one/harmony/internal/beaconchain/rpc" "github.com/harmony-one/harmony/internal/utils" "github.com/harmony-one/harmony/p2p" "github.com/harmony-one/harmony/p2p/host" diff --git a/p2p/host.go b/p2p/host.go index 2a61d9c99..e19970c74 100644 --- a/p2p/host.go +++ b/p2p/host.go @@ -1,6 +1,6 @@ package p2p -import "github.com/libp2p/go-libp2p-peer" +import peer "github.com/libp2p/go-libp2p-peer" // Host is the client + server in p2p network. type Host interface { From 18804ded81b8f2406f8714972240c9fb9983e5b3 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Fri, 25 Jan 2019 16:53:58 -0800 Subject: [PATCH 12/16] Factor BLS build flag setup into its own script --- scripts/go_executable_build.sh | 19 ++++++------------- scripts/setup_bls_build_flags.sh | 16 ++++++++++++++++ scripts/travis_checker.sh | 15 +-------------- test/deploy.sh | 15 +-------------- 4 files changed, 24 insertions(+), 41 deletions(-) create mode 100644 scripts/setup_bls_build_flags.sh diff --git a/scripts/go_executable_build.sh b/scripts/go_executable_build.sh index 9dd0014e8..b36a1945b 100755 --- a/scripts/go_executable_build.sh +++ b/scripts/go_executable_build.sh @@ -13,21 +13,14 @@ GOARCH=amd64 FOLDER=/${WHOAMI:-$USER} RACE= -HMY_PATH=$GOPATH/src/github.com/harmony-one -export CGO_CFLAGS="-I$HMY_PATH/bls/include -I$HMY_PATH/mcl/include" -export CGO_LDFLAGS="-L$HMY_PATH/bls/lib" -export LD_LIBRARY_PATH=$HMY_PATH/bls/lib:$HMY_PATH/mcl/lib - -OS=$(uname -s) -case $OS in - Darwin) - export CGO_CFLAGS="-I$HMY_PATH/bls/include -I$HMY_PATH/mcl/include -I/usr/local/opt/openssl/include" - export CGO_LDFLAGS="-L$HMY_PATH/bls/lib -L/usr/local/opt/openssl/lib" - export LD_LIBRARY_PATH=$HMY_PATH/bls/lib:$HMY_PATH/mcl/lib:/usr/local/opt/openssl/lib - export DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH - ;; +unset -v progdir +case "${0}" in +*/*) progdir="${0%/*}";; +*) progdir=.;; esac +. "${progdir}/setup_bls_build_flags.sh" + if [ "$(uname -s)" == "Darwin" ]; then MD5='md5 -r' GOOS=darwin diff --git a/scripts/setup_bls_build_flags.sh b/scripts/setup_bls_build_flags.sh new file mode 100644 index 000000000..9cb62b7f2 --- /dev/null +++ b/scripts/setup_bls_build_flags.sh @@ -0,0 +1,16 @@ +# no shebang; to be sourced from other scripts + +HMY_PATH=$GOPATH/src/github.com/harmony-one +export CGO_CFLAGS="-I$HMY_PATH/bls/include -I$HMY_PATH/mcl/include" +export CGO_LDFLAGS="-L$HMY_PATH/bls/lib" +export LD_LIBRARY_PATH=$HMY_PATH/bls/lib:$HMY_PATH/mcl/lib + +OS=$(uname -s) +case $OS in + Darwin) + export CGO_CFLAGS="-I$HMY_PATH/bls/include -I$HMY_PATH/mcl/include -I/usr/local/opt/openssl/include" + export CGO_LDFLAGS="-L$HMY_PATH/bls/lib -L/usr/local/opt/openssl/lib" + export LD_LIBRARY_PATH=$HMY_PATH/bls/lib:$HMY_PATH/mcl/lib:/usr/local/opt/openssl/lib + export DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH + ;; +esac diff --git a/scripts/travis_checker.sh b/scripts/travis_checker.sh index 171b71eb4..c717721b4 100755 --- a/scripts/travis_checker.sh +++ b/scripts/travis_checker.sh @@ -14,20 +14,7 @@ tmpdir= trap 'case "${tmpdir}" in ?*) rm -rf "${tmpdir}";; esac' EXIT tmpdir=$(mktemp -d) -HMY_PATH=$GOPATH/src/github.com/harmony-one -export CGO_CFLAGS="-I$HMY_PATH/bls/include -I$HMY_PATH/mcl/include" -export CGO_LDFLAGS="-L$HMY_PATH/bls/lib" -export LD_LIBRARY_PATH=$HMY_PATH/bls/lib:$HMY_PATH/mcl/lib - -OS=$(uname -s) -case $OS in - Darwin) - export CGO_CFLAGS="-I$HMY_PATH/bls/include -I$HMY_PATH/mcl/include -I/usr/local/opt/openssl/include" - export CGO_LDFLAGS="-L$HMY_PATH/bls/lib -L/usr/local/opt/openssl/lib" - export LD_LIBRARY_PATH=$HMY_PATH/bls/lib:$HMY_PATH/mcl/lib:/usr/local/opt/openssl/lib - export DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH - ;; -esac +. "${progdir}/setup_bls_build_flags.sh" echo "Running go test..." if go test -v -count=1 ./... diff --git a/test/deploy.sh b/test/deploy.sh index 5c9e594f5..f02342817 100755 --- a/test/deploy.sh +++ b/test/deploy.sh @@ -3,20 +3,7 @@ ROOT=$(dirname $0)/.. USER=$(whoami) -HMY_PATH=$GOPATH/src/github.com/harmony-one -export CGO_CFLAGS="-I$HMY_PATH/bls/include -I$HMY_PATH/mcl/include" -export CGO_LDFLAGS="-L$HMY_PATH/bls/lib" -export LD_LIBRARY_PATH=$HMY_PATH/bls/lib:$HMY_PATH/mcl/lib - -OS=$(uname -s) -case $OS in - Darwin) - export CGO_CFLAGS="-I$HMY_PATH/bls/include -I$HMY_PATH/mcl/include -I/usr/local/opt/openssl/include" - export CGO_LDFLAGS="-L$HMY_PATH/bls/lib -L/usr/local/opt/openssl/lib" - export LD_LIBRARY_PATH=$HMY_PATH/bls/lib:$HMY_PATH/mcl/lib:/usr/local/opt/openssl/lib - export DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH - ;; -esac +. "${ROOT}/scripts/setup_bls_build_flags.sh" set -x set -eo pipefail From 68594d8bd42ce852ed36b6146edd1a6ddef2f140 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Fri, 25 Jan 2019 16:55:20 -0800 Subject: [PATCH 13/16] If unset, take default GOPATH from go env --- scripts/setup_bls_build_flags.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/setup_bls_build_flags.sh b/scripts/setup_bls_build_flags.sh index 9cb62b7f2..cdff751c0 100644 --- a/scripts/setup_bls_build_flags.sh +++ b/scripts/setup_bls_build_flags.sh @@ -1,6 +1,8 @@ # no shebang; to be sourced from other scripts -HMY_PATH=$GOPATH/src/github.com/harmony-one +unset -v gopath +gopath=$(go env GOPATH) +HMY_PATH="${gopath}/src/github.com/harmony-one" export CGO_CFLAGS="-I$HMY_PATH/bls/include -I$HMY_PATH/mcl/include" export CGO_LDFLAGS="-L$HMY_PATH/bls/lib" export LD_LIBRARY_PATH=$HMY_PATH/bls/lib:$HMY_PATH/mcl/lib From 0ff17bebb065464446cc4ada4ab390e0566bc5d7 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Fri, 25 Jan 2019 16:56:23 -0800 Subject: [PATCH 14/16] Use the first element of GOPATH for the src dir MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See “go help gopath-get” for details. --- scripts/setup_bls_build_flags.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/setup_bls_build_flags.sh b/scripts/setup_bls_build_flags.sh index cdff751c0..ff94f3aec 100644 --- a/scripts/setup_bls_build_flags.sh +++ b/scripts/setup_bls_build_flags.sh @@ -2,7 +2,7 @@ unset -v gopath gopath=$(go env GOPATH) -HMY_PATH="${gopath}/src/github.com/harmony-one" +HMY_PATH="${gopath%%:*}/src/github.com/harmony-one" export CGO_CFLAGS="-I$HMY_PATH/bls/include -I$HMY_PATH/mcl/include" export CGO_LDFLAGS="-L$HMY_PATH/bls/lib" export LD_LIBRARY_PATH=$HMY_PATH/bls/lib:$HMY_PATH/mcl/lib From 7f5b1678494a8e61610fa6b09a02daa4a548a675 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Fri, 25 Jan 2019 17:00:08 -0800 Subject: [PATCH 15/16] Let caller specify where to find OpenSSL/MCL/BLS This is done by defining {OPENSSL,MCL,BLS}_DIR environment variable. --- scripts/setup_bls_build_flags.sh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/setup_bls_build_flags.sh b/scripts/setup_bls_build_flags.sh index ff94f3aec..eb0115c18 100644 --- a/scripts/setup_bls_build_flags.sh +++ b/scripts/setup_bls_build_flags.sh @@ -3,16 +3,19 @@ unset -v gopath gopath=$(go env GOPATH) HMY_PATH="${gopath%%:*}/src/github.com/harmony-one" -export CGO_CFLAGS="-I$HMY_PATH/bls/include -I$HMY_PATH/mcl/include" -export CGO_LDFLAGS="-L$HMY_PATH/bls/lib" -export LD_LIBRARY_PATH=$HMY_PATH/bls/lib:$HMY_PATH/mcl/lib +: ${OPENSSL_DIR="/usr/local/opt/openssl"} +: ${MCL_DIR="${HMY_PATH}/mcl"} +: ${BLS_DIR="${HMY_PATH}/bls"} +export CGO_CFLAGS="-I${BLS_DIR}/include -I${MCL_DIR}/include" +export CGO_LDFLAGS="-L${BLS_DIR}/lib" +export LD_LIBRARY_PATH=${BLS_DIR}/lib:${MCL_DIR}/lib OS=$(uname -s) case $OS in Darwin) - export CGO_CFLAGS="-I$HMY_PATH/bls/include -I$HMY_PATH/mcl/include -I/usr/local/opt/openssl/include" - export CGO_LDFLAGS="-L$HMY_PATH/bls/lib -L/usr/local/opt/openssl/lib" - export LD_LIBRARY_PATH=$HMY_PATH/bls/lib:$HMY_PATH/mcl/lib:/usr/local/opt/openssl/lib + export CGO_CFLAGS="-I${BLS_DIR}/include -I${MCL_DIR}/include -I${OPENSSL_DIR}/include" + export CGO_LDFLAGS="-L${BLS_DIR}/lib -L${OPENSSL_DIR}/lib" + export LD_LIBRARY_PATH=${BLS_DIR}/lib:${MCL_DIR}/lib:${OPENSSL_DIR}/lib export DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH ;; esac From 24fd9d67b8f8e9f0bc1277db88559450b6d8c5ef Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Fri, 25 Jan 2019 17:19:00 -0800 Subject: [PATCH 16/16] More goimports Apparently goimports does not handle anything after the first third-party import group (whose name starts with a URL such as github.com). --- api/proto/node/pingpong.go | 4 ---- cmd/client/txgen/main.go | 2 +- cmd/harmony.go | 1 + consensus/consensus.go | 2 -- crypto/pki/utils_test.go | 2 -- internal/newnode/newnode.go | 2 -- internal/utils/utils.go | 2 -- node/node_handler.go | 2 -- p2p/p2p.go | 2 +- test/crypto/bls/main.go | 2 -- 10 files changed, 3 insertions(+), 18 deletions(-) diff --git a/api/proto/node/pingpong.go b/api/proto/node/pingpong.go index 96d4b4520..9f340270f 100644 --- a/api/proto/node/pingpong.go +++ b/api/proto/node/pingpong.go @@ -17,10 +17,6 @@ import ( "log" "github.com/harmony-one/bls/ffi/go/bls" - - "github.com/harmony-one/harmony/api/proto" - "github.com/harmony-one/harmony/p2p" - "github.com/harmony-one/harmony/api/proto" "github.com/harmony-one/harmony/p2p" peer "github.com/libp2p/go-libp2p-peer" diff --git a/cmd/client/txgen/main.go b/cmd/client/txgen/main.go index db5ed0c4d..cd6a82d82 100644 --- a/cmd/client/txgen/main.go +++ b/cmd/client/txgen/main.go @@ -20,8 +20,8 @@ import ( "github.com/harmony-one/harmony/node" "github.com/harmony-one/harmony/p2p" "github.com/harmony-one/harmony/p2p/p2pimpl" - peerstore "github.com/libp2p/go-libp2p-peerstore" + multiaddr "github.com/multiformats/go-multiaddr" ) var ( diff --git a/cmd/harmony.go b/cmd/harmony.go index 4906b6e54..df52b0d70 100644 --- a/cmd/harmony.go +++ b/cmd/harmony.go @@ -20,6 +20,7 @@ import ( "github.com/harmony-one/harmony/p2p" "github.com/harmony-one/harmony/p2p/p2pimpl" peerstore "github.com/libp2p/go-libp2p-peerstore" + multiaddr "github.com/multiformats/go-multiaddr" ) var ( diff --git a/consensus/consensus.go b/consensus/consensus.go index 07c424051..907386d94 100644 --- a/consensus/consensus.go +++ b/consensus/consensus.go @@ -10,8 +10,6 @@ import ( "strconv" "sync" - "github.com/harmony-one/bls/ffi/go/bls" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rlp" diff --git a/crypto/pki/utils_test.go b/crypto/pki/utils_test.go index 0d4b16ccd..831fc485f 100644 --- a/crypto/pki/utils_test.go +++ b/crypto/pki/utils_test.go @@ -8,8 +8,6 @@ import ( "github.com/harmony-one/bls/ffi/go/bls" "github.com/harmony-one/harmony/crypto" - - "github.com/harmony-one/harmony/crypto" ) func TestGetAddressFromPublicKey(test *testing.T) { diff --git a/internal/newnode/newnode.go b/internal/newnode/newnode.go index 40abd123c..ba4850efc 100644 --- a/internal/newnode/newnode.go +++ b/internal/newnode/newnode.go @@ -7,8 +7,6 @@ import ( "strconv" "time" - "github.com/harmony-one/bls/ffi/go/bls" - "github.com/ethereum/go-ethereum/log" "github.com/harmony-one/bls/ffi/go/bls" "github.com/harmony-one/harmony/api/proto/bcconn" diff --git a/internal/utils/utils.go b/internal/utils/utils.go index 19735fdbf..6337715e6 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -12,8 +12,6 @@ import ( "strconv" "sync" - "github.com/harmony-one/bls/ffi/go/bls" - "github.com/dedis/kyber" "github.com/harmony-one/bls/ffi/go/bls" "github.com/harmony-one/harmony/crypto" diff --git a/node/node_handler.go b/node/node_handler.go index d312d90f2..085b379fa 100644 --- a/node/node_handler.go +++ b/node/node_handler.go @@ -6,8 +6,6 @@ import ( "os" "time" - "github.com/harmony-one/bls/ffi/go/bls" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/rlp" "github.com/harmony-one/bls/ffi/go/bls" diff --git a/p2p/p2p.go b/p2p/p2p.go index e8adbe836..f8f5cdce6 100644 --- a/p2p/p2p.go +++ b/p2p/p2p.go @@ -5,8 +5,8 @@ import ( "net" "github.com/harmony-one/bls/ffi/go/bls" - peer "github.com/libp2p/go-libp2p-peer" + multiaddr "github.com/multiformats/go-multiaddr" ) // StreamHandler handles incoming p2p message. diff --git a/test/crypto/bls/main.go b/test/crypto/bls/main.go index 62e5e7c43..96c38a67c 100644 --- a/test/crypto/bls/main.go +++ b/test/crypto/bls/main.go @@ -9,8 +9,6 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/harmony-one/bls/ffi/go/bls" - - "github.com/harmony-one/bls/ffi/go/bls" ) func init() {