[BUILD] Use bazel-skylib rule to check bazel version (#20990)

Bazel has a rule for enforcing the version so we can just reuse that.

This redundant bazel version check logic in setup.py is also causing issue when building conda package, because conda has its own version of bazel and it doesn't support `--version`.
This commit is contained in:
Jiajun Yao 2021-12-09 23:25:22 +00:00 committed by GitHub
parent 2410ec5ef0
commit 5b21bc5c93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 13 deletions

View file

@ -17,4 +17,6 @@ grpc_extra_deps()
load("@bazel_skylib//lib:versions.bzl", "versions") load("@bazel_skylib//lib:versions.bzl", "versions")
versions.check(minimum_bazel_version = "3.4.0") # When the bazel version is updated, make sure to update it
# in setup.py as well.
versions.check(minimum_bazel_version = "4.2.1")

View file

@ -13,7 +13,6 @@ import tempfile
import zipfile import zipfile
from itertools import chain from itertools import chain
from itertools import takewhile
from enum import Enum from enum import Enum
import urllib.error import urllib.error
@ -23,6 +22,8 @@ import urllib.request
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
SUPPORTED_PYTHONS = [(3, 6), (3, 7), (3, 8), (3, 9)] SUPPORTED_PYTHONS = [(3, 6), (3, 7), (3, 8), (3, 9)]
# When the bazel version is updated, make sure to update it
# in WORKSPACE file as well.
SUPPORTED_BAZEL = (4, 2, 1) SUPPORTED_BAZEL = (4, 2, 1)
ROOT_DIR = os.path.dirname(__file__) ROOT_DIR = os.path.dirname(__file__)
@ -485,17 +486,6 @@ def build(build_python, build_java, build_cpp):
] + pip_packages, ] + pip_packages,
env=dict(os.environ, CC="gcc")) env=dict(os.environ, CC="gcc"))
version_info = bazel_invoke(subprocess.check_output, ["--version"])
bazel_version_str = version_info.rstrip().decode("utf-8").split(" ", 1)[1]
bazel_version_split = bazel_version_str.split(".")
bazel_version_digits = [
"".join(takewhile(str.isdigit, s)) for s in bazel_version_split
]
bazel_version = tuple(map(int, bazel_version_digits))
if bazel_version < SUPPORTED_BAZEL:
logger.warning("Expected Bazel version {} but found {}".format(
".".join(map(str, SUPPORTED_BAZEL)), bazel_version_str))
bazel_flags = ["--verbose_failures"] bazel_flags = ["--verbose_failures"]
if BAZEL_LIMIT_CPUS: if BAZEL_LIMIT_CPUS:
n = int(BAZEL_LIMIT_CPUS) # the value must be an int n = int(BAZEL_LIMIT_CPUS) # the value must be an int