bazel-gazelle icon indicating copy to clipboard operation
bazel-gazelle copied to clipboard

gazelle() rule fail with custom gazelle_binary

Open mpatou opened this issue 1 year ago • 5 comments

What version of gazelle are you using?

v0.32.0

What version of Bazel are you using?

6.3.2

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

yes

What operating system and processor architecture are you using?

Ubuntu 20.04, Intel x86_64

What did you do?

Using the rules_python's build_generation example (https://github.com/bazelbuild/rules_python/tree/main/examples/build_file_generation) I changed the rules to have (taking inspiration from https://github.com/bazelbuild/bazel-gazelle/blob/master/extend.md)

gazelle(
    name = "gazelle",
    data = GAZELLE_PYTHON_RUNTIME_DEPS,
    gazelle = "//:my_gazelle",
)


gazelle_binary(
    name = "mygazelle",
    languages = [
        "@rules_python_gazelle_plugin//python:python",
        "@bazel_gazelle//language/go",  # Built-in rule from gazelle for Golang.
    ],
    visibility = ["//visibility:public"],
)

What did you expect to see?

No error, gazelle would work and generate files

What did you see instead?

INFO: Running command line: bazel-bin/py_gazelle
gazelle: failed to create a runfiles object: runfiles: no runfiles found 

Note setting RUNFILES_MANIFEST_FILE to something like $(workspace)/bazel-bin/mygazelle_/mygazelle.runfiles_manifest does the trick but it's not great given that $(workspace) is actually not extrapolating.

mpatou avatar Oct 11 '23 05:10 mpatou

Note it's not just custom gazelle_binaryusing what is proposed by rules_python is also not working:

gazelle(
    name = "gazelle",
    data = GAZELLE_PYTHON_RUNTIME_DEPS,
    gazelle = "@rules_python//gazelle:gazelle_python_binary",
)

mpatou avatar Oct 11 '23 06:10 mpatou

If I check out rules_python and update the Gazelle version in examples/build_file_generation to v0.32.0, running bazel run //:gazelle in that directory succeeds. Could you check whether you are using the latest version of rules_python?

fmeum avatar Oct 11 '23 07:10 fmeum

I am. I have a synthetic repro that is a few files only I can upload it somewhere if you want to have a look.

mpatou avatar Oct 12 '23 03:10 mpatou

I can reproduce it now, I was on an older commit when I first tried this.

fmeum avatar Oct 12 '23 06:10 fmeum

I can reproduce this with Gazelle up to v0.32.0, but not with v0.33.0. I think that it was fixed by https://github.com/bazelbuild/bazel-gazelle/commit/e3deb49b65ad8d7ec6cbc54b7ff511a537f8de56.

@aignas It looks like some :gazelle target in rules_python's examples were broken without causing CI failures. In bazel-gazelle, we run the targets explicitly in CI and check that there is no diff for the examples. That could provide additional test coverage.

fmeum avatar Oct 12 '23 06:10 fmeum