bazelbuild / bazel-gazelle

Gazelle is a Bazel build file generator for Bazel projects. It natively supports Go and protobuf, and it may be extended to support new languages and custom rule sets.
Apache License 2.0
1.18k stars 377 forks source link

go_deps extension doesn't generate indirect dependencies #1698

Closed linzhp closed 9 months ago

linzhp commented 9 months ago

What version of gazelle are you using?

0.35.0

What version of rules_go are you using?

0.44.0

What version of Bazel are you using?

7.0.0

Does this issue reproduce with the latest releases of all the above?

YES

What operating system and processor architecture are you using?

macOS and Linux ARM64

What did you do?

Create a small workspace like this:

-- go/go.mod --
module example.com/go

go 1.21.3

require github.com/pseudomuto/protoc-gen-doc v1.5.2-0.20230920192302-df9dd4078971

require (
        github.com/Masterminds/semver v1.4.2 // indirect
        github.com/Masterminds/sprig v2.15.0+incompatible // indirect
        github.com/aokoli/goutils v1.0.1 // indirect
        github.com/davecgh/go-spew v1.1.1 // indirect
        github.com/golang/protobuf v1.5.2 // indirect
        github.com/google/uuid v1.1.2 // indirect
        github.com/huandu/xstrings v1.0.0 // indirect
        github.com/imdario/mergo v0.3.12 // indirect
        github.com/pseudomuto/protokit v0.2.0 // indirect
        github.com/stretchr/testify v1.7.0 // indirect
        golang.org/x/crypto v0.1.0 // indirect
        golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
        google.golang.org/protobuf v1.28.0 // indirect
        gopkg.in/yaml.v3 v3.0.1 // indirect
)
-- go/tools.go --
package main

import (
        _ "github.com/pseudomuto/protoc-gen-doc" // bazel/rules/proto/proto_doc.bzl
)
-- MODULE.bazel --
module(name="proto_validator")

bazel_dep(name = "rules_go", version = "0.44.0", repo_name = "io_bazel_rules_go")
bazel_dep(name = "gazelle", version = "0.35.0", repo_name = "bazel_gazelle")

go_sdk = use_extension("@io_bazel_rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(
    name = "go_sdk",
    version = "1.21.5",
)
use_repo(go_sdk, "go_sdk")

go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//go:go.mod")
use_repo(
    go_deps,
    "com_github_pseudomuto_protoc_gen_doc",
)

Run bazel build @com_github_pseudomuto_protoc_gen_doc//extensions/validator_field

What did you expect to see?

Build completes successfully

What did you see instead?

ERROR: no such package '@@[unknown repo 'com_github_mwitkow_go_proto_validators' requested from @@gazelle~0.35.0~go_deps~com_github_pseudomuto_protoc_gen_doc]//': The repository '@@[unknown repo 'com_github_mwitkow_go_proto_validators' requested from @@gazelle~0.35.0~go_deps~com_github_pseudomuto_protoc_gen_doc]' could not be resolved: No repository visible as '@com_github_mwitkow_go_proto_validators' from repository '@@gazelle~0.35.0~go_deps~com_github_pseudomuto_protoc_gen_doc'
ERROR: /private/var/tmp/_bazel_zplin/b44d72da7f9647162d3d0b95cd9d5b5a/external/gazelle~0.35.0~go_deps~com_github_pseudomuto_protoc_gen_doc/extensions/validator_field/BUILD.bazel:3:11: no such package '@@[unknown repo 'com_github_mwitkow_go_proto_validators' requested from @@gazelle~0.35.0~go_deps~com_github_pseudomuto_protoc_gen_doc]//': The repository '@@[unknown repo 'com_github_mwitkow_go_proto_validators' requested from @@gazelle~0.35.0~go_deps~com_github_pseudomuto_protoc_gen_doc]' could not be resolved: No repository visible as '@com_github_mwitkow_go_proto_validators' from repository '@@gazelle~0.35.0~go_deps~com_github_pseudomuto_protoc_gen_doc' and referenced by '@@gazelle~0.35.0~go_deps~com_github_pseudomuto_protoc_gen_doc//extensions/validator_field:validator_field'
ERROR: Analysis of target '@@gazelle~0.35.0~go_deps~com_github_pseudomuto_protoc_gen_doc//extensions/validator_field:validator_field' failed; build aborted: Analysis failed
INFO: Elapsed time: 13.517s, Critical Path: 0.02s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully
fmeum commented 9 months ago

Could you try adding an import of github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc to your tools.go? The top-level Go package does not seem to depend on the extensions.

linzhp commented 9 months ago

That fixed the issue!