Skip to content

Commit abd4cbb

Browse files
committed
Add runtime overrides --bcce-threads and --bcce-output-dir
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.
1 parent e786a7f commit abd4cbb

2 files changed

Lines changed: 26 additions & 5 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ The tool has a few parameters that control output generation:
191191
* `--bcce-color[=`_auto_`]` — Enable or disable colored output. Useful for environments where the color codes are not handled (e.g. the VSCode OUTPUT window). With the default `auto`, the environment is consulted (both [`NO_COLOR`](https://no-color.org) and `TERM`). To force off, use `0`/`no`, or pass `--nobcce-color`. To force on, use `1`/`yes`.
192192
* `--bcce-compiler[=`_compiler_`]` — Override the detected compiler. Useful if the compiler found in the editor environment is different from the one that should appear in `compile_commands.json`. May interfere with cross-compilation. If the goal is to retarget `clangd`, the [clangd compileflags](https://clangd.llvm.org/config#compileflags) config can do this on the `clangd` side instead.
193193
* `--bcce-copt[=`_option_`]` — Pass an additional `option` to every arg list in `compile_commands.json` (can be repeated). As above, you can also do this on the `clangd` side via compileflags.
194+
* `--bcce-threads[=`_N_`]` — Override the worker-pool size for one run. Falls back to the macro `max_threads`, then the executor default (`os.cpu_count()`).
195+
* `--bcce-output-dir[=`_dir_`]` — Override the directory `compile_commands.json` is written to. Falls back to the macro `output_dir`, then the workspace root.
194196

195197
As with options passed through to `bazel aquery`, these flags must be separated from the bazel invocation by `--`. For example, to suppress colored output:
196198

refresh.template.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,32 @@ def _bazel():
5454

5555

5656
def _threads():
57-
"""User-requested worker pool size, or the executor default if unset."""
57+
"""Worker pool size: --bcce-threads > macro `max_threads` > executor default.
58+
59+
Returning `None` lets ProcessPoolExecutor pick its own default
60+
(os.cpu_count(), which becomes os.process_cpu_count() on Python 3.13+).
61+
"""
62+
runtime = _get_last_arg('bcce-threads')
63+
if runtime:
64+
try:
65+
n = int(runtime)
66+
if n > 0:
67+
return n
68+
except ValueError:
69+
pass
70+
log_warning(f">>> Ignoring invalid --bcce-threads={runtime!r}; must be a positive integer.")
5871
user_max_threads = {max_threads}
59-
# `None` lets ProcessPoolExecutor pick its own default (os.cpu_count(),
60-
# which becomes os.process_cpu_count() on Python 3.13+).
6172
return user_max_threads if user_max_threads else None
6273

6374

75+
def _output_dir():
76+
"""Output directory: --bcce-output-dir > macro `output_dir` > workspace root."""
77+
runtime = _get_last_arg('bcce-output-dir')
78+
if runtime is not None:
79+
return runtime
80+
return {output_dir}
81+
82+
6483
@functools.lru_cache(maxsize=None)
6584
def _non_bcce_args():
6685
"""Returns `sys.argv[1:]` with all bcce args removed."""
@@ -1564,8 +1583,8 @@ def main():
15641583
There should be actionable warnings, above, that led to this.""")
15651584
sys.exit(1)
15661585

1567-
# Resolve the output path; `output_dir` is the macro parameter (empty == cwd).
1568-
output_path = os.path.join({output_dir}, 'compile_commands.json')
1586+
# Resolve the output path: `--bcce-output-dir` flag > macro `output_dir` > workspace root.
1587+
output_path = os.path.join(_output_dir(), 'compile_commands.json')
15691588

15701589
# Remove any existing compile_commands.json before opening; handles the common
15711590
# case where it's a symlink (e.g. pointing into a cmake build dir), which would

0 commit comments

Comments
 (0)