Skip to content

Commit

Permalink
KTOR-7501 Use target hierarchy DSL
Browse files Browse the repository at this point in the history
  • Loading branch information
osipxd committed Sep 30, 2024
1 parent f94980f commit 3f43f90
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 386 deletions.
6 changes: 2 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ doctor {
enableTestCaching = false
}

allprojects {
subprojects {
group = "io.ktor"
version = configuredVersion
extra["hostManager"] = HostManager()

setupTrainForSubproject()

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

apply(plugin = "kotlin-multiplatform")
apply(plugin = "atomicfu-conventions")
Expand All @@ -138,9 +138,7 @@ allprojects {
if (!skipPublish.contains(project.name)) {
configurePublication()
}
}

subprojects {
configureCodestyle()
}

Expand Down
56 changes: 27 additions & 29 deletions buildSrc/src/main/kotlin/JsConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@

import internal.*
import org.gradle.api.*
import org.gradle.internal.extensions.stdlib.*
import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.targets.js.ir.*
import org.jetbrains.kotlin.gradle.targets.js.dsl.*
import java.io.*
import kotlin.toString

fun Project.configureJs() {
configureJsTasks()

kotlin {
js {
if (project.targetIsEnabled("js.nodeJs")) nodejs { useMochaForTests() }
if (project.targetIsEnabled("js.browser")) browser { useKarmaForTests() }

binaries.library()
}

sourceSets {
jsTest {
dependencies {
Expand All @@ -21,40 +28,31 @@ fun Project.configureJs() {
}
}

configureJsTestTasks()
configureJsTestTasks(target = "js")
}

private fun Project.configureJsTasks() {
kotlin {
js {
if (project.targetIsEnabled("js.nodeJs")) {
nodejs {
testTask {
useMocha {
timeout = "10000"
}
}
}
}

(this as KotlinJsIrTarget).whenBrowserConfigured {
testTask {
useKarma {
useChromeHeadless()
useConfigDirectory(File(project.rootProject.projectDir, "karma"))
}
}
}
internal fun KotlinJsSubTargetDsl.useMochaForTests() {
testTask {
useMocha {
timeout = "10000"
}
}
}

binaries.library()
internal fun KotlinJsSubTargetDsl.useKarmaForTests() {
testTask {
useKarma {
useChromeHeadless()
useConfigDirectory(File(project.rootProject.projectDir, "karma"))
}
}
}

private fun Project.configureJsTestTasks() {
internal fun Project.configureJsTestTasks(target: String) {
val shouldRunJsBrowserTest = !hasProperty("teamcity") || hasProperty("enable-js-tests")
if (shouldRunJsBrowserTest) return

tasks.maybeNamed("cleanJsBrowserTest") { onlyIf { false } }
tasks.maybeNamed("jsBrowserTest") { onlyIf { false } }
val capitalizedTarget = target.replaceFirstChar { it.titlecase() }
tasks.maybeNamed("clean${capitalizedTarget}BrowserTest") { onlyIf { false } }
tasks.maybeNamed("${target}BrowserTest") { onlyIf { false } }
}
Loading

0 comments on commit 3f43f90

Please sign in to comment.