Files
codebase-memory-mcp/scripts/vendor-grammar.sh
T
Martin Vogel bd6bbc2ab1 Add Go LSP hybrid type resolver, config store, and supporting infrastructure
- Go LSP cross-file type resolution engine (internal/cbm/lsp/) with C-based
  type registry, scope tracking, and Go stdlib data (30K+ definitions)
- lsp_bridge.go: CrossFileDef struct and RunGoLSPCrossFile CGo bridge
- config.go: persistent ConfigStore (SQLite) for auto_index, mem_limit settings
- CLI config subcommand for get/set/list/delete operations
- Store: edge batch upsert, project config columns, goleak test harness
- Pipeline: prefetch parallelism, resolver improvements, memleak tests
- CI: dry-run workflow improvements, vendor-grammar.sh enhancements
2026-03-12 13:26:13 +01:00

80 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
# vendor-grammar.sh: Vendor a single tree-sitter grammar into internal/cbm/vendored/grammars/<name>/
# Usage: ./scripts/vendor-grammar.sh <repo_url> <name> [subdir]
# repo_url: GitHub repository URL (e.g., https://github.com/tree-sitter/tree-sitter-json)
# name: Target directory name (e.g., json)
# subdir: Optional subdirectory within repo containing src/ (e.g., "fsharp" for monorepo grammars)
set -euo pipefail
REPO_URL="$1"
NAME="$2"
SUBDIR="${3:-}"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
GRAMMAR_DIR="$PROJECT_DIR/internal/cbm/vendored/grammars/$NAME"
TMPDIR="$(mktemp -d)"
trap 'rm -rf "$TMPDIR"' EXIT
echo "Vendoring $NAME from $REPO_URL..."
git clone --depth 1 "$REPO_URL" "$TMPDIR/repo" 2>/dev/null
SRC_DIR="$TMPDIR/repo/src"
if [ -n "$SUBDIR" ]; then
SRC_DIR="$TMPDIR/repo/$SUBDIR/src"
fi
if [ ! -f "$SRC_DIR/parser.c" ]; then
echo "ERROR: $SRC_DIR/parser.c not found" >&2
exit 1
fi
mkdir -p "$GRAMMAR_DIR/tree_sitter"
cp "$SRC_DIR/parser.c" "$GRAMMAR_DIR/"
if [ -f "$SRC_DIR/scanner.c" ]; then
cp "$SRC_DIR/scanner.c" "$GRAMMAR_DIR/"
fi
if [ -f "$SRC_DIR/scanner.cc" ]; then
echo "WARNING: $NAME has C++ scanner (scanner.cc) — needs special handling" >&2
fi
# Copy tree_sitter headers
if [ -d "$SRC_DIR/tree_sitter" ]; then
cp "$SRC_DIR/tree_sitter/"*.h "$GRAMMAR_DIR/tree_sitter/" 2>/dev/null || true
fi
# Copy LICENSE file from upstream repo
REPO_ROOT="$TMPDIR/repo"
if [ -n "$SUBDIR" ]; then
# For monorepos, check subdir first, then repo root
if [ -f "$REPO_ROOT/$SUBDIR/LICENSE" ]; then
cp "$REPO_ROOT/$SUBDIR/LICENSE" "$GRAMMAR_DIR/LICENSE"
elif [ -f "$REPO_ROOT/LICENSE" ]; then
cp "$REPO_ROOT/LICENSE" "$GRAMMAR_DIR/LICENSE"
elif [ -f "$REPO_ROOT/LICENSE.md" ]; then
cp "$REPO_ROOT/LICENSE.md" "$GRAMMAR_DIR/LICENSE"
elif [ -f "$REPO_ROOT/COPYING" ]; then
cp "$REPO_ROOT/COPYING" "$GRAMMAR_DIR/LICENSE"
else
echo "WARNING: No LICENSE file found for $NAME" >&2
fi
else
if [ -f "$REPO_ROOT/LICENSE" ]; then
cp "$REPO_ROOT/LICENSE" "$GRAMMAR_DIR/LICENSE"
elif [ -f "$REPO_ROOT/LICENSE.md" ]; then
cp "$REPO_ROOT/LICENSE.md" "$GRAMMAR_DIR/LICENSE"
elif [ -f "$REPO_ROOT/COPYING" ]; then
cp "$REPO_ROOT/COPYING" "$GRAMMAR_DIR/LICENSE"
else
echo "WARNING: No LICENSE file found for $NAME" >&2
fi
fi
echo "Vendored $NAME to $GRAMMAR_DIR"
ls -la "$GRAMMAR_DIR/"