Skip to content

Commit

Permalink
[K2] Reorganize project model for MPP (#3236)
Browse files Browse the repository at this point in the history
* Reorganize project model for MPP

We map Dokka's source set directly to a source module of Analysis API inside one Analysis Standalone session.

Analysis API session is created in src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/plugin/KotlinAnalysis.kt (see fun createAnalysisSession)

Before the PR, one Dokka's source set corresponded to one Standalone API session with one source module that has source roots from dependent source sets.

* Add 'caffeine' dependency from Analysis API

* Fix sample provider

* Fix tests

* Enable tests and update the version of Analysis API.

The PR allows the enabling of some tests annotated with OnlyDescriptorsMPP.
Also, tests with OnlyDescriptorsMPP that have unresolved common symbols are fixed by the new version of Analysis API.
  • Loading branch information
vmishenev committed Oct 25, 2023
1 parent c745f96 commit 3be4dd9
Show file tree
Hide file tree
Showing 22 changed files with 246 additions and 206 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ kotlinx-bcv = "0.13.2"

## Analysis
kotlin-compiler = "1.9.10"
kotlin-compiler-k2 = "1.9.30-dev-3330"
kotlin-compiler-k2 = "2.0.0-dev-5387"

# MUST match the version of the intellij platform used in the kotlin compiler,
# otherwise this will lead to different versions of psi API and implementations
Expand Down
95 changes: 78 additions & 17 deletions plugins/base/src/test/kotlin/content/annotations/SinceKotlinTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ import org.jetbrains.dokka.model.doc.CustomTagWrapper
import org.jetbrains.dokka.model.doc.Text
import org.jetbrains.dokka.pages.ContentPage
import signatures.AbstractRenderingTest
import utils.ParamAttributes
import utils.TestOutputWriterPlugin
import utils.assertNotNull
import utils.bareSignature
import utils.*
import kotlin.test.*


Expand Down Expand Up @@ -125,30 +122,58 @@ class SinceKotlinTest : AbstractRenderingTest() {
val configuration = dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src/")
sourceRoots = listOf("src/jvm/")
analysisPlatform = "jvm"
}
sourceSet {
sourceRoots = listOf("src/")
sourceRoots = listOf("src/native/")
analysisPlatform = "native"
name = "native"
}
sourceSet {
sourceRoots = listOf("src/")
sourceRoots = listOf("src/common/")
analysisPlatform = "common"
name = "common"
}
sourceSet {
sourceRoots = listOf("src/")
sourceRoots = listOf("src/js/")
analysisPlatform = "js"
name = "js"
}
sourceSet {
sourceRoots = listOf("src/")
sourceRoots = listOf("src/wasm/")
analysisPlatform = "wasm"
name = "wasm"
}
}
}
testInline(
"""
|/src/main/kotlin/test/source.kt
|/src/jvm/kotlin/test/source.kt
|package test
|
|fun ring(abc: String): String {
| return "My precious " + abc
|}
|/src/native/kotlin/test/source.kt
|package test
|
|fun ring(abc: String): String {
| return "My precious " + abc
|}
|/src/common/kotlin/test/source.kt
|package test
|
|fun ring(abc: String): String {
| return "My precious " + abc
|}
|/src/js/kotlin/test/source.kt
|package test
|
|fun ring(abc: String): String {
| return "My precious " + abc
|}
|/src/wasm/kotlin/test/source.kt
|package test
|
|fun ring(abc: String): String {
Expand Down Expand Up @@ -185,33 +210,69 @@ class SinceKotlinTest : AbstractRenderingTest() {
val configuration = dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src/")
sourceRoots = listOf("src/jvm/")
classpath = listOfNotNull(jvmStdlibPath)
analysisPlatform = "jvm"
}
sourceSet {
sourceRoots = listOf("src/")
sourceRoots = listOf("src/native/")
analysisPlatform = "native"
name = "native"
}
sourceSet {
sourceRoots = listOf("src/")
sourceRoots = listOf("src/common/")
classpath = listOfNotNull(commonStdlibPath)
analysisPlatform = "common"
name = "common"
}
sourceSet {
sourceRoots = listOf("src/")
sourceRoots = listOf("src/js/")
classpath = listOfNotNull(jsStdlibPath)
analysisPlatform = "js"
name = "js"
}
sourceSet {
sourceRoots = listOf("src/")
sourceRoots = listOf("src/wasm/")
analysisPlatform = "wasm"
name = "wasm"
}
}
}
testInline(
"""
|/src/main/kotlin/test/source.kt
|/src/jvm/kotlin/test/source.kt
|package test
|
|/** dssdd */
|@SinceKotlin("1.3")
|fun ring(abc: String): String {
| return "My precious " + abc
|}
|/src/native/kotlin/test/source.kt
|package test
|
|/** dssdd */
|@SinceKotlin("1.3")
|fun ring(abc: String): String {
| return "My precious " + abc
|}
|/src/common/kotlin/test/source.kt
|package test
|
|/** dssdd */
|@SinceKotlin("1.3")
|fun ring(abc: String): String {
| return "My precious " + abc
|}
|/src/js/kotlin/test/source.kt
|package test
|
|/** dssdd */
|@SinceKotlin("1.3")
|fun ring(abc: String): String {
| return "My precious " + abc
|}
|/src/wasm/kotlin/test/source.kt
|package test
|
|/** dssdd */
Expand All @@ -238,7 +299,7 @@ class SinceKotlinTest : AbstractRenderingTest() {
find { it.sourceSets.first().analysisPlatform == i.key }?.documentation?.values?.first()
?.dfs { it is CustomTagWrapper && it.name == "Since Kotlin" }
.assertNotNull("SinceKotlin[${i.key}]")
assertEquals((tag.children.first() as Text).body, i.value.toString())
assertEquals(i.value.toString(), (tag.children.first() as Text).body , "Platform ${i.key}")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ class ContentForExceptions : BaseAbstractTest() {
}
}

@OnlyDescriptorsMPP("Return type for native `function` should be null rather than kotlin/Unit")
@Test
fun `throws in merged functions`() {
testInline(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,6 @@ class ContentForSeeAlsoTest : BaseAbstractTest() {
}
}

@OnlyDescriptorsMPP
@Test
fun `multiplatform class with seealso in few platforms`() {
testInline(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotEquals
import kotlin.test.assertNotNull
import utils.OnlyDescriptors
import utils.OnlyDescriptorsMPP

class LinkableContentTest : BaseAbstractTest() {

@OnlyDescriptorsMPP
@OnlyDescriptorsMPP("#3238")
@Test
fun `Include module and package documentation`() {

Expand Down Expand Up @@ -151,7 +150,7 @@ class LinkableContentTest : BaseAbstractTest() {
}
}

@OnlyDescriptorsMPP
@OnlyDescriptorsMPP("#3238")
@Test
fun `Samples multiplatform documentation`() {

Expand Down Expand Up @@ -286,15 +285,15 @@ class LinkableContentTest : BaseAbstractTest() {
sourceSets {
sourceSet {
analysisPlatform = "js"
sourceRoots = listOf("jsMain", "commonMain", "jvmAndJsSecondCommonMain").map {
sourceRoots = listOf("jsMain").map {
Paths.get("$testDataDir/$it/kotlin").toString()
}
name = "js"
includes = listOf(Paths.get("$includesDir/include2.md").toString())
}
sourceSet {
analysisPlatform = "jvm"
sourceRoots = listOf("jvmMain", "commonMain", "jvmAndJsSecondCommonMain").map {
sourceRoots = listOf("jvmMain").map {
Paths.get("$testDataDir/$it/kotlin").toString()
}
name = "jvm"
Expand Down
11 changes: 9 additions & 2 deletions plugins/base/src/test/kotlin/model/InheritorsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,22 @@ class InheritorsTest : AbstractModelTest("/src/main/kotlin/inheritors/Test.kt",
fun multiplatform() {
val configuration = dokkaConfiguration {
sourceSets {
val commonSourceSet = sourceSet {
name = "common"
sourceRoots = listOf("common/src/")
analysisPlatform = "common"
}
sourceSet {
name = "jvm"
sourceRoots = listOf("common/src/", "jvm/src/")
sourceRoots = listOf("jvm/src/")
analysisPlatform = "jvm"
dependentSourceSets = setOf(commonSourceSet.value.sourceSetID)
}
sourceSet {
name = "js"
sourceRoots = listOf("common/src/", "js/src/")
sourceRoots = listOf("js/src/")
analysisPlatform = "js"
dependentSourceSets = setOf(commonSourceSet.value.sourceSetID)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ package signatures
import utils.TestOutputWriterPlugin
import kotlin.test.Test
import kotlin.test.assertEquals
import utils.OnlyDescriptors
import utils.OnlyDescriptorsMPP

@OnlyDescriptorsMPP

class DivergentSignatureTest : AbstractRenderingTest() {

@Test
Expand Down
2 changes: 0 additions & 2 deletions plugins/base/src/test/kotlin/signatures/SignatureTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,6 @@ class SignatureTest : BaseAbstractTest() {
}
}
}
@OnlyDescriptorsMPP
@Test
fun `actual typealias should have generic parameters and fully qualified name of the expansion type`() {
val writerPlugin = TestOutputWriterPlugin()
Expand Down Expand Up @@ -590,7 +589,6 @@ class SignatureTest : BaseAbstractTest() {
}
}

@OnlyDescriptorsMPP
@Test
fun `type with an actual typealias`() {
val writerPlugin = TestOutputWriterPlugin()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import kotlin.test.assertEquals

class ModuleAndPackageDocumentationTransformerFunctionalTest : BaseAbstractTest() {

@OnlyDescriptorsMPP
@OnlyDescriptorsMPP("#3238")
@Test
fun `multiplatform project`(@TempDir tempDir: Path) {
val include = tempDir.resolve("include.md").toFile()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import org.jetbrains.dokka.SourceLinkDefinitionImpl
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.jsoup.nodes.Element
import signatures.renderedContent
import utils.OnlyDescriptorsMPP
import utils.TestOutputWriterPlugin
import java.net.URL
import kotlin.test.Test
Expand Down Expand Up @@ -71,7 +70,6 @@ class SourceLinkTransformerTest : BaseAbstractTest() {
}
}

@OnlyDescriptorsMPP
@Test
fun `source link should be for actual typealias`() {
val mppConfiguration = dokkaConfiguration {
Expand Down
4 changes: 4 additions & 0 deletions subprojects/analysis-kotlin-symbols/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,17 @@ dependencies {
isTransitive = false // see KTIJ-19820
}
}
// copy-pasted from Analysis API https://github.com/JetBrains/kotlin/blob/a10042f9099e20a656dec3ecf1665eea340a3633/analysis/low-level-api-fir/build.gradle.kts#L37
runtimeOnly("com.github.ben-manes.caffeine:caffeine:2.9.3")

runtimeOnly(libs.kotlinx.collections.immutable)
implementation(libs.kotlin.compiler.k2) {
isTransitive = false
}

// TODO [beresnev] get rid of it
compileOnly(libs.kotlinx.coroutines.core)

}

tasks {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal class KotlinDocCommentParser(
}
val kotlinAnalysis = context.plugin<SymbolsAnalysisPlugin>().querySingle { kotlinAnalysis }
val elementName = element.resolveDocContext.ktElement.name
return analyze(kotlinAnalysis[sourceSet].mainModule) {
return analyze(kotlinAnalysis.getModule(sourceSet)) {
parseFromKDocTag(
kDocTag = element.comment,
externalDri = { link -> resolveKDocLink(link).ifUnresolved { context.logger.logUnresolvedLink(link.getLinkText(), elementName) } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ internal fun ModuleAndPackageDocumentationParsingContext(
if (kotlinAnalysis == null || sourceSet == null) {
MarkdownParser(externalDri = { null }, sourceLocation)
} else {
val analysisContext = kotlinAnalysis[sourceSet]
val contextPsi = analyze(analysisContext.mainModule) {
val sourceModule = kotlinAnalysis.getModule(sourceSet)
val contextPsi = analyze(sourceModule) {
val contextSymbol = when (fragment.classifier) {
Module -> ROOT_PACKAGE_SYMBOL
Package -> getPackageSymbolIfPackageExists(FqName(fragment.name))
Expand All @@ -46,7 +46,7 @@ internal fun ModuleAndPackageDocumentationParsingContext(
}
MarkdownParser(
externalDri = { link ->
analyze(analysisContext.mainModule) {
analyze(sourceModule) {
resolveKDocTextLink(
link,
contextPsi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private class ContextModuleAndPackageDocumentationReader(
): SourceSetDependent<DocumentationNode> {
return sourceSets.associateWithNotNull { sourceSet ->
val fragments = documentationFragments[sourceSet].orEmpty().filter(predicate)
kotlinAnalysis[sourceSet] // test: to throw exception for unknown sourceSet
kotlinAnalysis.getModule(sourceSet)// test: to throw exception for unknown sourceSet
val documentations = fragments.map { fragment ->
parseModuleAndPackageDocumentation(
context = ModuleAndPackageDocumentationParsingContext(context.logger, kotlinAnalysis, sourceSet),
Expand Down
Loading

0 comments on commit 3be4dd9

Please sign in to comment.