Skip to content

Commit

Permalink
[K2] Fix resolving symbols from transitive dependencies (#3437)
Browse files Browse the repository at this point in the history
  • Loading branch information
vmishenev authored Jan 11, 2024
1 parent 6904571 commit 74ed5e5
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 1 deletion.
6 changes: 6 additions & 0 deletions build-logic/src/main/kotlin/dokkabuild.test-k2.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ val symbolsTest = tasks.register<Test>("symbolsTest") {
// run symbols and descriptors tests
tasks.test {
//enabled = false
useJUnitPlatform {
excludeTags("onlySymbols")
}
classpath += descriptorsTestConfiguration
dependsOn(symbolsTest)
}

val descriptorsTest = tasks.register<Test>("descriptorsTest") {
useJUnitPlatform {
excludeTags("onlySymbols")
}
classpath += descriptorsTestConfiguration
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ internal fun createAnalysisSession(
jdkModule?.let { addRegularDependency(it) }
}
sourceSet.dependentSourceSets.forEach {
addRegularDependency(
/**
* @see org.jetbrains.kotlin.analysis.project.structure.KtModule.directDependsOnDependencies
*/
addDependsOnDependency(
sourcesModuleBySourceSetId[it]
?: error("There is no source module for $it")
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

package multiplatform

import org.jetbrains.dokka.base.signatures.KotlinSignatureUtils.driOrNull
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.DFunction
import org.jetbrains.dokka.model.dfs
import utils.OnlySymbols
import kotlin.test.Test
import kotlin.test.assertEquals

Expand Down Expand Up @@ -55,4 +60,54 @@ class BasicMultiplatformTest : BaseAbstractTest() {
}
}
}


@OnlySymbols("#3377 - types from transitive source sets are unresolved in K1")
@Test
fun `should resolve types from transitive source sets`() {
val configuration = dokkaConfiguration {
sourceSets {
val common = sourceSet {
name = "common"
displayName = "common"
analysisPlatform = "common"
sourceRoots = listOf("src/main/kotlin/common/Test.kt")
}

val shared = sourceSet {
name = "shared"
displayName = "shared"
analysisPlatform = "common"
dependentSourceSets = setOf(common.value.sourceSetID)
}
sourceSet {
name = "jvm"
displayName = "jvm"
analysisPlatform = "jvm"
sourceRoots = listOf("src/main/kotlin/jvm/Test.kt")
dependentSourceSets = setOf(shared.value.sourceSetID)
}
}
}

testInline(
"""
|/src/main/kotlin/common/Test.kt
|package multiplatform
|
|class A
|
|/src/main/kotlin/jvm/Test.kt
|package multiplatform
|
|fun fn(a: A) {}
""".trimMargin(),
configuration
) {
documentablesMergingStage = {
val fn = it.dfs { it is DFunction && it.name == "fn" } as DFunction
assertEquals(DRI("multiplatform", "A"), fn.parameters.firstOrNull()?.type?.driOrNull)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ import org.junit.jupiter.api.Tag
@Tag("onlyDescriptors")
annotation class OnlyDescriptors(val reason: String = "")


/**
* Run a test only for symbols (aka K2), not descriptors (K1).
*
* After remove K1 in dokka, this annotation should be also removed without consequences
*/
@Target(
AnnotationTarget.CLASS,
AnnotationTarget.FUNCTION,
AnnotationTarget.PROPERTY_GETTER,
AnnotationTarget.PROPERTY_SETTER
)
@Retention(
AnnotationRetention.RUNTIME
)
@Tag("onlySymbols")
annotation class OnlySymbols(val reason: String = "")

/**
* Run a test only for descriptors, not symbols.
*
Expand Down

0 comments on commit 74ed5e5

Please sign in to comment.