bazelbuild / bazelbuild/bazel

`bazel info --host_platform=@my-mod//:host_platform` fails on bazel 9.x with local path override

Open
#28,954 8 comments 0 reactions 0 assignees View on GitHub
help wanted P2 team-ExternalDeps type: bug
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the bug:

When upgrading to bazel 9:

```
$ bazel info --host_platform=@mod1//:host_platform
ERROR: com.google.devtools.build.lib.packages.BuildFileNotFoundException: no such package '@@mod1//': The repository '@@mod1' could not be resolved: Repository '@@mod1' is not defined
```

However:

```
$ bazel build --host_platform=@mod1//:host_platform
WARNING: Usage: bazel build .
Invoke `bazel help build` for full description of usage and options.
Your request is correct, but requested an empty set of targets. Nothing will be built.
INFO: Found 0 targets...
INFO: Elapsed time: 0.123s, Critical Path: 0.01s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
```

(so the `--host_platform` setting is correct).

### Which category does this issue belong to?

External Dependency

### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Two modules are required:

```bzl
# mod1/MODULE.bazel
module(name = "mod1")
```

```bzl
# mod1/BUILD.bazel
platform(
name = "host_platform",
constraint_values = [],
visibility = ["//visibility:public"],
)
```

```bzl
# mod2/MODULE.bazel
bazel_dep(name = "mod1", version = "0.0.0")

local_path_override(
module_name = "mod1",
path = "../mod1",
)
```

Then run `bazel info --host_platform=@mod1//:host_platform` in mod2:

```
mod2$ bazel info --host_platform=@mod1//:host_platform
ERROR: com.google.devtools.build.lib.packages.BuildFileNotFoundException: no such package '@@mod1//': The repository '@@mod1' could not be resolved: Repository '@@mod1' is not defined
```

Expected behavior: The command shows bazel info (that's the behavior of bazel 8.5.0).

Notes:
- `build` accepts the platform (`bazel build --host_platform=@mod1//:host_platform`)
- Running adding `bazel_dep(name = "platforms", version = "1.0.0")` and running `bazel info --host_platform=@platforms//host` succeeds (so the local_path_override is likely the culprit).
- Adding an alias to mod2 to also fixes the issue (run ` bazel info --host_platform=//:host_platform`):
```bzl
# mod2/BUILD.bazel
alias(
name = "host_platform",
actual = "@mod1//:host_platform",
)
```

### Which operating system are you running Bazel on?

Linux tos 6.14.0-37-generic #37~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Nov 20 10:25:38 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

### What is the output of `bazel info release`?

release 9.0.0

### 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` ?

```text

```

### If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.

`bazelisk --bisect=8.5.0..9.0.0 info --host_platform=@mod1//:host_platform`

leads to:

https://github.com/bazelbuild/bazel/commit/632540df12a1fa96b6db3d8f5cb45a9255c0a903

Note: that `bazel info --host_platform=@mod1//:host_platform --noincompatible_target_cpu_from_platform` also seems to fail on bazel 9.0.0

### Have you found anything relevant by searching the web?

_No response_

### Any other information, logs, or outputs that you want to share?

# Workaround

Define a module-local alias for the platform:

```bzl
alias(
name = "host_platform",
actual = "@mod1//:host_platform",
)
```

The use `--host_platform=//:host_platform` instead of `--@mod1//:host_platform`.

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the two-module MODULE.bazel and BUILD.bazel files described, comparing Bazel 8.5.0 and 9.0.0. Start by examining regression commit 632540df12a1fa96b6db3d8f5cb45a9255c0a903 and the --host_platform handling; done means bazel info succeeds with the local_path_override while the existing build behavior remains valid.

Written by the indexing model from the issue text.

Assessment

Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.