bazelbuild / bazelbuild/bazel

`config_setting` false positive when `label_flag` points at an `alias`

Open
#21,189 6 comments 1 reaction 1 assignee Claimed by @gregestren 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` is set up to detect whether a `label_flag` points to a particular target, it will not fire if that target is pointed to via an alias.

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

Consider the following BUILD file, and assume a file `main.cc` exists.

```
label_flag(
name = "testflag",
build_setting_default = ":one",
)

config_setting(
name = "testflag_one",
flag_values = {
"//:testflag": "//:one",
},
)

config_setting(
name = "testflag_two",
flag_values = {
"//:testflag": "//:two",
},
)

cc_library(
name = "one",
)

cc_library(
name = "two",
)

alias(
name = "alias_for_one",
actual = ":one",
)

cc_binary(
name = "which",
srcs = select({
":testflag_one": ["main.cc"],
":testflag_two": ["doesntexist.cc"],
"//conditions:default": ["alsodoesntexist.cc"],
}),
)
```

Running,

```
bazel build --//:testflag=:one :which
```

builds `main.cc`, as expected. Running,

```
bazel build --//:testflag=:two :which
```
returns an error, `missing input file '//:doesntexist.cc'`. This is also expected.

Running,

```
bazel build --/:testflag=:alias_for_one :which
```

returns an error, `missing input file '//:alsodoesntexist.cc'`. This is *unexpected*. The `testflag` does point to the expected target, it just does so through an alias.

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

Linux

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

release 8.0.0-pre.20240108.6

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

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

No, I don't believe this ever worked.

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

This is related to https://github.com/bazelbuild/bazel/issues/13463. That issue was about false negatives arising when the _key_ in `config_setting.flag_value` was an alias. This issue is about false negatives when the _value_ in `config_setting.flag_values` is an alias.

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

I'd appreciate if someone knowledgeable (@lberki ?) could comment on whether this is a relatively trivial issue, or profoundly intractable.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.