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

gazelle treats legal package name as containing invalid characters

Open alexeagle opened this issue 2 years ago • 2 comments

I have a package starting with @ which has been legal in Bazel since somewhere in the pre-1.0 release time. (It's needed to express packages which are also published to npm, where the @ prefix signifies a scoped package)

gazelle: @aspect_rules_webpack//:index: import of "//@bazel/webpack:defs.bzl" is invalid: label parse error: package has invalid characters: "//@bazel/webpack:defs.bzl"

What version of gazelle are you using?

0.24.0

What version of rules_go are you using?

0.29.0

What version of Bazel are you using?

4.2.0

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

What operating system and processor architecture are you using?

What did you do?

Run gazelle where it walks into a .bzl file in a folder starting with @

What did you expect to see?

Should just generate targets in there.

What did you see instead?

error above

alexeagle avatar Nov 08 '21 16:11 alexeagle

I think this is controlled by this regex

https://github.com/bazelbuild/bazel-gazelle/blob/c97d7e3be2db1ec88cd6437f5026e7a95e284a29/label/label.go#L66

and I'd be happy to merge an update to that regexp to make it consistent with what Bazel expects. There is even a TestParse

https://github.com/bazelbuild/bazel-gazelle/blob/c97d7e3be2db1ec88cd6437f5026e7a95e284a29/label/label_test.go#L57-L66

that could be extended to add a regression test.

achew22 avatar Nov 08 '21 22:11 achew22

I was going to address this but this looks like it works on main? at least these test cases work:

{str: "@npm//@bazel/typescript:typescript", want: Label{Repo: "npm", Pkg: "@bazel/typescript", Name: "typescript"}},
{str: "//@bazel/webpack:defs.bzl", want: Label{Pkg: "@bazel/webpack", Name: "defs.bzl"}},

Edit: yeah fixed in https://github.com/bazelbuild/bazel-gazelle/commit/757e291d1befe9174fb1fcf0d9ade733cbb6b904

iamricard avatar Sep 02 '22 16:09 iamricard