From 677f1b8af095ead955be0e58dde1b241e0d42ddb Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 16 Jun 2022 16:13:11 -0400 Subject: [PATCH] Update check_tree to better detect errors in cargo-tree. --- maint/check_tree | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/maint/check_tree b/maint/check_tree index 2f591db96..e688bf80c 100755 --- a/maint/check_tree +++ b/maint/check_tree @@ -3,17 +3,37 @@ # Use cargo-tree to check our dependencies for crates which we must # not depend on unconditionally. +set -eu forbid () { local our_crate="$1" local feature="$2" local forbidden="$3" - if cargo tree -i "$forbidden" -p "$our_crate" --features "$feature" 2>/dev/null ; then - echo "Uh-oh: $forbidden has shown up in $our_crate/$feature." - exit 1 - else - echo "Didn't find $forbidden in $our_crate/$feature. Good." - fi + + set +e + cargo tree --prefix=none -p "$our_crate" --features "$feature" \ + --format=" {p}" | grep "^ $forbidden" + local result="${PIPESTATUS[*]}" + set -e + + case "$result" in + "0 0") + # cargo-tree succeeded, and so did grep: we found the + # forbidden package. + echo "Uh-oh: $forbidden has shown up in $our_crate/$feature." + exit 1 + ;; + "0 1") + # cargo-tree succeeded, and grep failed: we didn't find the + # forbidden package. + echo "Didn't find $forbidden in $our_crate/$feature. Good." + ;; + *) + # cargo-tree failed (or maybe grep is gruesomely nonstandard) + echo "cargo tree failed unexpectedly when checking for $forbidden in $our_crate/$feature" >&2 + exit 1 + ;; + esac } # We can't use these crates in arti/full, since they expose us to the old