bazelbuild / bazelbuild/bazel

cquery missing dependencies or incorrectly reporting transitions

Open
#17,916 11 comments 0 reactions 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 18h
Merged PRs (30d)
75

Description

### Description of the bug:

I am running cquery to find out, including transitions, about the dependency chain of configured targets of a `go_proto_library`.

If I `bazel cquery --output=jsonproto --transitions=lite 'deps(//:epb_go_proto)'` some `go_proto_library`, `configuredRuleInputs` declares there's a dependency on `@io_bazel_rules_go//:go_context_data` in the same configuration as the target itself.

That target itself claims to have a dependency on `@io_bazel_rules_go//:stdlib` also in the same configuration.

However, there is no entry in the cquery output for `@io_bazel_rules_go//:stdlib` in that configuration. That target is present in three configurations, but not the one declared.

I would expect the transition following and expansion of cquery to ensure any ConfiguredTarget which appears in configuredRuleInputs is also present in the output of a `deps` query.

From inspecting the relevant rules, `go_proto_library` just has a regular dependency on `@io_bazel_rules_go//:go_context_data`, and then `@io_bazel_rules_go//:go_context_data` self-transitions.

As far as I can tell, these dependencies don't go via any toolchains, and though `go_proto_library` does have an aspect, that's not relevant for this dependency path.

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

With this WORKSPACE:
```starlark
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "io_bazel_rules_go",
sha256 = "6b65cb7917b4d1709f9410ffe00ecf3e160edf674b78c54a894471320862184f",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.39.0/rules_go-v0.39.0.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.39.0/rules_go-v0.39.0.zip",
],
)

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")

go_rules_dependencies()

go_register_toolchains(version = "1.19.3")

http_archive(
name = "com_google_protobuf",
sha256 = "c6003e1d2e7fefa78a3039f19f383b4f3a61e81be8c19356f85b6461998ad3db",
strip_prefix = "protobuf-3.17.3",
urls = [
"https://github.com/protocolbuffers/protobuf/archive/v3.17.3.tar.gz",
],
)

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()
```

and this BUILD file:
```starlark
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")

proto_library(
name = "epb_proto",
srcs = ["example.proto"],
visibility = ["//visibility:public"],
)

go_proto_library(
name = "epb_go_proto",
importpath = "github.com/example/project/epb",
proto = ":epb_proto",
visibility = ["//visibility:public"],
)

go_library(
name = "project_lib",
srcs = ["main.go"],
importpath = "github.com/example/project",
visibility = ["//visibility:private"],
deps = [":epb_go_proto"],
)

go_binary(
name = "project",
embed = [":project_lib"],
visibility = ["//visibility:public"],
)
```

Run `bazel cquery --output=jsonproto --transitions=lite 'deps(//:epb_go_proto)'`

And inspect the output for the particular targets I've mentioned in the issue description.

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

macOS

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

release 6.1.1

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

_No response_

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