From 6a810522cc43662dfb4a5eb8ba9d14aa6e2be427 Mon Sep 17 00:00:00 2001 From: Osip Fatkullin Date: Mon, 13 Jan 2025 17:58:41 +0100 Subject: [PATCH] Move train configuration to build-logic --- .../src/main/kotlin/ktorbuild.kmp.gradle.kts | 3 +- .../main/kotlin/ktorbuild/internal/Train.kt | 75 +++++++++++++++++++ build.gradle.kts | 3 - buildSrc/src/main/kotlin/Train.kt | 68 ----------------- 4 files changed, 77 insertions(+), 72 deletions(-) create mode 100644 build-logic/src/main/kotlin/ktorbuild/internal/Train.kt delete mode 100644 buildSrc/src/main/kotlin/Train.kt diff --git a/build-logic/src/main/kotlin/ktorbuild.kmp.gradle.kts b/build-logic/src/main/kotlin/ktorbuild.kmp.gradle.kts index bd4a602687..21fdaa0895 100644 --- a/build-logic/src/main/kotlin/ktorbuild.kmp.gradle.kts +++ b/build-logic/src/main/kotlin/ktorbuild.kmp.gradle.kts @@ -4,8 +4,8 @@ @file:OptIn(ExperimentalKotlinGradlePluginApi::class) +import ktorbuild.internal.* import ktorbuild.internal.gradle.* -import ktorbuild.internal.ktorBuild import ktorbuild.maybeNamed import ktorbuild.targets.* import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi @@ -67,4 +67,5 @@ if (targets.hasNative) { } } +setupTrain() if (ktorBuild.isCI.get()) configureTestTasksOnCi() diff --git a/build-logic/src/main/kotlin/ktorbuild/internal/Train.kt b/build-logic/src/main/kotlin/ktorbuild/internal/Train.kt new file mode 100644 index 0000000000..403918ba6c --- /dev/null +++ b/build-logic/src/main/kotlin/ktorbuild/internal/Train.kt @@ -0,0 +1,75 @@ +/* + * Copyright 2014-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package ktorbuild.internal + +import org.gradle.api.Project +import org.gradle.api.provider.Provider +import org.gradle.api.tasks.testing.Test +import org.gradle.kotlin.dsl.withType + +fun Project.setupTrain() { + if (!buildSnapshotTrain) return + + if (name == "ktor-client") { + println("Manifest of kotlin-compiler-embeddable.jar") + printManifest() + } + + configureVersion() + filterSnapshotTests() +} + +// Hacking test tasks, removing stress and flaky tests" +private fun Project.filterSnapshotTests() { + tasks.withType().configureEach { + exclude("**/*ServerSocketTest*") + exclude("**/*NettyStressTest*") + exclude("**/*CIOMultithreadedTest*") + exclude("**/*testBlockingConcurrency*") + exclude("**/*testBigFile*") + exclude("**/*numberTest*") + exclude("**/*testWithPause*") + exclude("**/*WebSocketTest*") + exclude("**/*PostTest*") + exclude("**/*testCustomUrls*") + exclude("**/*testStaticServeFromDir*") + exclude("**/*testRedirect*") + exclude("**/*CIOHttpsTest*") + } +} + +private fun Project.printManifest() { + configurations.matching { it.name == "kotlinCompilerClasspath" }.all { + resolvedConfiguration.files.filter { it.name.contains("kotlin-compiler-embeddable") }.forEach { + val manifest = zipTree(it).matching { + include("META-INF/MANIFEST.MF") + }.files.first() + + manifest.readLines().forEach { + println(it) + } + } + } +} + +private fun Project.configureVersion() { + version = findProperty("DeployVersion") ?: return + + if (buildSnapshotTrain && !rootProject.hasProperty("skip_snapshot_checks")) { + check(version, rootProject.libs.versions.atomicfu, "atomicfu") + check(version, rootProject.libs.versions.coroutines, "coroutines") + check(version, rootProject.libs.versions.serialization, "serialization") + } +} + +private val Project.buildSnapshotTrain: Boolean + get() = rootProject.findProperty("build_snapshot_train")?.toString().toBoolean() + +private fun check(version: Any, libVersionProvider: Provider, libName: String) { + val libVersion = libVersionProvider.get() + check(version == libVersion) { + "Current deploy version is $version, but $libName version is not overridden ($libVersion)" + } +} diff --git a/build.gradle.kts b/build.gradle.kts index 9a841c7b55..ffdc0a91a8 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -43,8 +43,6 @@ subprojects { extra["hostManager"] = HostManager() - setupTrainForSubproject() - val nonDefaultProjectStructure: List by rootProject.extra if (nonDefaultProjectStructure.contains(project.name)) return@subprojects @@ -59,7 +57,6 @@ subprojects { } println("Using Kotlin compiler version: ${libs.versions.kotlin.get()}") -filterSnapshotTests() fun configureDokka() { allprojects { diff --git a/buildSrc/src/main/kotlin/Train.kt b/buildSrc/src/main/kotlin/Train.kt deleted file mode 100644 index cc9f6f0784..0000000000 --- a/buildSrc/src/main/kotlin/Train.kt +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2014-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ -import internal.libs -import org.gradle.api.Project -import org.gradle.api.provider.Provider -import org.gradle.api.tasks.testing.Test -import org.gradle.kotlin.dsl.withType - -fun Project.filterSnapshotTests() { - if (!buildSnapshotTrain) return - - println("Hacking test tasks, removing stress and flaky tests") - subprojects { - tasks.withType().configureEach { - exclude("**/*ServerSocketTest*") - exclude("**/*NettyStressTest*") - exclude("**/*CIOMultithreadedTest*") - exclude("**/*testBlockingConcurrency*") - exclude("**/*testBigFile*") - exclude("**/*numberTest*") - exclude("**/*testWithPause*") - exclude("**/*WebSocketTest*") - exclude("**/*PostTest*") - exclude("**/*testCustomUrls*") - exclude("**/*testStaticServeFromDir*") - exclude("**/*testRedirect*") - exclude("**/*CIOHttpsTest*") - } - } - - println("Manifest of kotlin-compiler-embeddable.jar") - - subprojects.filter { it.name == "ktor-client" }.forEach { - configurations.matching { it.name == "kotlinCompilerClasspath" }.all { - resolvedConfiguration.files.filter { it.name.contains("kotlin-compiler-embeddable") }.forEach { - val manifest = zipTree(it).matching { - include("META-INF/MANIFEST.MF") - }.files.first() - - manifest.readLines().forEach { - println(it) - } - } - } - } -} - -fun Project.setupTrainForSubproject() { - val deployVersion = properties["DeployVersion"] - if (deployVersion != null) version = deployVersion - - if (buildSnapshotTrain && !rootProject.hasProperty("skip_snapshot_checks")) { - check(version, rootProject.libs.versions.atomicfu, "atomicfu") - check(version, rootProject.libs.versions.coroutines, "coroutines") - check(version, rootProject.libs.versions.serialization, "serialization") - } -} - -private val Project.buildSnapshotTrain: Boolean - get() = rootProject.findProperty("build_snapshot_train")?.toString().toBoolean() - -private fun check(version: Any, libVersionProvider: Provider, libName: String) { - val libVersion = libVersionProvider.get() - check(version == libVersion) { - "Current deploy version is $version, but $libName version is not overridden ($libVersion)" - } -}