Skip to content

Commit

Permalink
Fix processor failing with 'FileAlreadyExistsException'
Browse files Browse the repository at this point in the history
The problem was due to the file we created being picked up by `autoSearch` from `getNewFiles()`, we now filter away all auto searched files that do not actually contain any nodes. This might just be a band-aid fix tho, as I don't fully understand how KSP handles all this stuff.

This wasn't caught until now due to this bug google/ksp#887
  • Loading branch information
Olivki committed Apr 12, 2022
1 parent 8f040bd commit 22ddf60
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion example/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/

plugins {
id("com.google.devtools.ksp") version "1.6.20-1.0.4"
id("com.google.devtools.ksp") version "1.6.20-1.0.5"
kotlin("plugin.serialization") version "1.6.20"
}

Expand Down
2 changes: 1 addition & 1 deletion processor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ plugins {
kotlin("kapt")
}

version = "0.3.1"
version = "0.4.0"

dependencies {
implementation("com.squareup:kotlinpoet-ksp:1.11.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ internal class KommandoProcessor(
if (modules.isEmpty()) return emptyList()

val (toInject, kommandoTypes) = segregateTypes(modules)
FileSpec.builder(packageName, fileName)
val file = FileSpec.builder(packageName, fileName)
.addImport("org.kodein.di", "instance")
.addFunction(buildKodeinSetup(toInject))
.addFunction(buildKommandoBuilder(kommandoTypes))
.build()
.writeTo(codeGenerator, Dependencies(aggregating = true, *modules.map { it.file }.toTypedArray()))
file.writeTo(codeGenerator, Dependencies(aggregating = true, *modules.map { it.file }.toTypedArray()))

return emptyList()
}
Expand Down Expand Up @@ -180,6 +180,7 @@ internal class KommandoProcessor(
.toList()
ModuleFile(file, nodes)
}
.filter { it.nodes.isNotEmpty() }

private fun Sequence<KSDeclaration>.mapToTypedNodes(): Sequence<TypedNode> =
mapNotNull { node -> node.accept(ReturnTypeVisitor, logger)?.let { TypedNode(it, node) } }
Expand Down

0 comments on commit 22ddf60

Please sign in to comment.