Gradle, native: Propagate compilation free args to link tasks
The free args DSL may be changed in 1.3.70 for all platforms. So it was decided to preserve the old behaviour here to avoid making similar changes in two releases in a row.
This commit is contained in:
+7
@@ -19,6 +19,7 @@ import org.jetbrains.kotlin.gradle.util.*
|
||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
||||
import org.jetbrains.kotlin.konan.target.HostManager
|
||||
import org.junit.Assert
|
||||
import org.junit.Ignore
|
||||
import org.junit.Test
|
||||
import java.util.jar.JarFile
|
||||
import java.util.zip.ZipFile
|
||||
@@ -1037,6 +1038,9 @@ class NewMultiplatformIT : BaseGradleIT() {
|
||||
assertTrue(it.contains("-Xtime"))
|
||||
// Check that kotlinOptions of the compilation don't affect the binary.
|
||||
assertFalse(it.contains("-verbose"))
|
||||
// Check that free args are still propagated to the binary (unlike other kotlinOptions, see KT-33717).
|
||||
// TODO: Reverse this check when the args are fully separated.
|
||||
assertTrue(it.contains("-nowarn"))
|
||||
}
|
||||
assertTrue(output.contains("tests.foo"))
|
||||
}
|
||||
@@ -1141,6 +1145,9 @@ class NewMultiplatformIT : BaseGradleIT() {
|
||||
}
|
||||
}
|
||||
|
||||
// We propagate compilation args to link tasks for now (see KT-33717).
|
||||
// TODO: Reenable the test when the args are separated.
|
||||
@Ignore
|
||||
@Test
|
||||
fun testNativeFreeArgsWarning() = with(transformProjectWithPluginsDsl("kotlin-dsl", gradleVersion, "new-mpp-native-binaries")) {
|
||||
gradleBuildScript().appendText(
|
||||
|
||||
+2
-1
@@ -37,7 +37,8 @@ kotlin {
|
||||
mingwX64("mingw64")
|
||||
|
||||
configure([macos64, linux64, mingw64]) {
|
||||
compilations.main.kotlinOptions.verbose = true
|
||||
compilations.all { kotlinOptions.verbose = true }
|
||||
compilations.test.kotlinOptions.freeCompilerArgs += "-nowarn"
|
||||
binaries {
|
||||
|
||||
executable() // Executable with default name.
|
||||
|
||||
+2
-1
@@ -27,7 +27,8 @@ kotlin {
|
||||
val windows = mingwX64("mingw64")
|
||||
|
||||
configure(listOf(macos, linux, windows)) {
|
||||
compilations["main"].kotlinOptions.verbose = true
|
||||
compilations.all { kotlinOptions.verbose = true }
|
||||
compilations["test"].kotlinOptions.freeCompilerArgs += "-nowarn"
|
||||
binaries {
|
||||
|
||||
executable() // Executable with default name.
|
||||
|
||||
+4
-3
@@ -24,8 +24,9 @@ class KotlinNativeCompilationFactory(
|
||||
if (name == KotlinCompilation.TEST_COMPILATION_NAME) {
|
||||
friendCompilationName = KotlinCompilation.MAIN_COMPILATION_NAME
|
||||
}
|
||||
project.whenEvaluated {
|
||||
CompilationFreeArgsValidator.validate(this@apply)
|
||||
}
|
||||
// TODO: Validate compilation free args using the [CompilationFreeArgsValidator]
|
||||
// when the compilation and the link args are separated (see KT-33717).
|
||||
// Note: such validation should be done in the whenEvaluate block because
|
||||
// a user can change args during project configuration.
|
||||
}
|
||||
}
|
||||
+12
-3
@@ -121,15 +121,15 @@ abstract class AbstractKotlinNativeCompile<T : KotlinCommonToolOptions> : Abstra
|
||||
val target: String
|
||||
@Input get() = compilation.target.konanTarget.name
|
||||
|
||||
val additionalCompilerOptions: Collection<String>
|
||||
@Input get() = kotlinOptions.freeCompilerArgs
|
||||
|
||||
// region Compiler options.
|
||||
@get:Internal
|
||||
abstract val kotlinOptions: T
|
||||
abstract fun kotlinOptions(fn: T.() -> Unit)
|
||||
abstract fun kotlinOptions(fn: Closure<*>)
|
||||
|
||||
@get:Input
|
||||
abstract val additionalCompilerOptions: Collection<String>
|
||||
|
||||
@get:Internal
|
||||
val languageSettings: LanguageSettingsBuilder?
|
||||
get() = project.kotlinExtension.sourceSets.findByName(compilation.defaultSourceSetName)?.languageSettings
|
||||
@@ -310,6 +310,10 @@ open class KotlinNativeCompile : AbstractKotlinNativeCompile<KotlinCommonOptions
|
||||
}
|
||||
}
|
||||
|
||||
@get:Input
|
||||
override val additionalCompilerOptions: Collection<String>
|
||||
get() = kotlinOptions.freeCompilerArgs
|
||||
|
||||
override val kotlinOptions: KotlinCommonOptions = NativeCompileOptions()
|
||||
|
||||
override fun kotlinOptions(fn: KotlinCommonOptions.() -> Unit) {
|
||||
@@ -412,6 +416,11 @@ open class KotlinNativeLink : AbstractKotlinNativeCompile<KotlinCommonToolOption
|
||||
override var freeCompilerArgs: List<String> = listOf()
|
||||
}
|
||||
|
||||
// We propagate compilation free args to the link task for now (see KT-33717).
|
||||
@get:Input
|
||||
override val additionalCompilerOptions: Collection<String>
|
||||
get() = kotlinOptions.freeCompilerArgs + compilation.kotlinOptions.freeCompilerArgs
|
||||
|
||||
override val kotlinOptions: KotlinCommonToolOptions = NativeLinkOptions()
|
||||
|
||||
override fun kotlinOptions(fn: KotlinCommonToolOptions.() -> Unit) {
|
||||
|
||||
Reference in New Issue
Block a user