Skip to content

Commit

Permalink
UPDATE_KOTLIN_VERSION: 1.9.30-dev-2548
Browse files Browse the repository at this point in the history
Kotlin: Migrate from ChangedFiles to SourcesChanges
  • Loading branch information
ALikhachev authored and neetopia committed Sep 13, 2023
1 parent 85a6412 commit eeb1cb7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,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
Expand All @@ -57,7 +58,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
Expand Down Expand Up @@ -175,7 +175,7 @@ interface KspTask : Task {
val commandLineArgumentProviders: ListProperty<CommandLineArgumentProvider>

@get:Internal
val incrementalChangesTransformers: ListProperty<(ChangedFiles) -> List<SubpluginOption>>
val incrementalChangesTransformers: ListProperty<(SourcesChanges) -> List<SubpluginOption>>
}

@CacheableTask
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import org.gradle.language.jvm.tasks.ProcessResources
import org.gradle.process.CommandLineArgumentProvider
import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
import org.gradle.util.GradleVersion
import org.jetbrains.kotlin.buildtools.api.SourcesChanges
import org.jetbrains.kotlin.config.ApiVersion
import org.jetbrains.kotlin.config.LanguageVersion.Companion.LATEST_STABLE
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
Expand All @@ -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.util.capitalizeDecapitalize.capitalizeAsciiOnly
Expand Down Expand Up @@ -661,15 +661,16 @@ 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>,
processorCP: List<File>,
): 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 }
Expand Down Expand Up @@ -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()
}
Expand All @@ -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()
}
}
Expand All @@ -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
Expand All @@ -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) {
Expand Down

0 comments on commit eeb1cb7

Please sign in to comment.