Zac Sweers
12/17/2021, 10:14 PMYoussef Shoaib [MOD]
12/20/2021, 4:24 PMCollectAdditionalSources
(if memory serves) extension point where you can place in new files. So, your plugin can just create dummy files, and IR files will be generated for them accordingly.Zac Sweers
12/20/2021, 4:36 PMYoussef Shoaib [MOD]
12/20/2021, 4:37 PMZac Sweers
12/20/2021, 5:37 PMYoussef Shoaib [MOD]
12/20/2021, 5:47 PMYoussef Shoaib [MOD]
12/20/2021, 5:59 PMfile.declarations.add()
and I set that specific declaration's parent to be the file. Like this simply:
val deferredAddedFunctions: MutableMap<IrDeclarationWithParent, IrFile> = mutableMapOf()
MyTransformer(deferredAddedFunctions).lower(moduleFragment) //Add any created declaration to that mutable list
for ((deferredAddedFunction, file) in deferredAddedFunctions) {
file.declarations.add(deferredAddedFunction)
deferredAddedFunction.parent = file
}
IIRC this avoids a CME and works properly. Creating those declarations, btw, can be done using IrDeclaration.factory.buildXX
. In the linked repository, you can see an example of this in practice, but keep in mind that the code isn't the most comprehensible in the world right now since it's just a side project.Youssef Shoaib [MOD]
12/20/2021, 5:59 PMZac Sweers
12/20/2021, 6:00 PMZac Sweers
12/20/2021, 6:55 PMZac Sweers
12/24/2021, 10:24 PMYoussef Shoaib [MOD]
12/25/2021, 7:53 AMbuildDir/generated/sources/${pluginName}/${sourceSetName}
. I believe for resources they're usually placed in buildDir/resources/${sourceSetName}
(based on the behavior of the Maven plexus plugin I believe). BTW, it's absolutely okay to generate those files as blanks and then populate them in the IR phase since resources are merged in the JVM backend itself (and for JS their equivalent for resources is sent to whatever build system is used to pack all the files together).Youssef Shoaib [MOD]
12/25/2021, 7:56 AMZac Sweers
12/25/2021, 5:32 PMZac Sweers
12/25/2021, 5:32 PMYoussef Shoaib [MOD]
12/26/2021, 11:53 AMYoussef Shoaib [MOD]
12/26/2021, 11:55 AMZac Sweers
12/26/2021, 3:19 PM