bazel-skylib icon indicating copy to clipboard operation
bazel-skylib copied to clipboard

versions.check needs documentation/better error message explaining it can only be used in repository rules

Open jmhodges opened this issue 6 years ago • 6 comments

For some reason, using versions.check("0.9.0") fails on macOS with a homebrew installed bazel.

Here's the error:

ERROR: /Users/jmhodges/founding/src/founding/BUILD:12:1: Traceback (most recent call last):
	File "/Users/jmhodges/founding/src/founding/BUILD", line 12
		versions.check("0.9.0")
	File "/private/var/tmp/_bazel_jmhodges/ee957dabdee1b1a9e1f2fe90369cf80f/external/bazel_skylib/lib/versions.bzl", line 96, in versions.check
		fail(("\nCurrent Bazel version is low...))

Current Bazel version is lower than 0.2.1, expected at least 0.9.0

but my bazel version reports

Build label: 0.9.0-homebrew
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Sun Jul 12 12:24:01 +49936 (1513677414241)
Build timestamp: 1513677414241
Build timestamp as int: 1513677414241

jmhodges avatar Jan 27 '18 07:01 jmhodges

Oh, this is with:

http_archive(
    name = "bazel_skylib",
    sha256 = "bbccf674aa441c266df9894182d80de104cabd19be98be002f6d478aaa31574d",
    strip_prefix = "bazel-skylib-2169ae1c374aab4a09aa90e65efe1a3aad4e279b",
    urls = [
        "https://github.com/bazelbuild/bazel-skylib/archive/2169ae1c374aab4a09aa90e65efe1a3aad4e279b.tar.gz",
    ],
)

in my WORKSPACE

jmhodges avatar Jan 27 '18 07:01 jmhodges

Reproduced. For some reason, homebrew Bazel does not have bazel_version in the native Skylark module. Opened https://github.com/bazelbuild/bazel/issues/4566

jin avatar Feb 01 '18 21:02 jin

I am on current HEAD ff23a62c57d2912c3073a69c12f42c3d6e58a957, and provided that I am not looking for an absolute value and using minimum_bazel_version / maximum_bazel_version I am not having issues with homebrew installs.

promiseofcake avatar Feb 02 '18 18:02 promiseofcake

Weird, I can't reproduce it anymore with 0.10.0-homebrew with bazel-skylib itself on HEAD.

→ bazel version
Build label: 0.10.0-homebrew
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Tue Jan 9 21:07:27 +50057 (1517479996047)
Build timestamp: 1517479996047
Build timestamp as int: 1517479996047

→ cat WORKSPACE
workspace(name = "bazel_skylib")

load(":lib.bzl", "versions")

versions.check(minimum_bazel_version="0.9.0")

→ bazel build //...
INFO: Analysed 38 targets (11 packages loaded).
INFO: Found 38 targets...
INFO: Elapsed time: 0.698s, Critical Path: 0.02s
INFO: Build completed successfully, 1 total action

And the expected failure:

→ cat WORKSPACE
workspace(name = "bazel_skylib")

load(":lib.bzl", "versions")

versions.check(minimum_bazel_version="0.11.0")

→ bazel build //...
ERROR: /Users/jin/Code/bazel-skylib/WORKSPACE:5:1: Traceback (most recent call last):
	File "/Users/jin/Code/bazel-skylib/WORKSPACE", line 5
		versions.check(minimum_bazel_version = "0.11.0")
	File "/Users/jin/Code/bazel-skylib/lib/versions.bzl", line 107, in versions.check
		fail("\nCurrent Bazel version is {}, ...))

Current Bazel version is 0.10.0-homebrew, expected at least 0.11.0
ERROR: Error evaluating WORKSPACE file
ERROR: error loading package 'external': Package 'external' contains errors
INFO: Elapsed time: 0.167s
FAILED: Build did NOT complete successfully (0 packages loaded)

jin avatar Feb 04 '18 04:02 jin

I've just ran into this issue. But I think everything is working as intended - native.bazel_version is only available to repository rules i.e. it cannot be used from a BUILD file, only from WORKSPACE or from load()ed files.

ash2k avatar Jun 30 '18 10:06 ash2k

The problem is that versions.bzl can only be used in repository rule context - which is something we ought to (1) actually document in versionz.bzl, and (2) (ideally) check for in each exported function in versions.

See also https://github.com/bazelbuild/bazel/issues/8305 (maybe Bazel ought to allow native.bazel_version in macros and non-repository rules).

tetromino avatar Apr 17 '21 16:04 tetromino