commit
9e33b0366f
@ -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}" |
@ -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 |
@ -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 |
@ -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. |
@ -0,0 +1,19 @@ |
||||
// 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 ( |
||||
_ "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" |
||||
) |
Loading…
Reference in new issue