bazelbuild / bazelbuild/bazel

Passing `bool_flag` to `analysistest.make` infers wrong label for the given string

Open
#19,286 5 comments 1 reaction 0 assignees View on GitHub
P2 team-Configurability type: bug
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 18h
Merged PRs (30d)
75

Description

### Description of the bug:

When creating a custom analysistest to set specific config_settings like this:

```bzl
"""Example"""

load(
"@bazel_skylib//lib:unittest.bzl",
"analysistest",
)

def _impl(ctx):
env = analysistest.begin(ctx)
return analysistest.end(env)

custom_test = analysistest.make(
_impl,
config_settings = {
"//:some_setting": True,
},
)
```

Where `some_setting` is a simple `bool_flag`:

```bzl
bool_flag(
name = "some_setting",
build_setting_default = False,
)
```

You get this error:

```
ERROR: /private/tmp/skylibrepro/BUILD:9:12: On dependency edge //:test (40d9365) -|target_under_test|-> //:lib: com.google.devtools.build.lib.packages.NoSuchTargetException: no such target '@bazel_skylib//:some_setting': target 'some_setting' not declared in package '' defined by /private/var/tmp/_bazel_ksmiley/e68a004d2ac494f072d7bb5e0fb7c459/external/bazel_skylib/BUILD (Tip: use `query "@bazel_skylib//:*"` to see all the targets in that package)
```

This appears to be because skylib is inferring `some_setting` in the context of its own repo. If you prefix `//:some_setting` with `@//:some_setting` it works in this case, but if the label lives in a ruleset that might not work for other tests that run in the context of a test workspace.

It seems that skylib should accept labels here instead, but with some quick tests locally that doesn't work either.

### 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.

In this project: [skylibrepro.zip](https://github.com/bazelbuild/bazel/files/12383177/skylibrepro.zip) run `bazel test test`

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

macOS

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

cc5889c4325f2f8bb5c18faa672fd10e3cc59f3a

### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.

bazelisk last_green

### What's the output of `git remote get-url origin; git rev-parse master; git rev-parse HEAD` ?

_No response_

### Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.

_No response_

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

_No response_

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

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with the linked skylibrepro.zip and `bazel test test`. Read the `analysistest.make` handling of `config_settings`, especially label resolution for `bool_flag` values. Done means the setting resolves in the intended workspace context and the reproducer test passes without incorrectly targeting `@bazel_skylib`.

Written by the indexing model from the issue text.

Assessment

Domain
build-system, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.