From d586b29fd6b507237e55bfce791c2b51ad415864 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Sat, 30 Mar 2019 15:14:30 -0700 Subject: [PATCH 01/12] Record tools in tools/tools.go The list is empty; it will be populated in later commits. --- tools/tools.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tools/tools.go diff --git a/tools/tools.go b/tools/tools.go new file mode 100644 index 000000000..7c05b17f7 --- /dev/null +++ b/tools/tools.go @@ -0,0 +1,13 @@ +// Do not remove the following build tag line: It exempts this file from normal +// builds, which would fail because the imports are programs – package main – +// and not really importable packages. +// +// +build tools + +// Package tools provides build tools necessary for Harmony. +package tools + +// Put only installable tools into this list. +// scripts/install_build_tools.sh parses these imports to install them. +import ( +) From e080bfe9029665a4601bbf0bcd0290c80e2a19f6 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Wed, 20 Mar 2019 10:26:04 -0700 Subject: [PATCH 02/12] Add goget.sh to install version-pegged packages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For each package name P given, goget.sh examines go.mod to find a matching module and its pegged version V, then executes “go get P@V” to install that specific version. --- scripts/goget.sh | 69 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100755 scripts/goget.sh diff --git a/scripts/goget.sh b/scripts/goget.sh new file mode 100755 index 000000000..6f5c8584c --- /dev/null +++ b/scripts/goget.sh @@ -0,0 +1,69 @@ +#!/bin/sh + +set -eu + +unset -v progname progdir +progname="${0##*/}" +case "${0}" in +*/*) progdir="${0%/*}";; +*) progdir=.;; +esac + +unset -v tmpdir +sigs="0 1 2 15" # EXIT HUP INT TERM +trapfunc() { + case "${tmpdir-}" in ?*) rm -rf "${tmpdir}";; esac + trap -- ${sigs} + case "${1}" in 0|EXIT) ;; *) kill "-${1}" "$$";; esac +} +unset -v sig; for sig in ${sigs}; do trap "trapfunc ${sig}" "${sig}"; done +tmpdir=$(mktemp -d) + +unset -v jq +jq=$(which jq) || { echo "${progname}: jq not found" >&2; exit 69; } + +cd "${progdir}" +while [ ! -f go.mod ] +do + case "$(pwd)" in + /) echo "${progname}: go.mod not found" >&2; exit 69;; + esac + cd .. +done + +go mod edit -json | \ + "${jq}" -r '.Require[] | .Path + "@" + .Version' \ + > "${tmpdir}/gomod.txt" + +ok=true +unset -v pkg +for pkg +do + unset -v best_path best_version path version + while IFS=@ read -r path version + do + # Is requested package at or under this path? Skip if not. + case "${pkg}" in + "${path}"|"${path}"/*) ;; + *) continue;; + esac + : ${best_path="${path}"} + : ${best_version="${version}"} + # Is this path more specific than the current best? + case "${path}" in + "${best_path}"/*) + best_path="${path}" + best_version="${version}" + esac + done < "${tmpdir}/gomod.txt" + case "${best_path-}" in + "") + echo "${progname}: no module provides package ${pkg}" >&2 + ok=false + continue + ;; + esac + echo "${progname}: ${pkg} is provided by ${best_path}@${best_version}" + go get "${pkg}@${best_version}" +done +"${ok}" && exit 0 || exit 1 From ca6fd788ce96fb35396d82399d4927572cc86b24 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Sat, 30 Mar 2019 12:42:35 -0700 Subject: [PATCH 03/12] Factor build tool installation out into a script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For now it only moves protoc installation. Support for version-pegging “go get”-able tools is included, but since tools/tools.go lists no tools yet, it is a no-op. The list will be populated/migrated in later commits. --- .travis.yml | 2 +- scripts/install_build_tools.sh | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100755 scripts/install_build_tools.sh diff --git a/.travis.yml b/.travis.yml index a9380b7ab..eec7b85d1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,7 +26,7 @@ install: - go get github.com/harmony-ek/gencodec - go get github.com/golang/mock/mockgen - go get github.com/golang/protobuf/protoc-gen-go - - ./scripts/install_protoc.sh -V 3.6.1 + - scripts/install_build_tools.sh script: - go build -v ./... - ./scripts/travis_checker.sh diff --git a/scripts/install_build_tools.sh b/scripts/install_build_tools.sh new file mode 100755 index 000000000..00b68f75d --- /dev/null +++ b/scripts/install_build_tools.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +set -eu + +unset -v progdir +case "${0}" in +/*) progdir="/";; +*/*) progdir="${0%/*}";; +*) progdir="."; +esac + +sed -n 's/^ _ "\([^"]*\)"$/\1/p' "${progdir}/../tools/tools.go" | \ + xargs "${progdir}/goget.sh" + +"${progdir}/install_protoc.sh" -V 3.6.1 From b6ad958a5344d9689ad210511209bf5e843f23c9 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Wed, 20 Mar 2019 10:42:10 -0700 Subject: [PATCH 04/12] Version-peg golint --- .travis.yml | 1 - go.mod | 1 + tools/tools.go | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index eec7b85d1..b0f353452 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,6 @@ install: - make - cd ../harmony - go get -v ./... - - go get -u golang.org/x/lint/golint - go get -u golang.org/x/tools/cmd/goimports - go get gopkg.in/check.v1 - go get github.com/harmony-ek/gencodec diff --git a/go.mod b/go.mod index a546fe093..07b73f999 100644 --- a/go.mod +++ b/go.mod @@ -42,6 +42,7 @@ require ( github.com/stretchr/testify v1.3.0 github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 + golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3 google.golang.org/grpc v1.19.0 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect diff --git a/tools/tools.go b/tools/tools.go index 7c05b17f7..235474818 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -10,4 +10,5 @@ package tools // Put only installable tools into this list. // scripts/install_build_tools.sh parses these imports to install them. import ( + _ "golang.org/x/lint/golint" ) From a9e4b7fa14d8aa10149e267a2e51dc32375d1bd9 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Wed, 20 Mar 2019 10:42:55 -0700 Subject: [PATCH 05/12] Version-peg goimports --- .travis.yml | 1 - go.mod | 1 + tools/tools.go | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b0f353452..ede662b9b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,6 @@ install: - make - cd ../harmony - go get -v ./... - - go get -u golang.org/x/tools/cmd/goimports - go get gopkg.in/check.v1 - go get github.com/harmony-ek/gencodec - go get github.com/golang/mock/mockgen diff --git a/go.mod b/go.mod index 07b73f999..6273f9dd9 100644 --- a/go.mod +++ b/go.mod @@ -43,6 +43,7 @@ require ( github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3 + golang.org/x/tools v0.0.0-20190320160634-b6b7807791df google.golang.org/grpc v1.19.0 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect diff --git a/tools/tools.go b/tools/tools.go index 235474818..d9c3dc8e4 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -11,4 +11,5 @@ package tools // scripts/install_build_tools.sh parses these imports to install them. import ( _ "golang.org/x/lint/golint" + _ "golang.org/x/tools/cmd/goimports" ) From 757897858abc5b959edef7996ce8a6ecf214b1ee Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Wed, 20 Mar 2019 10:47:24 -0700 Subject: [PATCH 06/12] Version-peg gencodec --- .travis.yml | 1 - go.mod | 3 +++ tools/tools.go | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ede662b9b..6cfce6840 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,6 @@ install: - cd ../harmony - go get -v ./... - go get gopkg.in/check.v1 - - go get github.com/harmony-ek/gencodec - go get github.com/golang/mock/mockgen - go get github.com/golang/protobuf/protoc-gen-go - scripts/install_build_tools.sh diff --git a/go.mod b/go.mod index 6273f9dd9..d8a896612 100644 --- a/go.mod +++ b/go.mod @@ -12,17 +12,20 @@ require ( github.com/edsrzf/mmap-go v1.0.0 // indirect github.com/ethereum/go-ethereum v1.8.23 github.com/fjl/memsize v0.0.0-20180929194037-2a09253e352a // indirect + github.com/garslo/gogen v0.0.0-20170307003452-d6ebae628c7c // indirect github.com/go-ole/go-ole v1.2.4 // indirect github.com/go-stack/stack v1.8.0 // indirect github.com/golang/mock v1.2.0 github.com/golang/protobuf v1.3.0 github.com/gorilla/handlers v1.4.0 github.com/gorilla/mux v1.7.0 + github.com/harmony-ek/gencodec v0.0.0-20190215044613-e6740dbdd846 github.com/harmony-one/bls v0.0.1 github.com/hashicorp/golang-lru v0.5.1 github.com/ipfs/go-datastore v0.0.1 github.com/ipfs/go-log v0.0.1 github.com/karalabe/hid v0.0.0-20181128192157-d815e0c1a2e2 // indirect + github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 // indirect github.com/libp2p/go-libp2p v0.0.2 github.com/libp2p/go-libp2p-crypto v0.0.1 github.com/libp2p/go-libp2p-discovery v0.0.1 diff --git a/tools/tools.go b/tools/tools.go index d9c3dc8e4..94bc5704f 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -10,6 +10,7 @@ package tools // Put only installable tools into this list. // scripts/install_build_tools.sh parses these imports to install them. import ( + _ "github.com/harmony-ek/gencodec" _ "golang.org/x/lint/golint" _ "golang.org/x/tools/cmd/goimports" ) From 3fe16fd8cc7878abb33cedf10737deb0b16e8cd3 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Wed, 20 Mar 2019 10:48:09 -0700 Subject: [PATCH 07/12] Version-peg mockgen The provider module (github.com/golang/mock) was already in go.mod as a test dependency. --- .travis.yml | 1 - tools/tools.go | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6cfce6840..7a5ff9eab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,6 @@ install: - cd ../harmony - go get -v ./... - go get gopkg.in/check.v1 - - go get github.com/golang/mock/mockgen - go get github.com/golang/protobuf/protoc-gen-go - scripts/install_build_tools.sh script: diff --git a/tools/tools.go b/tools/tools.go index 94bc5704f..6ea4cd22e 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -10,6 +10,7 @@ package tools // Put only installable tools into this list. // scripts/install_build_tools.sh parses these imports to install them. import ( + _ "github.com/golang/mock/mockgen" _ "github.com/harmony-ek/gencodec" _ "golang.org/x/lint/golint" _ "golang.org/x/tools/cmd/goimports" From d17a06dfe014f6dfadc4932c37e30576766d7f51 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Wed, 20 Mar 2019 10:51:42 -0700 Subject: [PATCH 08/12] Version-peg protoc-gen-go The provider module (github.com/golang/protobuf) was already in go.mod as a build dependency. --- .travis.yml | 1 - tools/tools.go | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7a5ff9eab..d25f5ab63 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,6 @@ install: - cd ../harmony - go get -v ./... - go get gopkg.in/check.v1 - - go get github.com/golang/protobuf/protoc-gen-go - scripts/install_build_tools.sh script: - go build -v ./... diff --git a/tools/tools.go b/tools/tools.go index 6ea4cd22e..1f3a784f2 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -11,6 +11,7 @@ package tools // scripts/install_build_tools.sh parses these imports to install them. import ( _ "github.com/golang/mock/mockgen" + _ "github.com/golang/protobuf/protoc-gen-go" _ "github.com/harmony-ek/gencodec" _ "golang.org/x/lint/golint" _ "golang.org/x/tools/cmd/goimports" From 7d2c88fa4741ddfc29bb975ccdcfe5afd2bcd317 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Sat, 30 Mar 2019 12:30:13 -0700 Subject: [PATCH 09/12] Do not manually install gopkg.in/check.v1 This is listed (and version-pegged) in go.mod and will be pulled in whenever needed by the build, thanks to the modules system. --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d25f5ab63..a1a3228bb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,6 @@ install: - make - cd ../harmony - go get -v ./... - - go get gopkg.in/check.v1 - scripts/install_build_tools.sh script: - go build -v ./... From d9fbfc8edf8fc8990704cea86b7fddf79f0f443c Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Sat, 30 Mar 2019 12:35:50 -0700 Subject: [PATCH 10/12] Remove protoc installation instruction This is now handled by scripts/install_build_tools.sh. --- scripts/protobuf_setup.md | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 scripts/protobuf_setup.md diff --git a/scripts/protobuf_setup.md b/scripts/protobuf_setup.md deleted file mode 100644 index 30c3ca376..000000000 --- a/scripts/protobuf_setup.md +++ /dev/null @@ -1,6 +0,0 @@ -# Setup - -You need to install protoc (protobuf compiler) and protoc-gen-go. - -- For protoc-gen-go just simple install by `go get -u github.com/golang/protobuf/protoc-gen-go` -- For protoc, you install from the release https://github.com/protocolbuffers/protobuf/releases. From dfe11a90d9092f129ffe7b8b5c18d4742d486c9e Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Sat, 30 Mar 2019 18:12:21 -0700 Subject: [PATCH 11/12] Add a script to install and track Go tool packages --- scripts/add_build_tool_package.sh | 94 +++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100755 scripts/add_build_tool_package.sh diff --git a/scripts/add_build_tool_package.sh b/scripts/add_build_tool_package.sh new file mode 100755 index 000000000..2755f4e56 --- /dev/null +++ b/scripts/add_build_tool_package.sh @@ -0,0 +1,94 @@ +#!/bin/sh + +set -eu + +unset -v progname progdir +progname="${0##*/}" +case "${0}" in +*/*) progdir="${0%/*}";; +*) progdir=".";; +esac + +msg() { case $# in [1-9]*) echo "${progname}: $*" >&2;; esac; } + +print_usage() { + cat <<- ENDEND + usage: ${progname} [-h] pkg ... + + Register the given tool package(s) in tools/tools.go and go.mod. + + pkg is a tool to install, ex: github.com/golangci/golangci-lint/cmd/golangci-lint@v1.15.0 + omitting the @version suffix installs the latest. + + options: + -h print this help + ENDEND +} + +usage() { + msg "$@" + print_usage >&2 + exit 64 +} + +unset -v opt +OPTIND=1 +while getopts :h opt +do + case "${opt}" in + "?") usage "unrecognized option -${OPTARG}";; + ":") usage "missing argument for -${OPTARG}";; + h) print_usage; exit 0;; + esac +done +shift $((${OPTIND} - 1)) + +cd "${progdir}/.." + +if git status --short go.mod tools/tools.go | grep -q . +then + msg "go.mod or tools/tools.go contains local change;" \ + "commit or stash them first." >&2 + exit 69 +fi + +go mod tidy +if git status --short go.mod | grep -q . +then + git commit -m 'go mod tidy' go.mod +fi + +doit() { + local pkg pkg_name + pkg="${1-}" + shift 1 || return $? + pkg_name="${pkg%%@*}" + msg "adding ${pkg} to tools/tools.go" + sed -i.orig '/^import ($/a\ + _ "'"${pkg_name}"'" +' tools/tools.go + rm -f tools/tools.go.orig + goimports -w tools/tools.go + if git diff --exit-code tools/tools.go + then + msg "${pkg_name} already seems to be in tools/tools.go" + return 0 + fi + msg "adding ${pkg} to go.mod" + go get "${pkg}" + go mod tidy + if git diff --exit-code go.mod + then + msg "${pkg} already seems to be in go.mod" \ + "(maybe it is already required as a build dependency)" + fi + git commit -m "Add ${pkg} as a build tool" tools/tools.go go.mod +} + +unset -v pkg ok +ok=true +for pkg +do + doit "${pkg}" || ok=false +done +exec "${ok}" From ee46ec36f6a59e673343700074d8e78d1b0a122c Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Sat, 30 Mar 2019 18:14:35 -0700 Subject: [PATCH 12/12] Add github.com/golangci/golangci-lint/cmd/golangci-lint@v1.15.0 as a build tool --- go.mod | 2 +- tools/tools.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index d8a896612..33cfa923f 100644 --- a/go.mod +++ b/go.mod @@ -17,6 +17,7 @@ require ( github.com/go-stack/stack v1.8.0 // indirect github.com/golang/mock v1.2.0 github.com/golang/protobuf v1.3.0 + github.com/golangci/golangci-lint v1.15.0 github.com/gorilla/handlers v1.4.0 github.com/gorilla/mux v1.7.0 github.com/harmony-ek/gencodec v0.0.0-20190215044613-e6740dbdd846 @@ -41,7 +42,6 @@ require ( github.com/rjeczalik/notify v0.9.2 // indirect github.com/rs/cors v1.6.0 // indirect github.com/shirou/gopsutil v2.18.12+incompatible - github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 // indirect github.com/stretchr/testify v1.3.0 github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 diff --git a/tools/tools.go b/tools/tools.go index 1f3a784f2..cd84b514c 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -12,6 +12,7 @@ package tools import ( _ "github.com/golang/mock/mockgen" _ "github.com/golang/protobuf/protoc-gen-go" + _ "github.com/golangci/golangci-lint/cmd/golangci-lint" _ "github.com/harmony-ek/gencodec" _ "golang.org/x/lint/golint" _ "golang.org/x/tools/cmd/goimports"