diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt index 9c69605210e..806f596c50c 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt @@ -5,7 +5,7 @@ package org.jetbrains.kotlin.gradle import org.gradle.api.logging.LogLevel -import org.jetbrains.kotlin.gradle.native.GeneralNativeIT.Companion.checkNativeCommandLineArguments +import org.jetbrains.kotlin.gradle.native.GeneralNativeIT.Companion.withNativeCommandLineArguments import org.jetbrains.kotlin.gradle.native.GeneralNativeIT.Companion.containsSequentially import org.gradle.api.logging.configuration.WarningMode import org.gradle.util.GradleVersion @@ -155,7 +155,7 @@ class NewMultiplatformIT : BaseGradleIT() { assertFileExists("build/bin/linux64/mainDebugExecutable/$nativeExeName") // Check that linker options were correctly passed to the K/N compiler. - checkNativeCommandLineArguments(":linkMainDebugExecutableLinux64") { arguments -> + withNativeCommandLineArguments(":linkMainDebugExecutableLinux64") { arguments -> assertTrue(arguments.containsSequentially("-linker-option", "-L.")) } } diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/GeneralNativeIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/GeneralNativeIT.kt index d8d0234b49e..4a081e62f34 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/GeneralNativeIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/GeneralNativeIT.kt @@ -362,17 +362,17 @@ class GeneralNativeIT : BaseGradleIT() { fileInWorkingDir(headerPaths[0]).readText().contains("+ (int32_t)exported") // Check that by default release frameworks have bitcode embedded. - checkNativeCommandLineArguments(":linkMainReleaseFrameworkIos") { arguments -> + withNativeCommandLineArguments(":linkMainReleaseFrameworkIos") { arguments -> assertTrue("-Xembed-bitcode" in arguments) assertTrue("-opt" in arguments) } // Check that by default debug frameworks have bitcode marker embedded. - checkNativeCommandLineArguments(":linkMainDebugFrameworkIos") { arguments -> + withNativeCommandLineArguments(":linkMainDebugFrameworkIos") { arguments -> assertTrue("-Xembed-bitcode-marker" in arguments) assertTrue("-g" in arguments) } // Check that bitcode can be disabled by setting custom compiler options - checkNativeCommandLineArguments(":linkCustomDebugFrameworkIos") { arguments -> + withNativeCommandLineArguments(":linkCustomDebugFrameworkIos") { arguments -> assertTrue(arguments.containsSequentially("-linker-option", "-L.")) assertTrue("-Xtime" in arguments) assertTrue("-Xstatic-framework" in arguments) @@ -380,7 +380,7 @@ class GeneralNativeIT : BaseGradleIT() { assertFalse("-Xembed-bitcode" in arguments) } // Check that bitcode is disabled for iOS simulator. - checkNativeCommandLineArguments(":linkMainReleaseFrameworkIosSim", ":linkMainDebugFrameworkIosSim") { arguments -> + withNativeCommandLineArguments(":linkMainReleaseFrameworkIosSim", ":linkMainDebugFrameworkIosSim") { arguments -> assertFalse("-Xembed-bitcode" in arguments) assertFalse("-Xembed-bitcode-marker" in arguments) } @@ -519,7 +519,7 @@ class GeneralNativeIT : BaseGradleIT() { ) { build(":compileKotlinHost") { assertSuccessful() - checkNativeCommandLineArguments(":compileKotlinHost") { arguments -> + withNativeCommandLineArguments(":compileKotlinHost") { arguments -> assertFalse("-verbose" in arguments) } } @@ -533,7 +533,7 @@ class GeneralNativeIT : BaseGradleIT() { ) build(":compileKotlinHost") { assertSuccessful() - checkNativeCommandLineArguments(":compileKotlinHost") { arguments -> + withNativeCommandLineArguments(":compileKotlinHost") { arguments -> assertTrue("-verbose" in arguments) } } @@ -828,7 +828,7 @@ class GeneralNativeIT : BaseGradleIT() { assertSuccessful() assertTasksExecuted(":projectLibrary:cinteropAnotherNumberHost") libraryFiles("projectLibrary", "anotherNumber").forEach { assertFileExists(it) } - checkNativeCustomEnvironment(":projectLibrary:cinteropAnotherNumberHost", toolName = "cinterop") { env -> + withNativeCustomEnvironment(":projectLibrary:cinteropAnotherNumberHost", toolName = "cinterop") { env -> assertEquals("1", env["LIBCLANG_DISABLE_CRASH_RECOVERY"]) } } @@ -959,21 +959,21 @@ class GeneralNativeIT : BaseGradleIT() { @Test fun testNativeArgsWithSpaces() = with(transformNativeTestProject("sample-lib", directoryPrefix = "new-mpp-lib-and-app")) { - val compilcatedDirectoryName = if (HostManager.hostIsMingw) { + val complicatedDirectoryName = if (HostManager.hostIsMingw) { // Windows doesn't allow creating a file with " in its name. "path with spaces" } else { "path with spaces and \"" } - val fileWithSpacesInPath = projectDir.resolve("src/commonMain/kotlin/$compilcatedDirectoryName") + val fileWithSpacesInPath = projectDir.resolve("src/commonMain/kotlin/$complicatedDirectoryName") .apply { mkdirs() } .resolve("B.kt") fileWithSpacesInPath.writeText("fun foo() = 42") build("compileKotlin${nativeHostTargetName.capitalize()}") { assertSuccessful() - checkNativeCommandLineArguments(":compileKotlin${nativeHostTargetName.capitalize()}") { arguments -> + withNativeCommandLineArguments(":compileKotlin${nativeHostTargetName.capitalize()}") { arguments -> val escapedQuotedPath = "\"${fileWithSpacesInPath.absolutePath.replace("\\", "\\\\").replace("\"", "\\\"")}\"" assertTrue( @@ -989,6 +989,51 @@ class GeneralNativeIT : BaseGradleIT() { } } + @Test + fun testBinaryOptionsDSL() = with(transformNativeTestProjectWithPluginDsl("executables", directoryPrefix = "native-binaries")) { + gradleBuildScript().appendText( + """ + kotlin.targets.withType(org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget::class.java) { + binaries.all { binaryOptions["memoryModel"] = "experimental" } + } + """.trimIndent() + ) + build(":linkDebugExecutableHost") { + assertSuccessful() + withNativeCommandLineArguments(":linkDebugExecutableHost") { + assertTrue(it.contains("-Xbinary=memoryModel=experimental")) + } + } + } + + @Test + fun testBinaryOptionsProperty() = with(transformNativeTestProjectWithPluginDsl("executables", directoryPrefix = "native-binaries")) { + build(":linkDebugExecutableHost", "-Pkotlin.native.binary.memoryModel=experimental") { + assertSuccessful() + withNativeCommandLineArguments(":linkDebugExecutableHost") { + assertTrue(it.contains("-Xbinary=memoryModel=experimental")) + } + } + } + + @Test + fun testBinaryOptionsPriority() = with(transformNativeTestProjectWithPluginDsl("executables", directoryPrefix = "native-binaries")) { + gradleBuildScript().appendText( + """ + kotlin.targets.withType(org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget::class.java) { + binaries.all { binaryOptions["memoryModel"] = "experimental" } + } + """.trimIndent() + ) + build(":linkDebugExecutableHost", "-Pkotlin.native.binary.memoryModel=strict") { + assertSuccessful() + withNativeCommandLineArguments(":linkDebugExecutableHost") { + // Options set in the DSL have higher priority than options set in project properties. + assertTrue(it.contains("-Xbinary=memoryModel=experimental")) + } + } + } + companion object { fun List.containsSequentially(vararg elements: String): Boolean { check(elements.isNotEmpty()) @@ -1044,19 +1089,19 @@ class GeneralNativeIT : BaseGradleIT() { key.trim() to value.trim() }.toMap() - fun CompiledProject.checkNativeCommandLineArguments( + fun CompiledProject.withNativeCommandLineArguments( vararg taskPaths: String, toolName: String = "konanc", check: (List) -> Unit ) = taskPaths.forEach { taskPath -> check(extractNativeCommandLineArguments(taskPath, toolName)) } - fun CompiledProject.checkNativeCompilerClasspath( + fun CompiledProject.withNativeCompilerClasspath( vararg taskPaths: String, toolName: String = "konanc", check: (List) -> Unit ) = taskPaths.forEach { taskPath -> check(extractNativeCompilerClasspath(taskPath, toolName)) } - fun CompiledProject.checkNativeCustomEnvironment( + fun CompiledProject.withNativeCustomEnvironment( vararg taskPaths: String, toolName: String = "konanc", check: (Map) -> Unit diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/NativeEmbeddableCompilerJarIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/NativeEmbeddableCompilerJarIT.kt index 6c35393fe46..3322782474d 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/NativeEmbeddableCompilerJarIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/NativeEmbeddableCompilerJarIT.kt @@ -7,7 +7,7 @@ package org.jetbrains.kotlin.gradle.native import org.jetbrains.kotlin.gradle.BaseGradleIT import org.jetbrains.kotlin.gradle.GradleVersionRequired -import org.jetbrains.kotlin.gradle.native.GeneralNativeIT.Companion.checkNativeCompilerClasspath +import org.jetbrains.kotlin.gradle.native.GeneralNativeIT.Companion.withNativeCompilerClasspath import org.junit.Test import kotlin.test.assertFalse import kotlin.test.assertTrue @@ -27,7 +27,7 @@ class NativeEmbeddableCompilerJarIT : BaseGradleIT() { fun testDefault() = with(transformNativeTestProjectWithPluginDsl("executables", directoryPrefix = "native-binaries")) { build(":linkDebugExecutableHost") { assertSuccessful() - checkNativeCompilerClasspath(":linkDebugExecutableHost", ":compileKotlinHost") { + withNativeCompilerClasspath(":linkDebugExecutableHost", ":compileKotlinHost") { assertTrue(it.includesRegularJar()) assertFalse(it.includesEmbeddableJar()) } @@ -38,7 +38,7 @@ class NativeEmbeddableCompilerJarIT : BaseGradleIT() { fun testEmbeddableJarFalse() = with(transformNativeTestProjectWithPluginDsl("executables", directoryPrefix = "native-binaries")) { build(":linkDebugExecutableHost", "-Pkotlin.native.useEmbeddableCompilerJar=false") { assertSuccessful() - checkNativeCompilerClasspath(":linkDebugExecutableHost", ":compileKotlinHost") { + withNativeCompilerClasspath(":linkDebugExecutableHost", ":compileKotlinHost") { assertTrue(it.includesRegularJar()) assertFalse(it.includesEmbeddableJar()) } @@ -49,7 +49,7 @@ class NativeEmbeddableCompilerJarIT : BaseGradleIT() { fun testEmbeddableJarTrue() = with(transformNativeTestProjectWithPluginDsl("executables", directoryPrefix = "native-binaries")) { build(":linkDebugExecutableHost", "-Pkotlin.native.useEmbeddableCompilerJar=true") { assertSuccessful() - checkNativeCompilerClasspath(":linkDebugExecutableHost", ":compileKotlinHost") { + withNativeCompilerClasspath(":linkDebugExecutableHost", ":compileKotlinHost") { assertFalse(it.includesRegularJar()) assertTrue(it.includesEmbeddableJar()) } @@ -60,7 +60,7 @@ class NativeEmbeddableCompilerJarIT : BaseGradleIT() { fun testSwitch() = with(transformNativeTestProjectWithPluginDsl("executables", directoryPrefix = "native-binaries")) { build(":linkDebugExecutableHost") { assertSuccessful() - checkNativeCompilerClasspath(":linkDebugExecutableHost", ":compileKotlinHost") { + withNativeCompilerClasspath(":linkDebugExecutableHost", ":compileKotlinHost") { assertTrue(it.includesRegularJar()) assertFalse(it.includesEmbeddableJar()) } @@ -73,7 +73,7 @@ class NativeEmbeddableCompilerJarIT : BaseGradleIT() { build(":linkDebugExecutableHost", "-Pkotlin.native.useEmbeddableCompilerJar=true") { assertSuccessful() assertTasksExecuted(":linkDebugExecutableHost", ":compileKotlinHost") - checkNativeCompilerClasspath(":linkDebugExecutableHost", ":compileKotlinHost") { + withNativeCompilerClasspath(":linkDebugExecutableHost", ":compileKotlinHost") { assertFalse(it.includesRegularJar()) assertTrue(it.includesEmbeddableJar()) }