Skip to content

Commit d6d1ed6

Browse files
timofey-soloninSpace Team
authored andcommitted
[MPP] Fix NewMultiplatformIT and make it run on arm macOS
^KT-58822
1 parent f467c97 commit d6d1ed6

File tree

9 files changed

+43
-72
lines changed

9 files changed

+43
-72
lines changed

libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/BaseGradleIT.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,14 @@ abstract class BaseGradleIT {
830830
fun CompiledProject.assertTestResults(
831831
@TestDataFile assertionFileName: String,
832832
vararg testReportNames: String
833+
) = assertTestResults(
834+
resourcesRootFile.resolve(assertionFileName),
835+
*testReportNames
836+
)
837+
838+
fun CompiledProject.assertTestResults(
839+
assertionXmlFile: File,
840+
vararg testReportNames: String
833841
) {
834842
val projectDir = project.projectDir
835843
val testReportDirs = testReportNames.map { projectDir.resolve("build/test-results/$it").toPath() }
@@ -844,7 +852,7 @@ abstract class BaseGradleIT {
844852
val excl = "Invalid connection: com.apple.coresymbolicationd"
845853
s.lines().filter { it != excl }.joinToString("\n")
846854
}
847-
val expectedTestResults = prettyPrintXml(resourcesRootFile.resolve(assertionFileName).readText())
855+
val expectedTestResults = prettyPrintXml(assertionXmlFile.readText())
848856

849857
assertEquals(expectedTestResults, actualTestResults)
850858
}

libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/NewMultiplatformIT.kt

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin
2222
import org.jetbrains.kotlin.gradle.plugin.sources.METADATA_CONFIGURATION_NAME_SUFFIX
2323
import org.jetbrains.kotlin.gradle.plugin.sources.UnsatisfiedSourceSetVisibilityException
2424
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
25-
import org.jetbrains.kotlin.gradle.testbase.TestVersions
26-
import org.jetbrains.kotlin.gradle.testbase.assertHasDiagnostic
27-
import org.jetbrains.kotlin.gradle.testbase.assertNoDiagnostic
25+
import org.jetbrains.kotlin.gradle.testbase.*
2826
import org.jetbrains.kotlin.gradle.util.*
2927
import org.jetbrains.kotlin.konan.target.HostManager
28+
import org.jetbrains.kotlin.konan.target.KonanTarget
3029
import org.jetbrains.kotlin.library.KLIB_PROPERTY_SHORT_NAME
3130
import org.jetbrains.kotlin.library.KLIB_PROPERTY_UNIQUE_NAME
3231
import org.junit.Assert
@@ -688,6 +687,14 @@ open class NewMultiplatformIT : BaseGradleIT() {
688687
}
689688
}
690689

690+
private val targetName = when (HostManager.host) {
691+
KonanTarget.LINUX_X64 -> "linux64"
692+
KonanTarget.MACOS_X64 -> "macos64"
693+
KonanTarget.MACOS_ARM64 -> "macosArm64"
694+
KonanTarget.MINGW_X64 -> "mingw64"
695+
else -> fail("Unsupported host")
696+
}
697+
691698
@Test
692699
fun testLibWithTests() = doTestLibWithTests(transformNativeTestProject("new-mpp-lib-with-tests", gradleVersion))
693700

@@ -737,7 +744,6 @@ open class NewMultiplatformIT : BaseGradleIT() {
737744
arrayOf(
738745
it + "com/example/lib/CommonKt.class",
739746
it + "com/example/lib/MainKt.class",
740-
it + "Script.class",
741747
it + "META-INF/new-mpp-lib-with-tests.kotlin_module"
742748
)
743749
},
@@ -751,22 +757,15 @@ open class NewMultiplatformIT : BaseGradleIT() {
751757
)
752758

753759
expectedKotlinOutputFiles.forEach { assertFileExists(it) }
760+
val expectedTestResults = projectDir.resolve("TEST-all.xml")
754761

755-
// Gradle 6.6+ slightly changed format of xml test results
756-
// If, in the test project, preset name was updated,
757-
// update accordingly test result output for Gradle 6.6+
758-
val testGradleVersion = chooseWrapperVersionOrFinishTest()
759-
val expectedTestResults = if (GradleVersion.version(testGradleVersion) < GradleVersion.version("6.6")) {
760-
"testProject/new-mpp-lib-with-tests/TEST-all-pre6.6.xml"
761-
} else {
762-
"testProject/new-mpp-lib-with-tests/TEST-all.xml"
763-
}
762+
expectedTestResults.replaceText("<target>", targetName)
764763

