Generate Gradle compiler types into separate project
This will allow to use them on the DSL generation. ^KT-27301 In Progress
This commit is contained in:
@@ -77,6 +77,7 @@ dependencies {
|
||||
testImplementation(projectTests(":compiler:test-infrastructure"))
|
||||
testImplementation(projectTests(":compiler:tests-common-new"))
|
||||
testImplementation(projectTests(":js:js.tests"))
|
||||
testImplementation(project(":kotlin-gradle-compiler-types"))
|
||||
testApiJUnit5()
|
||||
|
||||
if (Ide.IJ()) {
|
||||
@@ -97,7 +98,11 @@ val generateTests by generator("org.jetbrains.kotlin.generators.tests.GenerateTe
|
||||
val generateProtoBuf by generator("org.jetbrains.kotlin.generators.protobuf.GenerateProtoBufKt", protobufSourceSet)
|
||||
val generateProtoBufCompare by generator("org.jetbrains.kotlin.generators.protobuf.GenerateProtoBufCompare", protobufCompareSourceSet)
|
||||
|
||||
val generateGradleCompilerTypes by generator("org.jetbrains.kotlin.generators.arguments.GenerateGradleCompilerTypesKt") {
|
||||
description = "Generate Kotlin compiler arguments types Gradle representation"
|
||||
}
|
||||
val generateGradleOptions by generator("org.jetbrains.kotlin.generators.arguments.GenerateGradleOptionsKt") {
|
||||
dependsOn(generateGradleCompilerTypes)
|
||||
description = "Generate Gradle plugin compiler options"
|
||||
}
|
||||
val generateKeywordStrings by generator("org.jetbrains.kotlin.generators.frontend.GenerateKeywordStrings")
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.generators.arguments
|
||||
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
import java.io.File
|
||||
import java.io.PrintStream
|
||||
|
||||
fun generateGradleCompilerTypes(withPrinterToFile: (targetFile: File, Printer.() -> Unit) -> Unit) {
|
||||
val destDir = File("libraries/tools/kotlin-gradle-compiler-types/src/generated/kotlin")
|
||||
|
||||
// Common
|
||||
generateKotlinVersion(destDir, withPrinterToFile)
|
||||
|
||||
// Jvm
|
||||
generateJvmTarget(destDir, withPrinterToFile)
|
||||
|
||||
// Js
|
||||
generateJsMainFunctionExecutionMode(destDir, withPrinterToFile)
|
||||
generateJsModuleKind(destDir, withPrinterToFile)
|
||||
generateJsSourceMapEmbedMode(destDir, withPrinterToFile)
|
||||
generateJsDiagnosticMode(destDir, withPrinterToFile)
|
||||
}
|
||||
|
||||
fun main() {
|
||||
fun getPrinter(file: File, fn: Printer.() -> Unit) {
|
||||
if (!file.exists()) {
|
||||
file.parentFile.mkdirs()
|
||||
file.createNewFile()
|
||||
}
|
||||
PrintStream(file.outputStream().buffered()).use {
|
||||
val printer = Printer(it)
|
||||
printer.fn()
|
||||
}
|
||||
}
|
||||
|
||||
generateGradleCompilerTypes(::getPrinter)
|
||||
}
|
||||
@@ -32,14 +32,6 @@ fun generateKotlinGradleOptions(withPrinterToFile: (targetFile: File, Printer.()
|
||||
val apiSrcDir = File("libraries/tools/kotlin-gradle-plugin-api/src/common/kotlin")
|
||||
val srcDir = File("libraries/tools/kotlin-gradle-plugin/src/common/kotlin")
|
||||
|
||||
// specific Gradle types from internal compiler types
|
||||
generateKotlinVersion(apiSrcDir, withPrinterToFile)
|
||||
generateJvmTarget(apiSrcDir, withPrinterToFile)
|
||||
generateJsMainFunctionExecutionMode(apiSrcDir, withPrinterToFile)
|
||||
generateJsModuleKind(apiSrcDir, withPrinterToFile)
|
||||
generateJsSourceMapEmbedMode(apiSrcDir, withPrinterToFile)
|
||||
generateJsDiagnosticMode(apiSrcDir, withPrinterToFile)
|
||||
|
||||
// common interface
|
||||
val commonInterfaceFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinCommonToolOptions")
|
||||
val commonOptions = gradleOptions<CommonToolArguments>()
|
||||
|
||||
+17
@@ -7,6 +7,7 @@
|
||||
package org.jetbrains.kotlin.generators.arguments.test
|
||||
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.kotlin.generators.arguments.generateGradleCompilerTypes
|
||||
import org.jetbrains.kotlin.generators.arguments.generateKotlinGradleOptions
|
||||
import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
@@ -30,4 +31,20 @@ class GenerateKotlinGradleOptionsTest : TestCase() {
|
||||
|
||||
generateKotlinGradleOptions(::getPrinter)
|
||||
}
|
||||
|
||||
fun testKotlinGradleTypesAreUpToDate() {
|
||||
fun getPrinter(file: File, fn: Printer.() -> Unit) {
|
||||
val bytesOut = ByteArrayOutputStream()
|
||||
|
||||
PrintStream(bytesOut).use {
|
||||
val printer = Printer(it)
|
||||
printer.fn()
|
||||
}
|
||||
|
||||
val upToDateContent = bytesOut.toString()
|
||||
KtUsefulTestCase.assertSameLinesWithFile(file.absolutePath, upToDateContent)
|
||||
}
|
||||
|
||||
generateGradleCompilerTypes(::getPrinter)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user