Make gate scripts handle table-form dependencies and fail closed

Implemented-By: Laguna S 2.1 (OpenCode)
This commit is contained in:
2026-09-17 10:14:22 -07:00
parent 69120af092
commit 46d26e868b
5 changed files with 130 additions and 55 deletions
Regular → Executable
+29 -15
View File
@@ -1,12 +1,20 @@
#!/bin/sh
# Fails if `proto` depends on any workspace crate, or if any other crate depends on
# a workspace crate other than `proto`. Every manifest section whose name contains
# "dependencies" (including [dev-dependencies]) is inspected. A dependency is the
# key in such a section, however it is written: `x.workspace = true`,
# `x = { path = ".." }` or `x = "1"`.
# "dependencies" (including [dev-dependencies] and [build-dependencies]) is
# inspected. A dependency name can appear as a plain key (`x = "1"`), a dotted key
# (`x.workspace = true` or `x.path = ".."`) or a table header (`[dependencies.x]`);
# the lines inside a table-form dependency are settings of that dependency, not
# further dependencies.
ROOT="${1:-.}"
status=0
# Fail closed: there is nothing to check without a crates directory.
if [ ! -d "$ROOT/crates" ]; then
echo "check-crate-deps: $ROOT/crates is not a directory" >&2
exit 1
fi
# Workspace crate names: directories under ROOT/crates that contain a Cargo.toml.
workspace=""
for d in "$ROOT"/crates/*/; do
@@ -19,25 +27,31 @@ for crate in "$ROOT"/crates/*/; do
[ -d "$crate" ] || continue
crate_name=$(basename "$crate")
[ -f "$crate/Cargo.toml" ] || continue
# Emit one dependency name per line, from plain/dotted keys and table headers.
keys=$(awk '
BEGIN { in_deps = 0; depth = 0 }
/^\[/ {
sec = $0
sub(/^\[[ \t]*/, "", sec)
sub(/[ \t]*\][ \t]*.*$/, "", sec)
in_deps = (sec ~ /dependencies/)
BEGIN { in_deps = 0; in_table = 0; depth = 0 }
/^[ \t]*\[/ {
hdr = $0
sub(/^[ \t]*\[/, "", hdr)
sub(/[ \t]*\][ \t]*.*$/, "", hdr)
if (hdr ~ /dependencies/) {
n = split(hdr, parts, ".")
if (parts[n] ~ /dependencies$/) { in_deps = 1; in_table = 0 }
else { in_deps = 1; in_table = 1; print parts[n] }
} else { in_deps = 0; in_table = 0 }
depth = 0
next
}
in_table { next }
in_deps {
if (depth == 0) {
t = $0
sub(/^[ \t]+/, "", t)
if (t ~ /^[A-Za-z0-9][A-Za-z0-9_-]*(\.workspace)?[ \t]*=/) {
if (match(t, /[A-Za-z0-9][A-Za-z0-9_-]*/)) {
k = substr(t, RSTART, RLENGTH)
if (RSTART == 1) print k
}
if (match(t, /^[A-Za-z0-9][A-Za-z0-9_-]*(\.[A-Za-z0-9_-]+)*[ \t]*=/)) {
name = t
sub(/[ \t]*=.*/, "", name)
sub(/\..*/, "", name)
print name
}
}
s = $0
@@ -48,7 +62,7 @@ for crate in "$ROOT"/crates/*/; do
s = substr(s, RSTART + 1)
}
}
' "$crate/Cargo.toml" 2>/dev/null)
' "$crate/Cargo.toml")
for key in $keys; do
hit=0
for w in $workspace; do