Repository: evant/kotlin-inject
Pull request #94 (2021-02-25 22:10:57)

Update ksp to alpha


Patch:
diff --git a/gradle.properties b/gradle.properties
index d0a24a1..eda4377 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,4 +1,4 @@
-kotlin_version=1.4.20
-ksp_version=1.4.20-dev-experimental-20210111
+kotlin_version=1.4.30
+ksp_version=1.4.30-1.0.0-alpha03
 org.gradle.parallel=true
 ksp.incremental=true
\ No newline at end of file
diff --git a/kotlin-inject-compiler-ksp/src/main/kotlin/me/tatarka/inject/compiler/ksp/InjectProcessor.kt b/kotlin-inject-compiler-ksp/src/main/kotlin/me/tatarka/inject/compiler/ksp/InjectProcessor.kt
index 39eb026..794f83e 100644
--- a/kotlin-inject-compiler-ksp/src/main/kotlin/me/tatarka/inject/compiler/ksp/InjectProcessor.kt
+++ b/kotlin-inject-compiler-ksp/src/main/kotlin/me/tatarka/inject/compiler/ksp/InjectProcessor.kt
@@ -4,6 +4,7 @@ import com.google.devtools.ksp.processing.CodeGenerator
 import com.google.devtools.ksp.processing.KSPLogger
 import com.google.devtools.ksp.processing.Resolver
 import com.google.devtools.ksp.processing.SymbolProcessor
+import com.google.devtools.ksp.symbol.KSAnnotated
 import com.google.devtools.ksp.symbol.KSClassDeclaration
 import me.tatarka.inject.annotations.Component
 import me.tatarka.inject.compiler.FailedToGenerateException
@@ -30,7 +31,7 @@ class InjectProcessor(private val profiler: Profiler? = null) : SymbolProcessor,
     }
 
     @Suppress("LoopWithTooManyJumpStatements")
-    override fun process(resolver: Resolver) {
+    override fun process(resolver: Resolver): List<KSAnnotated> {
         this.resolver = resolver
 
         profiler?.onStart()
@@ -52,9 +53,11 @@ class InjectProcessor(private val profiler: Profiler? = null) : SymbolProcessor,
         }
 
         profiler?.onStop()
+
+        return emptyList()
     }
 
     override fun finish() {
-        messenger.finalize()
+        // ignore
     }
 }
\ No newline at end of file
diff --git a/kotlin-inject-compiler-ksp/src/main/kotlin/me/tatarka/inject/compiler/ksp/KSAst.kt b/kotlin-inject-compiler-ksp/src/main/kotlin/me/tatarka/inject/compiler/ksp/KSAst.kt
index 6a4c689..6a3d31d 100644
--- a/kotlin-inject-compiler-ksp/src/main/kotlin/me/tatarka/inject/compiler/ksp/KSAst.kt
+++ b/kotlin-inject-compiler-ksp/src/main/kotlin/me/tatarka/inject/compiler/ksp/KSAst.kt
@@ -49,7 +49,6 @@ import me.tatarka.inject.compiler.AstTypeSpec
 import me.tatarka.inject.compiler.AstVisibility
 import me.tatarka.inject.compiler.Messenger
 import me.tatarka.inject.compiler.OutputProvider
-import org.jetbrains.kotlin.analyzer.AnalysisResult
 
 import kotlin.reflect.KClass
 
