#!/usr/bin/env bash # check-unwired-patches.sh — detect patch files not referenced in any recipe.toml # # Scans local/patches/ for .patch files that exist on disk but are NOT listed # in any recipe's patches = [...] array. Also detects patches that are symlinked # into recipes/ but whose recipe.toml entry no longer exists. # # Usage: ./local/scripts/check-unwired-patches.sh [--strict] # --strict: exit non-zero if any unwired patches found (for CI) set -euo pipefail ROOT="$(cd "$(dirname "$0")/../.." && pwd)" STRICT=false [[ "${1:-}" == "--strict" ]] && STRICT=true UNWIRED=0 echo "=== Unwired Patch Check ===" # Map patch file → list of recipe.toml files that reference it declare -A PATCH_REFS # Find all recipe.toml files while IFS= read -r -d '' recipe; do # Extract patch filenames from patches = [...] array # Handles both local/patches/... and relative paths while IFS= read -r patch_ref; do # Resolve the patch path relative to the recipe directory recipe_dir="$(dirname "$recipe")" patch_path="$(cd "$recipe_dir" && realpath -m "$patch_ref" 2>/dev/null || echo "$recipe_dir/$patch_ref")" PATCH_REFS["$patch_path"]+="$recipe " done < <(grep -oP '"[^"]+\.patch"' "$recipe" | tr -d '"') done < <(find "$ROOT/recipes" "$ROOT/local/recipes" -name 'recipe.toml' -print0 2>/dev/null) # Find all patch files in local/patches/ while IFS= read -r -d '' patch; do patch_real="$(realpath "$patch")" found=false for ref in "${!PATCH_REFS[@]}"; do ref_real="$(realpath "$ref" 2>/dev/null || echo "$ref")" if [[ "$ref_real" == "$patch_real" ]]; then found=true break fi done if ! $found; then UNWIRED=$((UNWIRED + 1)) echo " UNWIRED: $patch" fi done < <(find "$ROOT/local/patches" -name '*.patch' -print0 2>/dev/null) echo "" if [[ $UNWIRED -eq 0 ]]; then echo "✅ All patches wired" else echo "⚠️ $UNWIRED unwired patch(es) found" $STRICT && exit 1 fi exit 0