[Gradle, K/N] Configure memory properties for tests in single place

This commit is contained in:
Alexander.Likhachev
2020-09-29 16:08:45 +07:00
parent 780b85e3ec
commit 5dd1e75793
17 changed files with 73 additions and 98 deletions
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.gradle
import org.jetbrains.kotlin.gradle.internals.MULTIPLATFORM_PROJECT_METADATA_JSON_FILE_NAME
import org.jetbrains.kotlin.gradle.internals.parseKotlinSourceSetMetadataFromJson
import org.jetbrains.kotlin.gradle.native.transformNativeTestProjectWithPluginDsl
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinProjectStructureMetadata
import org.jetbrains.kotlin.gradle.plugin.mpp.ModuleDependencyIdentifier
@@ -32,25 +33,19 @@ class HierarchicalMppIT : BaseGradleIT() {
fun testPublishedModules() {
publishThirdPartyLib(withGranularMetadata = false)
Project("my-lib-foo", gradleVersion, "hierarchical-mpp-published-modules").run {
setupWorkingDir()
gradleBuildScript().modify(::transformBuildScriptWithPluginsDsl)
transformNativeTestProjectWithPluginDsl("my-lib-foo", gradleVersion, "hierarchical-mpp-published-modules").run {
build("publish") {
checkMyLibFoo(this, subprojectPrefix = null)
}
}
Project("my-lib-bar", gradleVersion, "hierarchical-mpp-published-modules").run {
setupWorkingDir()
gradleBuildScript().modify(::transformBuildScriptWithPluginsDsl)
transformNativeTestProjectWithPluginDsl("my-lib-bar", gradleVersion, "hierarchical-mpp-published-modules").run {
build("publish") {
checkMyLibBar(this, subprojectPrefix = null)
}
}
Project("my-app", gradleVersion, "hierarchical-mpp-published-modules").run {
setupWorkingDir()
gradleBuildScript().modify(::transformBuildScriptWithPluginsDsl)
transformNativeTestProjectWithPluginDsl("my-app", gradleVersion, "hierarchical-mpp-published-modules").run {
build("assemble") {
checkMyApp(this, subprojectPrefix = null)
}
@@ -61,10 +56,7 @@ class HierarchicalMppIT : BaseGradleIT() {
fun testNoSourceSetsVisibleIfNoVariantMatched() {
publishThirdPartyLib(withGranularMetadata = true)
Project("my-lib-foo", gradleVersion, "hierarchical-mpp-published-modules").run {
setupWorkingDir()
gradleBuildScript().modify(::transformBuildScriptWithPluginsDsl)
transformNativeTestProjectWithPluginDsl("my-lib-foo", gradleVersion, "hierarchical-mpp-published-modules").run {
// --- Move the dependency from jvmAndJsMain to commonMain, where there's a linuxX64 target missing in the lib
gradleBuildScript().modify {
it.checkedReplace("api(\"com.example.thirdparty:third-party-lib:1.0\")", "//") + "\n" + """
@@ -94,10 +86,7 @@ class HierarchicalMppIT : BaseGradleIT() {
gradleBuildScript().appendText("\nkotlin.linuxX64()")
}
Project("my-lib-foo", gradleVersion, "hierarchical-mpp-published-modules").run {
setupWorkingDir()
gradleBuildScript().modify(::transformBuildScriptWithPluginsDsl)
transformNativeTestProjectWithPluginDsl("my-lib-foo", gradleVersion, "hierarchical-mpp-published-modules").run {
testDependencyTransformations { reports ->
val testApiTransformationReports =
reports.filter { report ->
@@ -171,10 +160,7 @@ class HierarchicalMppIT : BaseGradleIT() {
fun testProjectDependencies() {
publishThirdPartyLib(withGranularMetadata = false)
with(Project("hierarchical-mpp-project-dependency", gradleVersion)) {
setupWorkingDir()
gradleBuildScript().modify(::transformBuildScriptWithPluginsDsl)
with(transformNativeTestProjectWithPluginDsl("hierarchical-mpp-project-dependency", gradleVersion)) {
build("publish", "assemble") {
checkMyLibFoo(this, subprojectPrefix = "my-lib-foo")
checkMyLibBar(this, subprojectPrefix = "my-lib-bar")
@@ -193,10 +179,7 @@ class HierarchicalMppIT : BaseGradleIT() {
jsCompilerType = KotlinJsCompilerType.BOTH
)
with(Project("my-lib-foo", gradleVersion, directoryPrefix)) {
setupWorkingDir()
gradleBuildScript().modify(::transformBuildScriptWithPluginsDsl)
with(transformNativeTestProjectWithPluginDsl("my-lib-foo", gradleVersion, directoryPrefix)) {
build(
"publish",
"assemble",
@@ -209,10 +192,7 @@ class HierarchicalMppIT : BaseGradleIT() {
@Test
fun testHmppWithProjectJsIrDependency() {
with(Project("hierarchical-mpp-with-js-project-dependency", gradleVersion)) {
setupWorkingDir()
gradleBuildScript().modify(::transformBuildScriptWithPluginsDsl)
with(transformNativeTestProjectWithPluginDsl("hierarchical-mpp-with-js-project-dependency", gradleVersion)) {
build(
"assemble",
options = defaultBuildOptions().copy(jsCompilerType = KotlinJsCompilerType.IR)
@@ -229,10 +209,7 @@ class HierarchicalMppIT : BaseGradleIT() {
jsCompilerType: KotlinJsCompilerType = KotlinJsCompilerType.LEGACY,
beforePublishing: Project.() -> Unit = { }
): Project =
Project(projectName, gradleVersion, directoryPrefix).apply {
setupWorkingDir()
gradleBuildScript().modify(::transformBuildScriptWithPluginsDsl)
transformNativeTestProjectWithPluginDsl(projectName, gradleVersion, directoryPrefix).apply {
beforePublishing()
if (withGranularMetadata) {
@@ -495,10 +472,8 @@ class HierarchicalMppIT : BaseGradleIT() {
}
@Test
fun testCompileOnlyDependencyProcessingForMetadataCompilations() = with(Project("hierarchical-mpp-project-dependency")) {
fun testCompileOnlyDependencyProcessingForMetadataCompilations() = with(transformNativeTestProjectWithPluginDsl("hierarchical-mpp-project-dependency")) {
publishThirdPartyLib(withGranularMetadata = true)
setupWorkingDir()
gradleBuildScript().modify(::transformBuildScriptWithPluginsDsl)
gradleBuildScript("my-lib-foo").appendText("\ndependencies { \"jvmAndJsMainCompileOnly\"(kotlin(\"test-annotations-common\")) }")
projectDir.resolve("my-lib-foo/src/jvmAndJsMain/kotlin/UseCompileOnlyDependency.kt").writeText(
@@ -533,10 +508,7 @@ class HierarchicalMppIT : BaseGradleIT() {
fun testProcessingDependencyDeclaredInNonRootSourceSet() {
publishThirdPartyLib(withGranularMetadata = true)
Project("my-lib-foo", gradleVersion, "hierarchical-mpp-published-modules").run {
setupWorkingDir()
gradleBuildScript().modify(::transformBuildScriptWithPluginsDsl)
transformNativeTestProjectWithPluginDsl("my-lib-foo", gradleVersion, "hierarchical-mpp-published-modules").run {
val intermediateMetadataCompileTask = ":compileJvmAndJsMainKotlinMetadata"
build(intermediateMetadataCompileTask) {
@@ -556,10 +528,7 @@ class HierarchicalMppIT : BaseGradleIT() {
fun testDependenciesInNonPublishedSourceSets() {
publishThirdPartyLib(withGranularMetadata = true)
Project("my-lib-foo", gradleVersion, "hierarchical-mpp-published-modules").run {
setupWorkingDir()
gradleBuildScript().modify(::transformBuildScriptWithPluginsDsl)
transformNativeTestProjectWithPluginDsl("my-lib-foo", gradleVersion, "hierarchical-mpp-published-modules").run {
testDependencyTransformations { reports ->
reports.single {
it.sourceSetName == "jvmAndJsMain" && it.scope == "api" && it.groupAndModule.startsWith("com.example")
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.gradle
import org.jetbrains.kotlin.gradle.native.MPPNativeTargets
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.ProjectLocalConfigurations
@@ -54,8 +55,8 @@ class NewMultiplatformIT : BaseGradleIT() {
libProjectName: String,
appProjectName: String
) {
val libProject = transformProjectWithPluginsDsl(libProjectName, directoryPrefix = "new-mpp-lib-and-app")
val appProject = transformProjectWithPluginsDsl(appProjectName, directoryPrefix = "new-mpp-lib-and-app")
val libProject = transformNativeTestProjectWithPluginDsl(libProjectName, directoryPrefix = "new-mpp-lib-and-app")
val appProject = transformNativeTestProjectWithPluginDsl(appProjectName, directoryPrefix = "new-mpp-lib-and-app")
val oldStyleAppProject = Project("sample-old-style-app", directoryPrefix = "new-mpp-lib-and-app")
val compileTasksNames =
@@ -22,6 +22,8 @@ class CommonNativeIT : BaseGradleIT() {
libTargets: List<String>,
appTargets: List<String>
) = with(transformProjectWithPluginsDsl(projectName, directoryPrefix = "new-mpp-common-native")) {
configureMemoryInGradleProperties()
val libCompileTasks = libTargets.map { ":lib:compileKotlin${it.capitalize()}" }
val appCompileTasks = appTargets.map { ":app:compileKotlin${it.capitalize()}" }
val appLinkFrameworkTasks = appTargets.map { ":app:linkDebugFramework${it.capitalize()}" }
@@ -47,6 +47,44 @@ internal object MPPNativeTargets {
val supported = listOf("linux64", "macos64", "mingw64").filter { !unsupported.contains(it) }
}
private fun BaseGradleIT.transformNativeTestProject(projectName: String, directoryPrefix: String? = null): BaseGradleIT.Project {
val project = Project(projectName, directoryPrefix = directoryPrefix)
project.setupWorkingDir()
project.configureSingleNativeTarget()
project.configureMemoryInGradleProperties()
return project
}
fun BaseGradleIT.transformNativeTestProjectWithPluginDsl(projectName: String, wrapperVersion: GradleVersionRequired = defaultGradleVersion, directoryPrefix: String? = null): BaseGradleIT.Project {
val project = transformProjectWithPluginsDsl(projectName, wrapperVersion, directoryPrefix = directoryPrefix)
project.configureSingleNativeTarget()
project.configureMemoryInGradleProperties()
return project
}
internal fun BaseGradleIT.Project.configureMemoryInGradleProperties() {
val files = projectDir.walk()
.filter { it.isFile && (it.name == "gradle.properties") }.toMutableList()
if (files.isEmpty()) {
files.add(projectDir.resolve("gradle.properties").also { it.createNewFile() })
}
files.forEach { file ->
file.appendText("\norg.gradle.jvmargs=-Xmx1g\n")
}
}
private const val SINGLE_NATIVE_TARGET_PLACEHOLDER = "<SingleNativeTarget>"
private fun BaseGradleIT.Project.configureSingleNativeTarget(preset: String = HostManager.host.presetName) {
projectDir.walk()
.filter { it.isFile && (it.name == "build.gradle.kts" || it.name == "build.gradle") }
.forEach { file ->
file.modify {
it.replace(SINGLE_NATIVE_TARGET_PLACEHOLDER, preset)
}
}
}
class GeneralNativeIT : BaseGradleIT() {
val nativeHostTargetName = MPPNativeTargets.current
@@ -57,20 +95,8 @@ class GeneralNativeIT : BaseGradleIT() {
override val defaultGradleVersion: GradleVersionRequired
get() = GradleVersionRequired.FOR_MPP_SUPPORT
private val SINGLE_NATIVE_TARGET_PLACHOLDER = "<SingleNativeTarget>"
private fun Project.configureSingleNativeTarget(preset: String = HostManager.host.presetName) {
projectDir.walk()
.filter { it.isFile && (it.name == "build.gradle.kts" || it.name == "build.gradle") }
.forEach { file ->
file.modify {
it.replace(SINGLE_NATIVE_TARGET_PLACHOLDER, preset)
}
}
}
@Test
fun testParallelExecutionSmoke(): Unit = with(transformProjectWithPluginsDsl("native-parallel")) {
fun testParallelExecutionSmoke(): Unit = with(transformNativeTestProjectWithPluginDsl("native-parallel")) {
// Check that the K/N compiler can be started in-process in parallel.
build(":one:compileKotlinLinux", ":two:compileKotlinLinux") {
assertSuccessful()
@@ -78,8 +104,7 @@ class GeneralNativeIT : BaseGradleIT() {
}
@Test
fun testIncorrectDependenciesWarning() = with(Project("sample-lib", directoryPrefix = "new-mpp-lib-and-app")) {
setupWorkingDir()
fun testIncorrectDependenciesWarning() = with(transformNativeTestProject("sample-lib", directoryPrefix = "new-mpp-lib-and-app")) {
gradleBuildScript().modify {
it.replace(
"api 'org.jetbrains.kotlin:kotlin-stdlib-common'",
@@ -100,11 +125,8 @@ class GeneralNativeIT : BaseGradleIT() {
@Test
fun testEndorsedLibsController() {
with(
transformProjectWithPluginsDsl("native-endorsed")
transformNativeTestProjectWithPluginDsl("native-endorsed")
) {
configureSingleNativeTarget()
setupWorkingDir()
build("build") {
assertSuccessful()
}
@@ -118,9 +140,7 @@ class GeneralNativeIT : BaseGradleIT() {
}
@Test
fun testCanProduceNativeLibraries() = with(transformProjectWithPluginsDsl("libraries", directoryPrefix = "native-binaries")) {
configureSingleNativeTarget()
fun testCanProduceNativeLibraries() = with(transformNativeTestProjectWithPluginDsl("libraries", directoryPrefix = "native-binaries")) {
val baseName = "native_library"
val sharedPrefix = CompilerOutputKind.DYNAMIC.prefix(HostManager.host)
@@ -194,7 +214,7 @@ class GeneralNativeIT : BaseGradleIT() {
}
@Test
fun testCanProduceNativeFrameworks() = with(transformProjectWithPluginsDsl("frameworks", directoryPrefix = "native-binaries")) {
fun testCanProduceNativeFrameworks() = with(transformNativeTestProjectWithPluginDsl("frameworks", directoryPrefix = "native-binaries")) {
Assume.assumeTrue(HostManager.hostIsMac)
val baseName = "main"
@@ -271,9 +291,7 @@ class GeneralNativeIT : BaseGradleIT() {
}
@Test
fun testExportApiOnlyToLibraries() = with(transformProjectWithPluginsDsl("libraries", directoryPrefix = "native-binaries")) {
configureSingleNativeTarget()
fun testExportApiOnlyToLibraries() = with(transformNativeTestProjectWithPluginDsl("libraries", directoryPrefix = "native-binaries")) {
// Check that plugin doesn't allow exporting dependencies not added in the API configuration.
gradleBuildScript().modify {
it.replace("api(project(\":exported\"))", "")
@@ -303,9 +321,7 @@ class GeneralNativeIT : BaseGradleIT() {
}
@Test
fun testNativeExecutables() = with(transformProjectWithPluginsDsl("executables", directoryPrefix = "native-binaries")) {
configureSingleNativeTarget()
fun testNativeExecutables() = with(transformNativeTestProjectWithPluginDsl("executables", directoryPrefix = "native-binaries")) {
val binaries = mutableListOf(
"debugExecutable" to "native-binary",
"releaseExecutable" to "native-binary",
@@ -362,7 +378,7 @@ class GeneralNativeIT : BaseGradleIT() {
}
private fun testNativeBinaryDsl(project: String) = with(
transformProjectWithPluginsDsl(project, directoryPrefix = "native-binaries")
transformNativeTestProjectWithPluginDsl(project, directoryPrefix = "native-binaries")
) {
val hostSuffix = nativeHostTargetName.capitalize()
@@ -383,10 +399,8 @@ class GeneralNativeIT : BaseGradleIT() {
@Test
fun testKotlinOptions() = with(
transformProjectWithPluginsDsl("native-kotlin-options")
transformNativeTestProjectWithPluginDsl("native-kotlin-options")
) {
configureSingleNativeTarget()
build(":compileKotlinHost") {
assertSuccessful()
checkNativeCommandLineFor(":compileKotlinHost") {
@@ -413,7 +427,7 @@ class GeneralNativeIT : BaseGradleIT() {
// TODO: Reenable the test when the args are separated.
@Ignore
@Test
fun testNativeFreeArgsWarning() = with(transformProjectWithPluginsDsl("kotlin-dsl", directoryPrefix = "native-binaries")) {
fun testNativeFreeArgsWarning() = with(transformNativeTestProjectWithPluginDsl("kotlin-dsl", directoryPrefix = "native-binaries")) {
gradleBuildScript().appendText(
"""kotlin.targets["macos64"].compilations["main"].kotlinOptions.freeCompilerArgs += "-opt""""
)
@@ -459,9 +473,7 @@ class GeneralNativeIT : BaseGradleIT() {
}
@Test
fun testNativeTests() = with(Project("native-tests")) {
setupWorkingDir()
configureSingleNativeTarget()
fun testNativeTests() = with(transformNativeTestProject("native-tests")) {
val testTasks = listOf("hostTest", "iosTest")
val hostTestTask = "hostTest"
@@ -588,7 +600,7 @@ class GeneralNativeIT : BaseGradleIT() {
}
@Test
fun testNativeTestGetters() = with(Project("native-tests")) {
fun testNativeTestGetters() = with(transformNativeTestProject("native-tests")) {
// Check that test binaries can be accessed in a buildscript.
build("checkNewGetters") {
assertSuccessful()
@@ -636,8 +648,7 @@ class GeneralNativeIT : BaseGradleIT() {
@Test
fun kt33750() {
// Check that build fails if a test executable crashes.
with(Project("native-tests")) {
setupWorkingDir()
with(transformNativeTestProject("native-tests")) {
projectDir.resolve("src/commonTest/kotlin/test.kt").appendText("\nval fail: Int = error(\"\")\n")
build("check") {
assertFailed()
@@ -648,9 +659,7 @@ class GeneralNativeIT : BaseGradleIT() {
@Test
fun testCinterop() {
with(transformProjectWithPluginsDsl("native-cinterop")) {
configureSingleNativeTarget()
with(transformNativeTestProjectWithPluginDsl("native-cinterop")) {
build(":build") {
assertSuccessful()
assertFileExists("build/libs/host/main/native-cinterop-cinterop-number.klib")
@@ -761,8 +770,7 @@ class GeneralNativeIT : BaseGradleIT() {
}
@Test
fun testNativeArgsWithSpaces() = with(Project("sample-lib", directoryPrefix = "new-mpp-lib-and-app")) {
setupWorkingDir()
fun testNativeArgsWithSpaces() = with(transformNativeTestProject("sample-lib", directoryPrefix = "new-mpp-lib-and-app")) {
val compilcatedDirectoryName = if (HostManager.hostIsMingw) {
// Windows doesn't allow creating a file with " in its name.
"path with spaces"
@@ -44,6 +44,7 @@ class NativePlatformLibsIT : BaseGradleIT() {
"kotlin.$it()"
}
)
configureMemoryInGradleProperties()
}
private fun deleteInstalledCompilers() {
@@ -92,6 +93,7 @@ class NativePlatformLibsIT : BaseGradleIT() {
val rootProject = Project("native-platform-libraries").apply {
embedProject(Project("native-platform-libraries"), renameTo = "subproject")
configureMemoryInGradleProperties()
gradleBuildScript().modify(::transformBuildScriptWithPluginsDsl)
gradleBuildScript().appendText("\nkotlin.linuxX64()\n")
@@ -1,3 +1,2 @@
kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.disableCompilerDaemon=true
kotlin.mpp.enableCompatibilityMetadataVariant=true
@@ -1,3 +1,2 @@
kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.disableCompilerDaemon=true
kotlin.mpp.enableCompatibilityMetadataVariant=true
@@ -1,3 +1,2 @@
kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.disableCompilerDaemon=true
kotlin.mpp.enableCompatibilityMetadataVariant=true
@@ -1,3 +1,2 @@
kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.disableCompilerDaemon=true
kotlin.mpp.enableCompatibilityMetadataVariant=true