test_lib.sh (etcd-3.5.6) | : | test_lib.sh (etcd-3.5.7) | ||
---|---|---|---|---|
skipping to change at line 73 | skipping to change at line 73 | |||
# From http://stackoverflow.com/a/12498485 | # From http://stackoverflow.com/a/12498485 | |||
function relativePath { | function relativePath { | |||
# both $1 and $2 are absolute paths beginning with / | # both $1 and $2 are absolute paths beginning with / | |||
# returns relative path to $2 from $1 | # returns relative path to $2 from $1 | |||
local source=$1 | local source=$1 | |||
local target=$2 | local target=$2 | |||
local commonPart=$source | local commonPart=$source | |||
local result="" | local result="" | |||
while [[ "${target#$commonPart}" == "${target}" ]]; do | # Refer to https://www.shellcheck.net/wiki/SC2295 | |||
while [[ "${target#"$commonPart"}" == "${target}" ]]; do | ||||
# no match, means that candidate common part is not correct | # no match, means that candidate common part is not correct | |||
# go up one level (reduce common part) | # go up one level (reduce common part) | |||
commonPart="$(dirname "$commonPart")" | commonPart="$(dirname "$commonPart")" | |||
# and record that we went back, with correct / handling | # and record that we went back, with correct / handling | |||
if [[ -z $result ]]; then | if [[ -z $result ]]; then | |||
result=".." | result=".." | |||
else | else | |||
result="../$result" | result="../$result" | |||
fi | fi | |||
done | done | |||
if [[ $commonPart == "/" ]]; then | if [[ $commonPart == "/" ]]; then | |||
# special case for root (no common path) | # special case for root (no common path) | |||
result="$result/" | result="$result/" | |||
fi | fi | |||
# since we now have identified the common part, | # since we now have identified the common part, | |||
# compute the non-common part | # compute the non-common part | |||
local forwardPart="${target#$commonPart}" | # Refer to https://www.shellcheck.net/wiki/SC2295 | |||
local forwardPart="${target#"$commonPart"}" | ||||
# and now stick all parts together | # and now stick all parts together | |||
if [[ -n $result ]] && [[ -n $forwardPart ]]; then | if [[ -n $result ]] && [[ -n $forwardPart ]]; then | |||
result="$result$forwardPart" | result="$result$forwardPart" | |||
elif [[ -n $forwardPart ]]; then | elif [[ -n $forwardPart ]]; then | |||
# extra slash removal | # extra slash removal | |||
result="${forwardPart:1}" | result="${forwardPart:1}" | |||
fi | fi | |||
echo "$result" | echo "$result" | |||
skipping to change at line 309 | skipping to change at line 311 | |||
fi | fi | |||
} | } | |||
# Ensure gobin is available, as it runs majority of the tools | # Ensure gobin is available, as it runs majority of the tools | |||
if ! command -v "gobin" >/dev/null; then | if ! command -v "gobin" >/dev/null; then | |||
run env GO111MODULE=off go get github.com/myitcv/gobin || exit 1 | run env GO111MODULE=off go get github.com/myitcv/gobin || exit 1 | |||
fi | fi | |||
# tool_get_bin [tool] - returns absolute path to a tool binary (or returns error ) | # tool_get_bin [tool] - returns absolute path to a tool binary (or returns error ) | |||
function tool_get_bin { | function tool_get_bin { | |||
tool_exists "gobin" "GO111MODULE=off go get github.com/myitcv/gobin" || return | ||||
2 | ||||
local tool="$1" | local tool="$1" | |||
local pkg_part="$1" | ||||
if [[ "$tool" == *"@"* ]]; then | if [[ "$tool" == *"@"* ]]; then | |||
pkg_part=$(echo "${tool}" | cut -d'@' -f1) | ||||
# shellcheck disable=SC2086 | # shellcheck disable=SC2086 | |||
run gobin ${GOBINARGS:-} -p "${tool}" || return 2 | run go install ${GOBINARGS:-} "${tool}" || return 2 | |||
else | else | |||
# shellcheck disable=SC2086 | # shellcheck disable=SC2086 | |||
run_for_module ./tools/mod run gobin ${GOBINARGS:-} -p -m --mod=readonly "${ | run_for_module ./tools/mod run go install ${GOBINARGS:-} "${tool}" || return | |||
tool}" || return 2 | 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 | 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 pk g. | # tool_pkg_dir [pkg] - returns absolute path to a directory that stores given pk g. | |||
# The pkg versions must be defined in ./tools/mod directory. | # The pkg versions must be defined in ./tools/mod directory. | |||
function tool_pkg_dir { | function tool_pkg_dir { | |||
run_for_module ./tools/mod run go list -f '{{.Dir}}' "${1}" | run_for_module ./tools/mod run go list -f '{{.Dir}}' "${1}" | |||
} | } | |||
# tool_get_bin [tool] | # tool_get_bin [tool] | |||
function run_go_tool { | function run_go_tool { | |||
End of changes. 8 change blocks. | ||||
8 lines changed or deleted | 18 lines changed or added |