@@ -19,7 +19,7 @@ as the continuous integration, so they don't trip over incompatibilities with
1919rules used in the project.
2020"""
2121
22- load (":check_version.bzl" , "check_version" )
22+ load (":check_version.bzl" , "check_version" , "check_version_range" )
2323
2424# From https://github.com/tensorflow/tensorflow/blob/5541ef4fbba56cf8930198373162dd3119e6ee70/tensorflow/workspace.bzl#L44
2525
@@ -55,3 +55,44 @@ def check_bazel_version(minimum_bazel_version, message = ""):
5555 minimum_bazel_version ,
5656 message ,
5757 ))
58+
59+ # Check that a bazel version being used is in the version range.
60+ # Args:
61+ # minimum_bazel_version in the form "<major>.<minor>.<patch>"
62+ # maximum_bazel_version in the form "<major>.<minor>.<patch>"
63+ def check_bazel_version_range (minimum_bazel_version , maximum_bazel_version , message = "" ):
64+ """
65+ Verify the users Bazel version is in the version range.
66+
67+ This should be called from the `WORKSPACE` file so that the build fails as
68+ early as possible. For example:
69+
70+ ```
71+ # in WORKSPACE:
72+ load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version_range")
73+ check_bazel_version_range("0.11.0", "0.22.0")
74+ ```
75+
76+ Args:
77+ minimum_bazel_version: a string indicating the minimum version
78+ maximum_bazel_version: a string indicating the maximum version
79+ message: optional string to print to your users, could be used to help them update
80+ """
81+ if "bazel_version" not in dir (native ):
82+ fail ("\n Current Bazel version is lower than 0.2.1, expected at least %s\n " %
83+ minimum_bazel_version )
84+ elif not native .bazel_version :
85+ print ("\n Current Bazel is not a release version, cannot check for " +
86+ "compatibility." )
87+ print ("Make sure that you are running at least Bazel %s.\n " % minimum_bazel_version )
88+ elif not check_version_range (
89+ native .bazel_version ,
90+ minimum_bazel_version ,
91+ maximum_bazel_version ,
92+ ):
93+ fail ("\n Current Bazel version is {}, expected >= {} and <= {}\n {}" .format (
94+ native .bazel_version ,
95+ minimum_bazel_version ,
96+ maximum_bazel_version ,
97+ message ,
98+ ))
0 commit comments