script/genproto.sh: Refactor to be explicit about versions.

Refactoring script/genproto.sh around state-of-the-art techniques of
managing tooling in go:
  - https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module
  - uses https://github.com/myitcv/gobin instead of customly created gopath.proto dir
  - caches tools between executions
  - guaratees hermetics runs (it was not guaranteed for protoc_grpc_gateway that used latest)

The change is no-op for the generated code.

The commit reveals a few 'worring things':
  1  We depend on : github.com/grpc-ecosystem/grpc-gateway/@v/v1.4.1/protoc-gen-grpc-gateway
  2. And also     : github.com/grpc-ecosystem/grpc-gateway/@v/v1.15.0/protoc-gen-swagger/protoc-gen-swagger
  3. And on extremely old: github.com/gogo/protobuf@v1.0.0 protoc-gen-gofast that is out of sync with the library linked to binaries: github.com/gogo/protobuf@v1.2.1
This commit is contained in:
Piotr Tabor
2020-10-08 19:48:35 +02:00
parent 2c66612e0e
commit dfdda47bd8
6 changed files with 369 additions and 87 deletions

View File

@@ -191,6 +191,9 @@ function go_test {
# tool_exists [tool] [instruction]
# Checks whether given [tool] is installed. In case of failure,
# prints a warning with installation [instruction] and returns !=0 code.
#
# WARNING: This depend on "any" version of the 'binary' that might be tricky
# from hermetic build perspective. For go binaries prefer 'tool_go_run'
function tool_exists {
local tool="${1}"
local instruction="${2}"
@@ -200,3 +203,31 @@ function tool_exists {
fi
}
# tool_get_bin [tool] - returns absolute path to a tool binary (or returns error)
function tool_get_bin {
tool_exists "gobin" "GO111MODULE=off go get -u github.com/myitcv/gobin" || return 2
local tool="$1"
if [[ "$tool" == *"@"* ]]; then
run gobin -p "${tool}" || return 2
else
run_for_module ./tools/mod run gobin -p -m --mod=readonly "${tool}" || return 2
fi
}
# tool_pkg_dir [pkg] - returns absolute path to a directory that stores given pkg.
# The pkg versions must be defined in ./tools/mod directory.
function tool_pkg_dir {
run_for_module ./tools/mod run go list -f '{{.Dir}}' "${1}"
}
# tool_get_bin [tool]
function run_go_tool {
local cmdbin
if ! cmdbin=$(tool_get_bin "${1}"); then
return 2
fi
shift 1
run "${cmdbin}" "$@" || return 2
}