Skip to content

Commit 332d118

Browse files
authored
Merge pull request #16315 from github/redsun82/buildifier
Bazel: introduce buildifier formatting
2 parents 82bbecc + 196b6d7 commit 332d118

File tree

11 files changed

+54
-17
lines changed

11 files changed

+54
-17
lines changed

.github/workflows/buildifier.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Check bazel formatting
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "**.bazel"
7+
- "**.bzl"
8+
branches:
9+
- main
10+
- "rc/*"
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
check:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
- name: Check bazel formatting
22+
uses: pre-commit/action@646c83fcd040023954eafda54b4db0192ce70507
23+
with:
24+
extra_args: >
25+
buildifier --all-files 2>&1 ||
26+
(
27+
echo -e "In order to format all bazel files, please run:\n bazel run //:buildifier"; exit 1
28+
)

.pre-commit-config.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ repos:
2020
- id: autopep8
2121
files: ^misc/codegen/.*\.py
2222

23-
- repo: https://github.com/warchant/pre-commit-buildifier
24-
rev: 0.0.2
23+
- repo: local
2524
hooks:
2625
- id: buildifier
26+
name: Format bazel files
27+
files: \.(bazel|bzl)
28+
language: system
29+
entry: bazel run //:buildifier
30+
pass_filenames: false
2731

28-
- repo: local
29-
hooks:
3032
- id: codeql-format
3133
name: Fix QL file formatting
3234
files: \.qll?$

BUILD.bazel

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
load("@buildifier_prebuilt//:rules.bzl", "buildifier")
2+
3+
buildifier(
4+
name = "buildifier",
5+
exclude_patterns = [
6+
"./.git/*",
7+
],
8+
lint_mode = "fix",
9+
)

MODULE.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ bazel_dep(name = "abseil-cpp", version = "20240116.0", repo_name = "absl")
2222
bazel_dep(name = "nlohmann_json", version = "3.11.3", repo_name = "json")
2323
bazel_dep(name = "fmt", version = "10.0.0")
2424

25+
bazel_dep(name = "buildifier_prebuilt", version = "6.4.0", dev_dependency = True)
26+
2527
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
2628
pip.parse(
2729
hub_name = "codegen_deps",

javascript/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
load("@semmle_code//:dist.bzl", "dist")
21
load("@rules_pkg//pkg:mappings.bzl", "pkg_files")
2+
load("@semmle_code//:dist.bzl", "dist")
33
load("@semmle_code//buildutils-internal:zipmerge.bzl", "zipmerge")
44

55
package(default_visibility = ["//visibility:public"])

javascript/extractor/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
load("@semmle_code//:common.bzl", "codeql_fat_jar", "codeql_java_project")
21
load("@rules_pkg//pkg:mappings.bzl", "pkg_files")
2+
load("@semmle_code//:common.bzl", "codeql_fat_jar", "codeql_java_project")
33

44
java_library(
55
name = "deps",

misc/codegen/BUILD.bazel

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
load("@codegen_deps//:requirements.bzl", "requirement")
2-
31
py_binary(
42
name = "codegen",
53
srcs = ["codegen.py"],

misc/codegen/generators/BUILD.bazel

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
load("@codegen_deps//:requirements.bzl", "requirement")
2-
31
py_library(
42
name = "generators",
53
srcs = glob(["*.py"]),

python/extractor/tsg-python/tsp/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
load("@py_deps//:defs.bzl", "aliases", "all_crate_deps")
12
load("@rules_rust//cargo:defs.bzl", "cargo_build_script")
23
load("@rules_rust//rust:defs.bzl", "rust_library")
3-
load("@py_deps//:defs.bzl", "aliases", "all_crate_deps")
44

55
package(default_visibility = ["//visibility:public"])
66

swift/extractor/BUILD.bazel

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
load("//swift:rules.bzl", "swift_cc_binary")
21
load("//misc/bazel:pkg_runfiles.bzl", "pkg_runfiles")
2+
load("//swift:rules.bzl", "swift_cc_binary")
33

44
swift_cc_binary(
55
name = "extractor.real",
66
srcs = glob([
77
"*.h",
88
"*.cpp",
99
]),
10+
linkopts = select({
11+
"@platforms//os:macos": ["-headerpad_max_install_names"],
12+
"//conditions:default": [],
13+
}),
1014
visibility = ["//swift:__pkg__"],
1115
deps = [
1216
"//swift/extractor/config",
@@ -17,10 +21,6 @@ swift_cc_binary(
1721
"//swift/third_party/swift-llvm-support",
1822
"@absl//absl/strings",
1923
],
20-
linkopts = select({
21-
"@platforms//os:macos": ["-headerpad_max_install_names"],
22-
"//conditions:default": [],
23-
}),
2424
)
2525

2626
sh_binary(

0 commit comments

Comments
 (0)