Add '-progressive' option into Gradle compiler options DSL
^KT-53923 Fixed
This commit is contained in:
committed by
Space Team
parent
8bb0c5135b
commit
5ddd60a015
+4
@@ -85,6 +85,10 @@ abstract class CommonCompilerArguments : CommonToolArguments() {
|
||||
field = if (value.isNullOrEmpty()) null else value
|
||||
}
|
||||
|
||||
@GradleOption(
|
||||
value = DefaultValue.BOOLEAN_FALSE_DEFAULT,
|
||||
gradleInputType = GradleInputTypes.INPUT
|
||||
)
|
||||
@Argument(
|
||||
value = "-progressive",
|
||||
deprecatedName = "-Xprogressive",
|
||||
|
||||
@@ -753,7 +753,7 @@ private fun Printer.generateDoc(property: KProperty1<*, *>) {
|
||||
val defaultValue = property.gradleDefaultValue
|
||||
|
||||
println("/**")
|
||||
println(" * $description")
|
||||
println(" * ${description.replace("\n", " ")}")
|
||||
if (possibleValues != null) {
|
||||
println(" * Possible values: ${possibleValues.joinToString()}")
|
||||
}
|
||||
|
||||
@@ -166,6 +166,7 @@ public abstract interface class org/jetbrains/kotlin/gradle/dsl/KotlinCommonComp
|
||||
public abstract fun getApiVersion ()Lorg/gradle/api/provider/Property;
|
||||
public abstract fun getLanguageVersion ()Lorg/gradle/api/provider/Property;
|
||||
public abstract fun getOptIn ()Lorg/gradle/api/provider/ListProperty;
|
||||
public abstract fun getProgressiveMode ()Lorg/gradle/api/provider/Property;
|
||||
public abstract fun getUseK2 ()Lorg/gradle/api/provider/Property;
|
||||
}
|
||||
|
||||
|
||||
+7
@@ -32,6 +32,13 @@ interface KotlinCommonCompilerOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCo
|
||||
@get:org.gradle.api.tasks.Input
|
||||
val optIn: org.gradle.api.provider.ListProperty<kotlin.String>
|
||||
|
||||
/**
|
||||
* Enable progressive compiler mode. In this mode, deprecations and bug fixes for unstable code take effect immediately, instead of going through a graceful migration cycle. Code written in the progressive mode is backward compatible; however, code written in non-progressive mode may cause compilation errors in the progressive mode.
|
||||
* Default value: false
|
||||
*/
|
||||
@get:org.gradle.api.tasks.Input
|
||||
val progressiveMode: org.gradle.api.provider.Property<kotlin.Boolean>
|
||||
|
||||
/**
|
||||
* Compile using experimental K2. K2 is a new compiler pipeline, no compatibility guarantees are yet provided
|
||||
* Default value: false
|
||||
|
||||
+134
@@ -299,4 +299,138 @@ internal class CompilerOptionsIT : KGPBaseTest() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DisplayName("Should pass -progressive from compiler options DSL")
|
||||
@JvmGradlePluginTests
|
||||
@GradleTest
|
||||
fun passesProgressive(gradleVersion: GradleVersion) {
|
||||
project(
|
||||
projectName = "simpleProject",
|
||||
gradleVersion = gradleVersion,
|
||||
buildOptions = defaultBuildOptions.copy(logLevel = LogLevel.DEBUG)
|
||||
) {
|
||||
buildGradle.appendText(
|
||||
//language=Groovy
|
||||
"""
|
||||
|
|
||||
|tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask.class).configureEach {
|
||||
| compilerOptions.progressiveMode.set(true)
|
||||
|}
|
||||
""".trimMargin()
|
||||
)
|
||||
|
||||
build("compileKotlin") {
|
||||
val compilerArgs = output
|
||||
.lineSequence()
|
||||
.first {
|
||||
it.contains("Kotlin compiler args:")
|
||||
}
|
||||
.substringAfter("Kotlin compiler args:")
|
||||
|
||||
val expectedArg = "-progressive"
|
||||
assert(compilerArgs.contains(expectedArg)) {
|
||||
printBuildOutput()
|
||||
"compiler arguments does not contain '$expectedArg' - actual value: $compilerArgs"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DisplayName("Should not pass -progressive by default from compiler options DSL")
|
||||
@JvmGradlePluginTests
|
||||
@GradleTest
|
||||
fun notPassesDefaultProgressive(gradleVersion: GradleVersion) {
|
||||
project(
|
||||
projectName = "simpleProject",
|
||||
gradleVersion = gradleVersion,
|
||||
buildOptions = defaultBuildOptions.copy(logLevel = LogLevel.DEBUG)
|
||||
) {
|
||||
build("compileKotlin") {
|
||||
val compilerArgs = output
|
||||
.lineSequence()
|
||||
.first {
|
||||
it.contains("Kotlin compiler args:")
|
||||
}
|
||||
.substringAfter("Kotlin compiler args:")
|
||||
|
||||
val expectedArg = "-progressive"
|
||||
assert(!compilerArgs.contains(expectedArg)) {
|
||||
printBuildOutput()
|
||||
"compiler arguments contains '$expectedArg' - actual value: $compilerArgs"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DisplayName("Should pass -progressive from languageSettings if compiler options DSL is not configured")
|
||||
@JvmGradlePluginTests
|
||||
@GradleTest
|
||||
fun passesProgressiveFromLanguageSettings(gradleVersion: GradleVersion) {
|
||||
project(
|
||||
projectName = "simpleProject",
|
||||
gradleVersion = gradleVersion,
|
||||
buildOptions = defaultBuildOptions.copy(logLevel = LogLevel.DEBUG)
|
||||
) {
|
||||
buildGradle.appendText(
|
||||
//language=Groovy
|
||||
"""
|
||||
|
|
||||
|kotlin.sourceSets.all {
|
||||
| languageSettings {
|
||||
| progressiveMode = true
|
||||
| }
|
||||
|}
|
||||
""".trimMargin()
|
||||
)
|
||||
|
||||
build("compileKotlin") {
|
||||
val compilerArgs = output
|
||||
.lineSequence()
|
||||
.first {
|
||||
it.contains("Kotlin compiler args:")
|
||||
}
|
||||
.substringAfter("Kotlin compiler args:")
|
||||
|
||||
val expectedArg = "-progressive"
|
||||
assert(compilerArgs.contains(expectedArg)) {
|
||||
printBuildOutput()
|
||||
"compiler arguments does not contain '$expectedArg' - actual value: $compilerArgs"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DisplayName("Should pass -progressive from compiler options DSL in native project")
|
||||
@NativeGradlePluginTests
|
||||
@GradleTest
|
||||
fun passesProgressiveModeNative(gradleVersion: GradleVersion) {
|
||||
nativeProject(
|
||||
projectName = "native-link-simple",
|
||||
gradleVersion = gradleVersion,
|
||||
) {
|
||||
buildGradle.appendText(
|
||||
//language=Groovy
|
||||
"""
|
||||
|
|
||||
|tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask.class).configureEach {
|
||||
| compilerOptions.progressiveMode.set(true)
|
||||
|}
|
||||
""".trimMargin()
|
||||
)
|
||||
|
||||
build("compileKotlinHost", forceOutput = true) {
|
||||
val expectedArg = "-progressive"
|
||||
val compilerArgs = output
|
||||
.substringAfter("Arguments = [")
|
||||
.substringBefore("]")
|
||||
.lines()
|
||||
val progressiveArg = compilerArgs.find { it.trim() == expectedArg }
|
||||
|
||||
assert(progressiveArg != null) {
|
||||
printBuildOutput()
|
||||
"compiler arguments does not contain '$expectedArg': ${compilerArgs.joinToString()}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
@@ -18,6 +18,9 @@ internal abstract class KotlinCommonCompilerOptionsDefault @javax.inject.Inject
|
||||
override val optIn: org.gradle.api.provider.ListProperty<kotlin.String> =
|
||||
objectFactory.listProperty(kotlin.String::class.java).convention(emptyList<String>())
|
||||
|
||||
override val progressiveMode: org.gradle.api.provider.Property<kotlin.Boolean> =
|
||||
objectFactory.property(kotlin.Boolean::class.java).convention(false)
|
||||
|
||||
@Deprecated(message = "Compiler flag -Xuse-k2 is deprecated; please use language version 2.0 instead", level = DeprecationLevel.WARNING)
|
||||
override val useK2: org.gradle.api.provider.Property<kotlin.Boolean> =
|
||||
objectFactory.property(kotlin.Boolean::class.java).convention(false)
|
||||
@@ -27,6 +30,7 @@ internal abstract class KotlinCommonCompilerOptionsDefault @javax.inject.Inject
|
||||
args.apiVersion = apiVersion.orNull?.version
|
||||
args.languageVersion = languageVersion.orNull?.version
|
||||
args.optIn = optIn.get().toTypedArray()
|
||||
args.progressiveMode = progressiveMode.get()
|
||||
args.useK2 = useK2.get()
|
||||
}
|
||||
|
||||
@@ -35,6 +39,7 @@ internal abstract class KotlinCommonCompilerOptionsDefault @javax.inject.Inject
|
||||
args.apiVersion = null
|
||||
args.languageVersion = null
|
||||
args.optIn = emptyList<String>().toTypedArray()
|
||||
args.progressiveMode = false
|
||||
args.useK2 = false
|
||||
}
|
||||
}
|
||||
|
||||
+1
-4
@@ -106,13 +106,10 @@ internal fun applyLanguageSettingsToCompilerOptions(
|
||||
) = with(compilerOptions) {
|
||||
languageVersion.convention(languageSettingsBuilder.languageVersion?.let { KotlinVersion.fromVersion(it) })
|
||||
apiVersion.convention(languageSettingsBuilder.apiVersion?.let { KotlinVersion.fromVersion(it) })
|
||||
progressiveMode.convention(languageSettingsBuilder.progressiveMode)
|
||||
optIn.addAll(languageSettingsBuilder.optInAnnotationsInUse)
|
||||
|
||||
val freeArgs = mutableListOf<String>().apply {
|
||||
if (languageSettingsBuilder.progressiveMode) {
|
||||
add("-progressive")
|
||||
}
|
||||
|
||||
languageSettingsBuilder.enabledLanguageFeatures.forEach { featureName ->
|
||||
add("-XXLanguage:+$featureName")
|
||||
}
|
||||
|
||||
+1
-1
@@ -178,7 +178,6 @@ internal fun buildKotlinNativeCompileCommonArgs(
|
||||
}
|
||||
|
||||
languageSettings.run {
|
||||
addKey("-progressive", progressiveMode)
|
||||
enabledLanguageFeatures.forEach { add("-XXLanguage:+$it") }
|
||||
}
|
||||
|
||||
@@ -187,6 +186,7 @@ internal fun buildKotlinNativeCompileCommonArgs(
|
||||
addKey("-Werror", compilerOptions.allWarningsAsErrors.get())
|
||||
addKey("-nowarn", compilerOptions.suppressWarnings.get())
|
||||
addKey("-verbose", compilerOptions.verbose.get())
|
||||
addKey("-progressive", compilerOptions.progressiveMode.get())
|
||||
compilerOptions.optIn.get().forEach { add("-opt-in=$it") }
|
||||
|
||||
addAll(compilerOptions.freeCompilerArgs.get())
|
||||
|
||||
+3
-1
@@ -197,7 +197,9 @@ abstract class AbstractKotlinNativeCompile<
|
||||
compilation.languageSettings
|
||||
}
|
||||
|
||||
@get:Input
|
||||
@Suppress("DeprecatedCallableAddReplaceWith")
|
||||
@get:Deprecated("Replaced with 'compilerOptions.progressiveMode'")
|
||||
@get:Internal
|
||||
val progressiveMode: Boolean
|
||||
get() = languageSettings.progressiveMode
|
||||
// endregion.
|
||||
|
||||
Reference in New Issue
Block a user