| 1 | #!/usr/bin/env bash | |
| 2 | # | |
| 3 | # Enforce spec §3 rule 1: "No crate other than `df-store` may depend on `gix`. | |
| 4 | # Add this to CI as a dependency check." | |
| 5 | # | |
| 6 | # The whole value of the RepoStore abstraction is that swapping in a jj-native | |
| 7 | # backend later touches one crate. That guarantee is worth exactly as much as | |
| 8 | # this check — the moment a second crate reaches for `gix`, the boundary is | |
| 9 | # gone and nobody notices until the migration. | |
| 10 | ||
| 11 | set -euo pipefail | |
| 12 | ||
| 13 | ROOT="" | |
| 14 | FAIL=0 | |
| 15 | ||
| 16 | echo "==> checking the df-store boundary" | |
| 17 | ||
| 18 | # 1. Only df-store may declare gix as a dependency. | |
| 19 | while IFS= read -r manifest; do | |
| 20 | crate="" | |
| 21 | [[ "$crate" == "df-store" ]] && continue | |
| 22 | ||
| 23 | if grep -qE '^\s*gix\s*[=.]|^\s*gix\s*=\s*\{' "$manifest"; then | |
| 24 | echo " FAIL: $crate declares a dependency on gix ($manifest)" | |
| 25 | FAIL=1 | |
| 26 | fi | |
| 27 | done < | |
| 28 | ||
| 29 | # 2. Only df-store may name gix in its source. | |
| 30 | while IFS= read -r file; do | |
| 31 | case "$file" in | |
| 32 | "$ROOT"/crates/df-store/*) continue ;; | |
| 33 | esac | |
| 34 | if grep -nE '(^|[^A-Za-z_])gix::|extern crate gix' "$file" >/dev/null 2>&1; then | |
| 35 | echo " FAIL: references gix::" | |
| 36 | grep -nE '(^|[^A-Za-z_])gix::|extern crate gix' "$file" | head -3 | sed 's/^/ /' | |
| 37 | FAIL=1 | |
| 38 | fi | |
| 39 | done < | |
| 40 | ||
| 41 | # 3. RevId must stay opaque: nothing outside df-store may slice or measure it. | |
| 42 | # Spec §3 rule 2 — "do not parse it, do not assume it is 40 hex characters, | |
| 43 | # do not abbreviate it outside df-store." | |
| 44 | while IFS= read -r file; do | |
| 45 | case "$file" in | |
| 46 | "$ROOT"/crates/df-store/*) continue ;; | |
| 47 | esac | |
| 48 | if grep -nE '\.as_str\(\)\s*\[|rev\s*\[\s*\.\.|\.rev\.as_str\(\)\[' "$file" >/dev/null 2>&1; then | |
| 49 | echo " FAIL: appears to slice a RevId" | |
| 50 | FAIL=1 | |
| 51 | fi | |
| 52 | done < | |
| 53 | ||
| 54 | if [[ $FAIL -eq 0 ]]; then | |
| 55 | echo " ok — gix is confined to df-store, RevId is opaque" | |
| 56 | else | |
| 57 | echo | |
| 58 | echo "The storage boundary exists so that moving to a jj-native backend is a" | |
| 59 | echo "swap of one implementation rather than a rewrite. Route what you need" | |
| 60 | echo "through the RepoStore trait instead." | |
| 61 | exit 1 | |
| 62 | fi |
62 lines · Shell