Skip to content

Commit

Permalink
Move train configuration to build-logic
Browse files Browse the repository at this point in the history
  • Loading branch information
osipxd committed Jan 20, 2025
1 parent 016083e commit 6a81052
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 72 deletions.
3 changes: 2 additions & 1 deletion build-logic/src/main/kotlin/ktorbuild.kmp.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -67,4 +67,5 @@ if (targets.hasNative) {
}
}

setupTrain()
if (ktorBuild.isCI.get()) configureTestTasksOnCi()
75 changes: 75 additions & 0 deletions build-logic/src/main/kotlin/ktorbuild/internal/Train.kt
Original file line number Diff line number Diff line change
@@ -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<Test>().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<String>, libName: String) {
val libVersion = libVersionProvider.get()
check(version == libVersion) {
"Current deploy version is $version, but $libName version is not overridden ($libVersion)"
}
}
3 changes: 0 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ subprojects {

extra["hostManager"] = HostManager()

setupTrainForSubproject()

val nonDefaultProjectStructure: List<String> by rootProject.extra
if (nonDefaultProjectStructure.contains(project.name)) return@subprojects

Expand All @@ -59,7 +57,6 @@ subprojects {
}

println("Using Kotlin compiler version: ${libs.versions.kotlin.get()}")
filterSnapshotTests()

fun configureDokka() {
allprojects {
Expand Down
68 changes: 0 additions & 68 deletions buildSrc/src/main/kotlin/Train.kt

This file was deleted.

0 comments on commit 6a81052

Please sign in to comment.