Add BUILD.bazel dependency linting (#5437)

* Add BUILD.bazel dependency linting

Adds tooling to enforce architectural boundaries in the codebase:

1. Shell script `scripts/check_build_deps.sh` with multiple modes:
   - Default: runs all checks and shows dependency counts
   - --ci: fails only on hard violations (src/main depends on src/test)
   - --strict: also fails if proto deps in library/ increase from baseline
   - --count: just show current dependency counts
   - --update-baseline: update the baseline file for tracking

2. Bazel test `//:build_deps_test` for integration with test suite

3. Baseline file `scripts/build_deps_baseline.txt` tracking proto dep count

Current enforced rules:
- src/main must not depend on src/test (enforced now)
- library/ proto dependencies tracked (167 currently, deproto in progress)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Update DEPROTO_PLAN.md with accurate proto import inventory

The previous status was inaccurate. This update:

- Corrects summary table: Availability, Command Choice Helpers,
  and other utilities still have Hostility proto imports
- Adds Phase 8b documenting Hostility proto migration (4 files)
- Updates detailed inventory showing actual 13 files with direct
  proto imports (vs 167 transitive deps from bazel query)
- Corrects success criteria checkboxes to reflect actual status
- Documents the grep command used to verify imports

The 167 proto deps from bazel query are transitive dependencies.
Only 13 files have direct proto imports:
- 5 boundary files (expected to keep proto)
- 4 files using Hostility proto (Phase 8b)
- 4 LLM prompt generator files (Phase 8)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-19 07:28:58 -08:00
committed by GitHub
co-authored by Claude Opus 4.5
parent a0bf6050b4
commit 7ab8fc796b
4 changed files with 274 additions and 85 deletions
+3
View File
@@ -0,0 +1,3 @@
# BUILD dependency baseline - updated Sun Jan 18 15:45:56 PST 2026
# Do not increase these numbers - only decrease!
library_proto_deps=167
+158
View File
@@ -0,0 +1,158 @@
#!/bin/bash
# Check BUILD.bazel dependency constraints
# This script enforces architectural boundaries in the codebase.
#
# Usage:
# ./scripts/check_build_deps.sh # Check all rules
# ./scripts/check_build_deps.sh --ci # CI mode (fail on any violation)
# ./scripts/check_build_deps.sh --count # Just count current violations (for tracking progress)
# ./scripts/check_build_deps.sh --strict # Fail if proto deps in library/ exceed baseline
#
# The baseline for proto deps is stored in scripts/build_deps_baseline.txt
# Update it with: ./scripts/check_build_deps.sh --update-baseline
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
BASELINE_FILE="$SCRIPT_DIR/build_deps_baseline.txt"
cd "$REPO_ROOT"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
MODE="${1:-check}"
EXIT_CODE=0
# Get baseline proto count (default to a high number if no baseline exists)
get_baseline() {
if [ -f "$BASELINE_FILE" ]; then
grep "^library_proto_deps=" "$BASELINE_FILE" | cut -d= -f2
else
echo "999999" # No baseline = don't fail
fi
}
# Rule 1: src/main should not depend on src/test
check_main_depends_on_test() {
echo -e "${YELLOW}Checking: src/main should not depend on src/test...${NC}"
violations=$(bazel query 'deps(//src/main/...) intersect //src/test/...' 2>/dev/null || true)
if [ -n "$violations" ]; then
echo -e "${RED}VIOLATION: src/main depends on src/test:${NC}"
echo "$violations"
return 1
else
echo -e "${GREEN}✓ No violations${NC}"
return 0
fi
}
# Rule 2: library/ should not depend on src/main/protobuf
# Note: This rule is aspirational - there are currently many violations as part of ongoing deproto effort
check_library_depends_on_proto() {
echo -e "${YELLOW}Checking: library/ should not depend on src/main/protobuf...${NC}"
violations=$(bazel query 'deps(//src/main/scala/net/eagle0/eagle/library/...) intersect //src/main/protobuf/...' 2>/dev/null || true)
count=$(echo "$violations" | grep -c "^//" || echo "0")
if [ "$count" -gt 0 ]; then
echo -e "${YELLOW}Found $count proto dependencies in library/ (deproto in progress)${NC}"
if [ "$MODE" == "--count" ]; then
echo "$violations" | head -20
if [ "$count" -gt 20 ]; then
echo "... and $((count - 20)) more"
fi
fi
# Don't fail on this rule yet - it's aspirational
return 0
else
echo -e "${GREEN}✓ No proto dependencies in library/${NC}"
return 0
fi
}
# Count proto deps for tracking deproto progress
count_proto_deps() {
echo -e "${YELLOW}=== Proto dependency counts ===${NC}"
library_count=$(bazel query 'deps(//src/main/scala/net/eagle0/eagle/library/...) intersect //src/main/protobuf/...' 2>/dev/null | grep -c "^//" || echo "0")
echo "library/: $library_count proto dependencies"
baseline=$(get_baseline)
if [ "$baseline" != "999999" ]; then
echo "baseline: $baseline"
if [ "$library_count" -lt "$baseline" ]; then
echo -e "${GREEN}↓ Reduced by $((baseline - library_count)) from baseline${NC}"
elif [ "$library_count" -gt "$baseline" ]; then
echo -e "${RED}↑ Increased by $((library_count - baseline)) from baseline${NC}"
fi
fi
}
# Check if proto deps exceed baseline (for strict mode)
check_proto_baseline() {
library_count=$(bazel query 'deps(//src/main/scala/net/eagle0/eagle/library/...) intersect //src/main/protobuf/...' 2>/dev/null | grep -c "^//" || echo "0")
baseline=$(get_baseline)
echo -e "${YELLOW}Checking: proto deps in library/ should not exceed baseline...${NC}"
echo "Current: $library_count, Baseline: $baseline"
if [ "$library_count" -gt "$baseline" ]; then
echo -e "${RED}VIOLATION: Proto dependencies increased from $baseline to $library_count${NC}"
echo "Run './scripts/check_build_deps.sh --count' to see which protos are used"
return 1
else
echo -e "${GREEN}✓ Proto deps at or below baseline${NC}"
return 0
fi
}
# Update baseline file
update_baseline() {
library_count=$(bazel query 'deps(//src/main/scala/net/eagle0/eagle/library/...) intersect //src/main/protobuf/...' 2>/dev/null | grep -c "^//" || echo "0")
echo "# BUILD dependency baseline - updated $(date)" > "$BASELINE_FILE"
echo "# Do not increase these numbers - only decrease!" >> "$BASELINE_FILE"
echo "library_proto_deps=$library_count" >> "$BASELINE_FILE"
echo -e "${GREEN}Updated baseline: library_proto_deps=$library_count${NC}"
}
echo "=== BUILD.bazel Dependency Check ==="
echo ""
case "$MODE" in
--count)
count_proto_deps
;;
--ci)
check_main_depends_on_test || EXIT_CODE=1
check_library_depends_on_proto || EXIT_CODE=1
;;
--strict)
check_main_depends_on_test || EXIT_CODE=1
check_proto_baseline || EXIT_CODE=1
;;
--update-baseline)
update_baseline
;;
*)
check_main_depends_on_test || EXIT_CODE=1
check_library_depends_on_proto
echo ""
count_proto_deps
;;
esac
echo ""
if [ $EXIT_CODE -eq 0 ]; then
echo -e "${GREEN}=== All checks passed ===${NC}"
else
echo -e "${RED}=== Some checks failed ===${NC}"
fi
exit $EXIT_CODE