Skip to content

bazel_gazelle dependency needs to be moved out of // (the root package) #152

@jacky8hyf

Description

@jacky8hyf

To reproduce this issue:

  1. Go to commit 6ad7743
  2. Do the following edits:

e2e/smoke/BUILD

load("@bazel_skylib//rules:build_test.bzl", "build_test")

alias(
    name = "empty",
    actual = "@com_myorg_rules_mylang//mylang:resolved_toolchain",
)

build_test(
    name = "smoke_test",
    targets = [
        # targets you add above
        ":empty",
    ],
)

Then:

cd e2e/smoke && bazel build //:empty

This will fail with the following error message on Bazel 8.3.1:

ERROR: error loading package '@@com_myorg_rules_mylang+//': Unable to find package for @@[unknown repo 'bazel_gazelle' requested from @@com_myorg_rules_mylang+]//:def.bzl: The repository '@@[unknown repo 'bazel_gazelle' requested from @@com_myorg_rules_mylang+]' could not be resolved: No repository visible as '@bazel_gazelle' from repository '@@com_myorg_rules_mylang+'.
ERROR: <HOME>/.cache/bazel/_bazel_elsk/176206515ed6554e22e9ad36c6477dc2/external/com_myorg_rules_mylang+/mylang/BUILD.bazel:10:15: every rule of type toolchain_type implicitly depends upon the target '@@com_myorg_rules_mylang+//:package_metadata', but this target could not be found because of: error loading package '@@com_myorg_rules_mylang+//': Unable to find package for @@[unknown repo 'bazel_gazelle' requested from @@com_myorg_rules_mylang+]//:def.bzl: The repository '@@[unknown repo 'bazel_gazelle' requested from @@com_myorg_rules_mylang+]' could not be resolved: No repository visible as '@bazel_gazelle' from repository '@@com_myorg_rules_mylang+'.
ERROR: <HOME>/.cache/bazel/_bazel_elsk/176206515ed6554e22e9ad36c6477dc2/external/com_myorg_rules_mylang+/mylang/BUILD.bazel:15:19: Analysis failed
ERROR: Analysis of target '//:empty' failed; build aborted: Analysis failed
INFO: Elapsed time: 0.076s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully

To resolve this issue, I think the root BUILD.bazel file cannot have a dependency on bazel_gazelle; it needs to be moved to another package. We can use an alias to keep backwards compatibility.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions