aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander.Likhachev <Alexander.Likhachev@jetbrains.com>2023-08-24 14:49:36 +0200
committerJiaxiang Chen <roaringacw@gmail.com>2024-01-18 15:54:29 -0800
commitaa9b0effb490aadfca68529a13cd04075e904ee6 (patch)
treefd071e3736ce188e9c43a20e686abfc4a707d9f9
parent9fe5c327805dd25a2113fe978a220b2f01917164 (diff)
downloadksp-aa9b0effb490aadfca68529a13cd04075e904ee6.tar.gz
UPDATE_KOTLIN_VERSION: 1.9.30-dev-2548
Kotlin: Migrate from ChangedFiles to SourcesChanges (cherry picked from commit eeb1cb7e22ce570248eac2159ac2eb6e111f28e8)
-rw-r--r--gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KotlinFactories.kt4
-rw-r--r--gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspSubplugin.kt29
2 files changed, 17 insertions, 16 deletions
diff --git a/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KotlinFactories.kt b/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KotlinFactories.kt
index 291dc7f3..518ab1af 100644
--- a/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KotlinFactories.kt
+++ b/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KotlinFactories.kt
@@ -39,6 +39,7 @@ import org.gradle.process.CommandLineArgumentProvider
import org.gradle.process.ExecOperations
import org.gradle.work.InputChanges
import org.gradle.workers.WorkerExecutor
+import org.jetbrains.kotlin.buildtools.api.SourcesChanges
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
@@ -67,7 +68,6 @@ import org.jetbrains.kotlin.gradle.tasks.TaskOutputsBackup
import org.jetbrains.kotlin.gradle.tasks.configuration.BaseKotlin2JsCompileConfig
import org.jetbrains.kotlin.gradle.tasks.configuration.KotlinCompileCommonConfig
import org.jetbrains.kotlin.gradle.tasks.configuration.KotlinCompileConfig
-import org.jetbrains.kotlin.incremental.ChangedFiles
import org.jetbrains.kotlin.konan.target.HostManager
import java.io.File
import java.nio.file.Paths
@@ -186,7 +186,7 @@ interface KspTask : Task {
val commandLineArgumentProviders: ListProperty<CommandLineArgumentProvider>
@get:Internal
- val incrementalChangesTransformers: ListProperty<(ChangedFiles) -> List<SubpluginOption>>
+ val incrementalChangesTransformers: ListProperty<(SourcesChanges) -> List<SubpluginOption>>
}
@CacheableTask
diff --git a/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspSubplugin.kt b/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspSubplugin.kt
index 64a5e50c..5dcf0fef 100644
--- a/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspSubplugin.kt
+++ b/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspSubplugin.kt
@@ -36,6 +36,7 @@ import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
import org.gradle.util.GradleVersion
import org.gradle.work.ChangeType
import org.gradle.work.InputChanges
+import org.jetbrains.kotlin.buildtools.api.SourcesChanges
import org.jetbrains.kotlin.config.ApiVersion
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.internal.kapt.incremental.CLASS_STRUCTURE_ARTIFACT_TYPE
@@ -56,7 +57,6 @@ import org.jetbrains.kotlin.gradle.plugin.SubpluginOption
import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
import org.jetbrains.kotlin.gradle.plugin.mpp.*
import org.jetbrains.kotlin.gradle.tasks.*
-import org.jetbrains.kotlin.incremental.ChangedFiles
import org.jetbrains.kotlin.incremental.isJavaFile
import org.jetbrains.kotlin.incremental.isKotlinFile
import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty
@@ -661,7 +661,7 @@ internal fun getClassStructureFiles(
// Reuse Kapt's infrastructure to compute affected names in classpath.
// This is adapted from KaptTask.findClasspathChanges.
internal fun findClasspathChanges(
- changes: ChangedFiles,
+ changes: SourcesChanges,
cacheDir: File,
allDataFiles: Set<File>,
libs: List<File>,
@@ -669,7 +669,8 @@ internal fun findClasspathChanges(
): KaptClasspathChanges {
cacheDir.mkdirs()
- val changedFiles = (changes as? ChangedFiles.Known)?.let { it.modified + it.removed }?.toSet() ?: allDataFiles
+ val changedFiles =
+ (changes as? SourcesChanges.Known)?.let { it.modifiedFiles + it.removedFiles }?.toSet() ?: allDataFiles
val loadedPrevious = ClasspathSnapshot.ClasspathSnapshotFactory.loadFrom(cacheDir)
val previousAndCurrentDataFiles = lazy { loadedPrevious.getAllDataFiles() + allDataFiles }
@@ -698,7 +699,7 @@ internal fun findClasspathChanges(
)
val classpathChanges = currentSnapshot.diff(previousSnapshot, changedFiles)
- if (classpathChanges is KaptClasspathChanges.Unknown || changes is ChangedFiles.Unknown) {
+ if (classpathChanges is KaptClasspathChanges.Unknown || changes is SourcesChanges.Unknown) {
cacheDir.deleteRecursively()
cacheDir.mkdirs()
}
@@ -707,11 +708,11 @@ internal fun findClasspathChanges(
return classpathChanges
}
-internal fun ChangedFiles.hasNonSourceChange(): Boolean {
- if (this !is ChangedFiles.Known)
+internal fun SourcesChanges.hasNonSourceChange(): Boolean {
+ if (this !is SourcesChanges.Known)
return true
- return !(this.modified + this.removed).all {
+ return !(this.modifiedFiles + this.removedFiles).all {
it.isKotlinFile(listOf("kt")) || it.isJavaFile()
}
}
@@ -726,13 +727,13 @@ fun KaptClasspathChanges.toSubpluginOptions(): List<SubpluginOption> {
}
}
-fun ChangedFiles.toSubpluginOptions(): List<SubpluginOption> {
- return if (this is ChangedFiles.Known) {
+fun SourcesChanges.toSubpluginOptions(): List<SubpluginOption> {
+ return if (this is SourcesChanges.Known) {
val options = mutableListOf<SubpluginOption>()
- this.modified.filter { it.isKotlinFile(listOf("kt")) || it.isJavaFile() }.ifNotEmpty {
+ this.modifiedFiles.filter { it.isKotlinFile(listOf("kt")) || it.isJavaFile() }.ifNotEmpty {
options += SubpluginOption("knownModified", map { it.path }.joinToString(File.pathSeparator))
}
- this.removed.filter { it.isKotlinFile(listOf("kt")) || it.isJavaFile() }.ifNotEmpty {
+ this.removedFiles.filter { it.isKotlinFile(listOf("kt")) || it.isJavaFile() }.ifNotEmpty {
options += SubpluginOption("knownRemoved", map { it.path }.joinToString(File.pathSeparator))
}
options
@@ -749,7 +750,7 @@ internal fun createIncrementalChangesTransformer(
classpathStructure: Provider<FileCollection>,
libraries: Provider<FileCollection>,
processorCP: Provider<FileCollection>,
-): (ChangedFiles) -> List<SubpluginOption> = { changedFiles ->
+): (SourcesChanges) -> List<SubpluginOption> = { changedFiles ->
val options = mutableListOf<SubpluginOption>()
val apClasspath = processorCP.get().files.toList()
if (isKspIncremental) {
@@ -790,7 +791,7 @@ internal fun getCPChanges(
): List<String> {
val apClasspath = processorCP.files.toList()
val changedFiles = if (!inputChanges.isIncremental) {
- ChangedFiles.Unknown()
+ SourcesChanges.Unknown
} else {
incrementalProps.fold(mutableListOf<File>() to mutableListOf<File>()) { (modified, removed), prop ->
inputChanges.getFileChanges(prop).forEach {
@@ -802,7 +803,7 @@ internal fun getCPChanges(
}
modified to removed
}.run {
- ChangedFiles.Known(first, second)
+ SourcesChanges.Known(first, second)
}
}
val classpathChanges = findClasspathChanges(