From e6c738a33e6083c71e53b8f2400356f68a672ee2 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Fri, 24 Jan 2025 20:21:51 +0100 Subject: [PATCH] Update buildifier hook and apply its fixes --- .pre-commit-config.yaml | 4 ++-- features.bzl | 2 +- private/globals_repo.bzl | 3 ++- private/repos.bzl | 4 ++-- private/util.bzl | 1 + test/test.bzl | 5 +++-- 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5b5bead..b3344df 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,13 +14,13 @@ default_language_version: repos: # Check formatting and lint for starlark code - repo: https://github.com/keith/pre-commit-buildifier - rev: 4.0.1.1 + rev: 8.0.1 hooks: - id: buildifier - id: buildifier-lint # Enforce that commit messages allow for later changelog generation - repo: https://github.com/commitizen-tools/commitizen - rev: v2.18.0 + rev: v4.1.0 hooks: # Requires that commitizen is already installed - id: commitizen diff --git a/features.bzl b/features.bzl index 0341c10..f0f49f7 100644 --- a/features.bzl +++ b/features.bzl @@ -1,7 +1,7 @@ """Defines all the features this module supports detecting.""" load("@bazel_features_globals//:globals.bzl", "globals") -load("//private:util.bzl", "ge", "ge_same_major", "gt", "lt") +load("//private:util.bzl", "ge", "ge_same_major", "lt") _cc = struct( # Whether @bazel_tools//tools/cpp:optional_current_cc_toolchain and the `mandatory` parameter diff --git a/private/globals_repo.bzl b/private/globals_repo.bzl index 676d8a6..78828c7 100644 --- a/private/globals_repo.bzl +++ b/private/globals_repo.bzl @@ -34,6 +34,7 @@ bzl_library( fail("Invalid global name: %s" % global_) value = global_ if bazel_version < parse_version(version) else "None" + # If the legacy_globals is available, we take the value from it. # The value is populated by --incompatible_autoload_externally and may apply to older Bazel versions lines.append(" %s = getattr(getattr(native, 'legacy_globals', None), '%s', %s)," % (global_, global_, value)) @@ -53,7 +54,7 @@ globals_repo = repository_rule( "legacy_globals": attr.string_dict( mandatory = True, ), - }, + }, ) def _is_valid_identifier(s): diff --git a/private/repos.bzl b/private/repos.bzl index 38a6222..95ef9a1 100644 --- a/private/repos.bzl +++ b/private/repos.bzl @@ -1,14 +1,14 @@ """Contains the macro bazel_features_repos to install internal repositories.""" +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") load(":globals.bzl", "GLOBALS", "LEGACY_GLOBALS") load(":globals_repo.bzl", "globals_repo") load(":version_repo.bzl", "version_repo") -load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") def bazel_features_repos(): maybe( version_repo, - name = "bazel_features_version" + name = "bazel_features_version", ) maybe( globals_repo, diff --git a/private/util.bzl b/private/util.bzl index 99f54e4..afdcbfa 100644 --- a/private/util.bzl +++ b/private/util.bzl @@ -19,6 +19,7 @@ def ge(v): def ge_same_major(v): pv = parse_version(v) + # Version 1.2.3 parses to ([1, 2, 3], ...). return BAZEL_VERSION >= pv and BAZEL_VERSION[0][0] == pv[0][0] diff --git a/test/test.bzl b/test/test.bzl index b8a8848..04f8e19 100644 --- a/test/test.bzl +++ b/test/test.bzl @@ -1,8 +1,9 @@ """Provides a macro to do some loading-time test assertions.""" -load("//private:util.bzl", "BAZEL_VERSION", "ge", "lt") -load("//private:parse.bzl", "parse_version") +load("@com_google_protobuf//bazel/common:proto_info.bzl", "ProtoInfo") load("//:features.bzl", "bazel_features") +load("//private:parse.bzl", "parse_version") +load("//private:util.bzl", "BAZEL_VERSION", "ge", "lt") def _empty_test_impl(ctx): extension = ".bat" if ctx.attr.is_windows else ".sh"