@@ -115,7 +114,6 @@ interface KSAstProvider : AstProvider, OutputProvider<CodeGenerator> {
 }
 
 object KSAstMessenger : Messenger {
-    private val errorMessages = mutableListOf<Message>()
     internal lateinit var logger: KSPLogger
 
     override fun warn(message: String, element: AstElement?) {
@@ -124,39 +122,6 @@ object KSAstMessenger : Messenger {
 
     override fun error(message: String, element: AstElement?) {
         logger.error(message, (element as? KSAstAnnotated)?.declaration)
-        errorMessages.add(Message(message, element))
-    }
-
-    fun finalize() {
-        // ksp won't error out if no exception is thrown
-        if (errorMessages.isNotEmpty()) {
-            throw AnalysisResult.CompilationErrorException()
-        }
-    }
-
-    private data class Message(val message: String, val element: AstElement?) {
-        override fun toString(): String = StringBuilder().apply {
-            val containing = when (element) {
-                is KSAstFunction -> element.declaration.parentDeclaration
-                is KSAstConstructor -> element.declaration.parentDeclaration
-                is KSAstProperty -> element.declaration.parentDeclaration
-                is KSAstParam -> element.parent
-                else -> null
-            }
-            if (containing != null) {
-                if (containing.qualifiedName != null) {
-                    append(containing.qualifiedName?.asString())
-                } else {
-                    append(containing.parentDeclaration?.qualifiedName?.asString())
-                }
-                append(": ")
-            }
-            append(message)
-            if (element != null) {
-                append("\n\t")
-                append(element)
-            }
-        }.toString()
     }
 }
 


Test patch:
diff --git a/compiler-tests/build.gradle b/compiler-tests/build.gradle
index a726ad9..aa0ca6c 100644
--- a/compiler-tests/build.gradle
+++ b/compiler-tests/build.gradle
@@ -9,7 +9,7 @@ dependencies {
     implementation project(':kotlin-inject-compiler-kapt')
     implementation project(':kotlin-inject-compiler-ksp')
 
-    implementation 'com.github.tschuchortdev:kotlin-compile-testing-ksp:1.3.4'
+    implementation 'com.github.tschuchortdev:kotlin-compile-testing-ksp:1.3.5'
     implementation "org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlin_version"
     implementation "org.jetbrains.kotlin:kotlin-annotation-processing-embeddable:$kotlin_version"
     implementation "com.google.devtools.ksp:symbol-processing:$ksp_version"
diff --git a/compiler-tests/src/main/kotlin/me/tatarka/inject/ProjectCompiler.kt b/compiler-tests/src/main/kotlin/me/tatarka/inject/ProjectCompiler.kt
index a57b7b0..e731bcb 100644
--- a/compiler-tests/src/main/kotlin/me/tatarka/inject/ProjectCompiler.kt
+++ b/compiler-tests/src/main/kotlin/me/tatarka/inject/ProjectCompiler.kt
@@ -8,9 +8,7 @@ import me.tatarka.inject.compiler.Options
 import me.tatarka.inject.compiler.Profiler
 import me.tatarka.inject.compiler.kapt.InjectCompiler
 import me.tatarka.inject.compiler.ksp.InjectProcessor
-import java.io.ByteArrayOutputStream
 import java.io.File
-import java.io.PrintStream
 
 class ProjectCompiler(
     private val target: Target,
@@ -32,13 +30,8 @@ class ProjectCompiler(
     }
 
     fun compile() {
-        val output = ByteArrayOutputStream()
-        val printOut = PrintStream(output)
-        val oldErr = System.err
-        System.setErr(printOut)
         val result = KotlinCompilation().apply {
             sources = sourceFiles
-            messageOutputStream = printOut
             root?.let { workingDir = it }
             inheritClassPath = true
             when (target) {
@@ -56,11 +49,10 @@ class ProjectCompiler(
                 }
             }
         }.compile()
-        System.setErr(oldErr)
 
         if (result.exitCode != KotlinCompilation.ExitCode.OK) {
             @Suppress("TooGenericExceptionThrown")
-            throw Exception(output.toString())
+            throw Exception(result.messages)
         }
     }
 }
diff --git a/integration-tests/ksp-companion/build.gradle b/integration-tests/ksp-companion/build.gradle
index 16dcce0..532ad40 100644
--- a/integration-tests/ksp-companion/build.gradle
+++ b/integration-tests/ksp-companion/build.gradle
@@ -4,7 +4,7 @@ plugins {
 }
 
 dependencies {
-    ksp project(':kotlin-inject-compiler-ksp')
+    kspTest project(':kotlin-inject-compiler-ksp')
     implementation project(':kotlin-inject-runtime')
     implementation project(':integration-tests:module')
 
diff --git a/integration-tests/ksp/build.gradle b/integration-tests/ksp/build.gradle
index 7e19fdd..e3267ff 100644
--- a/integration-tests/ksp/build.gradle
+++ b/integration-tests/ksp/build.gradle
@@ -4,7 +4,7 @@ plugins {
 }
 
 dependencies {
-    ksp project(':kotlin-inject-compiler-ksp')
+    kspTest project(':kotlin-inject-compiler-ksp')
     implementation project(':kotlin-inject-runtime')
     implementation project(':integration-tests:module')