-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #996 from Kotlin/keywords-generator
Keywords generator plugin: moved and fixed for Kotlin 2.1
- Loading branch information
Showing
10 changed files
with
113 additions
and
57 deletions.
There are no files selected for viewing
28 changes: 0 additions & 28 deletions
28
generator/src/main/kotlin/org/jetbrains/dataframe/keywords/KeywordsGeneratorPlugin.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
generator/gradle.properties → plugins/keywords-generator/gradle.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...rds-generator/src/main/kotlin/org/jetbrains/dataframe/keywords/KeywordsGeneratorPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.jetbrains.dataframe.keywords | ||
|
||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.api.artifacts.DependencyScopeConfiguration | ||
import org.gradle.api.artifacts.ResolvableConfiguration | ||
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 | ||
|
||
@Suppress("UnstableApiUsage") | ||
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 dependencyScopeConfiguration: DependencyScopeConfiguration = configurations.dependencyScope("keywordsGeneratorDependencyScope").get() | ||
dependencies.add(dependencyScopeConfiguration.name, "$KOTLIN_COMPILER_EMBEDDABLE:$KOTLIN_COMPILER_VERSION") | ||
|
||
val resolvableConfiguration: ResolvableConfiguration = configurations.resolvable("keywordGeneratorResolvable") { | ||
extendsFrom(dependencyScopeConfiguration) | ||
}.get() | ||
|
||
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(resolvableConfiguration) | ||
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 | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...words-generator/src/main/kotlin/org/jetbrains/dataframe/keywords/KeywordsGeneratorTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
||
@TaskAction | ||
fun generate() { | ||
val workQueue = executor.classLoaderIsolation { | ||
classpath.from(kotlinCompiler) | ||
} | ||
workQueue.submit(KeywordsGeneratorAction::class) { | ||
srcDir = this@KeywordsGeneratorTask.srcDir | ||
} | ||
} | ||
|
||
companion object { | ||
const val NAME = "generateKeywordsSrc" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters