Skip to content

Commit 08491dc

Browse files
committed
Perform a major cleanup of Gradle scripts after the translation
* Remove the workarounds for IDEA import from gradle.kts Without the workarounds, everything still seems to be working fine, even after invalidating the caches. * Clarify the opt-ins. Unify the handling of all opt-ins in the project, and also add opt-ins for Native that would be widespread otherwise. Unfortunately, even after that, the IDE still complains about not having the right opt-in in kotlinx-coroutines-test/common/test/Helpers.kt. * Extract the logic of grouping several source sets into a single shared one. * Update the kotlinx-coroutines-core build script: - Utilize the multiplatform hierarchy to avoid defining extra source sets. - Reorder the code for readability. * Fix the IDE failing to find `actual` implementations for jvmCore by making sure `jvmCoreMain` is only defined when the IDE is not active. Without a dependency from jvmCoreMain to jvmMain, `expect` declarations in the IDE complained that they couldn't find `actual` in the `jvmCore` source-set. For example, this could be seen in kotlinx-coroutines-core/common/src/internal/Concurrent.common.kt. * Fix passing the stressTest system property to tests Broken in #3966 * kotlinOptions -> compilerOptions
1 parent 2bf1519 commit 08491dc

File tree

14 files changed

+109
-198
lines changed

14 files changed

+109
-198
lines changed

build.gradle.kts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import org.jetbrains.kotlin.config.KotlinCompilerVersion
22
import org.jetbrains.kotlin.gradle.dsl.*
33
import org.gradle.kotlin.dsl.*
4-
import org.jetbrains.kotlin.konan.target.HostManager
54

65
buildscript {
76
if (shouldUseLocalMaven(rootProject)) {
@@ -40,8 +39,6 @@ buildscript {
4039
apply(plugin = "configure-compilation-conventions")
4140

4241
allprojects {
43-
// the only place where HostManager could be instantiated
44-
project.ext["hostManager"] = HostManager()
4542
val deployVersion = properties["DeployVersion"]
4643
if (deployVersion != null) version = deployVersion
4744

buildSrc/src/main/kotlin/OptInPreset.kt

Lines changed: 0 additions & 11 deletions
This file was deleted.

buildSrc/src/main/kotlin/SourceSets.kt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import org.gradle.api.*
12
import org.jetbrains.kotlin.gradle.plugin.*
3+
import org.gradle.kotlin.dsl.*
24

35
fun KotlinSourceSet.configureDirectoryPaths() {
46
if (project.isMultiplatform) {
@@ -25,3 +27,30 @@ fun KotlinSourceSet.configureDirectoryPaths() {
2527
throw IllegalArgumentException("Unclear how to configure source sets for ${project.name}")
2628
}
2729
}
30+
31+
/**
32+
* Creates shared source sets for a group of source sets.
33+
*
34+
* [reverseDependencies] is a list of prefixes of names of source sets that depend on the new source set.
35+
* [dependencies] is a list of prefixes of names of source sets that the new source set depends on.
36+
* [groupName] is the prefix of the names of the new source sets.
37+
*
38+
* The suffixes of the source sets are "Main" and "Test".
39+
*/
40+
fun NamedDomainObjectContainer<KotlinSourceSet>.groupSourceSets(
41+
groupName: String,
42+
reverseDependencies: List<String>,
43+
dependencies: List<String>
44+
) {
45+
val sourceSetSuffixes = listOf("Main", "Test")
46+
for (suffix in sourceSetSuffixes) {
47+
register(groupName + suffix) {
48+
for (dep in dependencies) {
49+
dependsOn(get(dep + suffix))
50+
}
51+
for (revDep in reverseDependencies) {
52+
get(revDep + suffix).dependsOn(this)
53+
}
54+
}
55+
}
56+
}

buildSrc/src/main/kotlin/configure-compilation-conventions.gradle.kts

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,33 @@ configure(subprojects) {
2323
allWarningsAsErrors = true
2424
freeCompilerArgs.add("-Xexplicit-api=strict")
2525
}
26-
27-
/*
28-
* Coroutines do not interop with Java and these flags provide a significant
29-
* (i.e. close to double-digit) reduction in both bytecode and optimized dex size
30-
*/
31-
val bytecodeSizeReductionOptions =
32-
if (this@configureEach is KotlinJvmCompile) listOf(
26+
/* Coroutines do not interop with Java and these flags provide a significant
27+
* (i.e. close to double-digit) reduction in both bytecode and optimized dex size */
28+
if (this@configureEach is KotlinJvmCompile) {
29+
freeCompilerArgs.addAll(
3330
"-Xno-param-assertions",
3431
"-Xno-call-assertions",
3532
"-Xno-receiver-assertions"
36-
) else emptyList()
37-
38-
val newOptions = listOf(
39-
"-progressive", "-Xexpect-actual-classes"
40-
) + bytecodeSizeReductionOptions + optInAnnotations.map { "-opt-in=$it" }
41-
freeCompilerArgs.addAll(newOptions)
33+
)
34+
}
35+
if (this@configureEach is KotlinNativeCompile) {
36+
optIn.addAll(
37+
"kotlinx.cinterop.ExperimentalForeignApi",
38+
"kotlinx.cinterop.UnsafeNumber",
39+
"kotlin.experimental.ExperimentalNativeApi",
40+
)
41+
}
42+
freeCompilerArgs.addAll("-progressive", "-Xexpect-actual-classes")
43+
optIn.addAll(
44+
"kotlin.experimental.ExperimentalTypeInference",
45+
"kotlin.ExperimentalMultiplatform",
46+
// our own opt-ins that we don't want to bother with in our own code:
47+
"kotlinx.coroutines.DelicateCoroutinesApi",
48+
"kotlinx.coroutines.ExperimentalCoroutinesApi",
49+
"kotlinx.coroutines.ObsoleteCoroutinesApi",
50+
"kotlinx.coroutines.InternalCoroutinesApi",
51+
"kotlinx.coroutines.FlowPreview"
52+
)
4253
}
4354

4455
}

buildSrc/src/main/kotlin/kotlin-multiplatform-conventions.gradle.kts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -88,30 +88,20 @@ kotlin {
8888
// workaround for #3968 until this is fixed on atomicfu's side
8989
api("org.jetbrains.kotlinx:atomicfu:0.23.1")
9090
}
91-
val jsAndWasmSharedMain by registering {
92-
dependsOn(commonMain.get())
93-
}
94-
val jsAndWasmSharedTest by registering {
95-
dependsOn(commonTest.get())
96-
}
97-
jsMain {
98-
dependsOn(jsAndWasmSharedMain.get())
99-
}
91+
jsMain { }
10092
jsTest {
101-
dependsOn(jsAndWasmSharedTest.get())
10293
dependencies {
10394
api("org.jetbrains.kotlin:kotlin-test-js:${version("kotlin")}")
10495
}
10596
}
10697
val wasmJsMain by getting {
107-
dependsOn(jsAndWasmSharedMain.get())
10898
}
10999
val wasmJsTest by getting {
110-
dependsOn(jsAndWasmSharedTest.get())
111100
dependencies {
112101
api("org.jetbrains.kotlin:kotlin-test-wasm-js:${version("kotlin")}")
113102
}
114103
}
104+
groupSourceSets("jsAndWasmShared", listOf("js", "wasmJs"), listOf("common"))
115105
}
116106
}
117107

@@ -127,9 +117,5 @@ tasks.named("jvmTest", Test::class) {
127117
showStandardStreams = true
128118
events = setOf(TestLogEvent.PASSED, TestLogEvent.FAILED)
129119
}
130-
131-
val stressTest = project.properties["stressTest"]
132-
if (stressTest != null) {
133-
systemProperty("stressTest", "stressTest")
134-
}
120+
project.properties["stressTest"]?.let { systemProperty("stressTest", it) }
135121
}

0 commit comments

Comments
 (0)