Add --bcce-color, --bcce-compiler, --bcce-copt runtime flags - #14
Merged
Conversation
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
force-pushed
the
backport/122-custom-control-args-v2
branch
from
May 17, 2026 12:04
2381d1a to
abd4cbb
Compare
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds runtime command-line knobs (parsed from
sys.argvat runtime, after the--separator thatbazel runpasses through):--bcce-color[=auto|yes|no](and--nobcce-color)autoconsults TTY +NO_COLOR/TERM.--bcce-compiler=<path>--bcce-copt=<flag>--bcce-threads=<N>--bcce-output-dir=<dir>compile_commands.jsonis written to.--bcce-exclude-headers=all|external|noneexclude_headersfor 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_argsfactor 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_filesgains a_manual_platform_patchpass that applies--bcce-compilerand--bcce-copt.README gains a "Customizing the compile_commands.json generation" section documenting all six flags (placeholder copy — rewrite expected).
Decisions
--bcce-bazelintentionally not added. bazelisk +.bazelversionalready covers version selection; the macrobazel_commandcovers the binary-path case; a runtime override would invite confusion about whichbazelgot 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:bazel_command+max_threads(backport of hedronvision#215)output_dir(backport of hedronvision#210)The earlier branch's apparent removals of
nvcc_clang_diff.py,print_args.cpp,renovate.json5, and the transitiveworkspace_setup_*.bzlfiles 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_allwith 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 inbuild/compile_commands.json)... -- --bcce-exclude-headers=all(no header entries in output)