[Gradle] Add log level control for K/Native compiler arguments
Just like it was done for other Compile tasks. ^KT-64848 Verification Pending
This commit is contained in:
committed by
Space Team
parent
480b8ec516
commit
be1819da58
+24
@@ -1072,4 +1072,28 @@ class GeneralNativeIT : KGPBaseTest() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DisplayName("Test compiler arguments for K/Native Tasks")
|
||||
@GradleTest
|
||||
fun testCompilerArgumentsLogLevel(gradleVersion: GradleVersion) {
|
||||
nativeProject("native-libraries", gradleVersion) {
|
||||
val updatedBuildOptions = buildOptions.copy(
|
||||
compilerArgumentsLogLevel = "warning"
|
||||
)
|
||||
build("assemble", buildOptions = updatedBuildOptions) {
|
||||
val tasksWithNativeCompilerArguments = listOf(
|
||||
":compileCommonMainKotlinMetadata", // it is shared native metadata, which is compiled by konan
|
||||
":compileKotlinLinux64",
|
||||
":linkMainDebugStaticLinux64",
|
||||
)
|
||||
for (task in tasksWithNativeCompilerArguments) {
|
||||
val taskOutput = getOutputForTask(task, LogLevel.INFO)
|
||||
assertTrue(
|
||||
taskOutput.contains("Arguments = "),
|
||||
"Arguments were not logged by Task $task"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-1
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.compilerRunner
|
||||
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.jetbrains.kotlin.build.report.metrics.BuildMetricsReporter
|
||||
import org.jetbrains.kotlin.build.report.metrics.GradleBuildPerformanceMetric
|
||||
import org.jetbrains.kotlin.build.report.metrics.GradleBuildTime
|
||||
@@ -19,7 +20,8 @@ internal class KotlinNativeCommonizerToolRunner(
|
||||
class Settings(
|
||||
val kotlinPluginVersion: String,
|
||||
val classpath: Set<File>,
|
||||
val customJvmArgs: List<String>
|
||||
val customJvmArgs: List<String>,
|
||||
val compilerArgumentsLogLevel: Provider<KotlinCompilerArgumentsLogLevel>,
|
||||
)
|
||||
|
||||
override val displayName get() = "Kotlin/Native KLIB commonizer"
|
||||
@@ -35,5 +37,7 @@ internal class KotlinNativeCommonizerToolRunner(
|
||||
override val mustRunViaExec get() = true // because it's not enough the standard Gradle wrapper's heap size
|
||||
|
||||
override fun getCustomJvmArgs() = settings.customJvmArgs
|
||||
|
||||
override val compilerArgumentsLogLevel: KotlinCompilerArgumentsLogLevel get() = settings.compilerArgumentsLogLevel.get()
|
||||
}
|
||||
|
||||
|
||||
+11
-2
@@ -14,6 +14,7 @@ import org.gradle.process.ExecOperations
|
||||
import org.gradle.process.ExecResult
|
||||
import org.gradle.process.JavaExecSpec
|
||||
import org.jetbrains.kotlin.build.report.metrics.*
|
||||
import org.jetbrains.kotlin.gradle.logging.gradleLogLevel
|
||||
import org.jetbrains.kotlin.konan.target.HostManager
|
||||
import java.io.File
|
||||
import java.lang.reflect.InvocationTargetException
|
||||
@@ -105,6 +106,11 @@ abstract class KotlinToolRunner(
|
||||
open val enableAssertions: Boolean get() = true
|
||||
open val disableC2: Boolean get() = true
|
||||
|
||||
/**
|
||||
* Represents the log level for compiler arguments
|
||||
*/
|
||||
internal open val compilerArgumentsLogLevel: KotlinCompilerArgumentsLogLevel = KotlinCompilerArgumentsLogLevel.INFO
|
||||
|
||||
abstract val mustRunViaExec: Boolean
|
||||
open fun transformArgs(args: List<String>): List<String> = args
|
||||
|
||||
@@ -151,7 +157,9 @@ abstract class KotlinToolRunner(
|
||||
.escapeQuotesForWindows()
|
||||
.toMap() + execSystemProperties
|
||||
|
||||
executionContext.logger.info(
|
||||
|
||||
executionContext.logger.log(
|
||||
compilerArgumentsLogLevel.gradleLogLevel,
|
||||
"""|Run "$displayName" tool in a separate JVM process
|
||||
|Main class = $mainClass
|
||||
|Arguments = ${args.toPrettyString()}
|
||||
@@ -181,7 +189,8 @@ abstract class KotlinToolRunner(
|
||||
val transformedArgs = transformArgs(args)
|
||||
val isolatedClassLoader = getIsolatedClassLoader()
|
||||
|
||||
executionContext.logger.info(
|
||||
executionContext.logger.log(
|
||||
compilerArgumentsLogLevel.gradleLogLevel,
|
||||
"""|Run in-process tool "$displayName"
|
||||
|Entry point method = $mainClass.$daemonEntryPoint
|
||||
|Classpath = ${isolatedClassLoader.urLs.map { it.file }.toPrettyString()}
|
||||
|
||||
+7
-1
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.compilerRunner
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.file.FileCollection
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.jetbrains.kotlin.build.report.metrics.BuildMetricsReporter
|
||||
import org.jetbrains.kotlin.build.report.metrics.GradleBuildPerformanceMetric
|
||||
import org.jetbrains.kotlin.build.report.metrics.GradleBuildTime
|
||||
@@ -14,6 +15,7 @@ import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
|
||||
import org.jetbrains.kotlin.gradle.dsl.NativeCacheKind
|
||||
import org.jetbrains.kotlin.gradle.dsl.NativeCacheOrchestration
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.Companion.kotlinPropertiesProvider
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.apple.useXcodeMessageStyle
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.nativeUseEmbeddableCompilerJar
|
||||
import org.jetbrains.kotlin.gradle.report.GradleBuildMetricsReporter
|
||||
@@ -88,6 +90,7 @@ internal abstract class KotlinNativeToolRunner(
|
||||
val jvmArgs: List<String>,
|
||||
val classpath: FileCollection,
|
||||
val konanDataDir: String?,
|
||||
val kotlinCompilerArgumentsLogLevel: Provider<KotlinCompilerArgumentsLogLevel>,
|
||||
) {
|
||||
companion object {
|
||||
fun of(konanHome: String, konanDataDir: String?, project: Project) = Settings(
|
||||
@@ -97,7 +100,8 @@ internal abstract class KotlinNativeToolRunner(
|
||||
useXcodeMessageStyle = project.useXcodeMessageStyle,
|
||||
jvmArgs = project.jvmArgs,
|
||||
classpath = project.files(project.kotlinNativeCompilerJar, "${konanHome}/konan/lib/trove4j.jar"),
|
||||
konanDataDir = konanDataDir
|
||||
konanDataDir = konanDataDir,
|
||||
kotlinCompilerArgumentsLogLevel = project.kotlinPropertiesProvider.kotlinCompilerArgumentsLogLevel
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -149,6 +153,8 @@ internal abstract class KotlinNativeToolRunner(
|
||||
protected open fun extractArgsFromSettings(): List<String> {
|
||||
return settings.konanDataDir?.let { listOf("-Xkonan-data-dir=$it") } ?: emptyList()
|
||||
}
|
||||
|
||||
override val compilerArgumentsLogLevel: KotlinCompilerArgumentsLogLevel get() = settings.kotlinCompilerArgumentsLogLevel.get()
|
||||
}
|
||||
|
||||
/** A common ancestor for all runners that run the cinterop tool. */
|
||||
|
||||
+9
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.logging
|
||||
|
||||
import org.gradle.api.logging.LogLevel
|
||||
import org.gradle.api.logging.Logger
|
||||
import org.jetbrains.kotlin.buildtools.api.KotlinLogger
|
||||
import org.jetbrains.kotlin.compilerRunner.KotlinCompilerArgumentsLogLevel
|
||||
@@ -27,6 +28,14 @@ internal inline fun Logger.kotlinDebug(message: () -> String) {
|
||||
}
|
||||
}
|
||||
|
||||
internal val KotlinCompilerArgumentsLogLevel.gradleLogLevel: LogLevel
|
||||
get() = when(this) {
|
||||
KotlinCompilerArgumentsLogLevel.ERROR -> LogLevel.ERROR
|
||||
KotlinCompilerArgumentsLogLevel.WARNING -> LogLevel.WARN
|
||||
KotlinCompilerArgumentsLogLevel.INFO -> LogLevel.INFO
|
||||
KotlinCompilerArgumentsLogLevel.DEBUG -> LogLevel.DEBUG
|
||||
}
|
||||
|
||||
internal inline fun KotlinLogger.kotlinError(message: () -> String) {
|
||||
error("[KOTLIN] ${message()}")
|
||||
}
|
||||
|
||||
+10
-9
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.compilerRunner.*
|
||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtensionOrNull
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.Companion.kotlinPropertiesProvider
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.withDependsOnClosure
|
||||
import org.jetbrains.kotlin.gradle.report.GradleBuildMetricsReporter
|
||||
@@ -104,14 +105,7 @@ internal abstract class CInteropCommonizerTask
|
||||
.listProperty<String>()
|
||||
.chainedFinalizeValueOnRead()
|
||||
|
||||
private val runnerSettings: Provider<KotlinNativeCommonizerToolRunner.Settings> = kotlinPluginVersion
|
||||
.zip(customJvmArgs) { pluginVersion, customJvmArgs ->
|
||||
KotlinNativeCommonizerToolRunner.Settings(
|
||||
pluginVersion,
|
||||
commonizerClasspath.files,
|
||||
customJvmArgs
|
||||
)
|
||||
}
|
||||
private val kotlinCompilerArgumentsLogLevel = project.kotlinPropertiesProvider.kotlinCompilerArgumentsLogLevel
|
||||
|
||||
private val konanHome = project.file(project.konanHome)
|
||||
private val commonizerLogLevel = project.commonizerLogLevel
|
||||
@@ -202,9 +196,16 @@ internal abstract class CInteropCommonizerTask
|
||||
outputDirectory.deleteRecursively()
|
||||
if (cinteropsForTarget.isEmpty()) return
|
||||
|
||||
val runnerSettings = KotlinNativeCommonizerToolRunner.Settings(
|
||||
kotlinPluginVersion = kotlinPluginVersion.get(),
|
||||
classpath = commonizerClasspath.files,
|
||||
customJvmArgs = customJvmArgs.get(),
|
||||
compilerArgumentsLogLevel = kotlinCompilerArgumentsLogLevel
|
||||
)
|
||||
|
||||
val commonizerRunner = KotlinNativeCommonizerToolRunner(
|
||||
context = KotlinToolRunner.GradleExecutionContext.fromTaskContext(objectFactory, execOperations, logger),
|
||||
settings = runnerSettings.get(),
|
||||
settings = runnerSettings,
|
||||
metricsReporter = metrics.get(),
|
||||
)
|
||||
|
||||
|
||||
+8
-9
@@ -71,14 +71,7 @@ internal abstract class NativeDistributionCommonizerTask
|
||||
.listProperty<String>()
|
||||
.chainedFinalizeValueOnRead()
|
||||
|
||||
private val runnerSettings: Provider<KotlinNativeCommonizerToolRunner.Settings> = kotlinPluginVersion
|
||||
.zip(customJvmArgs) { pluginVersion, customJvmArgs ->
|
||||
KotlinNativeCommonizerToolRunner.Settings(
|
||||
pluginVersion,
|
||||
commonizerClasspath.files,
|
||||
customJvmArgs
|
||||
)
|
||||
}
|
||||
private val kotlinCompilerArgumentsLogLevel = project.kotlinPropertiesProvider.kotlinCompilerArgumentsLogLevel
|
||||
|
||||
private val logLevel = project.commonizerLogLevel
|
||||
|
||||
@@ -116,9 +109,15 @@ internal abstract class NativeDistributionCommonizerTask
|
||||
val metricsReporter = metrics.get()
|
||||
|
||||
addBuildMetricsForTaskAction(metricsReporter = metricsReporter, languageVersion = null) {
|
||||
val runnerSettings = KotlinNativeCommonizerToolRunner.Settings(
|
||||
kotlinPluginVersion.get(),
|
||||
commonizerClasspath.files,
|
||||
customJvmArgs.get(),
|
||||
kotlinCompilerArgumentsLogLevel,
|
||||
)
|
||||
val commonizerRunner = KotlinNativeCommonizerToolRunner(
|
||||
context = KotlinToolRunner.GradleExecutionContext.fromTaskContext(objectFactory, execOperations, logger),
|
||||
settings = runnerSettings.get(),
|
||||
settings = runnerSettings,
|
||||
metricsReporter = metricsReporter,
|
||||
)
|
||||
|
||||
|
||||
+29
@@ -2,13 +2,20 @@
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
@file:Suppress("FunctionName")
|
||||
|
||||
package org.jetbrains.kotlin.gradle.unitTests
|
||||
|
||||
import org.jetbrains.kotlin.compilerRunner.KotlinCompilerArgumentsLogLevel
|
||||
import org.jetbrains.kotlin.compilerRunner.KotlinNativeCompilerRunner
|
||||
import org.jetbrains.kotlin.compilerRunner.konanDataDir
|
||||
import org.jetbrains.kotlin.compilerRunner.konanHome
|
||||
import org.jetbrains.kotlin.gradle.plugin.extraProperties
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
|
||||
import org.jetbrains.kotlin.gradle.util.buildProjectWithJvm
|
||||
import org.jetbrains.kotlin.gradle.util.buildProjectWithMPP
|
||||
import org.jetbrains.kotlin.gradle.util.kotlin
|
||||
import org.jetbrains.kotlin.gradle.utils.named
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
@@ -56,4 +63,26 @@ class CompilerArgumentsLogLevelTest {
|
||||
project.tasks.named<KotlinCompile>("compileKotlin").get().kotlinCompilerArgumentsLogLevel.get()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `kotlin native compiler runner settings configures correctly with compiler arguments log level`() {
|
||||
val project = buildProjectWithMPP(
|
||||
preApplyCode = {
|
||||
project.extraProperties.set(
|
||||
"kotlin.internal.compiler.arguments.log.level",
|
||||
"warning"
|
||||
)
|
||||
}
|
||||
) {
|
||||
kotlin {
|
||||
linuxX64()
|
||||
linuxArm64()
|
||||
}
|
||||
}
|
||||
|
||||
project.evaluate()
|
||||
|
||||
val runnerSettings = KotlinNativeCompilerRunner.Settings.of(project.konanHome, project.konanDataDir, project)
|
||||
assertEquals(KotlinCompilerArgumentsLogLevel.WARNING, runnerSettings.parent.kotlinCompilerArgumentsLogLevel.get())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user