Skip to content

Commit

Permalink
Update buildifier hook and apply its fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Jan 24, 2025
1 parent 7cc3a36 commit 68d5a28
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .bcr/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ bcr_test_module:
- ubuntu2004
- macos
- windows
bazel: [6.x, 7.x]
bazel: [6.x, 7.x, 8.x]
tasks:
run_test_module:
name: Run test module
Expand Down
6 changes: 4 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ 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
args: [--warnings=-native-proto-info]
- id: buildifier-lint
args: [--warnings=-native-proto-info]
# 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
Expand Down
2 changes: 1 addition & 1 deletion features.bzl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion private/globals_repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -53,7 +54,7 @@ globals_repo = repository_rule(
"legacy_globals": attr.string_dict(
mandatory = True,
),
},
},
)

def _is_valid_identifier(s):
Expand Down
4 changes: 2 additions & 2 deletions private/repos.bzl
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
1 change: 1 addition & 0 deletions private/util.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
4 changes: 2 additions & 2 deletions test/test.bzl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""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("//: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"
Expand Down

0 comments on commit 68d5a28

Please sign in to comment.