Selaa lähdekoodia

Update pre-commit for bazel mod deps (#3525)

I feel kind of weird adding a pre-commit for this, but I think it may
make validating #3524 easier.
Jon Ross-Perkins 2 vuotta sitten
vanhempi
sitoutus
3885a3ba6e
2 muutettua tiedostoa jossa 35 lisäystä ja 0 poistoa
  1. 12 0
      .pre-commit-config.yaml
  2. 23 0
      scripts/bazel_mod_deps.py

+ 12 - 0
.pre-commit-config.yaml

@@ -63,9 +63,21 @@ repos:
         files: |
           (?x)^(
             .*BUILD.*|
+            .*MODULE.bazel.*|
             .*WORKSPACE.*|
             .*\.bzl
           )$
+      - id: check-bazel-mod-deps
+        # Check this after buildifier because buildifier may modify inputs, and
+        # MODULE.bazel.lock includes line/column details.
+        name: Check bazel mod deps
+        entry: scripts/bazel_mod_deps.py
+        language: python
+        files: |
+          (?x)^(
+            .*MODULE.bazel.*
+            .*WORKSPACE.*|
+          )$
       - id: clang-format
         name: clang-format
         entry: clang-format

+ 23 - 0
scripts/bazel_mod_deps.py

@@ -0,0 +1,23 @@
+#!/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", "deps"])
+
+
+if __name__ == "__main__":
+    main()