@@ -4,6 +4,7 @@ import org.gradle.api.*
44import org.gradle.api.artifacts.dsl.*
55import org.gradle.api.tasks.testing.Test
66import org.gradle.kotlin.dsl.*
7+ import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions
78import java.net.*
89import java.util.logging.*
910import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
@@ -102,7 +103,7 @@ fun Project.configureCommunityBuildTweaks() {
102103 }
103104 }
104105
105- println (" Manifest of kotlin-compiler-embeddable.jar for coroutines" )
106+ LOGGER .info (" Manifest of kotlin-compiler-embeddable.jar for coroutines" )
106107 val coreProject = subprojects.single { it.name == coreModule }
107108 configure(listOf (coreProject)) {
108109 configurations.matching { it.name == " kotlinCompilerClasspath" }.configureEach {
@@ -147,3 +148,50 @@ fun shouldUseLocalMaven(project: Project): Boolean {
147148 }
148149 return hasSnapshotDependency || isSnapshotTrainEnabled(project)
149150}
151+
152+ /* *
153+ * Returns a non-null value if the CI needs to override the default behavior of treating warnings as errors.
154+ * Then, `true` means that warnings should be treated as errors, `false` means that they should not.
155+ */
156+ private fun warningsAreErrorsOverride (project : Project ): Boolean? =
157+ when (val prop = project.rootProject.properties[" kotlin_Werror_override" ] as ? String ) {
158+ null -> null
159+ " enable" -> true
160+ " disable" -> false
161+ else -> error(" Unknown value for 'kotlin_Werror_override': $prop " )
162+ }
163+
164+ /* *
165+ * Set warnings as errors, but allow the Kotlin User Project configuration to take over. See KT-75078.
166+ */
167+ fun KotlinCommonCompilerOptions.setWarningsAsErrors (project : Project ) {
168+ if (warningsAreErrorsOverride(project) != false ) {
169+ allWarningsAsErrors = true
170+ } else {
171+ freeCompilerArgs.addAll(" -Wextra" , " -Xuse-fir-experimental-checkers" )
172+ }
173+ }
174+
175+ /* *
176+ * Compiler flags required of Kotlin User Projects. See KT-75078.
177+ */
178+ fun KotlinCommonCompilerOptions.configureKotlinUserProject () {
179+ freeCompilerArgs.addAll(
180+ " -Xreport-all-warnings" , // emit warnings even if there are also errors
181+ " -Xrender-internal-diagnostic-names" , // render the diagnostic names in CLI
182+ )
183+ }
184+
185+ /* *
186+ * Additional compiler flags passed on a case-by-case basis. Should be applied after the other flags.
187+ * See <https://github.com/Kotlin/kotlinx.coroutines/pull/4392#issuecomment-2775630200>
188+ */
189+ fun KotlinCommonCompilerOptions.addExtraCompilerFlags (project : Project ) {
190+ val extraOptions = project.rootProject.properties[" kotlin_additional_cli_options" ] as ? String
191+ if (extraOptions != null ) {
192+ LOGGER .info(""" Adding extra compiler flags '$extraOptions ' for a compilation in the project $${project.name} """ )
193+ extraOptions.split(" " )?.forEach {
194+ if (it.isNotEmpty()) freeCompilerArgs.add(it)
195+ }
196+ }
197+ }
0 commit comments