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

JavaCompilerPlugin doesn't handle outputs correctly #114

Open
jakepetroules opened this issue Oct 25, 2024 · 2 comments
Open

JavaCompilerPlugin doesn't handle outputs correctly #114

jakepetroules opened this issue Oct 25, 2024 · 2 comments
Labels
build plugin help wanted Extra attention is needed

Comments

@jakepetroules
Copy link

jakepetroules commented Oct 25, 2024

The JavaCompilerPlugin has a serious flaw in that it doesn't handle outputs correctly -- it simply maps each .java file path to an equivalent .class file path, but due to a combination of use of certain language features like inner classes, and compiler implementation details which can vary across versions and implementations, there is NO guarantee that compilation of a set of Java sources will produce corresponding .class files at a 1:1 relationship.

This means the outputFiles may fail to capture class files which are generated, leading to broken products and/or broken incremental builds.

In Qbs I implemented this via a tool using compiler APIs to get the list of the .class files which will be produced: https://github.com/qbs/qbs/blob/master/share/qbs/modules/java/io/qt/qbs/tools/utils/JavaCompilerScanner.java. But this is a more involved solution and is only needed if you want to pass individual .class files to downstream build rules for further processing.

For now, can we instead produce a jar file with the set of generated classes, and list THAT as the build tool plugin command output? This simplifies the solution significantly.

@ktoso
Copy link
Collaborator

ktoso commented Oct 28, 2024

Yeah that's a good observation; I'm a bit worried about the JavaCompilerPlugin exploding in complexity to be honest, especially once we add dependencies to the mix.

For this specific topic, I think it might be easier if we give up on it being a "build plugin" and make it a "prebuild plugin" as these do not have to list all the exact outputs: https://github.com/swiftlang/swift-package-manager/blob/main/Documentation/Plugins.md

We would have to do some smarter caching in the prebuild plugin then though, so it's not ideal but may be easier than figuring out what javac might decide to emit (with closures etc this may also become "fun").

So maybe that's a direction to consider?

@ktoso
Copy link
Collaborator

ktoso commented Oct 28, 2024

The jar producing idea also isn't bad, whoever picks up the work can figure out what'll be nicer 👍

@ktoso ktoso added help wanted Extra attention is needed build plugin labels Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build plugin help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants