diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 45212ef19e25..963e92559353 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -229,6 +229,19 @@ repos: .*/testdata/.*\.golden )$ - id: check-links + - repo: local + hooks: + - id: check-build-graph + name: Check build graph + entry: scripts/check_build_graph.py + language: python + files: | + (?x)^( + .*BUILD.*| + .*MODULE.bazel.*| + .*WORKSPACE.*| + .*\.bzl + )$ # This excludes third-party code, and patches to third-party code. exclude: | diff --git a/scripts/check_build_graph.py b/scripts/check_build_graph.py new file mode 100755 index 000000000000..d9237d541fc4 --- /dev/null +++ b/scripts/check_build_graph.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 + +"""Verify that the bazel build graph is in a valid state, for pre-commit.""" + +__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.check_call([bazel, "build", "--nobuild", "//..."]) + + +if __name__ == "__main__": + main()