[Gradle, K/N] Increase Xmx for MPP tests with native

This commit is contained in:
Alexander.Likhachev
2020-10-14 16:45:04 +03:00
parent babc7845af
commit ec877843fc
2 changed files with 24 additions and 34 deletions
@@ -5,6 +5,8 @@
package org.jetbrains.kotlin.gradle package org.jetbrains.kotlin.gradle
import org.jetbrains.kotlin.gradle.native.MPPNativeTargets import org.jetbrains.kotlin.gradle.native.MPPNativeTargets
import org.jetbrains.kotlin.gradle.native.configureMemoryInGradleProperties
import org.jetbrains.kotlin.gradle.native.transformNativeTestProject
import org.jetbrains.kotlin.gradle.native.transformNativeTestProjectWithPluginDsl import org.jetbrains.kotlin.gradle.native.transformNativeTestProjectWithPluginDsl
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType.* import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType.*
@@ -397,9 +399,7 @@ class NewMultiplatformIT : BaseGradleIT() {
@Test @Test
fun testMavenPublishAppliedBeforeMultiplatformPlugin() = fun testMavenPublishAppliedBeforeMultiplatformPlugin() =
with(Project("sample-lib", directoryPrefix = "new-mpp-lib-and-app")) { with(transformNativeTestProject("sample-lib", directoryPrefix = "new-mpp-lib-and-app")) {
setupWorkingDir()
gradleBuildScript().modify { "apply plugin: 'maven-publish'\n$it" } gradleBuildScript().modify { "apply plugin: 'maven-publish'\n$it" }
build { build {
@@ -456,6 +456,7 @@ class NewMultiplatformIT : BaseGradleIT() {
private fun doTestJvmWithJava(testJavaSupportInJvmTargets: Boolean) = private fun doTestJvmWithJava(testJavaSupportInJvmTargets: Boolean) =
with(Project("sample-lib", directoryPrefix = "new-mpp-lib-and-app")) { with(Project("sample-lib", directoryPrefix = "new-mpp-lib-and-app")) {
embedProject(Project("sample-lib-gradle-kotlin-dsl", directoryPrefix = "new-mpp-lib-and-app")) embedProject(Project("sample-lib-gradle-kotlin-dsl", directoryPrefix = "new-mpp-lib-and-app"))
configureMemoryInGradleProperties()
lateinit var classesWithoutJava: Set<String> lateinit var classesWithoutJava: Set<String>
@@ -613,11 +614,10 @@ class NewMultiplatformIT : BaseGradleIT() {
} }
@Test @Test
fun testLibWithTests() = doTestLibWithTests(Project("new-mpp-lib-with-tests", gradleVersion)) fun testLibWithTests() = doTestLibWithTests(transformNativeTestProject("new-mpp-lib-with-tests", gradleVersion))
@Test @Test
fun testLibWithTestsKotlinDsl() = with(Project("new-mpp-lib-with-tests", gradleVersion)) { fun testLibWithTestsKotlinDsl() = with(transformNativeTestProject("new-mpp-lib-with-tests", gradleVersion)) {
setupWorkingDir()
gradleBuildScript().delete() gradleBuildScript().delete()
projectDir.resolve("build.gradle.kts.alternative").renameTo(projectDir.resolve("build.gradle.kts")) projectDir.resolve("build.gradle.kts.alternative").renameTo(projectDir.resolve("build.gradle.kts"))
gradleBuildScript().modify(::transformBuildScriptWithPluginsDsl) gradleBuildScript().modify(::transformBuildScriptWithPluginsDsl)
@@ -687,9 +687,7 @@ class NewMultiplatformIT : BaseGradleIT() {
} }
@Test @Test
fun testLanguageSettingsApplied() = with(Project("sample-lib", gradleVersion, "new-mpp-lib-and-app")) { fun testLanguageSettingsApplied() = with(transformNativeTestProject("sample-lib", gradleVersion, "new-mpp-lib-and-app")) {
setupWorkingDir()
gradleBuildScript().appendText( gradleBuildScript().appendText(
"\n" + """ "\n" + """
kotlin.sourceSets.all { kotlin.sourceSets.all {
@@ -903,7 +901,7 @@ class NewMultiplatformIT : BaseGradleIT() {
} }
@Test @Test
fun testPublishingOnlySupportedNativeTargets() = with(Project("sample-lib", gradleVersion, "new-mpp-lib-and-app")) { fun testPublishingOnlySupportedNativeTargets() = with(transformNativeTestProject("sample-lib", gradleVersion, "new-mpp-lib-and-app")) {
val publishedVariant = nativeHostTargetName val publishedVariant = nativeHostTargetName
val nonPublishedVariant = unsupportedNativeTargets[0] val nonPublishedVariant = unsupportedNativeTargets[0]
@@ -923,8 +921,7 @@ class NewMultiplatformIT : BaseGradleIT() {
@Test @Test
fun testNonMppConsumersOfLibraryPublishedWithNoMetadataOptIn() { fun testNonMppConsumersOfLibraryPublishedWithNoMetadataOptIn() {
val repoDir = with(Project("sample-lib", gradleVersion, "new-mpp-lib-and-app")) { val repoDir = with(transformNativeTestProject("sample-lib", gradleVersion, "new-mpp-lib-and-app")) {
setupWorkingDir()
projectDir.resolve("settings.gradle").modify { it.replace("enableFeaturePreview", "// enableFeaturePreview") } projectDir.resolve("settings.gradle").modify { it.replace("enableFeaturePreview", "// enableFeaturePreview") }
build( build(
"publish" "publish"
@@ -975,9 +972,7 @@ class NewMultiplatformIT : BaseGradleIT() {
} }
@Test @Test
fun testOptionalExpectations() = with(Project("new-mpp-lib-with-tests", gradleVersion)) { fun testOptionalExpectations() = with(transformNativeTestProject("new-mpp-lib-with-tests", gradleVersion)) {
setupWorkingDir()
projectDir.resolve("src/commonMain/kotlin/Optional.kt").writeText( projectDir.resolve("src/commonMain/kotlin/Optional.kt").writeText(
""" """
@file:Suppress("EXPERIMENTAL_API_USAGE_ERROR") @file:Suppress("EXPERIMENTAL_API_USAGE_ERROR")
@@ -1018,7 +1013,7 @@ class NewMultiplatformIT : BaseGradleIT() {
} }
@Test @Test
fun testSourceJars() = with(Project("sample-lib", gradleVersion, "new-mpp-lib-and-app")) { fun testSourceJars() = with(transformNativeTestProject("sample-lib", gradleVersion, "new-mpp-lib-and-app")) {
setupWorkingDir() setupWorkingDir()
build("publish") { build("publish") {
@@ -1042,12 +1037,12 @@ class NewMultiplatformIT : BaseGradleIT() {
@Test @Test
fun testConsumeMppLibraryFromNonKotlinProject() { fun testConsumeMppLibraryFromNonKotlinProject() {
val libRepo = with(Project("sample-lib", gradleVersion, "new-mpp-lib-and-app")) { val libRepo = with(transformNativeTestProject("sample-lib", gradleVersion, "new-mpp-lib-and-app")) {
build("publish") { assertSuccessful() } build("publish") { assertSuccessful() }
projectDir.resolve("repo") projectDir.resolve("repo")
} }
with(Project("sample-app-without-kotlin", gradleVersion, "new-mpp-lib-and-app")) { with(transformNativeTestProject("sample-app-without-kotlin", gradleVersion, "new-mpp-lib-and-app")) {
setupWorkingDir() setupWorkingDir()
gradleBuildScript().appendText("\nrepositories { maven { url '${libRepo.toURI()}' } }") gradleBuildScript().appendText("\nrepositories { maven { url '${libRepo.toURI()}' } }")
@@ -1061,10 +1056,10 @@ class NewMultiplatformIT : BaseGradleIT() {
@Test @Test
fun testPublishMultimoduleProjectWithMetadata() { fun testPublishMultimoduleProjectWithMetadata() {
val libProject = Project("sample-lib", gradleVersion, "new-mpp-lib-and-app") val libProject = transformNativeTestProject("sample-lib", gradleVersion, "new-mpp-lib-and-app")
libProject.setupWorkingDir() libProject.setupWorkingDir()
Project("sample-external-lib", gradleVersion, "new-mpp-lib-and-app").apply { transformNativeTestProject("sample-external-lib", gradleVersion, "new-mpp-lib-and-app").apply {
setupWorkingDir() setupWorkingDir()
// Publish it into local repository of adjacent lib: // Publish it into local repository of adjacent lib:
gradleBuildScript().appendText( gradleBuildScript().appendText(
@@ -1081,7 +1076,7 @@ class NewMultiplatformIT : BaseGradleIT() {
} }
} }
val appProject = Project("sample-app", gradleVersion, "new-mpp-lib-and-app") val appProject = transformNativeTestProject("sample-app", gradleVersion, "new-mpp-lib-and-app")
with(libProject) { with(libProject) {
setupWorkingDir() setupWorkingDir()
@@ -1196,9 +1191,7 @@ class NewMultiplatformIT : BaseGradleIT() {
} }
@Test @Test
fun testMppBuildWithCompilerPlugins() = with(Project("sample-lib", gradleVersion, "new-mpp-lib-and-app")) { fun testMppBuildWithCompilerPlugins() = with(transformNativeTestProject("sample-lib", gradleVersion, "new-mpp-lib-and-app")) {
setupWorkingDir()
val printOptionsTaskName = "printCompilerPluginOptions" val printOptionsTaskName = "printCompilerPluginOptions"
val argsMarker = "=args=>" val argsMarker = "=args=>"
val classpathMarker = "=cp=>" val classpathMarker = "=cp=>"
@@ -47,15 +47,15 @@ internal object MPPNativeTargets {
val supported = listOf("linux64", "macos64", "mingw64").filter { !unsupported.contains(it) } val supported = listOf("linux64", "macos64", "mingw64").filter { !unsupported.contains(it) }
} }
private fun BaseGradleIT.transformNativeTestProject(projectName: String, directoryPrefix: String? = null): BaseGradleIT.Project { internal fun BaseGradleIT.transformNativeTestProject(projectName: String, wrapperVersion: GradleVersionRequired = defaultGradleVersion, directoryPrefix: String? = null): BaseGradleIT.Project {
val project = Project(projectName, directoryPrefix = directoryPrefix) val project = Project(projectName, wrapperVersion, directoryPrefix = directoryPrefix)
project.setupWorkingDir() project.setupWorkingDir()
project.configureSingleNativeTarget() project.configureSingleNativeTarget()
project.configureMemoryInGradleProperties() project.configureMemoryInGradleProperties()
return project return project
} }
fun BaseGradleIT.transformNativeTestProjectWithPluginDsl(projectName: String, wrapperVersion: GradleVersionRequired = defaultGradleVersion, directoryPrefix: String? = null): BaseGradleIT.Project { internal fun BaseGradleIT.transformNativeTestProjectWithPluginDsl(projectName: String, wrapperVersion: GradleVersionRequired = defaultGradleVersion, directoryPrefix: String? = null): BaseGradleIT.Project {
val project = transformProjectWithPluginsDsl(projectName, wrapperVersion, directoryPrefix = directoryPrefix) val project = transformProjectWithPluginsDsl(projectName, wrapperVersion, directoryPrefix = directoryPrefix)
project.configureSingleNativeTarget() project.configureSingleNativeTarget()
project.configureMemoryInGradleProperties() project.configureMemoryInGradleProperties()
@@ -63,14 +63,11 @@ fun BaseGradleIT.transformNativeTestProjectWithPluginDsl(projectName: String, wr
} }
internal fun BaseGradleIT.Project.configureMemoryInGradleProperties() { internal fun BaseGradleIT.Project.configureMemoryInGradleProperties() {
val files = projectDir.walk() val file = projectDir.resolve("gradle.properties")
.filter { it.isFile && (it.name == "gradle.properties") }.toMutableList() if (file.exists()) {
if (files.isEmpty()) { file.createNewFile()
files.add(projectDir.resolve("gradle.properties").also { it.createNewFile() })
}
files.forEach { file ->
file.appendText("\norg.gradle.jvmargs=-Xmx1g\n")
} }
file.appendText("\norg.gradle.jvmargs=-Xmx1g\n")
} }
private const val SINGLE_NATIVE_TARGET_PLACEHOLDER = "<SingleNativeTarget>" private const val SINGLE_NATIVE_TARGET_PLACEHOLDER = "<SingleNativeTarget>"