Don't override compilation freeCompilerArgs in link task
Calling '.addAll()' was replacing convention value leading for inability to add/modify Kotlin/Native link task freeCompilerArgs via KotlinCompilation.options.freeCompilerArgs. For now convention was replaced by normal value. ^KT-56280 Fixed
This commit is contained in:
committed by
Space Team
parent
ff2db23c11
commit
752de6c622
+47
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.gradle.native
|
|||||||
import org.gradle.util.GradleVersion
|
import org.gradle.util.GradleVersion
|
||||||
import org.jetbrains.kotlin.gradle.testbase.*
|
import org.jetbrains.kotlin.gradle.testbase.*
|
||||||
import org.junit.jupiter.api.DisplayName
|
import org.junit.jupiter.api.DisplayName
|
||||||
|
import kotlin.io.path.appendText
|
||||||
|
|
||||||
@DisplayName("KotlinNativeLink task tests")
|
@DisplayName("KotlinNativeLink task tests")
|
||||||
@NativeGradlePluginTests
|
@NativeGradlePluginTests
|
||||||
@@ -20,4 +21,50 @@ internal class KotlinNativeLinkIT : KGPBaseTest() {
|
|||||||
build("tasks")
|
build("tasks")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DisplayName("KT-56280: should propagate freeCompilerArgs from compilation")
|
||||||
|
@GradleTest
|
||||||
|
fun shouldUseCompilationFreeCompilerArgs(gradleVersion: GradleVersion) {
|
||||||
|
nativeProject("native-link-simple", gradleVersion) {
|
||||||
|
buildGradle.appendText(
|
||||||
|
"""
|
||||||
|
|
|
||||||
|
|kotlin {
|
||||||
|
| targets.named("host").configure {
|
||||||
|
| binaries.executable()
|
||||||
|
| }
|
||||||
|
|
|
||||||
|
| targets.withType(org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget.class) {
|
||||||
|
| compilations.main.kotlinOptions {
|
||||||
|
| freeCompilerArgs += ["-e", "main"]
|
||||||
|
| }
|
||||||
|
| }
|
||||||
|
|}
|
||||||
|
""".trimMargin()
|
||||||
|
)
|
||||||
|
|
||||||
|
build("linkReleaseExecutableHost") {
|
||||||
|
val linkTaskOutput = output
|
||||||
|
.substringAfter("Task :linkReleaseExecutableHost")
|
||||||
|
.substringBefore("Task :linkHost")
|
||||||
|
assert(linkTaskOutput.isNotEmpty()) {
|
||||||
|
"Could not get :linkReleaseExecutableHost task output!"
|
||||||
|
}
|
||||||
|
|
||||||
|
val args = linkTaskOutput
|
||||||
|
.substringAfterLast("Transformed arguments = [")
|
||||||
|
.substringBefore("]")
|
||||||
|
.lines()
|
||||||
|
.map { it.trim() }
|
||||||
|
assert(
|
||||||
|
args.isNotEmpty() &&
|
||||||
|
args.contains("-e") &&
|
||||||
|
args.contains("main")
|
||||||
|
) {
|
||||||
|
printBuildOutput()
|
||||||
|
"Link task arguments does not contain '-e main'!"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+3
-4
@@ -70,9 +70,8 @@ open class KotlinNativeTargetConfigurator<T : KotlinNativeTarget> : AbstractKotl
|
|||||||
it.enabled = binary.konanTarget.enabledOnCurrentHost
|
it.enabled = binary.konanTarget.enabledOnCurrentHost
|
||||||
it.konanPropertiesService.set(konanPropertiesBuildService)
|
it.konanPropertiesService.set(konanPropertiesBuildService)
|
||||||
it.usesService(konanPropertiesBuildService)
|
it.usesService(konanPropertiesBuildService)
|
||||||
it.toolOptions.freeCompilerArgs.convention(
|
it.toolOptions.freeCompilerArgs.value(compilationCompilerOptions.options.freeCompilerArgs)
|
||||||
compilationCompilerOptions.options.freeCompilerArgs
|
it.toolOptions.freeCompilerArgs.addAll(providers.provider { PropertiesProvider(project).nativeLinkArgs })
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -90,7 +89,7 @@ open class KotlinNativeTargetConfigurator<T : KotlinNativeTarget> : AbstractKotl
|
|||||||
tasks.named(binary.linkTaskName, KotlinNativeLink::class.java).configure {
|
tasks.named(binary.linkTaskName, KotlinNativeLink::class.java).configure {
|
||||||
// We propagate compilation free args to the link task for now (see KT-33717).
|
// We propagate compilation free args to the link task for now (see KT-33717).
|
||||||
val defaultLanguageSettings = binary.compilation.defaultSourceSet.languageSettings as? DefaultLanguageSettingsBuilder
|
val defaultLanguageSettings = binary.compilation.defaultSourceSet.languageSettings as? DefaultLanguageSettingsBuilder
|
||||||
if (defaultLanguageSettings != null) {
|
if (defaultLanguageSettings != null && defaultLanguageSettings.freeCompilerArgs.isNotEmpty()) {
|
||||||
it.toolOptions.freeCompilerArgs.addAll(
|
it.toolOptions.freeCompilerArgs.addAll(
|
||||||
defaultLanguageSettings.freeCompilerArgs
|
defaultLanguageSettings.freeCompilerArgs
|
||||||
)
|
)
|
||||||
|
|||||||
-3
@@ -59,9 +59,6 @@ constructor(
|
|||||||
|
|
||||||
final override val toolOptions: KotlinCommonCompilerToolOptions = objectFactory
|
final override val toolOptions: KotlinCommonCompilerToolOptions = objectFactory
|
||||||
.newInstance<KotlinCommonCompilerToolOptionsDefault>()
|
.newInstance<KotlinCommonCompilerToolOptionsDefault>()
|
||||||
.apply {
|
|
||||||
freeCompilerArgs.addAll(PropertiesProvider(project).nativeLinkArgs)
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
|
|||||||
Reference in New Issue
Block a user