bazelbuild / bazelbuild/bazel

genquery should fail when querying nonexistent targets, but if the target is the scope it doesn't

Open
#18,290 10 comments 0 reactions 1 assignee Claimed by @gregestren View on GitHub
P3 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:

the existence of a target in the scope of a genquery seems to create the target as a source file. I expect that genquery will not create targets other than itself.

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

```
genquery(
name = "query_nonexistent_target_deps",
scope = ["//:nonexistent_target"],
expression = "deps(//:nonexistent_target)",
)
```

building this query will succeed, with empty output. Running the same query with the CLI (`bazel query "deps(//:nonexistent_target)"` will error IF this genquery is not in the BUILD file, but also succeeds with empty output if this genquery is in the BUILD file.

another interesting data point: `bzl query --output=label_kind //:nonexistent_target` returns `source file //:nonexistent_target` if this genquery is defined, but errors otherwise.

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

Ubuntu 20.04

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

release 6.1.0-0b9dc52a311198b1cde5c2df9403bb5e9529057f

### 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 master; git rev-parse HEAD` ?

_No response_

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

I don't see anything relevant

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

_No response_

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.