mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Fix dependency inconsistency detection and add make verify-dep
Makefile's target `verify-dep` current behavior is to use `go list` to check consistent dependency versions from direct dependencies. Ignoring indirect dependencies in a multi-module project could lead to version mismatches. If module A imports module B, module B's dependency will be an indirect dependency in module A. Which can potentially have a version mismatch. Therefore, use `go mod edit` with indirect dependencies, too. So it can work with all dependencies defined in go.mod. Fix displaying dependencies with mismatches, as the old code was searching with grep just for the prefix, which would show other dependencies that shared the same prefix. Reference: - https://github.com/etcd-io/etcd/pull/18205 Signed-off-by: Ivan Valdes <ivan@vald.es> Signed-off-by: Chun-Hung Tseng <henrybear327@gmail.com>
This commit is contained in:
6
Makefile
6
Makefile
@@ -582,12 +582,16 @@ gofail-disable: install-gofail
|
||||
PASSES="toggle_failpoints" ./test.sh
|
||||
|
||||
.PHONY: verify
|
||||
verify: verify-go-versions
|
||||
verify: verify-go-versions verify-dep
|
||||
|
||||
.PHONY: verify-go-versions
|
||||
verify-go-versions:
|
||||
./scripts/verify_go_versions.sh
|
||||
|
||||
.PHONY: verify-dep
|
||||
verify-dep:
|
||||
PASSES="dep" ./test.sh 2<&1
|
||||
|
||||
.PHONY: fix
|
||||
fix: sync-toolchain-directive
|
||||
./scripts/fix.sh
|
||||
|
||||
4
test.sh
4
test.sh
@@ -610,7 +610,7 @@ function dump_deps_of_module() {
|
||||
if ! module=$(run go list -m); then
|
||||
return 255
|
||||
fi
|
||||
run go list -f "{{if not .Indirect}}{{if .Version}}{{.Path}},{{.Version}},${module}{{end}}{{end}}" -m all
|
||||
run go mod edit -json | jq -r '.Require[] | .Path+","+.Version+","+if .Indirect then " (indirect)" else "" end+",'"${module}"'"'
|
||||
}
|
||||
|
||||
# Checks whether dependencies are consistent across modules
|
||||
@@ -623,7 +623,7 @@ function dep_pass {
|
||||
|
||||
for dup in ${duplicates}; do
|
||||
log_error "FAIL: inconsistent versions for depencency: ${dup}"
|
||||
echo "${all_dependencies}" | grep "${dup}" | sed "s|\\([^,]*\\),\\([^,]*\\),\\([^,]*\\)| - \\1@\\2 from: \\3|g"
|
||||
echo "${all_dependencies}" | grep "${dup}," | sed 's|\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\)| - \1@\2\3 from: \4|g'
|
||||
done
|
||||
if [[ -n "${duplicates}" ]]; then
|
||||
log_error "FAIL: inconsistent dependencies"
|
||||
|
||||
Reference in New Issue
Block a user