Skip to content

Commit f6bffdc

Browse files
fzhinkinwoainikk
andauthored
Support recent KUP requirements (#303)
See KT-75078 for the requirements itself. Closes #298 --------- Co-authored-by: Margarita Bobova <[email protected]>
1 parent 4fb9caa commit f6bffdc

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

build.gradle.kts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,21 @@ 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+
freeCompilerArgs.addAll(getAdditionalKotlinCompilerOptions(project))
118+
}
119+
doFirst {
120+
logger.info("Added Kotlin compiler flags: ${compilerOptions.freeCompilerArgs.get().joinToString(", ")}")
121+
logger.info("allWarningsAsErrors=${compilerOptions.allWarningsAsErrors.get()}")
109122
}
110123
}
111124
}

buildSrc/src/main/kotlin/KotlinCommunity.kt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,29 @@ 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+
return opts?.split(' ').orEmpty().map(String::trim).filter(String::isNotBlank)
88+
}
89+
90+
/**
91+
* Check if `allWarningsAsErrors` was configured to be set using the `kotlin_Werror_override` property.
92+
*
93+
* @return `true` if `kotlin_Werror_override` was set to `enable` or it was not specified at all, `false` if it was set to `disable`.
94+
*/
95+
fun getAllWarningsAsErrorsValue(project: Project): Boolean {
96+
val werrorOverride = project.providers.gradleProperty("kotlin_Werror_override").orNull ?: return true
97+
project.logger.info("""Configured kotlin_Werror_override: '$werrorOverride' for project ${project.name}""")
98+
return when (werrorOverride) {
99+
"enable" -> true
100+
"disable" -> false
101+
else -> error("Unexpected value for 'kotlin_Werror_override' property: $werrorOverride")
102+
}
103+
}

0 commit comments

Comments
 (0)