Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: add bazel support#308

Open
cmolder wants to merge 6 commits intortk-ai:masterfrom
cmolder:bazel
Open

feat: add bazel support#308
cmolder wants to merge 6 commits intortk-ai:masterfrom
cmolder:bazel

Conversation

@cmolder
Copy link

@cmolder cmolder commented Mar 3, 2026

Adds support for bazel query, bazel build, bazel test, and bazel run commands.

It introduces:

  • rtk bazel build
  • rtk bazel test
  • rtk bazel run
  • rtk bazel query
  • passthrough for other bazel subcommands

The implementation is in src/bazel_cmd.rs, with command wiring in src/main.rs.

Motivation

Raw Bazel output is very noisy and expensive to consume. This change allows rtk to shrink Bazel outputs and remove a bunch of noise, similar to cargo, go, and npm, with compact summaries, focused diagnostics, and predictable truncation.

What Changed

CLI integration

  • Add bazel command group in src/main.rs.
  • Add subcommands build, run, test, query, with fallback for others.
  • Add --depth and --width arguments for rtk bazel query to handle large results (can shrink by >90%)

bazel build

  • Strips progress/status noise (Loading, Analyzing, INFO, progress bars)
  • Preserves and summarizes ERROR: and WARNING: lines
  • Preserves compiler diagnostic blocks
  • Includes action counts when available

bazel test

  • Summarizes pass/fail/cached outcomes.
  • Preserves failing target context and relevant test output.
  • Removes routine progress/info noise.

bazel run

  • Filters out build noise while preserving the full output of the underlying target
  • Uses the string Running command line: as a sentinel to identify when Bazel begins running the actual target
  • Preserves and prints all of the stdout/stderr output after the sentinel

bazel query

  • Groups targets and packages together for smaller output
  • Supports both local (starts with //) and external (starts with @package_name//) packages.
  • --depth flag moves grouping to lower levels (e.g. --depth=1 groups //src together, while --depth=2 groups //src/foo, //src/bar, etc. separately)
  • --width flag limits how many packages/targets are listed per group, with the rest being summarized as (+N more...)
  • Uses 📦 to represent packages and 🎯 to represent targets

Docs

  • Updated CLAUDE.md command/module table to include bazel_cmd.rs.

Testing

cargo test bazel_cmd -- --nocapture

To generate the test cases and evaluate the system, I used the https://github.com/bazelbuild/bazel repository, which uses Bazel to build itself. Here are some samples I checked:

  • bazel query "//src/..."
  • bazel query "//tools/..."
  • bazel query "kind(rule, //src/... + //tools/...)"
  • bazel query "deps(//src:bazel-dev)"
  • bazel build "//src:bazel-dev"
  • bazel query "@bazel_skylib//..."

cmolder and others added 6 commits March 2, 2026 22:56
Add Bazel support to RTK with `rtk bazel query` for grouped, hierarchical
target output. Strips stderr noise (INFO/WARNING/DEBUG), groups targets by
package, and renders a depth/width-controlled tree with cumulative counts.
Unsupported bazel subcommands pass through transparently.

Output uses 📦 for sub-packages and 🎯 for targets, with a header showing
total counts. Default --depth 1 --width 10 collapses large repos (e.g.
2,782 lines on the bazel repo) to ~8 top-level summary lines. --depth all
--width all shows everything.

- Limit type (number or "all") with FromStr for Clap
- TreeNode with cumulative_targets/cumulative_packages for subtree counts
- Width budget: sub-packages first, remaining slots for targets
- Condensed truncation: (+N more sub-packages, M more targets)
- detect_query_root extracts //path/... for scoped queries
- Passthrough for all other bazel subcommands (build, test, etc.)
- Exit code propagation, tee output recovery on failure
- 24 tests covering depth, width, truncation, relative names, edge cases

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Strip progress lines, INFO/DEBUG noise, Loading/Analyzing status,
Java notes, and target output paths. Keep ERROR/WARNING lines and
compiler diagnostics (gcc/clang warning:/error: blocks with context).

Success: "✓ bazel build (N actions)"
Issues:  header + error/warning blocks, truncated at 15

10 new tests including token savings verification (≥60%).

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Strip build noise (progress, INFO, Loading, Analyzing) and test
metadata, showing only a one-liner on success or FAIL blocks with
inline test output on failure. 9 tests covering all-pass, cached,
failure with inline output, build errors, and ≥60% token savings.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Add filter_bazel_run() that splits stderr at the "INFO: Running
command line:" sentinel, strips build noise from the build phase,
and forwards binary stdout/stderr verbatim. Clean builds show only
binary output; build errors show a separate build section with
errors and warnings for context.

Also refactors shared bazel filtering:
- Add strip_timestamp() helper to normalize "(HH:MM:SS) " prefixes,
  replacing 6 redundant _PLAIN/_WITH_TIMESTAMP regex pairs
- Simplify RUN_SENTINEL regex (timestamp handled by helper)
- Fix ACTION_COUNT regex to match singular "1 total action"
- Apply strip_timestamp to filter_bazel_build and filter_bazel_test

13 tests covering: clean build, warnings stripped, errors with/without
warnings, binary stderr, no sentinel fallback, timestamped lines,
post-sentinel INFO stripped, real-world output, and ≥60% token savings.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- remove detect-root tuple plumbing and default empty headers to //
- replace recursive tree query renderer with output-driven package index
- keep external repo grouping and subsection depth semantics
- preserve truncation/count behavior and associated bazel query tests

Co-authored-by: Codex <[email protected]>
- rewrite bazel build/test/run/query/aquery/cquery to rtk bazel
- add hook test coverage for bazel rewrite and env-prefixed cases
- document bazel rewrite mapping in README

Co-authored-by: Codex <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant