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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
plugins {
|
||||
id("org.jetbrains.kotlin.jvm")
|
||||
id("jps-compatible")
|
||||
}
|
||||
|
||||
configureKotlinCompileTasksGradleCompatibility()
|
||||
|
||||
sourceSets {
|
||||
"main" {
|
||||
kotlin.srcDir("src/generated/kotlin")
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(kotlinStdlib())
|
||||
}
|
||||
@@ -8,6 +8,7 @@ dependencies {
|
||||
commonApi(project(":kotlin-project-model"))
|
||||
commonImplementation(project(":kotlin-tooling-core"))
|
||||
|
||||
commonCompileOnly(project(":kotlin-gradle-compiler-types"))
|
||||
commonCompileOnly("com.android.tools.build:gradle:3.6.4") {
|
||||
// Without it - Gradle dependency resolution fails with unexpected error
|
||||
// Caused by: java.lang.IllegalStateException: Unexpected parent dependency id 131. Seen ids: [129, 2, 130, 9, 10, 138, 11, 139, 140, 14, 153, 154, 155, 156, 157, 158, 161, 164, 177, 178, 51, 179, 52, 180, 53, 54, 55, 183, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 195, 68, 200, 201, 202, 203, 206, 211, 212, 215, 222, 223, 224, 231, 232, 105, 233, 106, 107, 108, 109, 110, 111, 112, 113, 114, 242, 115, 243, 116, 244, 117, 118, 119, 120, 121, 122]
|
||||
@@ -16,4 +17,6 @@ dependencies {
|
||||
// Could be reproduced by running `:kotlin-gradle-plugin-api:gPFFPMP` task
|
||||
isTransitive = false
|
||||
}
|
||||
|
||||
embedded(project(":kotlin-gradle-compiler-types"))
|
||||
}
|
||||
|
||||
@@ -249,6 +249,7 @@ include ":kotlin-imports-dumper-compiler-plugin",
|
||||
":tools:kotlinp",
|
||||
":kotlin-project-model",
|
||||
":kotlin-project-model-tests-generator",
|
||||
":kotlin-gradle-compiler-types",
|
||||
":kotlin-gradle-plugin-api",
|
||||
":kotlin-gradle-plugin-idea",
|
||||
":kotlin-gradle-plugin-idea-proto",
|
||||
@@ -753,6 +754,7 @@ project(':kotlin-assignment-compiler-plugin.cli').projectDir = "$rootDir/plugins
|
||||
project(':tools:kotlinp').projectDir = "$rootDir/libraries/tools/kotlinp" as File
|
||||
project(':kotlin-project-model').projectDir = "$rootDir/libraries/tools/kotlin-project-model" as File
|
||||
project(':kotlin-project-model-tests-generator').projectDir = "$rootDir/libraries/tools/kotlin-project-model-tests-generator" as File
|
||||
project(':kotlin-gradle-compiler-types').projectDir = "$rootDir/libraries/tools/kotlin-gradle-compiler-types" as File
|
||||
project(':kotlin-gradle-plugin-api').projectDir = "$rootDir/libraries/tools/kotlin-gradle-plugin-api" as File
|
||||
project(':kotlin-gradle-plugin-idea').projectDir = "$rootDir/libraries/tools/kotlin-gradle-plugin-idea" as File
|
||||
project(':kotlin-gradle-plugin-idea-proto').projectDir = "$rootDir/libraries/tools/kotlin-gradle-plugin-idea-proto" as File
|
||||
|
||||
Reference in New Issue
Block a user