765764
assertTestResults(
766765
expectedTestResults,
767766
"jsNodeTest",
768767
"test", // jvmTest
769-
"${nativeHostTargetName}Test"
768+
"${targetName}Test"
770769
)
771770
}
772771
}
@@ -1796,7 +1795,11 @@ open class NewMultiplatformIT : BaseGradleIT() {
17961795
gradleBuildScript().modify(::transformBuildScriptWithPluginsDsl)
17971796

17981797
// TOOD: add Kotlin/JS tests once they can be tested without much performance overhead
1799-
val targetsToTest = listOf("jvm", nativeHostTargetName) + listOf("ios").takeIf { HostManager.hostIsMac }.orEmpty()
1798+
val targetsToTest = listOf("jvm", nativeHostTargetName) + when (HostManager.host) {
1799+
KonanTarget.MACOS_X64 -> listOf("iosX64")
1800+
KonanTarget.MACOS_ARM64 -> listOf("iosSimulatorArm64")
1801+
else -> emptyList()
1802+
}
18001803
val testTasks = targetsToTest.flatMap { listOf(":${it}Test", ":${it}IntegrationTest") }.toTypedArray()
18011804

18021805
build(*testTasks) {

libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/GeneralNativeIT.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ import kotlin.test.assertFalse
3030
import kotlin.test.assertTrue
3131

3232
internal object MPPNativeTargets {
33-
val current = when {
34-
HostManager.hostIsMingw -> "mingw64"
35-
HostManager.hostIsLinux -> "linux64"
36-
HostManager.hostIsMac -> "macos64"
37-
else -> error("Unknown host")
33+
val current = when (HostManager.host) {
34+
KonanTarget.LINUX_X64 -> "linux64"
35+
KonanTarget.MACOS_X64 -> "macos64"
36+
KonanTarget.MACOS_ARM64 -> "macosArm64"
37+
KonanTarget.MINGW_X64 -> "mingw64"
38+
else -> error("Unsupported host")
3839
}
3940

4041
val unsupported = when {

libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-associate-compilations/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ kotlin {
4949
mingwX64("mingw64") {}
5050
linuxX64("linux64") {}
5151
macosX64("macos64") {}
52-
iosX64("ios") {}
52+
macosArm64("macosArm64") {}
53+
iosX64("iosX64") {}
54+
iosSimulatorArm64("iosSimulatorArm64") {}
5355

5456
targets.matching { it.name != "metadata" }.all {
5557
compilations.create("integrationTest") {
@@ -90,7 +92,7 @@ kotlin {
9092
}
9193
}
9294

93-
targets.matching { it.name == "mingw64" || it.name == "linux64" || it.name == "macos64" || it.name == "ios" }.all {
95+
targets.matching { it.name == "mingw64" || it.name == "linux64" || it.name == "macos64" || it.name == "macosArm64" || it.name == "iosX64" || it.name == "iosSimulatorArm64" }.all {
9496
testRuns {
9597
getByName("test").filter { excludeTestsMatching("*.secondTest") }
9698

libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-with-tests/TEST-all-pre6.6.xml

Lines changed: 0 additions & 43 deletions
This file was deleted.

libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-with-tests/TEST-all.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
</testsuite>
1717
<testsuite name="com.example.lib.TestCommonCode" tests="2" skipped="0" failures="0" errors="0" timestamp="..." hostname="..." time="...">
1818
<properties />
19-
<testcase name="testId[linux64]" classname="com.example.lib.TestCommonCode" time="..." />
20-
<testcase name="testExpectedFun[linux64]" classname="com.example.lib.TestCommonCode" time="..." />
19+
<testcase name="testId[<target>]" classname="com.example.lib.TestCommonCode" time="..." />
20+
<testcase name="testExpectedFun[<target>]" classname="com.example.lib.TestCommonCode" time="..." />
2121
<system-out />
2222
<system-err />
2323
</testsuite>

libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-with-tests/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ kotlin {
2323
fromPreset(presets.jvm, 'jvmWithoutJava')
2424
fromPreset(presets.jvmWithJava, 'jvmWithJava')
2525
fromPreset(presets.macosX64, 'macos64')
26+
fromPreset(presets.macosArm64, 'macosArm64')
2627
fromPreset(presets.linuxX64, 'linux64')
2728
fromPreset(presets.mingwX64, 'mingw64')
2829
}
@@ -56,7 +57,7 @@ kotlin {
5657
}
5758
}
5859
nativeMain
59-
configure([macos64Main, linux64Main, mingw64Main]) {
60+
configure([macos64Main, macosArm64Main, linux64Main, mingw64Main]) {
6061
dependsOn nativeMain
6162
}
6263
}

libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-with-tests/build.gradle.kts.alternative

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ kotlin {
1414
nodejs()
1515
}
1616
val macos64 = macosX64("macos64")
17+
val macosArm64 = macosArm64("macosArm64")
1718
val linux64 = linuxX64("linux64")
1819
val mingw64 = mingwX64("mingw64")
1920

@@ -49,7 +50,7 @@ kotlin {
4950
}
5051

5152
val nativeMain by creating
52-
configure(listOf(macos64, linux64, mingw64)) {
53+
configure(listOf(macos64, macosArm64, linux64, mingw64)) {
5354
compilations["main"].defaultSourceSet.dependsOn(nativeMain)
5455
}
5556
}

libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-lib-with-tests/src/jvmWithoutJavaMain/kotlin/script.kts

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)