Skip to content

Commit

Permalink
Merge pull request #16315 from github/redsun82/buildifier
Browse files Browse the repository at this point in the history
Bazel: introduce buildifier formatting
  • Loading branch information
redsun82 authored Apr 25, 2024
2 parents 82bbecc + 196b6d7 commit 332d118
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 17 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/buildifier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Check bazel formatting

on:
pull_request:
paths:
- "**.bazel"
- "**.bzl"
branches:
- main
- "rc/*"

permissions:
contents: read

jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check bazel formatting
uses: pre-commit/action@646c83fcd040023954eafda54b4db0192ce70507
with:
extra_args: >
buildifier --all-files 2>&1 ||
(
echo -e "In order to format all bazel files, please run:\n bazel run //:buildifier"; exit 1
)
10 changes: 6 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ repos:
- id: autopep8
files: ^misc/codegen/.*\.py

- repo: https://github.com/warchant/pre-commit-buildifier
rev: 0.0.2
- repo: local
hooks:
- id: buildifier
name: Format bazel files
files: \.(bazel|bzl)
language: system
entry: bazel run //:buildifier
pass_filenames: false

- repo: local
hooks:
- id: codeql-format
name: Fix QL file formatting
files: \.qll?$
Expand Down
9 changes: 9 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
load("@buildifier_prebuilt//:rules.bzl", "buildifier")

buildifier(
name = "buildifier",
exclude_patterns = [
"./.git/*",
],
lint_mode = "fix",
)
2 changes: 2 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ bazel_dep(name = "abseil-cpp", version = "20240116.0", repo_name = "absl")
bazel_dep(name = "nlohmann_json", version = "3.11.3", repo_name = "json")
bazel_dep(name = "fmt", version = "10.0.0")

bazel_dep(name = "buildifier_prebuilt", version = "6.4.0", dev_dependency = True)

pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
hub_name = "codegen_deps",
Expand Down
2 changes: 1 addition & 1 deletion javascript/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@semmle_code//:dist.bzl", "dist")
load("@rules_pkg//pkg:mappings.bzl", "pkg_files")
load("@semmle_code//:dist.bzl", "dist")
load("@semmle_code//buildutils-internal:zipmerge.bzl", "zipmerge")

package(default_visibility = ["//visibility:public"])
Expand Down
2 changes: 1 addition & 1 deletion javascript/extractor/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@semmle_code//:common.bzl", "codeql_fat_jar", "codeql_java_project")
load("@rules_pkg//pkg:mappings.bzl", "pkg_files")
load("@semmle_code//:common.bzl", "codeql_fat_jar", "codeql_java_project")

java_library(
name = "deps",
Expand Down
2 changes: 0 additions & 2 deletions misc/codegen/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
load("@codegen_deps//:requirements.bzl", "requirement")

py_binary(
name = "codegen",
srcs = ["codegen.py"],
Expand Down
2 changes: 0 additions & 2 deletions misc/codegen/generators/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
load("@codegen_deps//:requirements.bzl", "requirement")

py_library(
name = "generators",
srcs = glob(["*.py"]),
Expand Down
2 changes: 1 addition & 1 deletion python/extractor/tsg-python/tsp/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
load("@py_deps//:defs.bzl", "aliases", "all_crate_deps")
load("@rules_rust//cargo:defs.bzl", "cargo_build_script")
load("@rules_rust//rust:defs.bzl", "rust_library")
load("@py_deps//:defs.bzl", "aliases", "all_crate_deps")

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

Expand Down
10 changes: 5 additions & 5 deletions swift/extractor/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
load("//swift:rules.bzl", "swift_cc_binary")
load("//misc/bazel:pkg_runfiles.bzl", "pkg_runfiles")
load("//swift:rules.bzl", "swift_cc_binary")

swift_cc_binary(
name = "extractor.real",
srcs = glob([
"*.h",
"*.cpp",
]),
linkopts = select({
"@platforms//os:macos": ["-headerpad_max_install_names"],
"//conditions:default": [],
}),
visibility = ["//swift:__pkg__"],
deps = [
"//swift/extractor/config",
Expand All @@ -17,10 +21,6 @@ swift_cc_binary(
"//swift/third_party/swift-llvm-support",
"@absl//absl/strings",
],
linkopts = select({
"@platforms//os:macos": ["-headerpad_max_install_names"],
"//conditions:default": [],
}),
)

sh_binary(
Expand Down
2 changes: 1 addition & 1 deletion swift/logging/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ cc_library(
hdrs = glob(["*.h"]),
visibility = ["//visibility:public"],
deps = [
"//shared/cpp:extractor_shared",
"@absl//absl/strings",
"@binlog",
"@fmt",
"@json",
"//shared/cpp:extractor_shared",
],
)

0 comments on commit 332d118

Please sign in to comment.