Skip to content

Commit 3b80c98

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

File tree

3 files changed

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

3 files changed

+127
-3
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,20 @@ internal object KotlinSourceSetMetrics : FusMetrics {
425425
it.put(BooleanMetrics.KOTLIN_WEB_MAIN_SOURCES_USED, true)
426426
}
427427
}
428+
429+
listOf(
430+
it.apiConfigurationName,
431+
it.implementationConfigurationName,
432+
it.compileOnlyConfigurationName,
433+
it.runtimeOnlyConfigurationName,
434+
).map { project.configurations.getByName(it) }
435+
.forEach { configuration ->
436+
if (configuration.dependencies.isNotEmpty()) {
437+
project.addConfigurationMetrics {
438+
it.put(BooleanMetrics.KOTLIN_WEB_MAIN_DEPENDENCIES_PRESENT, true)
439+
}
440+
}
441+
}
428442
}
429443
}
430444
}

libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/fus/FUSWebMainSourceSetTest.kt

Lines changed: 111 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
package org.jetbrains.kotlin.gradle.unitTests.fus
77

8-
import org.gradle.kotlin.dsl.get
98
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
109
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
1110
import org.jetbrains.kotlin.gradle.util.buildProjectWithMPP
@@ -56,4 +55,114 @@ class FUSWebMainSourceSetTest {
5655
}
5756
)
5857
}
59-
}
58+
59+
@Test
60+
fun emptyWebMainDependenciesAreNotReported() {
61+
val project = buildProjectWithMPP(preApplyCode = enableFusOnCI) {
62+
with(multiplatformExtension) {
63+
js { nodejs() }
64+
wasmJs()
65+
}
66+
}
67+
68+
project.evaluate()
69+
70+
assertNotNull(
71+
project.collectedFusConfigurationTimeMetrics.booleanMetrics.keys.none {
72+
it.name == BooleanMetrics.KOTLIN_WEB_MAIN_DEPENDENCIES_PRESENT.name
73+
}
74+
)
75+
}
76+
77+
@Test
78+
fun explicitlyAddedWebMainApiDependencyIsReported() {
79+
val project = buildProjectWithMPP(preApplyCode = enableFusOnCI) {
80+
with(multiplatformExtension) {
81+
js { browser() }
82+
wasmJs { browser() }
83+
84+
applyDefaultHierarchyTemplate()
85+
86+
sourceSets.getByName("webMain").dependencies {
87+
api("com.example:some-dependency:0.1")
88+
}
89+
}
90+
}
91+
project.evaluate()
92+
93+
assertNotNull(
94+
project.collectedFusConfigurationTimeMetrics.booleanMetrics.entries.singleOrNull {
95+
it.key == BooleanMetrics.KOTLIN_WEB_MAIN_DEPENDENCIES_PRESENT && it.value
96+
}
97+
)
98+
}
99+
100+
@Test
101+
fun explicitlyAddedWebMainImplementationDependencyIsReported() {
102+
val project = buildProjectWithMPP(preApplyCode = enableFusOnCI) {
103+
with(multiplatformExtension) {
104+
js { browser() }
105+
wasmJs { browser() }
106+
107+
applyDefaultHierarchyTemplate()
108+
109+
sourceSets.getByName("webMain").dependencies {
110+
implementation("com.example:some-dependency:0.1")
111+
}
112+
}
113+
}
114+
project.evaluate()
115+
116+
assertNotNull(
117+
project.collectedFusConfigurationTimeMetrics.booleanMetrics.entries.singleOrNull {
118+
it.key == BooleanMetrics.KOTLIN_WEB_MAIN_DEPENDENCIES_PRESENT && it.value
119+
}
120+
)
121+
}
122+
123+
@Test
124+
fun explicitlyAddedWebMainCompileOnlyDependencyIsReported() {
125+
val project = buildProjectWithMPP(preApplyCode = enableFusOnCI) {
126+
with(multiplatformExtension) {
127+
js { browser() }
128+
wasmJs { browser() }
129+
130+
applyDefaultHierarchyTemplate()
131+
132+
sourceSets.getByName("webMain").dependencies {
133+
compileOnly("com.example:some-dependency:0.1")
134+
}
135+
}
136+
}
137+
project.evaluate()
138+
139+
assertNotNull(
140+
project.collectedFusConfigurationTimeMetrics.booleanMetrics.entries.singleOrNull {
141+
it.key == BooleanMetrics.KOTLIN_WEB_MAIN_DEPENDENCIES_PRESENT && it.value
142+
}
143+
)
144+
}
145+
146+
@Test
147+
fun explicitlyAddedWebMainRuntimeOnlyDependencyIsReported() {
148+
val project = buildProjectWithMPP(preApplyCode = enableFusOnCI) {
149+
with(multiplatformExtension) {
150+
js { browser() }
151+
wasmJs { browser() }
152+
153+
applyDefaultHierarchyTemplate()
154+
155+
sourceSets.getByName("webMain").dependencies {
156+
runtimeOnly("com.example:some-dependency:0.1")
157+
}
158+
}
159+
}
160+
project.evaluate()
161+
162+
assertNotNull(
163+
project.collectedFusConfigurationTimeMetrics.booleanMetrics.entries.singleOrNull {
164+
it.key == BooleanMetrics.KOTLIN_WEB_MAIN_DEPENDENCIES_PRESENT && it.value
165+
}
166+
)
167+
}
168+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ enum class BooleanMetrics(val type: BooleanOverridePolicy, val anonymization: Bo
5050

5151
KOTLIN_GENERATED_SOURCES_USED(OR, SAFE),
5252
KOTLIN_WEB_MAIN_SOURCES_USED(OR, SAFE),
53+
KOTLIN_WEB_MAIN_DEPENDENCIES_PRESENT(OR, SAFE),
5354

5455
// Disabled explicitly by the user
5556
KOTLIN_CROSS_COMPILATION_DISABLED(OR, SAFE),
@@ -129,6 +130,6 @@ enum class BooleanMetrics(val type: BooleanOverridePolicy, val anonymization: Bo
129130
;
130131

131132
companion object {
132-
const val VERSION = 21
133+
const val VERSION = 22
133134
}
134135
}

0 commit comments

Comments
 (0)