Skip to content

Commit

Permalink
KSP1: better support of compilation avoidance
Browse files Browse the repository at this point in the history
by setting up the incremental properties on classpathStructure instead
of libraries.

(cherry picked from commit 4eab36a)
  • Loading branch information
ting-yuan authored and KSP Auto Pick committed Feb 26, 2025
1 parent 9b2d7d9 commit e764de7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package com.google.devtools.ksp.gradle
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.FileCollection
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.ListProperty
Expand All @@ -30,14 +31,17 @@ import org.gradle.api.tasks.IgnoreEmptyDirectories
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.Nested
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.SkipWhenEmpty
import org.gradle.api.tasks.TaskProvider
import org.gradle.process.CommandLineArgumentProvider
import org.gradle.process.ExecOperations
import org.gradle.work.Incremental
import org.gradle.work.InputChanges
import org.gradle.work.NormalizeLineEndings
import org.gradle.workers.WorkerExecutor
import org.jetbrains.kotlin.buildtools.api.SourcesChanges
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
Expand Down Expand Up @@ -90,20 +94,12 @@ class KotlinFactories {
KotlinCompileConfig(KotlinCompilationInfo(kotlinCompilation))
.execute(kspTaskProvider as TaskProvider<KotlinCompile>)

// useClasspathSnapshot isn't configurable per task.
// Workaround: enable the other path and ignore irrelevant changes
// See [KotlinCompileConfig] in for details.
// FIXME: make it configurable in upstream or support useClasspathSnapshot == true, if possible.
kspTaskProvider.configure {
val compilerOptions = kotlinCompilation.compilerOptions.options as KotlinJvmCompilerOptions
KotlinJvmCompilerOptionsHelper.syncOptionsAsConvention(
from = compilerOptions,
into = it.compilerOptions
)

if (it.classpathSnapshotProperties.useClasspathSnapshot.get()) {
it.classpathSnapshotProperties.classpath.from(project.provider { it.libraries })
}
}
}
}
Expand Down Expand Up @@ -205,13 +201,22 @@ abstract class KspTaskJvm @Inject constructor(
@get:OutputDirectory
abstract val destination: Property<File>

@get:PathSensitive(PathSensitivity.NONE)
@get:Incremental
@get:IgnoreEmptyDirectories
@get:NormalizeLineEndings
@get:Optional
@get:InputFiles
abstract val classpathStructure: ConfigurableFileCollection

// Override incrementalProps to exclude irrelevant changes
override val incrementalProps: List<FileCollection>
get() = listOf(
sources,
javaSources,
commonSourceSet,
classpathSnapshotProperties.classpath,
classpathStructure,
)

// Overrding an internal function is hacky.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ class KspGradleSubplugin @Inject internal constructor(private val registry: Tool
project.provider { processorClasspath }
)
)
kspTask.classpathStructure.from(classStructureFiles)
}
// Don't support binary generation for non-JVM platforms yet.
// FIXME: figure out how to add user generated libraries.
Expand Down

0 comments on commit e764de7

Please sign in to comment.