Skip to content

Add --bcce-color, --bcce-compiler, --bcce-copt runtime flags - #14

Merged
helly25 merged 4 commits into
mainfrom
backport/122-custom-control-args-v2
May 17, 2026
Merged

Add --bcce-color, --bcce-compiler, --bcce-copt runtime flags#14
helly25 merged 4 commits into
mainfrom
backport/122-custom-control-args-v2

Conversation

@helly25

@helly25 helly25 commented May 17, 2026

Copy link
Copy Markdown
Owner

Summary

Adds runtime command-line knobs (parsed from sys.argv at runtime, after the -- separator that bazel run passes through):

Flag Purpose
--bcce-color[=auto|yes|no] (and --nobcce-color) Colored output. Default auto consults TTY + NO_COLOR / TERM.
--bcce-compiler=<path> Override the detected compiler.
--bcce-copt=<flag> Append an extra option to every compile command (repeatable).
--bcce-threads=<N> Override the worker-pool size for one run.
--bcce-output-dir=<dir> Override the directory compile_commands.json is written to.
--bcce-exclude-headers=all|external|none Override exclude_headers for one run. none (or empty) restores the macro default.

Precedence: runtime flag > macro param > default.

Helpers _get_args / _get_last_arg / _get_bool_arg / _non_bcce_args factor out the lookups; color decisions route through _can_do_color(); thread count via _threads(); output dir via _output_dir(); header-exclusion mode via _exclude_headers(); the platform-patch chain in _get_cpp_command_for_files gains a _manual_platform_patch pass that applies --bcce-compiler and --bcce-copt.

README gains a "Customizing the compile_commands.json generation" section documenting all six flags (placeholder copy — rewrite expected).

Decisions

  • --bcce-bazel intentionally not added. bazelisk + .bazelversion already covers version selection; the macro bazel_command covers the binary-path case; a runtime override would invite confusion about which bazel got used (outer or inner). Discussion in the PR thread.

Upstream context

Rebase of the long-standing fork branch custom-control-args (corresponds to hedronvision#122, opened May 2023 by @helly25), extended with runtime overrides for the new macro params landed via:

The earlier branch's apparent removals of nvcc_clang_diff.py, print_args.cpp, renovate.json5, and the transitive workspace_setup_*.bzl files were branch-drift artefacts (the branch base predated those files); none of those deletions are reproduced here.

Test plan

  • bazel run @hedron_compile_commands//:refresh_all with no extra args (regression)
  • ... -- --bcce-color=no (suppressed color)
  • ... -- --bcce-compiler=/usr/bin/clang-19 (compiler override appears)
  • ... -- --bcce-copt=-Wno-foo --bcce-copt=-Wno-bar (repeated copts appear)
  • ... -- --bcce-threads=1 (single-threaded run)
  • ... -- --bcce-output-dir=build (output in build/compile_commands.json)
  • ... -- --bcce-exclude-headers=all (no header entries in output)

helly25 added 2 commits May 17, 2026 13:00
Adds runtime command-line knobs (parsed from sys.argv at runtime, after
the `--` separator passed to `bazel run @hedron_compile_commands//...`):

* `--bcce-color[=auto|yes|no]` (and `--nobcce-color`): controls colored
  output. Default `auto` consults TTY-detection plus NO_COLOR / TERM.
* `--bcce-compiler=<path>`: override the detected compiler.
* `--bcce-copt=<flag>`: append an extra option to every compile command
  in compile_commands.json (repeatable).

Helpers (`_get_args`, `_get_last_arg`, `_get_bool_arg`, `_non_bcce_args`)
factor out the lookups. Color decisions go through `_can_do_color()`.
The platform-patch chain in `_get_cpp_command_for_files` gains a
`_manual_platform_patch` pass that applies `--bcce-compiler` and
`--bcce-copt`.

README gets a short "Customizing the compile_commands.json generation"
section documenting all three flags.

Backport of hedronvision#122 (helly25),
rebased onto current main (was branched May 2023; resolved conflicts
against the bcce-color, bazel_command, max_threads, and parse-headers
backports landed since).
Make the macro-level `max_threads` and `output_dir` settings overridable
at runtime via flags after the `--` separator on `bazel run`. Precedence
is runtime flag > macro param > default.

* `--bcce-threads=N` plugs into the existing `_threads()` helper that
  feeds `ProcessPoolExecutor(max_workers=...)`. Invalid values warn and
  fall through to the macro/default.
* `--bcce-output-dir=DIR` is consulted via a new `_output_dir()` helper
  used by the `compile_commands.json` write path.

README's "Customizing the compile_commands.json generation" section
gains entries for both flags.

Same `--bcce-*` pattern as hedronvision#122; same precedence rule.
@helly25
helly25 force-pushed the backport/122-custom-control-args-v2 branch from 2381d1a to abd4cbb Compare May 17, 2026 12:04
helly25 added 2 commits May 17, 2026 13:08
Make the macro-level `exclude_headers` setting overridable at runtime.
Accepts "all", "external", or "none" (empty); invalid values warn and
fall through to the macro default. Same precedence as the other
--bcce-* flags: runtime > macro > default.

The four `{exclude_headers}`-substitution sites in `refresh.template.py`
now route through a new `_exclude_headers()` helper. The helper itself
keeps the template substitution as the fallback so the macro param is
still honoured.

README's "Customizing the compile_commands.json generation" section
documents the new flag.
Adds a "Why isn't there a `--bcce-bazel` runtime flag?" subsection to
the README explaining: bazelisk + .bazelversion already handles version
selection; outer `bazel run` already fixes the binary at invocation;
the `bazel_command` macro param covers the legitimate per-target cases.

Also documents *what reversing the decision would take* (a small,
additive change in `_bazel()`) so future maintainers don't have to
rediscover the trade-off.

Mirrors the rationale next to the `bazel_command` parameter in
refresh_compile_commands.bzl.
@helly25
helly25 merged commit 7c72b59 into main May 17, 2026
@helly25
helly25 deleted the backport/122-custom-control-args-v2 branch May 17, 2026 12:11
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