Skip to content

Commit ce41013

Browse files
committed
Support recent KUP requirements
See KT-75078 for the requirements itself. Closes #298
1 parent 4fb9caa commit ce41013

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

build.gradle.kts

+16-1
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,23 @@ allprojects {
104104
apiVersion = KotlinVersion.fromVersion(it)
105105
}
106106

107+
freeCompilerArgs.addAll("-Xreport-all-warnings", "-Xrender-internal-diagnostic-names")
108+
107109
progressiveMode = true
108-
allWarningsAsErrors = true
110+
111+
if (getAllWarningsAsErrorsValue(project)) {
112+
allWarningsAsErrors = true
113+
} else {
114+
freeCompilerArgs.addAll("-Wextra", "-Xuse-fir-experimental-checkers")
115+
}
116+
117+
getAdditionalKotlinCompilerOptions(project).let {
118+
freeCompilerArgs.addAll(it)
119+
}
120+
}
121+
doFirst {
122+
logger.info("Added Kotlin compiler flags: ${compilerOptions.freeCompilerArgs.get().joinToString(", ")}")
123+
logger.info("allWarningsAsErrors=${compilerOptions.allWarningsAsErrors.get()}")
109124
}
110125
}
111126
}

buildSrc/src/main/kotlin/KotlinCommunity.kt

+30-1
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,33 @@ fun getOverriddenKotlinNativeVersion(project: Project): String? {
7575
project.logger.info("""Configured Kotlin Native distribution version: '$nativeVersion' for project ${project.name}""")
7676
}
7777
return nativeVersion
78-
}
78+
}
79+
80+
/**
81+
* Parses additional compiler options specified using the `kotlin_additional_cli_options` property.
82+
*
83+
* @return a list of additional options, or an empty list if none were specified
84+
*/
85+
fun getAdditionalKotlinCompilerOptions(project: Project): List<String> {
86+
val opts = project.providers.gradleProperty("kotlin_additional_cli_options").orNull
87+
val parsedOpts = opts?.split(' ').orEmpty()
88+
if (parsedOpts.isNotEmpty()) {
89+
project.logger.info("""Configured Kotlin compiler options: '$opts' for project ${project.name}""")
90+
}
91+
return parsedOpts
92+
}
93+
94+
/**
95+
* Check if `allWarningsAsErrors` was configured to be set using the `kotlin_Werror_override` property.
96+
*
97+
* @return `true` if `kotlin_Werror_override` was set to `enable` or it was not specified at all, `false` if it was set to `disable`.
98+
*/
99+
fun getAllWarningsAsErrorsValue(project: Project): Boolean {
100+
val werrorOverride = project.providers.gradleProperty("kotlin_Werror_override").orNull ?: return true
101+
project.logger.info("""Configured kotlin_Werror_override: '$werrorOverride' for project ${project.name}""")
102+
return when (werrorOverride) {
103+
"enable" -> true
104+
"disable" -> false
105+
else -> error("Unexpected value for 'kotlin_Werror_override' property: $werrorOverride")
106+
}
107+
}

0 commit comments

Comments
 (0)