Skip to content

Commit 8f32d84

Browse files
evanttschuchortdev
authored andcommitted
Allow passing args to ksp
1 parent b8a9e05 commit 8f32d84

File tree

1 file changed

+20
-2
lines changed
  • ksp/src/main/kotlin/com/tschuchort/compiletesting

1 file changed

+20
-2
lines changed

ksp/src/main/kotlin/com/tschuchort/compiletesting/Ksp.kt

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ var KotlinCompilation.symbolProcessors: List<SymbolProcessor>
3434
val KotlinCompilation.kspSourcesDir: File
3535
get() = kspWorkingDir.resolve("sources")
3636

37+
/**
38+
* Arbitrary arguments to be passed to ksp
39+
*/
40+
var KotlinCompilation.kspArgs: MutableMap<String, String>
41+
get() = getKspRegistrar().options
42+
set(value) {
43+
val registrar = getKspRegistrar()
44+
registrar.options = value
45+
}
46+
3747
private val KotlinCompilation.kspJavaSourceDir: File
3848
get() = kspSourcesDir.resolve("java")
3949

@@ -42,6 +52,7 @@ private val KotlinCompilation.kspKotlinSourceDir: File
4252

4353
private val KotlinCompilation.kspResourceDir: File
4454
get() = kspSourcesDir.resolve("resource")
55+
4556
/**
4657
* The working directory for KSP
4758
*/
@@ -80,11 +91,16 @@ private class KspCompileTestingComponentRegistrar(
8091
private val compilation: KotlinCompilation
8192
) : ComponentRegistrar {
8293
var processors = emptyList<SymbolProcessor>()
94+
95+
var options: MutableMap<String, String> = mutableMapOf()
96+
8397
override fun registerProjectComponents(project: MockProject, configuration: CompilerConfiguration) {
8498
if (processors.isEmpty()) {
8599
return
86100
}
87101
val options = KspOptions.Builder().apply {
102+
this.processingOptions.putAll(compilation.kspArgs)
103+
88104
this.classOutputDir = compilation.kspClassesDir.also {
89105
it.deleteRecursively()
90106
it.mkdirs()
@@ -103,9 +119,11 @@ private class KspCompileTestingComponentRegistrar(
103119
}
104120
}.build()
105121
// TODO: replace with KotlinCompilation.internalMessageStream
106-
val registrar = KspTestExtension(options, processors, MessageCollectorBasedKSPLogger(
122+
val registrar = KspTestExtension(
123+
options, processors, MessageCollectorBasedKSPLogger(
107124
PrintingMessageCollector(System.err, MessageRenderer.GRADLE_STYLE, compilation.verbose)
108-
))
125+
)
126+
)
109127
AnalysisHandlerExtension.registerExtension(project, registrar)
110128
}
111129
}

0 commit comments

Comments
 (0)