Bazel 7.2.0 and 7.2.1: Label '//java/common:java_common.bzl' is invalid
Description of the bug:
Please see https://github.com/mvukov/rules_ros2/actions/runs/9665963740/job/26668343264?pr=331. Since 7.2.0 I get this error:
ERROR: Skipping '//...': error loading package under directory '': error loading package '~/.cache/bazel-repo/bazel/_bazel_runner/d53d663888cb7d4fa0ce43a097f11d2b/install/rules_java/toolchains': at /__w/rules_ros2/rules_ros2/~/.cache/bazel-repo/bazel/_bazel_runner/d53d663888cb7d4fa0ce43a097f11d2b/install/rules_java/toolchains/java_toolchain_alias.bzl:17:6: Label '//java/common:java_common.bzl' is invalid because 'java/common' is not a package; perhaps you meant to put the colon here: '//:java/common/java_common.bzl'?
ERROR: error loading package under directory '': error loading package '~/.cache/bazel-repo/bazel/_bazel_runner/d53d663888cb7d4fa0ce43a097f11d2b/install/rules_java/toolchains': at /__w/rules_ros2/rules_ros2/~/.cache/bazel-repo/bazel/_bazel_runner/d53d663888cb7d4fa0ce43a097f11d2b/install/rules_java/toolchains/java_toolchain_alias.bzl:17:6: Label '//java/common:java_common.bzl' is invalid because 'java/common' is not a package; perhaps you meant to put the colon here: '//:java/common/java_common.bzl'?
This is a PR in my repo where the failure happens: https://github.com/mvukov/rules_ros2/pull/331. The CI config is in https://github.com/mvukov/rules_ros2/blob/main/.github/workflows/main.yml, and the build image in https://github.com/mvukov/bazel_builder/blob/ba61fac1727043eb4e80fdd895ad4ad158b7b141/Dockerfile.
Which category does this issue belong to?
No response
What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
No response
Which operating system are you running Bazel on?
Ubuntu 22.04
What is the output of bazel info release?
7.2.1
If bazel info release returns development version or (@non-git), tell us how you built Bazel.
No response
What's the output of git remote get-url origin; git rev-parse HEAD ?
No response
If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.
The failures start with an update to Bazel 7.2.0, also happens with Bazel 7.2.1.
Have you found anything relevant by searching the web?
No response
Any other information, logs, or outputs that you want to share?
No response
@hvadehra
I'm not familiar with github actions/cache but I suspect the issue lies there.
From the CI run logs, I see it starts with:
key: v3-bazel-repo-cache-gcc-8724efc64ec2ae6f9c8726587d03c992069750154b944bc682b0d378f7f9a03c
restore-keys: v3-bazel-repo-cache-gcc-
and at the end:
Cache restored successfully
Cache restored from key: v3-bazel-repo-cache-gcc-31b31c1d4e0c637ac53d7075d262ffafe4bac9f95f42e50866e71a607f2e9184
ISTM this might be an incorrect usage of restore-keys (I would have expected at the very least the bazel version as well to be included?)
Hi, thanks for reaching out. I updated the key, but that didn't help unfortunately, please see https://github.com/mvukov/rules_ros2/actions/runs/9756344735/job/26926475145?pr=331.
For the reference, this was never a problem until Bazel 7.2.0.
Thanks for trying, it was just a shot in the dark :)
I presume this issue only occurs on CI, or have you managed to reproduce locally as well? If not, could you please let me know the simplest way to trigger CI so I can experiment?
This line is problematic: https://github.com/mvukov/rules_ros2/blob/6b4ccf52bc43b1903467adb37f8bc71e30e602ea/.github/workflows/ci.bazelrc#L7
Bazel doesn't resolve ~ to the home directory and instead creates the cache in a subdirectory of the WORKSPACE called ~. It then descends into this "package" during the build, causing all kinds of weird issues.
Try passing in the path from the CI workflow's command line instead of via .bazelrc.
@fmeum Thanks so much for the pointer. I also had to set XDG_CACHE_HOME as an absolute path. The PR builds now.