Skip to content

Commit 3b270fb

Browse files
TapchicomaSpace Team
authored andcommitted
[Gradle] Track 'webMain' sources usage
^KT-79482 In Progress
1 parent a8da516 commit 3b270fb

File tree

3 files changed

+75
-1
lines changed
  • libraries/tools
    • kotlin-gradle-plugin/src
    • kotlin-gradle-statistics/src/main/kotlin/org/jetbrains/kotlin/statistics/metrics

3 files changed

+75
-1
lines changed

libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/statistics/FusMetrics.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ internal object KotlinSourceSetMetrics : FusMetrics {
403403
internal fun collectMetrics(project: Project) {
404404
project.launchInStage(KotlinPluginLifecycle.Stage.AfterFinaliseDsl) {
405405
project.reportGeneratedSourcesUsage()
406+
project.reportWebMainSourceSetUsage()
406407
}
407408
}
408409

@@ -415,4 +416,16 @@ internal object KotlinSourceSetMetrics : FusMetrics {
415416
}
416417
}
417418
}
419+
420+
private suspend fun Project.reportWebMainSourceSetUsage() {
421+
project.kotlinExtension.awaitSourceSets().configureEach {
422+
if (it.name == "webMain") {
423+
if (!it.allKotlinSources.isEmpty) {
424+
project.addConfigurationMetrics {
425+
it.put(BooleanMetrics.KOTLIN_WEB_MAIN_SOURCES_USED, true)
426+
}
427+
}
428+
}
429+
}
430+
}
418431
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2010-2025 JetBrains s.r.o. and Kotlin Programming Language contributors.
3+
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
4+
*/
5+
6+
package org.jetbrains.kotlin.gradle.unitTests.fus
7+
8+
import org.gradle.kotlin.dsl.get
9+
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
10+
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
11+
import org.jetbrains.kotlin.gradle.util.buildProjectWithMPP
12+
import org.jetbrains.kotlin.statistics.metrics.BooleanMetrics
13+
import kotlin.test.Test
14+
import kotlin.test.assertNotNull
15+
16+
@OptIn(ExperimentalWasmDsl::class)
17+
class FUSWebMainSourceSetTest {
18+
19+
@Test
20+
fun emptyWebMainSourcesAreNotReported() {
21+
val project = buildProjectWithMPP(preApplyCode = enableFusOnCI) {
22+
with(multiplatformExtension) {
23+
js { nodejs() }
24+
wasmJs()
25+
}
26+
}
27+
28+
project.evaluate()
29+
30+
assertNotNull(
31+
project.collectedFusConfigurationTimeMetrics.booleanMetrics.keys.none {
32+
it.name == BooleanMetrics.KOTLIN_WEB_MAIN_SOURCES_USED.name
33+
},
34+
"FUS event is present for webMain sources"
35+
)
36+
}
37+
38+
@Test
39+
fun explicitlyAddedWebMainSourcesAreReported() {
40+
val project = buildProjectWithMPP(preApplyCode = enableFusOnCI) {
41+
with(multiplatformExtension) {
42+
js { browser() }
43+
wasmJs { browser() }
44+
}
45+
}
46+
47+
val sharedFile = project.layout.projectDirectory.file("src/webMain/kotlin/shared.kt").asFile
48+
sharedFile.parentFile.mkdirs()
49+
sharedFile.writeText("fun shared() = 1")
50+
51+
project.evaluate()
52+
53+
assertNotNull(
54+
project.collectedFusConfigurationTimeMetrics.booleanMetrics.entries.singleOrNull {
55+
it.key == BooleanMetrics.KOTLIN_WEB_MAIN_SOURCES_USED && it.value
56+
}
57+
)
58+
}
59+
}

libraries/tools/kotlin-gradle-statistics/src/main/kotlin/org/jetbrains/kotlin/statistics/metrics/BooleanMetrics.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ enum class BooleanMetrics(val type: BooleanOverridePolicy, val anonymization: Bo
4747
KOTLIN_PROGRESSIVE_MODE(OVERRIDE, SAFE),
4848
KOTLIN_KTS_USED(OR, SAFE),
4949
KOTLIN_BTA_USED(OR, SAFE),
50+
5051
KOTLIN_GENERATED_SOURCES_USED(OR, SAFE),
52+
KOTLIN_WEB_MAIN_SOURCES_USED(OR, SAFE),
5153

5254
// Disabled explicitly by the user
5355
KOTLIN_CROSS_COMPILATION_DISABLED(OR, SAFE),
@@ -127,6 +129,6 @@ enum class BooleanMetrics(val type: BooleanOverridePolicy, val anonymization: Bo
127129
;
128130

129131
companion object {
130-
const val VERSION = 20
132+
const val VERSION = 21
131133
}
132134
}

0 commit comments

Comments
 (0)