Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete stale code when output changes #7

Closed
MariusVolkhart opened this issue Mar 27, 2022 · 4 comments
Closed

Delete stale code when output changes #7

MariusVolkhart opened this issue Mar 27, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@MariusVolkhart
Copy link

Environment

  • JDK version: 19
  • Gradle version: 7.4.1
  • gradle-jextract version: 0.2.4
  • Operating system: MacOs

How does this bug occur?

When the output destination changes, such as when a new className or targetPackage is given, the previously-generated code remains until clean is run.

What happens when the bug occurs?

Compilation proceeds with both the new and the old code.

Would you like to submit a PR fixing this bug?

[ ] YES
[x] NO

@MariusVolkhart MariusVolkhart added the bug Something isn't working label Mar 27, 2022
@krakowski
Copy link
Owner

Hey, thanks for your interest in this project!

I'm not entirely sure if this is a bug. Do you experience problems (apart from disk usage) with this behavior? For example, protobuf-gradle-plugin does the same and keeps old classes after changing the .proto files.

  • If just className is changed, all generated files belonging to it should be overriden by jextract
  • If targetPackage is changed, the source code (i.e. imports) must be updated to reflect this change

Searching the Gradle documentation, I also could not find a way to detect changes in properties during task execution and retrieve the old value. There is InputChanges, however it only works with file properties.

@MariusVolkhart
Copy link
Author

No problems, no. Just seemed odd. Honestly, I initially started filing a feature request but then changed to a bug based on how I was phrasing the request. I think it's pretty rare that people change those values after the prototyping stage, so if you say "close, won't implement", I think that's reasonable.

The way I've seen other plugins do this is basically hashing their properties, and writing the files to a directory with the hash as a name. Then, on subsequent runs, they can see if any neighboring directories exist and delete them, since they indicate a different hash.

@MariusVolkhart
Copy link
Author

Also, thank you for making and publishing this plugin in the first place! It makes using jextract in a real project a ton easier

@krakowski
Copy link
Owner

Thanks for your input! I found an (very old) open issue at the protobuf-gradle-plugin repository which discusses a similar topic (google/protobuf-gradle-plugin#33).

The keypoints are:

  • Cleaning (i.e. deleting) the output directory could lead to unwillingly deleting other important files if the user specifies another directory than the default one inside the build directory (e.g. src).
  • Generated files from a previous task run can be queried using internal Gradle API DefaultTask#getOutputs. Using it in a plugin could result in unexpected behavior in the future.

Since, at the moment, it is only a matter of running gradle clean to delete old source files and deleting whole directories outside the build tree is pretty risky, I would like to go the "close, won't implement" way for now. Although, I'm happy to accept any pull requests solving this issue in a elegant way.

I'm glad this plugin helps other people spinning up projects using jextract! Also, thanks for using it! 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants