Files
carbon-lang/scripts/bazel_mod_deps.py
T
Chandler Carruth bb59a0b1d8 Optimize pre-commit checks (#7229)
First, this makes the Bazel invocations not try to uses curses which
prevents running them with `pre-commit run ... -v` showing the timings
for each check. The curses display overwrote the output.

Second, this fixes the main slowdown I was seeing. Because we passed
_all_ files to the check-build-graph hook and there are large number of
files, pre-commit would run the tool over and over on a subset of the
files. This is especially wasteful as the build graph check already
doesn't do anything with the files, it just checks `//...` on each
invocation. So this just added a (large) constant factor of cost.

Third, this tries to reduce the cost of `fix_cc_deps.py` in the case of
large numbers of files. This still isn't _super_ fast -- but the rest of
the cost is in running the `bazel query` and parsing the output. I tried
switching it to jsonproto and it wasn't any faster. I think this would
need to be in a non-Python language and use `proto` directly to
significantly improve the cost here.

Assisted-by: Antigravity with Gemini
2026-05-19 15:51:33 +00:00

24 lines
551 B
Python
Executable File

#!/usr/bin/env python3
"""Run `bazel mod deps` for pre-commit. Lets pre-commit handle modifications."""
__copyright__ = """
Part of the Carbon Language project, under the Apache License v2.0 with LLVM
Exceptions. See /LICENSE for license information.
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""
import subprocess
import scripts_utils
def main() -> None:
scripts_utils.chdir_repo_root()
bazel = scripts_utils.locate_bazel()
subprocess.run([bazel, "mod", "--curses=no", "deps"])
if __name__ == "__main__":
main()