Skip to content

Commit

Permalink
Don't override compilation freeCompilerArgs in link task
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Tapchicoma committed Jan 31, 2023
1 parent e2b4317 commit a8fee4d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.gradle.native
import org.gradle.util.GradleVersion
import org.jetbrains.kotlin.gradle.testbase.*
import org.junit.jupiter.api.DisplayName
import kotlin.io.path.appendText

@DisplayName("KotlinNativeLink task tests")
@NativeGradlePluginTests
Expand All @@ -20,4 +21,50 @@ internal class KotlinNativeLinkIT : KGPBaseTest() {
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'!"
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ open class KotlinNativeTargetConfigurator<T : KotlinNativeTarget> : AbstractKotl
val konanPropertiesBuildService = KonanPropertiesBuildService.registerIfAbsent(project.gradle)
it.konanPropertiesService.set(konanPropertiesBuildService)
it.usesService(konanPropertiesBuildService)
it.toolOptions.freeCompilerArgs.convention(
compilationCompilerOptions.options.freeCompilerArgs
)
it.toolOptions.freeCompilerArgs.value(compilationCompilerOptions.options.freeCompilerArgs)
it.toolOptions.freeCompilerArgs.addAll(providers.provider { PropertiesProvider(project).nativeLinkArgs })
}


Expand All @@ -90,7 +89,7 @@ open class KotlinNativeTargetConfigurator<T : KotlinNativeTarget> : AbstractKotl
tasks.named(binary.linkTaskName, KotlinNativeLink::class.java).configure {
// We propagate compilation free args to the link task for now (see KT-33717).
val defaultLanguageSettings = binary.compilation.languageSettings as? DefaultLanguageSettingsBuilder
if (defaultLanguageSettings != null) {
if (defaultLanguageSettings != null && defaultLanguageSettings.freeCompilerArgs.isNotEmpty()) {
it.toolOptions.freeCompilerArgs.addAll(
defaultLanguageSettings.freeCompilerArgs
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ constructor(

final override val toolOptions: KotlinCommonCompilerToolOptions = objectFactory
.newInstance<KotlinCommonCompilerToolOptionsDefault>()
.apply {
freeCompilerArgs.addAll(PropertiesProvider(project).nativeLinkArgs)
}

init {
@Suppress("DEPRECATION")
Expand Down

0 comments on commit a8fee4d

Please sign in to comment.