Skip to content

Commit

Permalink
Install buildifier via Bazel
Browse files Browse the repository at this point in the history
  • Loading branch information
npaun committed Sep 23, 2024
1 parent e1eb9b6 commit 946be0a
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
29 changes: 29 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -597,3 +597,32 @@ new_local_repository(
visibility = ["//visibility:public"],)""",
path = "empty",
)

# Dev tools
http_file(
name = "buildifier-darwin-arm64",
executable = True,
integrity = "sha256-Wmr8asegn1RVuguJvZnVriO0F03F3J1sDtXOjKrD+BM=",
url = "https://github.com/bazelbuild/buildtools/releases/download/v7.3.1/buildifier-darwin-arm64",
)

http_file(
name = "buildifier-linux-arm64",
executable = True,
integrity = "sha256-C/hsS//69PCO7Xe95bIILkrlA5oR4uiwOYTBc8NKVhw=",
url = "https://github.com/bazelbuild/buildtools/releases/download/v7.3.1/buildifier-linux-arm64",
)

http_file(
name = "buildifier-linux-amd64",
executable = True,
integrity = "sha256-VHTMUSinToBng9VAgfWBZixL6K5lAi9VfpKB7V3IgAk=",
url = "https://github.com/bazelbuild/buildtools/releases/download/v7.3.1/buildifier-linux-amd64",
)

http_file(
name = "buildifier-windows-amd64",
executable = True,
integrity = "sha256-NwzVdgda0pkwqC9d4TLxod5AhMeEqCUUvU2oDIWs9Kg=",
url = "https://github.com/bazelbuild/buildtools/releases/download/v7.3.1/buildifier-windows-amd64.exe",
)
43 changes: 43 additions & 0 deletions devtools/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
load("@bazel_skylib//lib:selects.bzl", "selects")

selects.config_setting_group(
name = "linux-amd64",
match_all = [
"@platforms//cpu:x86_64",
"@platforms//os:linux",
],
)

selects.config_setting_group(
name = "windows-amd64",
match_all = [
"@platforms//cpu:x86_64",
"@platforms//os:windows",
],
)

selects.config_setting_group(
name = "linux-arm64",
match_all = [
"@platforms//cpu:aarch64",
"@platforms//os:linux",
],
)

selects.config_setting_group(
name = "darwin-arm64",
match_all = [
"@platforms//cpu:aarch64",
"@platforms//os:macos",
],
)

alias(
name = "buildifier",
actual = select({
":darwin-arm64": "@buildifier-darwin-arm64//file:downloaded",
":linux-arm64": "@buildifier-linux-arm64//file:downloaded",
":linux-amd64": "@buildifier-linux-amd64//file:downloaded",
":windows-amd64": "@buildifier-windows-amd64//file:downloaded",
}),
)
9 changes: 7 additions & 2 deletions tools/cross/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
CLANG_FORMAT = os.environ.get("CLANG_FORMAT", "clang-format")
PRETTIER = os.environ.get("PRETTIER", "node_modules/.bin/prettier")
RUFF = os.environ.get("RUFF", "ruff")
BUILDIFIER = os.environ.get("BUILDIFIER", "buildifier")
BAZEL_RUN = ["bazel", "run", "--ui_event_filters=,+error,+fail", "--noshow_progress"]


def parse_args() -> Namespace:
Expand Down Expand Up @@ -117,7 +117,12 @@ def prettier(files: list[Path], check: bool = False) -> bool:


def buildifier(files: list[Path], check: bool = False) -> bool:
cmd = [BUILDIFIER, "--mode=check" if check else "--mode=fix"]
cmd = [
*BAZEL_RUN,
"//devtools:buildifier",
"--",
"--mode=check" if check else "--mode=fix",
]
result = subprocess.run(cmd + files)
return result.returncode == 0

Expand Down

0 comments on commit 946be0a

Please sign in to comment.