bazelbuild / bazel-gazelle

Gazelle is a Bazel build file generator for Bazel projects. It natively supports Go and protobuf, and it may be extended to support new languages and custom rule sets.
Apache License 2.0
1.17k stars 373 forks source link

Gazelle crashes in repository with MODULE but no WORKSPACE #1815

Open AttilaTheFun opened 3 months ago

AttilaTheFun commented 3 months ago

What version of gazelle are you using?

0.37.0

What version of rules_go are you using?

0.46.0

What version of Bazel are you using?

bazel 7.1.1-homebrew

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

Yes

What operating system and processor architecture are you using?

macOS Sonoma 14.1.1

What did you do?

Set up gazelle in a fresh repository for use with the Swift gazelle plugin and ran the update packages command.

What did you expect to see?

I expected it to update my MODULE.bazel file after resolving the dependency version.

What did you see instead?

Gazelle crashed with this stack trace:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x58 pc=0x10518efa8]

goroutine 1 [running]:
main.findWorkspaceInsertIndex(0x0, 0x140001f28c0?, {0x140000dc300, 0x3, 0x10529ee80?})
        external/gazelle~/cmd/gazelle/update-repos.go:458 +0x178
main.updateRepos({0x1400003410a, 0x31}, {0x140000200b0, 0x7, 0x7})
        external/gazelle~/cmd/gazelle/update-repos.go:269 +0x172c
main.run({0x1400003410a?, 0x31?}, {0x140000200a0?, 0x8?, 0x8?})
        external/gazelle~/cmd/gazelle/gazelle.go:99 +0x1ec
main.main()
        external/gazelle~/cmd/gazelle/gazelle.go:72 +0x104

I was informed that this is a known problem with Gazelle for MODULE-only repositories. Adding a blank WORKSPACE file fixed the issue. This should be resolved soon as Bazel 8 won't support WORKSPACE at all anymore.

fmeum commented 2 months ago

My hope is that with the state of bazel mod tidy in 7.2.0, we may be able to remove update-repos together with WORKSPACE support.

@cgrindel What do you think, would that be possible? Happy to discuss what would be needed to achieve a comparable user experience.

cgrindel commented 2 months ago

What do you think, would that be possible?

@fmeum Agreed. I am working on a branch that removes update-repos from rules_swift_package_manager. Does the WORKSPACE check only happen in the update-repos code path? If so, then this issue may be obsolete soon. If the update or fix code paths look for the workspace root, we will need to update Gazelle. Is that correct?