-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bumped to kotlin 2.0.0-Beta5, included the compiler plugin with tests…
… as separate module
- Loading branch information
1 parent
4f8d874
commit 2a878f1
Showing
32 changed files
with
1,338 additions
and
61 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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,92 @@ | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
||
plugins { | ||
java | ||
kotlin | ||
mavenPublishBase | ||
buildconfig | ||
} | ||
|
||
group = Versions.groupID | ||
version = Versions.project | ||
|
||
repositories { | ||
mavenCentral() | ||
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap") | ||
} | ||
|
||
sourceSets { | ||
test { | ||
val srcDirs = listOf("src/test-gen/kotlin") | ||
kotlin.srcDirs(srcDirs) | ||
java.srcDirs(srcDirs) | ||
} | ||
} | ||
|
||
dependencies { | ||
with(Dependencies) { | ||
compileOnly(kotlinCompiler) | ||
|
||
testRuntimeOnly( | ||
kotlinTest, | ||
kotlinScriptRuntime, | ||
kotlinAnnotationsJvm, | ||
) | ||
|
||
testImplementation( | ||
kotlinCompiler, | ||
reflect, | ||
kotlinCompilerInternalTestFramework, | ||
junit, | ||
|
||
platform(junitBom), | ||
junitJupiter, | ||
junitPlatformCommons, | ||
junitPlatformLauncher, | ||
junitPlatformRunner, | ||
junitPlatformSuiteApi, | ||
) | ||
} | ||
} | ||
|
||
tasks.test { | ||
useJUnitPlatform() | ||
doFirst { | ||
setLibraryProperty("org.jetbrains.kotlin.test.kotlin-stdlib", "kotlin-stdlib") | ||
setLibraryProperty("org.jetbrains.kotlin.test.kotlin-stdlib-jdk8", "kotlin-stdlib-jdk8") | ||
setLibraryProperty("org.jetbrains.kotlin.test.kotlin-reflect", "kotlin-reflect") | ||
setLibraryProperty("org.jetbrains.kotlin.test.kotlin-test", "kotlin-test") | ||
setLibraryProperty("org.jetbrains.kotlin.test.kotlin-script-runtime", "kotlin-script-runtime") | ||
setLibraryProperty("org.jetbrains.kotlin.test.kotlin-annotations-jvm", "kotlin-annotations-jvm") | ||
} | ||
} | ||
|
||
tasks.withType<KotlinCompile>().configureEach { | ||
kotlinOptions { | ||
languageVersion = "2.0" | ||
freeCompilerArgs = freeCompilerArgs + | ||
"-opt-in=org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi" + | ||
"-Xcontext-receivers" | ||
} | ||
} | ||
|
||
val generateTests by tasks.creating(JavaExec::class) { | ||
classpath = sourceSets.test.get().runtimeClasspath | ||
mainClass.set("org.jetbrains.kotlinx.spark.compilerPlugin.GenerateTestsKt") | ||
} | ||
|
||
val compileTestKotlin by tasks.getting { | ||
doLast { | ||
generateTests.exec() | ||
} | ||
} | ||
|
||
fun Test.setLibraryProperty(propName: String, jarName: String) { | ||
val path = project.configurations | ||
.testRuntimeClasspath.get() | ||
.files | ||
.find { """$jarName-\d.*jar""".toRegex().matches(it.name) } | ||
?.absolutePath | ||
?: return | ||
systemProperty(propName, path) | ||
} |
8 changes: 8 additions & 0 deletions
8
...lugin/src/main/kotlin/org/jetbrains/kotlinx/spark/compilerPlugin/SimplePluginRegistrar.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,8 @@ | ||
package org.jetbrains.kotlinx.spark.compilerPlugin | ||
|
||
import org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrar | ||
|
||
// Potential future K2 FIR hook | ||
class SimplePluginRegistrar(private val sparkifyAnnotationFqNames: List<String>) : FirExtensionRegistrar() { | ||
override fun ExtensionRegistrarContext.configurePlugin() {} | ||
} |
72 changes: 72 additions & 0 deletions
72
...rc/main/kotlin/org/jetbrains/kotlinx/spark/compilerPlugin/SparkifyCommandLineProcessor.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,72 @@ | ||
package org.jetbrains.kotlinx.spark.compilerPlugin | ||
|
||
import org.jetbrains.kotlin.compiler.plugin.AbstractCliOption | ||
import org.jetbrains.kotlin.compiler.plugin.CliOption | ||
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor | ||
import org.jetbrains.kotlin.config.CompilerConfiguration | ||
import org.jetbrains.kotlin.config.CompilerConfigurationKey | ||
import org.jetbrains.kotlinx.spark.Artifacts | ||
|
||
open class SparkifyCommandLineProcessor : CommandLineProcessor { | ||
|
||
init { | ||
println("SparkifyCommandLineProcessor loaded") | ||
} | ||
|
||
override val pluginId: String = Artifacts.compilerPluginId | ||
|
||
override val pluginOptions: Collection<AbstractCliOption> = listOf( | ||
OPTION_ENABLED, | ||
OPTION_SPARKIFY_ANNOTATION_FQ_NAMES, | ||
OPTION_COLUMN_NAME_ANNOTATION_FQ_NAMES, | ||
) | ||
|
||
override fun processOption(option: AbstractCliOption, value: String, configuration: CompilerConfiguration) { | ||
when (val optionName = option.optionName) { | ||
OPTION_ENABLED.optionName -> | ||
configuration.put(KEY_ENABLED, value.toBoolean()) | ||
|
||
OPTION_SPARKIFY_ANNOTATION_FQ_NAMES.optionName -> | ||
configuration.put(KEY_SPARKIFY_ANNOTATION_FQ_NAMES, value.split(",").map { it.trim() }) | ||
|
||
OPTION_COLUMN_NAME_ANNOTATION_FQ_NAMES.optionName -> | ||
configuration.put(KEY_COLUMN_NAME_ANNOTATION_FQ_NAMES, value.split(",").map { it.trim() }) | ||
|
||
else -> error("Unexpected option: $optionName") | ||
} | ||
} | ||
} | ||
|
||
internal val KEY_ENABLED = CompilerConfigurationKey<Boolean>("Whether to enable Sparkify") | ||
|
||
internal val OPTION_ENABLED = CliOption( | ||
optionName = "enabled", | ||
valueDescription = "<true|false>", | ||
description = "Whether to enable Sparkify", | ||
required = false, | ||
allowMultipleOccurrences = false, | ||
) | ||
|
||
internal val KEY_SPARKIFY_ANNOTATION_FQ_NAMES = CompilerConfigurationKey<List<String>>( | ||
"Fully qualified names of annotations for Sparkify" | ||
) | ||
|
||
internal val OPTION_SPARKIFY_ANNOTATION_FQ_NAMES = CliOption( | ||
optionName = "sparkifyAnnotationFqNames", | ||
valueDescription = "<fqName1,fqName2,...>", | ||
description = "Fully qualified names of annotations to sparkify", | ||
required = false, | ||
allowMultipleOccurrences = false, | ||
) | ||
|
||
internal val KEY_COLUMN_NAME_ANNOTATION_FQ_NAMES = CompilerConfigurationKey<List<String>>( | ||
"Fully qualified names of annotations for ColumnName" | ||
) | ||
|
||
internal val OPTION_COLUMN_NAME_ANNOTATION_FQ_NAMES = CliOption( | ||
optionName = "columnNameAnnotationFqNames", | ||
valueDescription = "<fqName1,fqName2,...>", | ||
description = "Fully qualified names of annotations for ColumnName", | ||
required = false, | ||
allowMultipleOccurrences = false, | ||
) |
33 changes: 33 additions & 0 deletions
33
...main/kotlin/org/jetbrains/kotlinx/spark/compilerPlugin/SparkifyCompilerPluginRegistrar.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,33 @@ | ||
package org.jetbrains.kotlinx.spark.compilerPlugin | ||
|
||
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension | ||
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar | ||
import org.jetbrains.kotlin.config.CompilerConfiguration | ||
import org.jetbrains.kotlinx.spark.Artifacts | ||
import org.jetbrains.kotlinx.spark.compilerPlugin.ir.SparkifyIrGenerationExtension | ||
|
||
open class SparkifyCompilerPluginRegistrar: CompilerPluginRegistrar() { | ||
init { | ||
println("SparkifyCompilerPluginRegistrar loaded") | ||
} | ||
|
||
override val supportsK2: Boolean | ||
get() = true | ||
|
||
override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) { | ||
if (configuration.get(KEY_ENABLED) != true) return | ||
|
||
val sparkifyAnnotationFqNames = configuration.get(KEY_SPARKIFY_ANNOTATION_FQ_NAMES) | ||
?: listOf(Artifacts.defaultSparkifyFqName) | ||
|
||
val columnNameAnnotationFqNames = configuration.get(KEY_COLUMN_NAME_ANNOTATION_FQ_NAMES) | ||
?: listOf(Artifacts.defaultColumnNameFqName) | ||
|
||
IrGenerationExtension.registerExtension( | ||
SparkifyIrGenerationExtension( | ||
sparkifyAnnotationFqNames = sparkifyAnnotationFqNames, | ||
columnNameAnnotationFqNames = columnNameAnnotationFqNames, | ||
) | ||
) | ||
} | ||
} |
Oops, something went wrong.