Remove dependency on gobin

Signed-off-by: Benjamin Wang <wachao@vmware.com>
This commit is contained in:
Benjamin Wang
2022-12-19 14:20:45 +08:00
parent 413ec16175
commit 925c0611e0
2 changed files with 27 additions and 4 deletions

View File

@@ -310,16 +310,25 @@ 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 github.com/myitcv/gobin" || return 2
local tool="$1"
local pkg_part="$1"
if [[ "$tool" == *"@"* ]]; then
pkg_part=$(echo "${tool}" | cut -d'@' -f1)
# shellcheck disable=SC2086
run gobin ${GOBINARGS:-} -p "${tool}" || return 2
run go install ${GOBINARGS:-} "${tool}" || return 2
else
# shellcheck disable=SC2086
run_for_module ./tools/mod run gobin ${GOBINARGS:-} -p -m --mod=readonly "${tool}" || return 2
run_for_module ./tools/mod run go install ${GOBINARGS:-} "${tool}" || return 2
fi
# remove the version suffix, such as removing "/v3" from "go.etcd.io/etcd/v3".
local cmd_base_name
cmd_base_name=$(basename "${pkg_part}")
if [[ ${cmd_base_name} =~ ^v[0-9]*$ ]]; then
pkg_part=$(dirname "${pkg_part}")
fi
run_for_module ./tools/mod go list -f '{{.Target}}' "${pkg_part}"
}
# tool_pkg_dir [pkg] - returns absolute path to a directory that stores given pkg.