70 lines
1.5 KiB
Bash
Executable File
70 lines
1.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
command -v jq >/dev/null 2>&1 || {
|
|
echo "ERROR: jq is required for check_deps.sh" >&2
|
|
exit 1
|
|
}
|
|
|
|
# Higher layer numbers may depend on lower numbers only.
|
|
layer_of() {
|
|
case "$1" in
|
|
shared)
|
|
echo 0
|
|
;;
|
|
web_api | js | js_vm | js_parser | dom | html | css | selectors | style | layout | display_list | render | graphics | net | storage | image | fonts | platform)
|
|
echo 1
|
|
;;
|
|
browser_runtime)
|
|
echo 2
|
|
;;
|
|
app_browser)
|
|
echo 3
|
|
;;
|
|
rust_browser)
|
|
echo 3
|
|
;;
|
|
*)
|
|
return 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
meta=$(cargo metadata --format-version=1 --no-deps)
|
|
|
|
fail=0
|
|
while IFS=$'\t' read -r from to; do
|
|
[[ -z "$from" ]] && continue
|
|
|
|
if ! from_layer=$(layer_of "$from"); then
|
|
echo "WARN: missing layer mapping for crate: $from (update scripts/check_deps.sh)"
|
|
continue
|
|
fi
|
|
|
|
if ! to_layer=$(layer_of "$to"); then
|
|
echo "WARN: missing layer mapping for crate: $to (update scripts/check_deps.sh)"
|
|
continue
|
|
fi
|
|
|
|
if (( from_layer < to_layer )); then
|
|
echo "ERROR: layering violation: $from (L${from_layer}) depends on $to (L${to_layer})"
|
|
fail=1
|
|
fi
|
|
done < <(
|
|
echo "$meta" | jq -r '
|
|
.packages[]
|
|
| select(.source==null)
|
|
| .name as $n
|
|
| .dependencies[]
|
|
| select(.source==null)
|
|
| "\($n)\t\(.name)"'
|
|
)
|
|
|
|
if [[ $fail -ne 0 ]]; then
|
|
echo
|
|
echo "Fix: remove the forbidden dependency or move shared interfaces downward into a lower layer crate."
|
|
exit 1
|
|
fi
|
|
|
|
echo "OK: dependency layering check passed"
|