This skill should be used when determining which Buck2 targets are affected by code changes for incremental builds and tests. Use this when users ask to test/build changed code, find affected targets, or run incremental workflows with jj revisions.
Target determination identifies which Buck2 targets are affected by code changes between two jj revisions. This enables incremental workflows that only build/test what changed, dramatically reducing build times (often 10-100x faster than full builds).
Use this skill when:
tdutil or target determinationThe tdutil tool:
'@-' and '@')--outputCritical: Always use the root// cell prefix with tdutil to avoid ambiguous cell references.
TARGETS_FILE="$(mktemp "${TMPDIR:-/tmp}/tdutil-targets.XXXXXX")"
trap 'rm -f -- "$TARGETS_FILE"' EXIT
# Defaults to parent (@-) versus current (@); limit the universe to src/.
buck2 run root//buck/tools/tdutil:tdutil -- \
--output "$TARGETS_FILE" --universe depot//src/...
# Build affected targets
buck2 build "@$TARGETS_FILE"
# Test affected targets
buck2 test "@$TARGETS_FILE"
Why at-file syntax (@path)? Target lists can be extremely large (thousands of targets), exceeding command-line length limits. At-file syntax loads targets from a file. mktemp avoids collisions between concurrent workflows, and the trap removes the file when the shell exits.
# Changes in current commit (most common)
buck2 run root//buck/tools/tdutil:tdutil -- depot//src/...
# Changes since trunk
buck2 run root//buck/tools/tdutil:tdutil -- \
--from 'trunk()' --to '@' --universe depot//src/...
# Last 3 commits
buck2 run root//buck/tools/tdutil:tdutil -- \
--from '@---' --to '@' --universe depot//src/...
# Specific commit range
buck2 run root//buck/tools/tdutil:tdutil -- \
--from 'abc123' --to 'def456' --universe depot//src/...
# Changes in pull request (compared to main)
buck2 run root//buck/tools/tdutil:tdutil -- --from 'trunk()' --to '@'
# Full repository scan
buck2 run root//buck/tools/tdutil:tdutil -- --from 'root()' --to '@'
# Only specific directory
buck2 run root//buck/tools/tdutil:tdutil -- depot//src/myproject/...
# Multiple directories
buck2 run root//buck/tools/tdutil:tdutil -- depot//src/... depot//tools/...
TARGETS_FILE="$(mktemp "${TMPDIR:-/tmp}/tdutil-targets.XXXXXX")"
trap 'rm -f -- "$TARGETS_FILE"' EXIT
# 1. Make changes
jj new -m "feat: implement feature"
# ... edit files ...
# 2. Find affected targets
buck2 run root//buck/tools/tdutil:tdutil -- --output "$TARGETS_FILE" --universe depot//src/...
# 3. Build affected targets
buck2 build "@$TARGETS_FILE"
# 4. Test affected targets
buck2 test "@$TARGETS_FILE"
# 5. If passing, commit
jj commit -m "feat: implement feature"
TARGETS_FILE="$(mktemp "${TMPDIR:-/tmp}/tdutil-targets.XXXXXX")"
trap 'rm -f -- "$TARGETS_FILE"' EXIT
# See what targets are affected
buck2 run root//buck/tools/tdutil:tdutil -- --output "$TARGETS_FILE" --universe depot//src/...
# Count affected targets
wc -l "$TARGETS_FILE"
# Show affected targets
cat "$TARGETS_FILE"
# Find which are tests
buck2 query "kind('.*_test', %Ss)" "@$TARGETS_FILE"
# Find which are binaries
buck2 query "kind('.*_binary', %Ss)" "@$TARGETS_FILE"
Use scripts/tdutil_helper.py for simplified invocations:
# Interactive mode - prompts for revsets
python3 scripts/tdutil_helper.py
# Quick patterns
python3 scripts/tdutil_helper.py --pattern current # '@-' to '@'
python3 scripts/tdutil_helper.py --pattern trunk # 'trunk()' to '@'
python3 scripts/tdutil_helper.py --pattern full # 'root()' to '@'
# Custom revsets
python3 scripts/tdutil_helper.py --from '@---' --to '@' --scope depot//src/myproject/...
# Auto-build affected targets
python3 scripts/tdutil_helper.py --pattern current --build
# Auto-test affected targets
python3 scripts/tdutil_helper.py --pattern current --test
# Both build and test
python3 scripts/tdutil_helper.py --pattern trunk --build --test
The helper provides:
Possible causes:
jj diff)depot//src/myproject/... to depot//src/...)jj status)Solution:
# Check what changed
jj diff
# Ask jj to snapshot and show the working copy
jj status
# Expand scope
buck2 run root//buck/tools/tdutil:tdutil
The root// prefix is missing. Always use:
# ✓ Correct
buck2 run root//buck/tools/tdutil:tdutil -- ...
# ✗ Wrong
buck2 run //buck/tools/tdutil:tdutil -- ...
Use at-file syntax (@filename) instead of passing targets directly:
TARGETS_FILE="$(mktemp "${TMPDIR:-/tmp}/tdutil-targets.XXXXXX")"
trap 'rm -f -- "$TARGETS_FILE"' EXIT
# ✓ Correct
buck2 run root//buck/tools/tdutil:tdutil -- --output "$TARGETS_FILE" --universe depot//src/...
buck2 test "@$TARGETS_FILE"
# ✗ Wrong (may exceed command-line limits)
buck2 test $(cat "$TARGETS_FILE")
Real-world example:
# Without target determination (builds everything)
time buck2 test depot//src/...
# → 1847 actions, 15m 23s
# With target determination (1 file changed)
TARGETS_FILE="$(mktemp "${TMPDIR:-/tmp}/tdutil-targets.XXXXXX")"
trap 'rm -f -- "$TARGETS_FILE"' EXIT
buck2 run root//buck/tools/tdutil:tdutil -- --output "$TARGETS_FILE" --universe depot//src/...
time buck2 test "@$TARGETS_FILE"
# → 12 actions, 8.3s
# → 111x faster!
root// prefix - Prevents cell reference errors@$TARGETS_FILE for multiple commands in the workflowwc -l "$TARGETS_FILE" to verify resultsdepot//buck/tests/... aren't in tdutil scopePython helper script that wraps tdutil with common patterns and better output formatting.
Comprehensive guide to jj revset patterns for use with tdutil.
npx skills add thoughtpolice/buck2-target-determination下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer