bazelbuild / intellij

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

`-filtered-gen.jar` and `-filtered-gen-src.jar` generated for packages without any `.java` files #6407

Closed dkashyn-sfdc closed 3 months ago

dkashyn-sfdc commented 4 months ago

Description of the feature request:

We do have "resources"-only packages that generate Java code and then compile it as part of the build. Those packages are consumed by others, and sources/classes are certainly used downstream. Some of such modules have absolutely no .java sources present that results in missing -filtered-gen.jar entries.

Since there are no source artifacts generated for such packages, there is nothing in .intellij-info.txt after aspects pass, and IDE cannot navigate to legitimate sources.

I suspect that https://github.com/bazelbuild/intellij/blame/86e31292434875ca1f86a02230cde5a3de5a70cf/aspect/intellij_info_impl.bzl#L794 should detect such cases to be able to generate required jars anyway here https://github.com/bazelbuild/intellij/blame/86e31292434875ca1f86a02230cde5a3de5a70cf/aspect/intellij_info_impl.bzl#L653

Which category does this issue belong to?

Intellij

What underlying problem are you trying to solve with this feature?

Navigation to the generated source code for non-standard targets without any .java sources.

What operating system, Intellij IDE and programming languages are you using? Please provide specific versions.

Any

Have you found anything relevant by searching the web?

No response

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

Before:

❯ ls -l bazel-bin/pppp/ | grep gen
dr-xr-xr-x. 4 user group  4096 Apr 25 14:59 rrr_generated
-rwxr-xr-x. 1 user group 10577 Apr 18 13:51 rrr_generated-0.params

Then I've created a dummy class that was just an empty file

image

After running Bazel Sync next time I see

❯ ls -l bazel-bin/pppp | grep gen
-r-xr-xr-x. 1 user group  1843 Apr 25 20:05 pppp_lib-filtered-gen.jar
-r-xr-xr-x. 1 user group  1808 Apr 25 20:05 pppp_lib-filtered-gen-src.jar
dr-xr-xr-x. 4 user group  4096 Apr 25 14:59 rrr_generated
-rwxr-xr-x. 1 user group 10577 Apr 18 13:51 rrr_generated-0.params
tpasternak commented 4 months ago

I'm not sure honestly. Maybe these targets could be just added to the libraries section in IntelliJ Project Structure? Would it be possible to prepare a minimal reproducible example?

dkashyn-sfdc commented 4 months ago

This is part of our large project and generation is happening inside a macro. So I don't even have a good repro to share here :(

I need to introduce some Code generation to greetings_project to even give you a repro.

Is there a way to do this now, @tpasternak ?

Maybe these targets could be just added to the libraries section in IntelliJ Project Structure

tpasternak commented 4 months ago

It might but I think it is expected to happen automatically. Are these targets included in your targets section in the projecview file?

dkashyn-sfdc commented 4 months ago

We not using targets and directories is the only mechanism that we using.

dkashyn-sfdc commented 4 months ago

Please note that we have hundreds of such "targets" so if we want to include all of those as part of .bazelproject we need to use some wildcards, and even this might not be possible. I need to explore our graph more and probably rename some things to make it work.

dkashyn-sfdc commented 4 months ago

@tpasternak you can find repro here https://github.com/bazelbuild/intellij/pull/6415/files. It probably not a wrong idea to add some code generation to sample project as well...

With

directories:
  # Add the directories you want added as source here
  # By default, we've added your entire workspace ('.')
  greeting_lib

# Automatically includes all relevant targets under the 'directories' above
derive_targets_from_directories: true

targets:
  # If source code isn't resolving, add additional targets that compile it here

additional_languages:
  # Uncomment any additional languages you want supported
  # android
  # dart
  # go
  # javascript
  # kotlin
  # python
  # scala
  # typescript
image

With

directories:
  # Add the directories you want added as source here
  # By default, we've added your entire workspace ('.')
  .

# Automatically includes all relevant targets under the 'directories' above
derive_targets_from_directories: true

targets:
  # If source code isn't resolving, add additional targets that compile it here

additional_languages:
  # Uncomment any additional languages you want supported
  # android
  # dart
  # go
  # javascript
  # kotlin
  # python
  # scala
  # typescript
image
dkashyn-sfdc commented 4 months ago

With a dummy java class

image image
tpasternak commented 4 months ago

Ok, to me it seems to be unrelated to the JarFilter logic. The generated library is correctly attached with the source jar, but the contents of the source jar doesn't match the contents of the jar. Doesn't it look like a bazel bug?

image

image

tpasternak commented 4 months ago

Reported to bazel https://github.com/bazelbuild/bazel/issues/22254

dkashyn-sfdc commented 3 months ago

This issue is more nuanced and not only filtered-gen-src.jar can be used as lib source.

_lib-src.jar is used when package with generated module referred from some other module.