Skip to content

Commit

Permalink
Fix wrongly reported ksp error upon compilation error (#386)
Browse files Browse the repository at this point in the history
* Add script with gradle command for debugging the entry gen

* Fix wrong error message on compilation errors
  • Loading branch information
chippmann authored Nov 25, 2022
1 parent 37f3d4f commit 9def9b2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
3 changes: 3 additions & 0 deletions harness/tests/build_with_compiler_plugin_debug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

./gradlew build --no-daemon -Dorg.gradle.debug=true -Dkotlin.compiler.execution.strategy="in-process" -Dkotlin.daemon.jvm.options="-Xdebug,-Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=n"
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class GodotKotlinSymbolProcessor(
?: throw IllegalStateException("No projectBasePath option provided")

val registerAnnotationVisitor = RegistrationAnnotationVisitor(
logger,
projectBasePath,
registeredClassToKSFileMap,
sourceFilesContainingRegisteredClasses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import godot.entrygenerator.model.RegisteredProperty
import godot.entrygenerator.model.RegisteredSignal
import java.io.File

fun KSClassDeclaration.hasCompilationErrors(): Boolean = superTypes.toList().any { it.resolve().isError }

fun KSClassDeclaration.getResPath(srcDirs: List<String>, projectDir: String): String = containingFile
?.filePath
?.let { filePath ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package godot.annotation.processor.visitor

import com.google.devtools.ksp.processing.KSPLogger
import com.google.devtools.ksp.symbol.KSClassDeclaration
import com.google.devtools.ksp.symbol.KSFile
import com.google.devtools.ksp.symbol.KSVisitorVoid
Expand All @@ -9,11 +10,13 @@ import godot.annotation.RegisterFunction
import godot.annotation.RegisterProperty
import godot.annotation.RegisterSignal
import godot.annotation.processor.ext.fqNameUnsafe
import godot.annotation.processor.ext.hasCompilationErrors
import godot.annotation.processor.ext.mapToClazz
import godot.entrygenerator.model.RegisteredClass
import godot.entrygenerator.model.SourceFile

class RegistrationAnnotationVisitor(
private val logger: KSPLogger,
private val projectBasePath: String,
private val registeredClassToKSFileMap: MutableMap<RegisteredClass, KSFile>,
private val sourceFilesContainingRegisteredClasses: MutableList<SourceFile>
Expand All @@ -34,10 +37,15 @@ class RegistrationAnnotationVisitor(
.mapNotNull { declaration ->
when (declaration) {
is KSClassDeclaration -> {
val clazz = declaration.mapToClazz(projectBasePath)
if (clazz is RegisteredClass) {
clazz
} else null
if (!declaration.hasCompilationErrors()) {
val clazz = declaration.mapToClazz(projectBasePath)
if (clazz is RegisteredClass) {
clazz
} else null
} else {
logger.warn("Declaration will not be processed as it seems to have compilation errors.", declaration)
null
}
}
else -> if (declaration.annotations.any { registerAnnotations.contains(it.fqNameUnsafe) }) {
throw IllegalStateException("${declaration.qualifiedName} was registered top level. Only classes can be registered top level.")
Expand Down

0 comments on commit 9def9b2

Please sign in to comment.