Something went wrong. Try again.
Identities for entities did.bot
agent llm did
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394#!/usr/bin/env bash# Builds the workspace reference index and asks it a question.## Usage: scripts/xray.sh <query> [args...]# scripts/xray.sh build # rebuild and stop## The queries are dead-pub, refs, crate-edges, file-items and info; run# `scripts/xray.sh info` for what the current index was built from, and see# tools/README.md for what each one answers.## The index is rebuilt when .xray/index.db is missing or was built from a# different revision than HEAD. It is not rebuilt for uncommitted edits, which# is the one way to get a stale answer: pass `build` after editing.## Three steps, because no single tool knows everything the index needs:## 1. `rust-analyzer scip` for the reference edges. Nothing else resolves a# name through modules, re-exports, trait impls and macros the way the# compiler does. Around 90 seconds and 4 GB on this workspace.# 2. `cargo doc --output-format json` for the item inventory -- kind,# visibility, module path and source span, none of which SCIP carries.# Nightly only, and run twice: rustdoc names its output after the crate,# and five packages here have a bin sharing their lib's name, so one run# into one directory would lose half of them.# 3. `xray build`, which joins the two into .xray/index.db.## Every step runs with all cargo features on. A dump taken with default# features reports everything behind an off feature as unreferenced, which is# the false "this is dead" the index exists to stop producing.set -euo pipefail
cd "$(dirname "$0")/.."
XRAY_DIR=.xrayTARGET_DIR=${CARGO_TARGET_DIR:-target}DB=$XRAY_DIR/index.dbBIN=$TARGET_DIR/release/xray
rebuild() { command -v rust-analyzer >/dev/null || { echo "xray: rust-analyzer is not installed (rustup component add rust-analyzer)" >&2; exit 1; } cargo +nightly --version >/dev/null 2>&1 || { echo "xray: rustdoc JSON needs a nightly toolchain (rustup toolchain install nightly)" >&2; exit 1; }
mkdir -p "$XRAY_DIR" cargo build --release --manifest-path tools/Cargo.toml --target-dir "$TARGET_DIR"
echo '{"cargo": {"features": "all", "allTargets": true}}' > "$XRAY_DIR/rust-analyzer.json" rust-analyzer scip . \ --config-path "$XRAY_DIR/rust-analyzer.json" \ --output "$XRAY_DIR/workspace.scip"
local doc="cargo +nightly doc --workspace --no-deps --all-features --document-private-items -Zunstable-options --output-format json" for kind in bins lib; do # Emptied first: rustdoc writes one file per crate and leaves whatever an # earlier run put there, so a directory kept across runs would hand the # index a mix of configurations. rm -rf "$TARGET_DIR/doc" "$XRAY_DIR/doc-$kind" # shellcheck disable=SC2086 $doc --"$kind" mkdir -p "$XRAY_DIR/doc-$kind" cp "$TARGET_DIR"/doc/*.json "$XRAY_DIR/doc-$kind/" done
"$BIN" --db "$DB" build \ --workspace . \ --scip "$XRAY_DIR/workspace.scip" \ --docs "$XRAY_DIR/doc-bins" \ --docs "$XRAY_DIR/doc-lib" \ --rev "$(git rev-parse HEAD)"}
stale() { [ -f "$DB" ] || return 0 [ -x "$BIN" ] || return 0 local built built=$("$BIN" --db "$DB" info 2>/dev/null | awk -F'\t' '$1 == "revision" { print $2 }') [ "$built" != "$(git rev-parse HEAD)" ]}
case "${1-}" in build) rebuild ;; "" | -h | --help) exec "$BIN" --help ;; *) if stale; then rebuild >&2; fi exec "$BIN" --db "$DB" "$@" ;;esac