Skip to content

Commit

Permalink
use file collection to support configuration caching
Browse files Browse the repository at this point in the history
  • Loading branch information
yigit committed Oct 15, 2023
1 parent 38cea31 commit 9338edc
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,11 @@ class KspGradleSubplugin @Inject internal constructor(private val registry: Tool
}
kspTask.commonSources.from(kotlinCompileTask.commonSources)
kspTask.options.add(
ClasspathFilesSubpluginOption("apclasspath", processorClasspath)
FileCollectionSubpluginOption.create(
project = project,
name = "apclasspath",
classpath = processorClasspath
)
)
kspTask.compilerOptions.freeCompilerArgs.addAll(
kspTask.options.map {
Expand Down Expand Up @@ -794,15 +798,30 @@ internal fun Configuration.markResolvable(): Configuration = apply {
}

/**
* A [SubpluginOption] that returns the joined path for files in the given [configuration].
* A [SubpluginOption] that returns the joined path for files in the given [fileCollection].
*/
internal class ClasspathFilesSubpluginOption(
internal class FileCollectionSubpluginOption(
key: String,
val configuration: Configuration
val fileCollection: ConfigurableFileCollection
) : SubpluginOption(
key = key,
lazyValue = lazy {
val files = configuration.resolve()
val files = fileCollection.files
files.joinToString(File.pathSeparator) { it.normalize().absolutePath }
}
)
) {
companion object {
fun create(
project: Project,
name: String,
classpath: Configuration
): FileCollectionSubpluginOption {
val fileCollection = project.objects.fileCollection()
fileCollection.from(classpath)
return FileCollectionSubpluginOption(
key = name,
fileCollection = fileCollection
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package com.google.devtools.ksp.gradle

import com.google.common.truth.Truth.assertThat
import com.google.devtools.ksp.gradle.testing.KspIntegrationTestRule
import org.junit.Rule
import org.junit.Test
Expand Down Expand Up @@ -151,9 +152,19 @@ class ProcessorClasspathConfigurationsTest {
)
// trigger task creation. KSP should not resolve classpaths
// at this step
testRule.runner()
val buildResult = testRule.runner()
.withArguments(":app:tasks")
.build()
val taskNames = listOf(
"kspKotlinJs",
"kspKotlinJvm",
"kspKotlinLinuxX64",
)
taskNames.forEach {
assertThat(
buildResult.output
).contains(it)
}
}

@Test
Expand Down Expand Up @@ -183,8 +194,18 @@ class ProcessorClasspathConfigurationsTest {
)
// trigger task creation. KSP should not resolve arguments
// at this step
testRule.runner()
.withArguments(":app:tasks")
val buildResult = testRule.runner()
.withArguments(":app:tasks", "--all")
.build()
val taskNames = listOf(
"kspKotlinJs",
"kspKotlinJvm",
"kspKotlinLinuxX64",
)
taskNames.forEach {
assertThat(
buildResult.output
).contains(it)
}
}
}

0 comments on commit 9338edc

Please sign in to comment.