4ef157dde6
Bazel is still supported in addition to the Bazel wrapper Bazelisk, that is recommended, as it would automatically switch to the right Bazel version on stable branches (like it was the case with Buck). That why minimum used Bazel version check is still needed in WORKSPACE file in addition to the .bazelversion used by Bazelisk. That means that currently, bazel version is maintained in two places: * .bazelversion * WORKSPACE This change introduces the repository rule to read the bazel version from the .bazelversion file and perform the minimum version check. When all Gerrit users and developers switched to using Bazelisk, we might consider to remove the check altogether. Inspired-By: Yannic Bonenberger <yannic@yannic-bonenberger.com> Change-Id: I2fb8b2e5524be501571a0d2418f4676c8fb484ae
17 lines
550 B
Python
17 lines
550 B
Python
_template = """
|
|
load("@bazel_skylib//lib:versions.bzl", "versions")
|
|
|
|
def check_bazel_version():
|
|
versions.check(minimum_bazel_version = "{version}")
|
|
""".strip()
|
|
|
|
def _impl(repository_ctx):
|
|
repository_ctx.symlink(Label("@//:.bazelversion"), ".bazelversion")
|
|
bazelversion = repository_ctx.read(".bazelversion").strip()
|
|
|
|
repository_ctx.file("BUILD", executable = False)
|
|
|
|
repository_ctx.file("check.bzl", executable = False, content = _template.format(version = bazelversion))
|
|
|
|
bazelisk_version = repository_rule(implementation = _impl)
|