From 946be0a6cee7b3532480bf27513b19ddbd354df6 Mon Sep 17 00:00:00 2001 From: Nicholas Paun Date: Mon, 23 Sep 2024 15:45:53 -0700 Subject: [PATCH] Install buildifier via Bazel --- WORKSPACE | 29 +++++++++++++++++++++++++++++ devtools/BUILD.bazel | 43 +++++++++++++++++++++++++++++++++++++++++++ tools/cross/format.py | 9 +++++++-- 3 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 devtools/BUILD.bazel diff --git a/WORKSPACE b/WORKSPACE index 51c4b21a49f..95d3092f3dc 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -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", +) diff --git a/devtools/BUILD.bazel b/devtools/BUILD.bazel new file mode 100644 index 00000000000..6e3ef89b52a --- /dev/null +++ b/devtools/BUILD.bazel @@ -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", + }), +) diff --git a/tools/cross/format.py b/tools/cross/format.py index 35f608d179d..c0cf479fd95 100644 --- a/tools/cross/format.py +++ b/tools/cross/format.py @@ -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: @@ -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