bazelbuild / buildtools

A bazel BUILD file formatter and editor
Apache License 2.0
994 stars 410 forks source link

no such target '@@com_github_bazelbuild_buildtools//buildifier:runner.bat.template' #1259

Closed steve-261370 closed 2 months ago

steve-261370 commented 3 months ago

In #1011 support for windows was added. It added the new attribute label _windows_runner as follows:

https://github.com/bazelbuild/buildtools/blob/v7.1.0/buildifier/internal/factory.bzl#L83

        "_runner": attr.label(
            default = "//buildifier:runner.bash.template",
            allow_single_file = True,
        ),
        "_windows_runner": attr.label(
            default = "@com_github_bazelbuild_buildtools//buildifier:runner.bat.template",
            allow_single_file = True,
        ),

Notice how the default key for the _windows_runner attribute, references runner.bat.template by the external dependency @com_github_bazelbuild_buildtools but the other _runner refers to it with an absolute path.

default = "//buildifier:runner.bash.template",

vs

default = "@com_github_bazelbuild_buildtools//buildifier:runner.bat.template",


I use this project to configure a buildifier target in my own Bazel project:

load("@bazel_buildtools//buildifier:def.bzl", "buildifier")

buildifier(
    name = "buildifier",
)

But when I upgraded to the latest version, v7.1.0, the target now fails with:

ERROR: /home/steve-261370/.cache/bazel/_bazel_steve-261370/2914a5da309afa1aa83708b7e78fb71f/external/com_github_bazelbuild_buildtools/buildifier/BUILD.bazel: no such target '@@com_github_bazelbuild_buildtools//buildifier:runner.bat.template': target 'runner.bat.template' not declared in package 'buildifier' defined by /home/steve-261370/.cache/bazel/_bazel_steve-261370/2914a5da309afa1aa83708b7e78fb71f/external/com_github_bazelbuild_buildtools/buildifier/BUILD.bazel (did you mean runner.bash.template?)
ERROR: /home/steve-261370/my-bazel-project/BUILD.bazel:10:11: every rule of type _buildifier implicitly depends upon the target '@@com_github_bazelbuild_buildtools//buildifier:runner.bat.template', but this target could not be found because of: no such target '@@com_github_bazelbuild_buildtools//buildifier:runner.bat.template': target 'runner.bat.template' not declared in package 'buildifier' defined by /home/steve-261370/.cache/bazel/_bazel_steve-261370/2914a5da309afa1aa83708b7e78fb71f/external/com_github_bazelbuild_buildtools/buildifier/BUILD.bazel (did you mean runner.bash.template?)

I ended up fixing this by replacing the line:

default = "@com_github_bazelbuild_buildtools//buildifier:runner.bat.template",

with

default = "//buildifier:runner.bat.template",