bazelbuild / intellij

IntelliJ plugin for Bazel projects
https://ij.bazel.build/
Apache License 2.0
761 stars 302 forks source link

Running `bazel mod ...` From Plugin Fails on Non-BzlMod Project #6703

Closed andponlin-canva closed 2 weeks ago

andponlin-canva commented 2 weeks ago

Description of the bug:

A recent change 0cd1de2aed660ffdda5f1f376d87dfea06c907e7 on master runs a command bazel mod which fails for repositories which have --noenable_bzlmod turned on (are using WORKSPACE) but are using a version of Bazel >= 7.1.0.

The error from the tool is;

ERROR: Bzlmod has to be enabled for mod command to work, run with --enable_bzlmod. Type 'bazel help mod' for syntax and help.

Can you please update ExternalWorkspaceDataProvider#isEnabled to always return false until there is a means to verify that the project has BzlMod configured before executing the bazel mod command?

Which category does this issue belong to?

No response

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Take a sample project that is not configured for BzlMod. Edit the .bazelrc file to contain;

common --noenable_bzlmod

Ensure you are using Bazel >= 7.1.0, open the project with a build of the Intelli-J plugin from master and sync.

Which Intellij IDE are you using? Please provide the specific version.

2024.1

What programming languages and tools are you using? Please provide specific versions.


What Bazel plugin version are you using?

7.3.1

Have you found anything relevant by searching the web?


Any other information, logs, or outputs that you want to share?


andponlin-canva commented 2 weeks ago

CC @mtoader

mtoader commented 2 weeks ago

Driving today, but i'll try to make it better at opting in here.

mtoader commented 2 weeks ago

@andponlin-canva posted a PR disabling this.

I will think through on a better opt-in (most likely it will be an explicit flag in projectview if i can't find a reliable way to querying default values of flags).

andponlin-canva commented 2 weeks ago

@mtoader ; Thank you for that. I'll wait for your PR to merge then remove it from my side.

Unfortunately finding out if BzlMod is enabled is a bit tricky. Before your logic runs there is a bazel info executed. I wonder if the Bazel authors would consider adding an indicator into that command's output to support this?

The only other way I know of is to do this in Starlark;

BZLMOD_ENABLED = "@@" in str(Label("//:unused"))
mtoader commented 2 weeks ago

@mtoader ; Thank you for that. I'll wait for your PR to merge then remove it from my side.

Unfortunately finding out if BzlMod is enabled is a bit tricky. Before your logic runs there is a bazel info executed. I wonder if the Bazel authors would consider adding an indicator into that command's output to support this?

The only other way I know of is to do this in Starlark;

BZLMOD_ENABLED = "@@" in str(Label("//:unused"))

I was also looking at running bazel info --announce_rc but not sure how that would work w.r.t. inheritance. Also that would require me writing a parser for some unstructured bazel output.

tpasternak commented 2 weeks ago

I also wanted to add a hidden flag that would disable it (just for basic troubleshooting). https://github.com/bazelbuild/intellij/pull/6706

When comes to bzlmod, we can even ask the bazel team to provide flag, or even check if bazel fails with "Bzlmod has to be enabled" error and recover silently

mtoader commented 2 weeks ago

I also wanted to add a hidden flag that would disable it (just for basic troubleshooting). https://github.com/bazelbuild/intellij/pull/6706

When comes to bzlmod, we can even ask the bazel team to provide flag, or even check if bazel fails with "Bzlmod has to be enabled" error and recover silently

A flag in bazel would help but that would be in the future. I would need something now.

Will try to see if i can use bazel query and maybe an expression like the one suggested above. And will definitely add a flag.

tpasternak commented 2 weeks ago

Oh, the flag is intended only to unblock users for whom it would fail for an unknown, unexpected reason.

We of course need to detect it (or precisely handle this failure and recover)

tpasternak commented 2 weeks ago

Registry flag is already there btw

mtoader commented 2 weeks ago

I meant a project view flag (or section). However, in meantime I randomly realized this exists:

➜ bazel info starlark-semantics
INFO: Invocation ID: a07b1705-e4c4-4d8d-af60-81566aa4b02b
StarlarkSemantics{enable_bzlmod=false, incompatible_use_plus_in_repo_names=true}

that thing should only show enable_bzlmod=false if the flag is actively disabled in bazel 7+.