Skip to content

Kotlin User Projects: add kotlin_additional_cli_options and logging #2996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion buildSrc/src/main/kotlin/global-compiler-options.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
*/

import org.jetbrains.kotlin.gradle.tasks.*
import kotlin.collections.joinToString

val kotlin_additional_cli_options = providers.gradleProperty("kotlin_additional_cli_options")
.map { it.split(" ") }
.orNull

val globalCompilerArgs
get() = listOf(
Expand All @@ -18,6 +23,10 @@ tasks.withType(KotlinCompilationTask::class).configureEach {
// Unconditional compiler options
freeCompilerArgs.addAll(globalCompilerArgs)

if (kotlin_additional_cli_options != null) {
freeCompilerArgs.addAll(kotlin_additional_cli_options)
}

val isMainTaskName = name.startsWith("compileKotlin")
if (isMainTaskName) {
val werrorEnabled = when (kotlin_Werror_override?.lowercase()) {
Expand All @@ -28,7 +37,6 @@ tasks.withType(KotlinCompilationTask::class).configureEach {
}

allWarningsAsErrors = werrorEnabled

// Add extra compiler options when -Werror is disabled
if (!werrorEnabled) {
freeCompilerArgs.addAll(
Expand All @@ -46,3 +54,10 @@ tasks.withType<Kotlin2JsCompile>().configureEach {
tasks.withType<KotlinNativeCompile>().configureEach {
compilerOptions { freeCompilerArgs.add("-Xpartial-linkage-loglevel=ERROR") }
}

tasks.withType<KotlinCompilationTask<*>>().configureEach {
doFirst {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest printing only the additional args if they were provided: if (kotlin_additional_cli_options?.isNotEmpty()) logger.info(...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's useful to have all options in log. now it look like this:
Added Kotlin compiler flags: -Xexplicit-api=strict, -Xsuppress-version-warnings, -Xexpect-actual-classes, -P, plugin:org.jetbrains.kotlinx.serialization:disableIntrinsic=false, -Xreport-all-warnings, -Xrender-internal-diagnostic-names, -nowarn

logger.info("Added Kotlin compiler flags: ${compilerOptions.freeCompilerArgs.get().joinToString(", ")}")
logger.info("allWarningsAsErrors=${compilerOptions.allWarningsAsErrors.get()}")
}
}