-
Notifications
You must be signed in to change notification settings - Fork 76
Keywords generator plugin: moved and fixed for Kotlin 2.1 #996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,11 @@ | ||
| ## :generator | ||
| ## :plugins:keywords-generator | ||
|
|
||
| This module holds a little Gradle plugin whose sole purpose is to provide | ||
| [:core](../core) with the `generateKeywordsSrc` task. | ||
| [:core](../../core) with the `generateKeywordsSrc` task. | ||
|
|
||
| This task, generates three enum classes: `HardKeywords`, `ModifierKeywords`, and `SoftKeywords`. | ||
| These enums together contain all restricted Kotlin keywords to be taken into account when generating our own | ||
| code in Notebooks or any of our [plugins](../plugins). Words like "package", "fun", "suspend", etc... | ||
| code in Notebooks or any of our [plugins](..). Words like "package", "fun", "suspend", etc... | ||
|
|
||
| As the Kotlin language can change over time, this task ensures that any changes to the language | ||
| will be reflected in our code generation. | ||
|
|
||
| This module will likely be moved under [:plugins](../plugins): | ||
| [Issue #899](https://github.com/Kotlin/dataframe/issues/899). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| kotlinCompilerVersion=2.0.20 | ||
| kotlinPoetVersion=1.18.1 | ||
| kotlinPoetVersion=2.0.0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package org.jetbrains.dataframe.keywords | ||
|
|
||
| import org.gradle.api.Plugin | ||
| import org.gradle.api.Project | ||
| import org.gradle.api.tasks.SourceSet | ||
| import org.gradle.api.tasks.SourceSetContainer | ||
| import org.gradle.kotlin.dsl.get | ||
| import org.gradle.kotlin.dsl.register | ||
| import org.jetbrains.kotlinx.dataframe.BuildConfig | ||
| import java.io.File | ||
|
|
||
| abstract class KeywordsGeneratorPlugin : Plugin<Project> { | ||
|
|
||
| override fun apply(target: Project): Unit = with(target) { | ||
| // from https://kotlinlang.org/docs/whatsnew21.html#compiler-symbols-hidden-from-the-kotlin-gradle-plugin-api | ||
| val taskDependencyScope = configurations.create("keywordsGeneratorScope") | ||
| dependencies.add(taskDependencyScope.name, "$KOTLIN_COMPILER_EMBEDDABLE:$KOTLIN_COMPILER_VERSION") | ||
| val taskResolvableConfiguration = configurations.create("keywordGeneratorResolvable") { | ||
Jolanrensen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| extendsFrom(taskDependencyScope) | ||
| } | ||
|
|
||
| val genSrcDir = layout.buildDirectory.asFile.get().resolve("generatedSrc") | ||
|
|
||
| val sourceSets = project.extensions.getByName("sourceSets") as SourceSetContainer | ||
| val mainSourceSet = sourceSets.named("main").get() | ||
| mainSourceSet.addDir(genSrcDir) | ||
|
|
||
| val genTask = tasks.register<KeywordsGeneratorTask>(KeywordsGeneratorTask.NAME) { | ||
| kotlinCompiler.from(taskResolvableConfiguration) | ||
| srcDir = genSrcDir | ||
| } | ||
|
|
||
| tasks["compileKotlin"].dependsOn(genTask) | ||
| } | ||
|
|
||
| private fun SourceSet.addDir(dir: File) { | ||
| java.setSrcDirs(java.srcDirs + dir) | ||
| } | ||
|
|
||
| companion object { | ||
| const val KOTLIN_COMPILER_EMBEDDABLE = "org.jetbrains.kotlin:kotlin-compiler-embeddable" | ||
| const val KOTLIN_COMPILER_VERSION: String = BuildConfig.kotlinCompilerVersion | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package org.jetbrains.dataframe.keywords | ||
|
|
||
| import org.gradle.api.DefaultTask | ||
| import org.gradle.api.file.ConfigurableFileCollection | ||
| import org.gradle.api.tasks.Classpath | ||
| import org.gradle.api.tasks.Input | ||
| import org.gradle.api.tasks.OutputDirectory | ||
| import org.gradle.api.tasks.TaskAction | ||
| import org.gradle.kotlin.dsl.submit | ||
| import org.gradle.workers.WorkerExecutor | ||
| import java.io.File | ||
| import javax.inject.Inject | ||
|
|
||
| abstract class KeywordsGeneratorTask: DefaultTask() { | ||
|
|
||
| @get:Inject | ||
| abstract val executor: WorkerExecutor | ||
|
|
||
| @get:Classpath | ||
| abstract val kotlinCompiler: ConfigurableFileCollection | ||
|
|
||
| @OutputDirectory | ||
| lateinit var srcDir: File | ||
|
|
||
| @Input | ||
| override fun getGroup() = "codegen" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's keep default group for this task? I don't think it deserves a group of its own
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just copied this over from the old implementation. Shall I still remove it?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it will be put in "other" if we don't supply a group (which is ginormous). Maybe a separate group for codegen stuff is not such a bad idea. |
||
|
|
||
| @TaskAction | ||
| fun generate() { | ||
| val workQueue = executor.classLoaderIsolation { | ||
| classpath.from(kotlinCompiler) | ||
| } | ||
| workQueue.submit(KeywordsGeneratorAction::class) { | ||
| srcDir = [email protected] | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| const val NAME = "generateKeywordsSrc" | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.