Skip to content

Commit 341365f

Browse files
authored
Merge pull request #592 from Kotlin/ksp-fix
Ksp fix
2 parents 739133b + 462ddd6 commit 341365f

File tree

4 files changed

+61
-12
lines changed

4 files changed

+61
-12
lines changed

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[versions]
2-
ksp = "1.9.21-1.0.15"
2+
ksp = "1.9.22-1.0.17"
33
kotlinJupyter = "0.11.0-358"
44
ktlint = "3.4.5"
5-
kotlin = "1.9.0"
5+
kotlin = "1.9.22"
66
dokka = "1.8.10"
77
libsPublisher = "0.0.60-dev-30"
88
# "Bootstrap" version of the dataframe, used in the build itself to generate @DataSchema APIs,

plugins/dataframe-gradle-plugin/src/main/kotlin/org/jetbrains/dataframe/gradle/ConvenienceSchemaGeneratorPlugin.kt

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ package org.jetbrains.dataframe.gradle
33
import com.google.devtools.ksp.gradle.KspExtension
44
import org.gradle.api.Plugin
55
import org.gradle.api.Project
6-
import org.gradle.kotlin.dsl.findByType
6+
import org.gradle.api.artifacts.UnknownConfigurationException
7+
import org.gradle.kotlin.dsl.getByType
78
import java.util.*
89

910
@Suppress("unused")
@@ -20,11 +21,43 @@ class ConvenienceSchemaGeneratorPlugin : Plugin<Project> {
2021
target.logger.warn("Invalid value '$property' for '$name' property. Defaulting to '$addKsp'. Please use 'true' or 'false'.")
2122
}
2223
}
24+
25+
val properties = Properties()
26+
properties.load(javaClass.getResourceAsStream("plugin.properties"))
27+
val preprocessorVersion = properties.getProperty("PREPROCESSOR_VERSION")
28+
29+
// regardless whether we add KSP or the user adds it, when it's added,
30+
// configure it to depend on symbol-processor-all
31+
target.plugins.whenPluginAdded {
32+
if ("com.google.devtools.ksp" in this.javaClass.packageName) {
33+
try {
34+
target.configurations.getByName("ksp").dependencies.add(
35+
target.dependencies.create("org.jetbrains.kotlinx.dataframe:symbol-processor-all:$preprocessorVersion")
36+
)
37+
} catch (e: UnknownConfigurationException) {
38+
target.logger.warn("Configuration 'ksp' not found. Please make sure the KSP plugin is applied.")
39+
}
40+
try {
41+
target.configurations.getByName("kspTest").dependencies.add(
42+
target.dependencies.create("org.jetbrains.kotlinx.dataframe:symbol-processor-all:$preprocessorVersion")
43+
)
44+
} catch (e: UnknownConfigurationException) {
45+
target.logger.warn("Configuration 'kspTest' not found. Please make sure the KSP plugin is applied.")
46+
}
47+
target.logger.info("Added DataFrame dependency to the KSP plugin.")
48+
target.extensions.getByType<KspExtension>().arg("dataframe.resolutionDir", target.projectDir.absolutePath)
49+
}
50+
}
51+
2352
if (addKsp) {
2453
target.plugins.apply(KspPluginApplier::class.java)
25-
}
26-
target.afterEvaluate {
27-
target.extensions.findByType<KspExtension>()?.arg("dataframe.resolutionDir", target.projectDir.absolutePath)
54+
} else {
55+
target.logger.warn(
56+
"Plugin 'org.jetbrains.kotlinx.dataframe' comes bundled with its own version of KSP which is " +
57+
"currently disabled as 'kotlin.dataframe.add.ksp' is set to 'false' in a 'properties' file. " +
58+
"Either set 'kotlin.dataframe.add.ksp' to 'true' or add the plugin 'com.google.devtools.ksp' " +
59+
"manually."
60+
)
2861
}
2962
target.plugins.apply(SchemaGeneratorPlugin::class.java)
3063
}
@@ -38,14 +71,13 @@ class DeprecatingSchemaGeneratorPlugin : Plugin<Project> {
3871
}
3972
}
4073

74+
/**
75+
* Applies the KSP plugin in the target project.
76+
*/
4177
internal class KspPluginApplier : Plugin<Project> {
4278
override fun apply(target: Project) {
4379
val properties = Properties()
4480
properties.load(javaClass.getResourceAsStream("plugin.properties"))
45-
val preprocessorVersion = properties.getProperty("PREPROCESSOR_VERSION")
4681
target.plugins.apply("com.google.devtools.ksp")
47-
target.configurations.getByName("ksp").dependencies.add(
48-
target.dependencies.create("org.jetbrains.kotlinx.dataframe:symbol-processor-all:$preprocessorVersion")
49-
)
5082
}
5183
}

plugins/dataframe-gradle-plugin/src/main/kotlin/org/jetbrains/dataframe/gradle/SchemaGeneratorPlugin.kt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.jetbrains.dataframe.gradle
22

3+
import com.google.devtools.ksp.gradle.KspTaskJvm
34
import org.gradle.api.Plugin
45
import org.gradle.api.Project
56
import org.gradle.api.Task
@@ -36,11 +37,16 @@ class SchemaGeneratorPlugin : Plugin<Project> {
3637
target.logger.warn("Schema generator plugin applied, but no Kotlin plugin was found")
3738
}
3839

39-
val generationTasks = extension.schemas.map { createTask(target, extension, appliedPlugin, it) }
40+
val generationTasks = extension.schemas.map {
41+
createTask(target, extension, appliedPlugin, it)
42+
}
4043
val generateAll = target.tasks.create("generateDataFrames") {
4144
group = GROUP
4245
dependsOn(*generationTasks.toTypedArray())
4346
}
47+
tasks.withType(KspTaskJvm::class.java).configureEach {
48+
dependsOn(generateAll)
49+
}
4450
tasks.withType<KotlinCompile> {
4551
dependsOn(generateAll)
4652
}
@@ -69,7 +75,18 @@ class SchemaGeneratorPlugin : Plugin<Project> {
6975
appliedPlugin ?: propertyError("src")
7076
val sourceSet = appliedPlugin.kotlinExtension.sourceSets.getByName(sourceSetName)
7177
val src = target.file(Paths.get("build/generated/dataframe/", sourceSetName, "kotlin").toFile())
78+
79+
// Add the new sources to the source set
7280
sourceSet.kotlin.srcDir(src)
81+
82+
// Configure the right ksp task to be aware of these new sources
83+
val kspTaskName = "ksp${sourceSetName.replaceFirstChar { it.uppercase() }}Kotlin"
84+
target.tasks.withType(KspTaskJvm::class.java).configureEach {
85+
if (sourceSetName == "main" && name == "kspKotlin" || name == kspTaskName) {
86+
source(src)
87+
}
88+
}
89+
7390
src
7491
}
7592

plugins/expressions-converter/src/org/jetbrains/kotlinx/dataframe/ExplainerIrTransformer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ class ExplainerIrTransformer(
222222
add(data.function?.name?.asString().irConstImpl())
223223
add(IrConstImpl.int(-1, -1, pluginContext.irBuiltIns.intType, data.statementIndex))
224224
}
225-
body = pluginContext.irFactory.createBlockBody(-1, -1) {
225+
body = pluginContext.irFactory.createBlockBody(-1, -1).apply {
226226
val callback = FqName("org.jetbrains.kotlinx.dataframe.explainer.PluginCallbackProxy.doAction")
227227
val doAction = pluginContext.referenceFunctions(callback).single()
228228
statements += IrCallImpl(

0 commit comments

Comments
 (0)