Skip to content

Commit 5404ad7

Browse files
authored
Add versioned, automatically installed 'buildifier' pre-commit hook. (iree-org#17589)
ლ(ಠ益ಠლ) Progress on iree-org#17430 This runs [`buildifier`](https://github.com/bazelbuild/buildtools/tree/master/buildifier) to format `BUILD.bazel`, `WORKSPACE`, and other [Bazel build system](https://bazel.build/) files. * Sample manual usage showing it working: https://gist.github.com/ScottTodd/615416803b5595e9b9c4cffb3b83b1b9. It can also run automatically via the git hook. * ~~The current version of `buildifier` changes line endings on Windows when it really shouldn't. Not sure how I want to fix or work around that.~~ ("fixed" by adding a `.gitattributes` file)
1 parent 6a43e05 commit 5404ad7

File tree

75 files changed

+103
-153
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+103
-153
lines changed

.gitattributes

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# See https://github.com/bazelbuild/buildtools/issues/914.
2+
# The buildifier tool used to format Bazel files decided that, despite claiming
3+
# to support Windows, it should convert line endings from \r\n to \n.
4+
# This conflicts with the `git config core.autocrlf` setting so unfortunate
5+
# users such as us are thus forced to either:
6+
# * get trivial line ending diffs on every change to a file
7+
# * constantly run `git add . --renormalize`
8+
# * override the git setting here
9+
*.bazel text eol=lf
10+
*.bzl text eol=lf
11+
WORKSPACE text eol=lf

.github/workflows/lint.yml

-23
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,6 @@ jobs:
2424
- name: Running pre-commit
2525
uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
2626

27-
buildifier:
28-
runs-on: ubuntu-20.04
29-
steps:
30-
- name: Checking out repository
31-
uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
32-
- name: Fetching Base Branch
33-
# We have to explicitly fetch the base branch as well
34-
run: git fetch --no-tags --prune --depth=1 origin "${GITHUB_BASE_REF?}:${GITHUB_BASE_REF?}"
35-
- name: Downloading Buildifier
36-
run: |
37-
mkdir -p "${HOME?}/bin"
38-
wget https://github.com/bazelbuild/buildtools/releases/download/4.0.1/buildifier -O "${HOME?}/bin/buildifier"
39-
chmod +x "${HOME?}/bin/buildifier"
40-
echo "${HOME?}/bin" >> $GITHUB_PATH
41-
- name: Running buildifier on changed files
42-
run: |
43-
# Fail if the script fails (unfixable lint warnings) or it creates a
44-
# diff (fixable lint warnings or formatting).
45-
EXIT_CODE=0
46-
./build_tools/scripts/run_buildifier.sh "${GITHUB_BASE_REF?}" || EXIT_CODE=1
47-
git diff --exit-code
48-
exit "${EXIT_CODE?}"
49-
5027
pytype:
5128
runs-on: ubuntu-20.04
5229
steps:

.pre-commit-config.yaml

+19-7
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,29 @@ repos:
6060
- repo: https://github.com/jlebar/pre-commit-hooks.git
6161
rev: f2d115a052860b09b2888b4f104be614bf3b4779
6262
hooks:
63-
# TODO(scotttodd): Download as needed
64-
# https://github.com/jlebar/pre-commit-hooks/issues/3
65-
# TODO(scotttodd): enable when this works on Windows
66-
# https://github.com/bazelbuild/buildtools/issues/914
67-
# could try `git add . --renormalize`
68-
# - id: bazel-buildifier
69-
7063
- id: do-not-submit
7164

7265
- repo: local
7366
hooks:
67+
- id: buildifier
68+
name: Run buildifier
69+
entry: buildifier
70+
language: golang
71+
# Pinned to v7.1.2, but of course we can't use a tag because semver
72+
# and "go install" just don't work together???
73+
# This makes absolutely no sense and the maintainers have no intention
74+
# of improving it or at least explaining it as hundreds of developers
75+
# search for basic support: https://github.com/golang/go/issues/35732.
76+
# Docs are technically at https://go.dev/ref/mod#go-install ¯\_(ツ)_/¯
77+
additional_dependencies: ["github.com/bazelbuild/buildtools/buildifier@1429e15ae755a6762d0edf9198062dc6ed04408d"]
78+
files: '^(.*/)?(BUILD\.bazel|BUILD|WORKSPACE|WORKSPACE\.bazel|WORKSPACE\.bzlmod|MODULE\.bazel)$|\.BUILD$|\.bzl$'
79+
# Pin the language version so other system version are _not_ used.
80+
# Older go versions used different syntax for "go install" (which is
81+
# apparently different from "go get" and "go build"), so for this to
82+
# work reliably at all we need to ensure at least some minimum. Syntax
83+
# probably changed again in a future version, whatever.
84+
language_version: "1.16"
85+
7486
- id: bazel_to_cmake
7587
name: Run bazel_to_cmake.py
7688
language: python

WORKSPACE

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ llvm_configure(name = "llvm-project")
4949
load("//build_tools/bazel:workspace.bzl", "configure_iree_cuda_deps", "configure_iree_submodule_deps")
5050

5151
configure_iree_submodule_deps()
52+
5253
configure_iree_cuda_deps()
5354

5455
###############################################################################
@@ -71,6 +72,6 @@ maybe(
7172
sha256 = "7c42d56fac126929a6a85dbc73ff1db2411d04f104fae9bdea51305663a83fd0",
7273
strip_prefix = "zstd-1.5.2",
7374
urls = [
74-
"https://github.com/facebook/zstd/releases/download/v1.5.2/zstd-1.5.2.tar.gz"
75+
"https://github.com/facebook/zstd/releases/download/v1.5.2/zstd-1.5.2.tar.gz",
7576
],
7677
)

build_tools/scripts/run_buildifier.sh

-52
This file was deleted.

compiler/plugins/input/StableHLO/Conversion/Preprocessing/test/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# See https://llvm.org/LICENSE.txt for license information.
55
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66

7-
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
87
load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
8+
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
99

1010
package(
1111
features = ["layering_check"],

compiler/plugins/input/StableHLO/Conversion/test/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# See https://llvm.org/LICENSE.txt for license information.
55
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66

7-
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
87
load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
8+
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
99

1010
package(
1111
features = ["layering_check"],

compiler/plugins/input/TOSA/InputConversion/test/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# See https://llvm.org/LICENSE.txt for license information.
55
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66

7-
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
87
load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
8+
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
99

1010
package(
1111
features = ["layering_check"],

compiler/plugins/target/LLVMCPU/test/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# See https://llvm.org/LICENSE.txt for license information.
55
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66

7-
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
87
load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
8+
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
99

1010
package(
1111
features = ["layering_check"],

compiler/plugins/target/MetalSPIRV/test/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# See https://llvm.org/LICENSE.txt for license information.
55
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66

7-
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
87
load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
8+
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
99

1010
package(
1111
features = ["layering_check"],

compiler/plugins/target/VMVX/test/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# See https://llvm.org/LICENSE.txt for license information.
55
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66

7-
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
87
load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
8+
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
99

1010
package(
1111
features = ["layering_check"],

compiler/plugins/target/VulkanSPIRV/test/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# See https://llvm.org/LICENSE.txt for license information.
55
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66

7-
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
87
load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
8+
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
99

1010
package(
1111
features = ["layering_check"],

compiler/src/iree/compiler/Bindings/Native/Transforms/test/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# See https://llvm.org/LICENSE.txt for license information.
55
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66

7-
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
87
load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
8+
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
99

1010
package(
1111
features = ["layering_check"],

compiler/src/iree/compiler/Bindings/TFLite/Transforms/test/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# See https://llvm.org/LICENSE.txt for license information.
55
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66

7-
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
87
load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
8+
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
99

1010
package(
1111
features = ["layering_check"],

compiler/src/iree/compiler/Codegen/Common/CPU/test/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
# Tests for common transforms.
88

9-
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
109
load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
10+
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
1111

1212
package(
1313
features = ["layering_check"],

compiler/src/iree/compiler/Codegen/Dialect/Codegen/IR/test/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
# Tests for common transforms.
88

9-
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
109
load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
10+
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
1111

1212
package(
1313
features = ["layering_check"],

compiler/src/iree/compiler/Codegen/Dialect/GPU/IR/test/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
# Tests for common transforms.
88

9-
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
109
load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
10+
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
1111

1212
package(
1313
features = ["layering_check"],

compiler/src/iree/compiler/Codegen/Dialect/GPU/TransformExtensions/test/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
# Tests for common transforms.
88

9-
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
109
load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
10+
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
1111

1212
package(
1313
features = ["layering_check"],

compiler/src/iree/compiler/Codegen/Dialect/GPU/Transforms/test/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
# Tests for iree_gpu transforms.
88

9-
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
109
load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
10+
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
1111

1212
package(
1313
features = ["layering_check"],

compiler/src/iree/compiler/Codegen/VMVX/test/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
# Tests for common transforms.
88

9-
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
109
load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
10+
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
1111

1212
package(
1313
features = ["layering_check"],

compiler/src/iree/compiler/Codegen/WGSL/test/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# See https://llvm.org/LICENSE.txt for license information.
55
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66

7-
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
87
load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
8+
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
99

1010
package(
1111
features = ["layering_check"],

compiler/src/iree/compiler/ConstEval/test/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# See https://llvm.org/LICENSE.txt for license information.
55
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66

7-
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
87
load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
8+
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
99

1010
package(
1111
features = ["layering_check"],

compiler/src/iree/compiler/Dialect/Flow/Conversion/MeshToFlow/test/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# See https://llvm.org/LICENSE.txt for license information.
55
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66

7-
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
87
load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
8+
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
99

1010
package(
1111
features = ["layering_check"],

compiler/src/iree/compiler/Dialect/Flow/Conversion/TensorToFlow/test/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# See https://llvm.org/LICENSE.txt for license information.
55
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66

7-
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
87
load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
8+
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
99

1010
package(
1111
features = ["layering_check"],

compiler/src/iree/compiler/Dialect/Flow/IR/test/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# See https://llvm.org/LICENSE.txt for license information.
55
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66

7-
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
87
load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
8+
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
99

1010
package(
1111
features = ["layering_check"],

compiler/src/iree/compiler/Dialect/HAL/Conversion/HALToHAL/test/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# See https://llvm.org/LICENSE.txt for license information.
55
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66

7-
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
87
load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
8+
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
99

1010
package(
1111
features = ["layering_check"],

compiler/src/iree/compiler/Dialect/HAL/Conversion/HALToVM/test/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# See https://llvm.org/LICENSE.txt for license information.
55
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66

7-
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
87
load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
8+
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
99

1010
package(
1111
features = ["layering_check"],

compiler/src/iree/compiler/Dialect/HAL/Conversion/StandardToHAL/test/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# See https://llvm.org/LICENSE.txt for license information.
55
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66

7-
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
87
load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
8+
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
99

1010
package(
1111
features = ["layering_check"],

compiler/src/iree/compiler/Dialect/HAL/Conversion/UtilToHAL/test/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# See https://llvm.org/LICENSE.txt for license information.
55
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66

7-
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
87
load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
8+
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
99

1010
package(
1111
features = ["layering_check"],

compiler/src/iree/compiler/Dialect/HAL/IR/test/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# See https://llvm.org/LICENSE.txt for license information.
55
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66

7-
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
87
load("//build_tools/bazel:enforce_glob.bzl", "enforce_glob")
8+
load("//build_tools/bazel:iree_lit_test.bzl", "iree_lit_test_suite")
99

1010
package(
1111
features = ["layering_check"],

0 commit comments

Comments
 (0)