Introduce Kotlin compiler options with Gradle Properties API types
Old one is deprecated and delegates to new options. All new options are marked with task input types, so they could be used as `@Nested` input. Generated options are using specific types in generated compiler options. This should simplify code completion and provide meaningful hints to user. At this point repository compilation will fail. ^KT-27301 In Progress
This commit is contained in:
@@ -14,6 +14,7 @@ dependencies {
|
||||
compileOnly(intellijCore())
|
||||
compileOnly(commonDependency("com.google.guava:guava"))
|
||||
compileOnly(commonDependency("org.jetbrains.intellij.deps:asm-all"))
|
||||
compileOnly(project(":kotlin-gradle-compiler-types"))
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
|
||||
+12
-3
@@ -31,7 +31,10 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
|
||||
@get:Transient
|
||||
var autoAdvanceLanguageVersion: Boolean by FreezableVar(true)
|
||||
|
||||
@GradleOption(DefaultValues.LanguageVersions::class)
|
||||
@GradleOption(
|
||||
value = DefaultValues.LanguageVersions::class,
|
||||
gradleInputType = GradleInputTypes.INPUT
|
||||
)
|
||||
@Argument(
|
||||
value = "-language-version",
|
||||
valueDescription = "<version>",
|
||||
@@ -42,7 +45,10 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
|
||||
@get:Transient
|
||||
var autoAdvanceApiVersion: Boolean by FreezableVar(true)
|
||||
|
||||
@GradleOption(DefaultValues.ApiVersions::class)
|
||||
@GradleOption(
|
||||
value = DefaultValues.ApiVersions::class,
|
||||
gradleInputType = GradleInputTypes.INPUT
|
||||
)
|
||||
@Argument(
|
||||
value = "-api-version",
|
||||
valueDescription = "<version>",
|
||||
@@ -296,7 +302,10 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
|
||||
)
|
||||
var checkStickyPhaseConditions: Boolean by FreezableVar(false)
|
||||
|
||||
@GradleOption(DefaultValues.BooleanFalseDefault::class)
|
||||
@GradleOption(
|
||||
DefaultValues.BooleanFalseDefault::class,
|
||||
gradleInputType = GradleInputTypes.INPUT
|
||||
)
|
||||
@Argument(
|
||||
value = "-Xuse-k2",
|
||||
deprecatedName = "-Xuse-fir",
|
||||
|
||||
+12
-3
@@ -38,15 +38,24 @@ abstract class CommonToolArguments : Freezable(), Serializable {
|
||||
@Argument(value = "-version", description = "Display compiler version")
|
||||
var version: Boolean by FreezableVar(false)
|
||||
|
||||
@GradleOption(DefaultValues.BooleanFalseDefault::class)
|
||||
@GradleOption(
|
||||
value = DefaultValues.BooleanFalseDefault::class,
|
||||
gradleInputType = GradleInputTypes.INTERNAL
|
||||
)
|
||||
@Argument(value = "-verbose", description = "Enable verbose logging output")
|
||||
var verbose: Boolean by FreezableVar(false)
|
||||
|
||||
@GradleOption(DefaultValues.BooleanFalseDefault::class)
|
||||
@GradleOption(
|
||||
value = DefaultValues.BooleanFalseDefault::class,
|
||||
gradleInputType = GradleInputTypes.INTERNAL
|
||||
)
|
||||
@Argument(value = "-nowarn", description = "Generate no warnings")
|
||||
var suppressWarnings: Boolean by FreezableVar(false)
|
||||
|
||||
@GradleOption(DefaultValues.BooleanFalseDefault::class)
|
||||
@GradleOption(
|
||||
value = DefaultValues.BooleanFalseDefault::class,
|
||||
gradleInputType = GradleInputTypes.INPUT
|
||||
)
|
||||
@Argument(value = "-Werror", description = "Report an error if there are any warnings")
|
||||
var allWarningsAsErrors: Boolean by FreezableVar(false)
|
||||
|
||||
|
||||
+84
-17
@@ -10,57 +10,124 @@ import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants.NO_CALL
|
||||
import org.jetbrains.kotlin.config.ApiVersion
|
||||
import org.jetbrains.kotlin.config.JvmTarget
|
||||
import org.jetbrains.kotlin.config.LanguageVersion
|
||||
import org.jetbrains.kotlin.gradle.dsl.JsMainFunctionExecutionMode
|
||||
import org.jetbrains.kotlin.gradle.dsl.JsModuleKind
|
||||
import org.jetbrains.kotlin.gradle.dsl.JsSourceMapEmbedMode
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion as KotlinVersionDsl
|
||||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget as JvmTargetDsl
|
||||
import kotlin.reflect.KType
|
||||
import kotlin.reflect.typeOf
|
||||
|
||||
open class DefaultValues(val defaultValue: String, val possibleValues: List<String>? = null) {
|
||||
object BooleanFalseDefault : DefaultValues("false")
|
||||
open class DefaultValues(
|
||||
val defaultValue: String,
|
||||
val type: KType,
|
||||
val kotlinOptionsType: KType,
|
||||
val possibleValues: List<String>? = null,
|
||||
val fromKotlinOptionConverterProp: String? = null,
|
||||
val toKotlinOptionConverterProp: String? = null,
|
||||
val toArgumentConverter: String? = toKotlinOptionConverterProp
|
||||
) {
|
||||
open class DefaultBoolean(defaultValue: Boolean) : DefaultValues(defaultValue.toString(), typeOf<Boolean>(), typeOf<Boolean>())
|
||||
|
||||
object BooleanTrueDefault : DefaultValues("true")
|
||||
object BooleanFalseDefault : DefaultBoolean(false)
|
||||
|
||||
object StringNullDefault : DefaultValues("null")
|
||||
object BooleanTrueDefault : DefaultBoolean(true)
|
||||
|
||||
object ListEmptyDefault : DefaultValues("<empty list>")
|
||||
object StringNullDefault : DefaultValues("null", typeOf<String?>(), typeOf<String?>())
|
||||
|
||||
object EmptyStringListDefault : DefaultValues("emptyList<String>()", typeOf<List<String>>(), typeOf<List<String>>())
|
||||
|
||||
object LanguageVersions : DefaultValues(
|
||||
"null",
|
||||
LanguageVersion.values()
|
||||
typeOf<KotlinVersionDsl?>(),
|
||||
typeOf<String?>(),
|
||||
possibleValues = LanguageVersion.values()
|
||||
.filterNot { it.isUnsupported }
|
||||
.map { "\"${it.description}\"" }
|
||||
.map { "\"${it.description}\"" },
|
||||
fromKotlinOptionConverterProp = """
|
||||
if (this != null) ${typeOf<KotlinVersionDsl>()}.fromVersion(this) else null
|
||||
""".trimIndent(),
|
||||
toKotlinOptionConverterProp = """
|
||||
this?.version
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
object ApiVersions : DefaultValues(
|
||||
"null",
|
||||
LanguageVersion.values()
|
||||
typeOf<KotlinVersionDsl?>(),
|
||||
typeOf<String?>(),
|
||||
possibleValues = LanguageVersion.values()
|
||||
.map(ApiVersion.Companion::createByLanguageVersion)
|
||||
.filterNot { it.isUnsupported }
|
||||
.map { "\"${it.description}\"" }
|
||||
.map { "\"${it.description}\"" },
|
||||
fromKotlinOptionConverterProp = """
|
||||
if (this != null) ${typeOf<KotlinVersionDsl>()}.fromVersion(this) else null
|
||||
""".trimIndent(),
|
||||
toKotlinOptionConverterProp = """
|
||||
this?.version
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
object JvmTargetVersions : DefaultValues(
|
||||
"null",
|
||||
JvmTarget.supportedValues().map { "\"${it.description}\"" }
|
||||
typeOf<JvmTargetDsl?>(),
|
||||
typeOf<String?>(),
|
||||
possibleValues = JvmTarget.supportedValues().map { "\"${it.description}\"" },
|
||||
fromKotlinOptionConverterProp = """
|
||||
if (this != null) ${typeOf<JvmTargetDsl>()}.fromTarget(this) else null
|
||||
""".trimIndent(),
|
||||
toKotlinOptionConverterProp = """
|
||||
this?.target
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
object JsEcmaVersions : DefaultValues(
|
||||
"\"v5\"",
|
||||
listOf("\"v5\"")
|
||||
typeOf<String>(),
|
||||
typeOf<String>(),
|
||||
possibleValues = listOf("\"v5\"")
|
||||
)
|
||||
|
||||
object JsModuleKinds : DefaultValues(
|
||||
"\"plain\"",
|
||||
listOf("\"plain\"", "\"amd\"", "\"commonjs\"", "\"umd\"")
|
||||
"${typeOf<JsModuleKind>()}.${JsModuleKind.MODULE_PLAIN.name}",
|
||||
typeOf<JsModuleKind>(),
|
||||
typeOf<String>(),
|
||||
possibleValues = listOf("\"plain\"", "\"amd\"", "\"commonjs\"", "\"umd\""),
|
||||
fromKotlinOptionConverterProp = """
|
||||
${typeOf<JsModuleKind>()}.fromKind(this)
|
||||
""".trimIndent(),
|
||||
toKotlinOptionConverterProp = """
|
||||
this.kind
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
object JsSourceMapContentModes : DefaultValues(
|
||||
"null",
|
||||
listOf(
|
||||
typeOf<JsSourceMapEmbedMode?>(),
|
||||
typeOf<String?>(),
|
||||
possibleValues = listOf(
|
||||
K2JsArgumentConstants.SOURCE_MAP_SOURCE_CONTENT_NEVER,
|
||||
K2JsArgumentConstants.SOURCE_MAP_SOURCE_CONTENT_ALWAYS,
|
||||
K2JsArgumentConstants.SOURCE_MAP_SOURCE_CONTENT_INLINING
|
||||
).map { "\"$it\"" }
|
||||
).map { "\"$it\"" },
|
||||
fromKotlinOptionConverterProp = """
|
||||
this?.let { ${typeOf<JsSourceMapEmbedMode>()}.fromMode(it) }
|
||||
""".trimIndent(),
|
||||
toKotlinOptionConverterProp = """
|
||||
this?.mode
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
object JsMain : DefaultValues(
|
||||
"\"" + CALL + "\"",
|
||||
listOf("\"" + CALL + "\"", "\"" + NO_CALL + "\"")
|
||||
"${typeOf<JsMainFunctionExecutionMode>()}.${JsMainFunctionExecutionMode.CALL.name}",
|
||||
typeOf<JsMainFunctionExecutionMode>(),
|
||||
typeOf<String>(),
|
||||
possibleValues = listOf("\"" + CALL + "\"", "\"" + NO_CALL + "\""),
|
||||
fromKotlinOptionConverterProp = """
|
||||
${typeOf<JsMainFunctionExecutionMode>()}.fromMode(this)
|
||||
""".trimIndent(),
|
||||
toKotlinOptionConverterProp = """
|
||||
this.mode
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
+12
-2
@@ -19,8 +19,18 @@ package org.jetbrains.kotlin.cli.common.arguments
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.KVisibility
|
||||
|
||||
/**
|
||||
* @param gradleInputType should be one of [GradleInputTypes] constants
|
||||
*/
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class GradleOption(
|
||||
val value: KClass<out DefaultValues> = DefaultValues::class,
|
||||
val backingFieldVisibility: KVisibility = KVisibility.PRIVATE
|
||||
val value: KClass<out DefaultValues>,
|
||||
val gradleInputType: String
|
||||
)
|
||||
|
||||
// Enum class here is not possible due to bug in K2 compiler:
|
||||
// https://youtrack.jetbrains.com/issue/KT-54079
|
||||
object GradleInputTypes {
|
||||
const val INPUT = "org.gradle.api.tasks.Input"
|
||||
const val INTERNAL = "org.gradle.api.tasks.Internal"
|
||||
}
|
||||
|
||||
+49
-12
@@ -16,11 +16,22 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
|
||||
@JvmStatic private val serialVersionUID = 0L
|
||||
}
|
||||
|
||||
@GradleOption(DefaultValues.StringNullDefault::class)
|
||||
@GradleOption(
|
||||
value = DefaultValues.StringNullDefault::class,
|
||||
gradleInputType = GradleInputTypes.INTERNAL // handled by task 'outputFileProperty'
|
||||
)
|
||||
@GradleDeprecatedOption(
|
||||
message = "Use task 'outputFileProperty' to specify location",
|
||||
level = DeprecationLevel.WARNING,
|
||||
removeAfter = "1.9.0"
|
||||
)
|
||||
@Argument(value = "-output", valueDescription = "<filepath>", description = "Destination *.js file for the compilation result")
|
||||
var outputFile: String? by NullableStringFreezableVar(null)
|
||||
|
||||
@GradleOption(DefaultValues.BooleanTrueDefault::class)
|
||||
@GradleOption(
|
||||
value = DefaultValues.BooleanTrueDefault::class,
|
||||
gradleInputType = GradleInputTypes.INPUT
|
||||
)
|
||||
@Argument(value = "-no-stdlib", description = "Don't automatically include the default Kotlin/JS stdlib into compilation dependencies")
|
||||
var noStdlib: Boolean by FreezableVar(false)
|
||||
|
||||
@@ -38,11 +49,17 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
|
||||
)
|
||||
var repositries: String? by NullableStringFreezableVar(null)
|
||||
|
||||
@GradleOption(DefaultValues.BooleanFalseDefault::class)
|
||||
@GradleOption(
|
||||
value = DefaultValues.BooleanFalseDefault::class,
|
||||
gradleInputType = GradleInputTypes.INPUT
|
||||
)
|
||||
@Argument(value = "-source-map", description = "Generate source map")
|
||||
var sourceMap: Boolean by FreezableVar(false)
|
||||
|
||||
@GradleOption(DefaultValues.StringNullDefault::class)
|
||||
@GradleOption(
|
||||
value = DefaultValues.StringNullDefault::class,
|
||||
gradleInputType = GradleInputTypes.INPUT
|
||||
)
|
||||
@Argument(value = "-source-map-prefix", description = "Add the specified prefix to paths in the source map")
|
||||
var sourceMapPrefix: String? by NullableStringFreezableVar(null)
|
||||
|
||||
@@ -58,7 +75,10 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
|
||||
* SourceMapEmbedSources should be null by default, since it has effect only when source maps are enabled.
|
||||
* When sourceMapEmbedSources are not null and source maps is disabled warning is reported.
|
||||
*/
|
||||
@GradleOption(DefaultValues.JsSourceMapContentModes::class)
|
||||
@GradleOption(
|
||||
value = DefaultValues.JsSourceMapContentModes::class,
|
||||
gradleInputType = GradleInputTypes.INPUT
|
||||
)
|
||||
@Argument(
|
||||
value = "-source-map-embed-sources",
|
||||
valueDescription = "{always|never|inlining}",
|
||||
@@ -66,15 +86,24 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
|
||||
)
|
||||
var sourceMapEmbedSources: String? by NullableStringFreezableVar(null)
|
||||
|
||||
@GradleOption(DefaultValues.BooleanTrueDefault::class)
|
||||
@GradleOption(
|
||||
value = DefaultValues.BooleanTrueDefault::class,
|
||||
gradleInputType = GradleInputTypes.INPUT
|
||||
)
|
||||
@Argument(value = "-meta-info", description = "Generate .meta.js and .kjsm files with metadata. Use to create a library")
|
||||
var metaInfo: Boolean by FreezableVar(false)
|
||||
|
||||
@GradleOption(DefaultValues.JsEcmaVersions::class)
|
||||
@GradleOption(
|
||||
value = DefaultValues.JsEcmaVersions::class,
|
||||
gradleInputType = GradleInputTypes.INPUT
|
||||
)
|
||||
@Argument(value = "-target", valueDescription = "{ v5 }", description = "Generate JS files for specific ECMA version")
|
||||
var target: String? by NullableStringFreezableVar(null)
|
||||
|
||||
@GradleOption(DefaultValues.JsModuleKinds::class)
|
||||
@GradleOption(
|
||||
value = DefaultValues.JsModuleKinds::class,
|
||||
gradleInputType = GradleInputTypes.INPUT
|
||||
)
|
||||
@Argument(
|
||||
value = "-module-kind",
|
||||
valueDescription = "{plain|amd|commonjs|umd}",
|
||||
@@ -82,7 +111,10 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
|
||||
)
|
||||
var moduleKind: String? by NullableStringFreezableVar(K2JsArgumentConstants.MODULE_PLAIN)
|
||||
|
||||
@GradleOption(DefaultValues.JsMain::class)
|
||||
@GradleOption(
|
||||
value = DefaultValues.JsMain::class,
|
||||
gradleInputType = GradleInputTypes.INPUT
|
||||
)
|
||||
@Argument(
|
||||
value = "-main",
|
||||
valueDescription = "{$CALL|$NO_CALL}",
|
||||
@@ -207,18 +239,23 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
|
||||
)
|
||||
var generateDts: Boolean by FreezableVar(false)
|
||||
|
||||
|
||||
@Argument(
|
||||
value = "-Xstrict-implicit-export-types",
|
||||
description = "Generate strict types for implicitly exported entities inside d.ts files. Available in IR backend only."
|
||||
)
|
||||
var strictImplicitExportType: Boolean by FreezableVar(false)
|
||||
|
||||
@GradleOption(DefaultValues.BooleanTrueDefault::class)
|
||||
@GradleOption(
|
||||
value = DefaultValues.BooleanTrueDefault::class,
|
||||
gradleInputType = GradleInputTypes.INPUT
|
||||
)
|
||||
@Argument(value = "-Xtyped-arrays", description = "Translate primitive arrays to JS typed arrays")
|
||||
var typedArrays: Boolean by FreezableVar(true)
|
||||
|
||||
@GradleOption(DefaultValues.BooleanFalseDefault::class)
|
||||
@GradleOption(
|
||||
value = DefaultValues.BooleanFalseDefault::class,
|
||||
gradleInputType = GradleInputTypes.INPUT
|
||||
)
|
||||
@Argument(value = "-Xfriend-modules-disabled", description = "Disable internal declaration export")
|
||||
var friendModulesDisabled: Boolean by FreezableVar(false)
|
||||
|
||||
|
||||
+13
-2
@@ -13,12 +13,20 @@ class K2JSDceArguments : CommonToolArguments() {
|
||||
@JvmStatic private val serialVersionUID = 0L
|
||||
}
|
||||
|
||||
@GradleOption(
|
||||
value = DefaultValues.StringNullDefault::class,
|
||||
gradleInputType = GradleInputTypes.INTERNAL // handled by 'destinationDirectory'
|
||||
)
|
||||
@GradleDeprecatedOption(
|
||||
message = "Use task 'destinationDirectory' to configure output directory",
|
||||
level = DeprecationLevel.WARNING,
|
||||
removeAfter = "1.9.0"
|
||||
)
|
||||
@Argument(
|
||||
value = "-output-dir",
|
||||
valueDescription = "<path>",
|
||||
description = "Output directory"
|
||||
)
|
||||
@GradleOption(DefaultValues.StringNullDefault::class)
|
||||
var outputDirectory: String? by NullableStringFreezableVar(null)
|
||||
|
||||
@Argument(
|
||||
@@ -34,11 +42,14 @@ class K2JSDceArguments : CommonToolArguments() {
|
||||
)
|
||||
var printReachabilityInfo: Boolean by FreezableVar(false)
|
||||
|
||||
@GradleOption(
|
||||
value = DefaultValues.BooleanFalseDefault::class,
|
||||
gradleInputType = GradleInputTypes.INPUT
|
||||
)
|
||||
@Argument(
|
||||
value = "-dev-mode",
|
||||
description = "Development mode: don't strip out any code, just copy dependencies"
|
||||
)
|
||||
@GradleOption(DefaultValues.BooleanFalseDefault::class)
|
||||
var devMode: Boolean by FreezableVar(false)
|
||||
|
||||
@Argument(
|
||||
|
||||
+13
-5
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.cli.common.arguments
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||
import org.jetbrains.kotlin.config.*
|
||||
import kotlin.reflect.KVisibility
|
||||
|
||||
class K2JVMCompilerArguments : CommonCompilerArguments() {
|
||||
companion object {
|
||||
@@ -37,7 +36,10 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
|
||||
)
|
||||
var jdkHome: String? by NullableStringFreezableVar(null)
|
||||
|
||||
@GradleOption(DefaultValues.BooleanFalseDefault::class)
|
||||
@GradleOption(
|
||||
value = DefaultValues.BooleanFalseDefault::class,
|
||||
gradleInputType = GradleInputTypes.INPUT
|
||||
)
|
||||
@Argument(value = "-no-jdk", description = "Don't automatically include the Java runtime into the classpath")
|
||||
var noJdk: Boolean by FreezableVar(false)
|
||||
|
||||
@@ -64,13 +66,16 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
|
||||
)
|
||||
var scriptTemplates: Array<String>? by FreezableVar(null)
|
||||
|
||||
@GradleOption(DefaultValues.StringNullDefault::class)
|
||||
@GradleOption(
|
||||
value = DefaultValues.StringNullDefault::class,
|
||||
gradleInputType = GradleInputTypes.INPUT
|
||||
)
|
||||
@Argument(value = "-module-name", valueDescription = "<name>", description = "Name of the generated .kotlin_module file")
|
||||
var moduleName: String? by NullableStringFreezableVar(null)
|
||||
|
||||
@GradleOption(
|
||||
value = DefaultValues.JvmTargetVersions::class,
|
||||
backingFieldVisibility = KVisibility.INTERNAL
|
||||
gradleInputType = GradleInputTypes.INPUT
|
||||
)
|
||||
@Argument(
|
||||
value = "-jvm-target",
|
||||
@@ -79,7 +84,10 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
|
||||
)
|
||||
var jvmTarget: String? by NullableStringFreezableVar(null)
|
||||
|
||||
@GradleOption(DefaultValues.BooleanFalseDefault::class)
|
||||
@GradleOption(
|
||||
value = DefaultValues.BooleanFalseDefault::class,
|
||||
gradleInputType = GradleInputTypes.INPUT
|
||||
)
|
||||
@Argument(value = "-java-parameters", description = "Generate metadata for Java 1.8 reflection on method parameters")
|
||||
var javaParameters: Boolean by FreezableVar(false)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user