Skip to content

Commit

Permalink
Reapply "UPDATE_KOTLIN_VERSION: 1.9.30-dev-2548"
Browse files Browse the repository at this point in the history
This reverts commit 053e5ce.
  • Loading branch information
neetopia committed Dec 19, 2023
1 parent d192498 commit e145cba
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 @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
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.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.internal.kapt.incremental.CLASS_STRUCTURE_ARTIFACT_TYPE
Expand All @@ -54,7 +55,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
Expand Down Expand Up @@ -659,15 +659,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 @@ -696,7 +697,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 @@ -705,11 +706,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 @@ -724,13 +725,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 @@ -747,7 +748,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 e145cba

Please sign in to comment.