bazelbuild / bazelbuild/bazel

config_setting on a label_flag pointing to a file breaks

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

Description

### Description of the bug:

If a config_setting has flag_values that contains a label_flag that resolves to a file, then it triggers "misplaced here (expected no files)" error.

### Which category does this issue belong to?

Configurability

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

```
label_flag(
name = "flag",
build_setting_default = ":default",
)

config_setting(
name = "flag_is_unset",
flag_values = {":flag": ":default"},
visibility = ["//visibility:public"],
)

filegroup(
name = "default",
srcs = [],
)

filegroup(
name = "x",
srcs = select({
":flag_is_unset": [],
"//conditions:default": [],
}),
)

exports_files(
["foo"]
)
```

Then create a empty file named `foo` in the package. Then build

```
bazel build //:x --//:flag=//:foo
```

This generates the following error:

```
ERROR: /mnt/sdc/android/temp/BUILD.bazel:6:15: in flag_values attribute of config_setting rule //:flag_is_unset: alias '//:flag' referring to source file '//:foo' is misplaced here (expected no files)
ERROR: /mnt/sdc/android/temp/BUILD.bazel:6:15: Analysis of target '//:flag_is_unset' failed
ERROR: /mnt/sdc/android/temp/BUILD.bazel:18:10: errors encountered resolving select() keys for //:x
ERROR: Analysis of target '//:x' failed; build aborted
INFO: Elapsed time: 0.181s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully
```

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

Linux

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

release 7.4.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` ?

_No response_

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

_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

Reproduce the failure with the BUILD.bazel example and the `bazel build //:x --//:flag=//:foo` command. Start by tracing config_setting flag_values handling for a label_flag that resolves to a source file. Done means the select() analysis completes without the misplaced-file error and the example builds successfully.

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
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.