Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing from repository with multiple modules fails #1865

Closed
mering opened this issue Aug 14, 2024 · 1 comment
Closed

Importing from repository with multiple modules fails #1865

mering opened this issue Aug 14, 2024 · 1 comment

Comments

@mering
Copy link
Contributor

mering commented Aug 14, 2024

What version of gazelle are you using?

0.38.0

What version of rules_go are you using?

0.49.0

What version of Bazel are you using?

7.3

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

Yes

What operating system and processor architecture are you using?

Linux x86_64

What did you do?

  1. Generated a go.mod file via
    1. go mod init test
    2. go get github.com/containerd/containerd
  2. Create a MODULE.bazel file with the following content
    module(
        name = "test",
    )
    
    bazel_dep(name = "rules_go", version = "0.49.0")
    
    go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
    go_sdk.download(version = "1.23.0")
    
    bazel_dep(name = "gazelle", version = "0.38.0")
    
    go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
    go_deps.from_file(go_mod = "//:go.mod")
    use_repo(
        go_deps,
        "com_github_containerd_containerd",
    )
    
  3. touch BUILD
  4. USE_BAZEL_VERSION=7.x bazelisk build @com_github_containerd_containerd//...

What did you expect to see?

Build succeeds.

What did you see instead?

ERROR: no such package '@@gazelle~~go_deps~com_github_containerd_containerd//github.com/containerd/containerd/api/types/task': BUILD file not found in directory 'github.com/containerd/containerd/api/types/task' of external repository @@gazelle~~go_deps~com_github_containerd_containerd. Add a BUILD file to a directory to mark it as a package.
ERROR: HOME/.cache/bazel/_bazel_USER/9d227236e269dae4c9e47180964091a9/external/gazelle~~go_deps~com_github_containerd_containerd/runtime/v1/shim/v1/BUILD.bazel:5:14: no such package '@@gazelle~~go_deps~com_github_containerd_containerd//github.com/containerd/containerd/api/types/task': BUILD file not found in directory 'github.com/containerd/containerd/api/types/task' of external repository @@gazelle~~go_deps~com_github_containerd_containerd. Add a BUILD file to a directory to mark it as a package. and referenced by '@@gazelle~~go_deps~com_github_containerd_containerd//runtime/v1/shim/v1:shim_proto'
ERROR: Analysis of target '@@gazelle~~go_deps~com_github_containerd_containerd//runtime/v1/shim/v1:shim_proto' failed; build aborted: Analysis failed

The repository github.com/containerd/containerd contains multiple modules. The relevant ones are

For some reasons Gazelle generates the package com_github_containerd_containerd//github.com/containerd/containerd/api/types/task instead of com_github_containerd_containerd_api//types/task. It's go.mod file contains a replace github.com/containerd/containerd/api => ./api line.

Related issues

#689

@mering
Copy link
Contributor Author

mering commented Aug 14, 2024

I fixed it by adding the following directives to MODULE.bazel:

go_deps.gazelle_override(
    directives = [
        "gazelle:proto disable",
    ],
    path = "github.com/containerd/containerd",
)
go_deps.gazelle_override(
    directives = [
        "gazelle:proto disable",
    ],
    path = "github.com/containerd/containerd/api",
)
go_deps.gazelle_override(
    directives = [
        "gazelle:proto disable",
    ],
    path = "github.com/containerd/ttrpc",
)

As suggested in rules_go documentation, I created #1866 in order to add them to the default directives.

@mering mering closed this as completed Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant