From 682cb991b8d0b391788c1be374fa79f091cc93d2 Mon Sep 17 00:00:00 2001 From: Dmitrii Krasnov Date: Wed, 9 Aug 2023 10:37:01 +0200 Subject: [PATCH] Test for PartialLinkageMode resolving fix #KT-60839 Fixed --- .../gradle/native/KotlinNativeLinkIT.kt | 34 ++++++++++++++++++- .../kotlin/gradle/testbase/BuildOptions.kt | 4 +++ .../build.gradle | 29 ++++++++++++++++ .../src/hostMain/kotlin/main.kt | 8 +++++ .../src/hostTest/kotlin/Test.kt | 11 ++++++ 5 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kt-60839-native-link-cache-builder/build.gradle create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kt-60839-native-link-cache-builder/src/hostMain/kotlin/main.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kt-60839-native-link-cache-builder/src/hostTest/kotlin/Test.kt diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/KotlinNativeLinkIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/KotlinNativeLinkIT.kt index 21f688a3658..baa84ab2dff 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/KotlinNativeLinkIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/KotlinNativeLinkIT.kt @@ -5,7 +5,9 @@ package org.jetbrains.kotlin.gradle.native +import org.gradle.api.logging.LogLevel import org.gradle.util.GradleVersion +import org.jetbrains.kotlin.gradle.dsl.NativeCacheKind import org.jetbrains.kotlin.gradle.testbase.* import org.junit.jupiter.api.DisplayName import kotlin.io.path.appendText @@ -67,4 +69,34 @@ internal class KotlinNativeLinkIT : KGPBaseTest() { } } } -} \ No newline at end of file + + @DisplayName("KT-60839: should provide correct default value for -Xpartial-linkage") + @GradleTest + fun defaultValueForPartialLinkage(gradleVersion: GradleVersion) { + nativeProject( + "kt-60839-native-link-cache-builder", + gradleVersion = gradleVersion, + buildOptions = defaultBuildOptions.copy( + logLevel = LogLevel.DEBUG, + // KT-60839 only reproduces when the build cache is enabled, + // but we must ignore it when running this test in order to + // ensure we actually try to pass -Xpartial-linkage to konanc. + buildCacheEnabled = true, + freeArgs = defaultBuildOptions.freeArgs + "--rerun-tasks", + nativeOptions = defaultBuildOptions.nativeOptions.copy( + cacheKind = NativeCacheKind.STATIC, + // Required as this only reproduces from CacheBuilder. + cacheOrchestration = "gradle" + ) + ), + ) { + + // Must be an unoptimized debug build. + build("linkDebugTestHost") { + extractNativeTasksCommandLineArgumentsFromOutput(":linkDebugTestHost") { + assertCommandLineArgumentsContain("-Xpartial-linkage=ENABLE") + } + } + } + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/testbase/BuildOptions.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/testbase/BuildOptions.kt index 86b13f96cfc..d1a9fba9872 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/testbase/BuildOptions.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/testbase/BuildOptions.kt @@ -79,6 +79,7 @@ data class BuildOptions( val restrictedDistribution: Boolean? = null, val useXcodeMessageStyle: Boolean? = null, val version: String? = null, + val cacheOrchestration: String? = null, ) fun toArguments( @@ -240,6 +241,9 @@ data class BuildOptions( nativeOptions.version?.let { arguments.add("-Pkotlin.native.version=${it}") } + nativeOptions.cacheOrchestration?.let { + arguments.add("-Pkotlin.native.cacheOrchestration=${it}") + } } } diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kt-60839-native-link-cache-builder/build.gradle b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kt-60839-native-link-cache-builder/build.gradle new file mode 100644 index 00000000000..c5dd2b9356f --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kt-60839-native-link-cache-builder/build.gradle @@ -0,0 +1,29 @@ +plugins { + id 'org.jetbrains.kotlin.multiplatform' +} + +repositories { + mavenLocal() + mavenCentral() +} + +kotlin { + ("host") + + targets.named("host").configure { + binaries.test("integrationTests") + } + + targets.named("host").configure { + binaries.executable() + } + + sourceSets { + hostTest { + dependencies { + // This is required as the bug only happens when restoring options to link a native dependency from cache + implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.3.3") + } + } + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kt-60839-native-link-cache-builder/src/hostMain/kotlin/main.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kt-60839-native-link-cache-builder/src/hostMain/kotlin/main.kt new file mode 100644 index 00000000000..f6e36b84c3e --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kt-60839-native-link-cache-builder/src/hostMain/kotlin/main.kt @@ -0,0 +1,8 @@ +/* + * Copyright 2010-2022 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. + */ + +fun main() { + println("Hello, Kotlin/Native!") +} diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kt-60839-native-link-cache-builder/src/hostTest/kotlin/Test.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kt-60839-native-link-cache-builder/src/hostTest/kotlin/Test.kt new file mode 100644 index 00000000000..be6c87032d5 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/kt-60839-native-link-cache-builder/src/hostTest/kotlin/Test.kt @@ -0,0 +1,11 @@ +/* + * 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. + */ + +import kotlin.test.Test + +class Test { + @Test + fun noopTest() {} +} \ No newline at end of file