-
Notifications
You must be signed in to change notification settings - Fork 12
[Question/Help Wanted] Annotation Processor get's called to late in the process? #11
Comments
I quickly made a minimal reproduction sample project (debugProject.zip)
After rebuild without clean i get the following:
Note the missing |
Hi @chippmann, i had a quick look at your demo project, you are kind of right with your observations. The problem is that the compiler runs through different phases. Usually the compiler checks the .kt files in the sourcesets only when the compiler/compiler plugin is starting. You can manually add additional source files, e.g in the ComponentRegistrar with "configuration.addKotlinSourceRoot()", but only in the analys phase. At the moment the annotation processor(mpapt) is too "late" for adding new sources. I use the DeclarationChecker to get the descriptors of the annotated Elements. But (as far as i understand), when the compiler creates the descriptors, it's too late to add additional sources for the compilation. I'm experimenting with using AdditionalTypeChecker to detect the annotations. It runs in the analysis phase, so it could be possible to add additional sources. But you can only get KtExpressions and not descriptors. And i had the problem that i could not get the package name of the annotation of KtExpressions, but i maybe found a workaround. |
That is very unfortunate. But makes sense of course. What kind of a workaround are you talking about? Maybe i could help you in some way or the other? Because i really need the code generation to work and am willing to help the best i can. Another idea? Is it possible to rerun a certain phase of the compiler during his execution? For example rerun the analysis phase after the code generation happened? And as another question. Which steps are part of the analysis phase? |
Maybe we find a solution in the kotlin serialization plugin? |
There is no official documentation, i did a lot of trial and error and digging through the compiler project source code. My idea was, that i use the AdditionalTypeChecker to check the annotations. I can only get the simple name(without package) of an annotation in this class, but i can also get the KtFile in which the found KtElement is contained. And then i can get the imports and check if my annotation is imported in this file. The serialization plugin generating is using platform specific codegen extensions to generate JvmBytecode/Javascript and IR Code. But i think, it wouldn't help in your specific case, because your generated Kotlin Source Files wouldn't be recognized and bytecode files wouldn't be checked for annotation with @cname. Maybe there is a way to restart a compiler plugin. I don't know |
That's what i thought but didn't hope. Yes I saw that yesterday evening as well. But this is over my head I think. Especially generating that much IR. Well I don't think this would be a problem as I don't need to see the CName annotation. I just need it to be compiled by the compiler. But something that might be interesting or you as well: https://github.com/vektory79/kotlin-script-parser-test/blob/master/src/main/java/hello/CompileTest.kt With this you get all information's that we get in the Annotation Processor but could execute it in a gradle task before build. This script is using the compiler version 1.1.0. But maybe i get it to work on 1.3.61 as well. But many things have changed since then. |
I just updated above linked script to kotlin compiler version Maybe that is a solution to my problem, but maybe it helps you as well: https://github.com/utopia-rise/godot-kotlin/blob/feature/rework_entry_code_generation/tools/entry-generator/src/main/kotlin/org/godotengine/kotlin/entrygenerator/parser/SourceCodeParser.kt |
Thank you, i will take a look at it and see if i can integrate parts of it somehow |
I'm actually not quite sure what problem I'm facing.
But to me it seems that the annotation processor gets called to late on a native target.
A bit of context:
I collect all classes, functions, and properties annotated in the processors
process
function (like in the examples).In the annotation processors
processingOver
function i generate code (like in the examples).This generated code is put into a subfolder of the build folder of the project. This subfolder is added as a src directory.
But on a clean build this generated code is not compiled into the final binary.
But if i don't clean the project first and build again (so the generated code is still in that subdir) it gets compiled into the final binary.
So my assumption is that my code gets compiled first, then the annotation processing happens, then the linking and so on.
I think i'm just misconfiguring something so that the annotation processing happens too late.
What am I doing wrong?
Also i don't really know what source code snippets you maybe need to help with my problem.
annotation processor
native component registrar
subplugin
The text was updated successfully, but these errors were encountered: