bazel-contrib / rules_go

Go rules for Bazel
Apache License 2.0
1.38k stars 656 forks source link

[context.bzl] add more helpful debug message to resolver issue #4072

Closed tyler-french closed 1 month ago

tyler-french commented 1 month ago

It's difficult to tell where this issue is coming from without some reference to the resolver or the target this is originating from.

This PR updates the debug message to be more explicit.

Before:

DEBUG: /home/user/.cache/bazel/_bazel_tfrench/b97476d719d716accead0f2d5b93104f/external/io_bazel_rules_go/go/private/context.bzl:322:22: Detected Targets in `source["deps"]` as a result of _resolver. Please pass a list of `GoArchive`s instead, for examples `deps = [deps[GoArchive] for dep in deps]`. This will be an error in the future.
DEBUG: /home/user/.cache/bazel/_bazel_tfrench/b97476d719d716accead0f2d5b93104f/external/io_bazel_rules_go/go/private/context.bzl:322:22: Detected Targets in `source["deps"]` as a result of _resolver. Please pass a list of `GoArchive`s instead, for examples `deps = [deps[GoArchive] for dep in deps]`. This will be an error in the future.
DEBUG: /home/user/.cache/bazel/_bazel_tfrench/b97476d719d716accead0f2d5b93104f/external/io_bazel_rules_go/go/private/context.bzl:322:22: Detected Targets in `source["deps"]` as a result of _resolver. Please pass a list of `GoArchive`s instead, for examples `deps = [deps[GoArchive] for dep in deps]`. This will be an error in the future.
DEBUG: /home/user/.cache/bazel/_bazel_tfrench/b97476d719d716accead0f2d5b93104f/external/io_bazel_rules_go/go/private/context.bzl:322:22: Detected Targets in `source["deps"]` as a result of _resolver. Please pass a list of `GoArchive`s instead, for examples `deps = [deps[GoArchive] for dep in deps]`. This will be an error in the future.
DEBUG: /home/user/.cache/bazel/_bazel_tfrench/b97476d719d716accead0f2d5b93104f/external/io_bazel_rules_go/go/private/context.bzl:322:22: Detected Targets in `source["deps"]` as a result of _resolver. Please pass a list of `GoArchive`s instead, for examples `deps = [deps[GoArchive] for dep in deps]`. This will be an error in the future.
DEBUG: /home/user/.cache/bazel/_bazel_tfrench/b97476d719d716accead0f2d5b93104f/external/io_bazel_rules_go/go/private/context.bzl:322:22: Detected Targets in `source["deps"]` as a result of _resolver. Please pass a list of `GoArchive`s instead, for examples `deps = [deps[GoArchive] for dep in deps]`. This will be an error in the future.
DEBUG: /home/user/.cache/bazel/_bazel_tfrench/b97476d719d716accead0f2d5b93104f/external/io_bazel_rules_go/go/private/context.bzl:322:22: Detected Targets in `source["deps"]` as a result of _resolver. Please pass a list of `GoArchive`s instead, for examples `deps = [deps[GoArchive] for dep in deps]`. This will be an error in the future.
DEBUG: /home/user/.cache/bazel/_bazel_tfrench/b97476d719d716accead0f2d5b93104f/external/io_bazel_rules_go/go/private/context.bzl:322:22: Detected Targets in `source["deps"]` as a result of _resolver. Please pass a list of `GoArchive`s instead, for examples `deps = [deps[GoArchive] for dep in deps]`. This will be an error in the future.
DEBUG: /home/user/.cache/bazel/_bazel_tfrench/b97476d719d716accead0f2d5b93104f/external/io_bazel_rules_go/go/private/context.bzl:322:22: Detected Targets in `source["deps"]` as a result of _resolver. Please pass a list of `GoArchive`s instead, for examples `deps = [deps[GoArchive] for dep in deps]`. This will be an error in the future.
DEBUG: /home/user/.cache/bazel/_bazel_tfrench/b97476d719d716accead0f2d5b93104f/external/io_bazel_rules_go/go/private/context.bzl:322:22: Detected Targets in `source["deps"]` as a result of _resolver. Please pass a list of `GoArchive`s instead, for examples `deps = [deps[GoArchive] for dep in deps]`. This will be an error in the future.

After:

DEBUG: /home/user/.cache/bazel/_bazel_tfrench/b97476d719d716accead0f2d5b93104f/external/io_bazel_rules_go/go/private/context.bzl:322:22: Detected Targets in `source["deps"]` as a result of _resolver: <function _resolve from //rules/glue:glue.bzl>, from target @//src/...:glue_gluefxPlease pass a list of `GoArchive`s instead, for examples `deps = [deps[GoArchive] for dep in deps]`. This will be an error in the future.
DEBUG: /home/user/.cache/bazel/_bazel_tfrench/b97476d719d716accead0f2d5b93104f/external/io_bazel_rules_go/go/private/context.bzl:322:22: Detected Targets in `source["deps"]` as a result of _resolver: <function _resolve from //src/.../rds/mappergen-go:rules.bzl>, from target @//src/../handler/mappers:go_default_libraryPlease pass a list of `GoArchive`s instead, for examples `deps = [deps[GoArchive] for dep in deps]`. This will be an error in the future.
...

Also this prints 1000s of messages. Is this overkill? Can we just warn once per rule?

tyler-french commented 1 month ago

nit: maybe add a period and space before "Please"? Warning once per rule makes sense, I wasn't sure offhand how to do that. can we have a map at module scope of "rule name" -> "has warned"? Or will starlark prevent that?

@dzbarsky Yeah, I'm not sure how to do it without some global state, which I don't think we'd want anyway, because it would probably mess up some caching logic or determinism somewhere.

fmeum commented 1 month ago

There is no way to warn once, but at least most of the warnings should go away as soon as the user starts migrating individual resolve functions.