Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dokka-runners/dokka-gradle-plugin/api/dokka-gradle-plugin.api
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ public final class org/jetbrains/dokka/gradle/engine/parameters/KotlinPlatform :
public static final field JVM Lorg/jetbrains/dokka/gradle/engine/parameters/KotlinPlatform;
public static final field Native Lorg/jetbrains/dokka/gradle/engine/parameters/KotlinPlatform;
public static final field Wasm Lorg/jetbrains/dokka/gradle/engine/parameters/KotlinPlatform;
public static final field WasmJs Lorg/jetbrains/dokka/gradle/engine/parameters/KotlinPlatform;
public static final field WasmWasi Lorg/jetbrains/dokka/gradle/engine/parameters/KotlinPlatform;
public static fun valueOf (Ljava/lang/String;)Lorg/jetbrains/dokka/gradle/engine/parameters/KotlinPlatform;
public static fun values ()[Lorg/jetbrains/dokka/gradle/engine/parameters/KotlinPlatform;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmAndroidCompilation
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMetadataCompilation
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMetadataTarget
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinWasmTargetDsl
import org.jetbrains.kotlin.tooling.core.KotlinToolingVersion
import java.io.File
import javax.inject.Inject
Expand Down Expand Up @@ -439,16 +440,23 @@ private class KotlinCompilationDetailsBuilder(
val compilationClasspath: FileCollection =
collectKotlinCompilationClasspath(compilation = compilation)


val target = compilation.target

return KotlinCompilationDetails(
target = compilation.target.name,
kotlinPlatform = KotlinPlatform.fromString(compilation.platformType.name),
target = target.name,
kotlinPlatform =
if (target is KotlinWasmTargetDsl && target.wasmTargetType != null) // Dokka needs to distinguish wasmWasi and wasmJs for analyzing
KotlinPlatform.fromString("wasm"+ (target.wasmTargetType?.name ?: ""))
else
KotlinPlatform.fromString(compilation.platformType.name),
primarySourceSetNames = primarySourceSetNames.toSet(),
allSourceSetNames = allSourceSetNames.toSet(),
publishedCompilation = compilation.isPublished(),
dependentSourceSetNames = dependentSourceSetNames.toSet(),
compilationClasspath = compilationClasspath,
defaultSourceSetName = compilation.defaultSourceSet.name,
isMetadata = compilation.target is KotlinMetadataTarget,
isMetadata = target is KotlinMetadataTarget,
)
}

Expand Down Expand Up @@ -740,9 +748,9 @@ private class KotlinSourceSetDetailsBuilder(
}
}

val transformedMetadataDependencies =
@Suppress("DEPRECATION") val transformedMetadataDependencies =
allAssociatedCompilations.map { associated ->
if (associated.all { it.kotlinPlatform == KotlinPlatform.Wasm }) {
if (associated.all { it.kotlinPlatform == KotlinPlatform.Wasm || it.kotlinPlatform == KotlinPlatform.WasmJs || it.kotlinPlatform == KotlinPlatform.WasmWasi}) {
transformedMetadataDependencyProvider?.get(kotlinSourceSet)
?: objects.fileCollection()
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ enum class KotlinPlatform(
JS("js"),
JVM("jvm"),
Native("native"),
@Deprecated("Use `wasmWasi` or `wasmJs`")
Wasm("wasm"),
WasmWasi("wasmWasi"),
WasmJs("wasmJs"),
;

companion object {
Expand All @@ -49,10 +52,12 @@ enum class KotlinPlatform(
// Not defined as a property to try and minimize the dependency on Dokka Core types
internal val KotlinPlatform.dokkaType: Platform
get() =
when (this) {
@Suppress("DEPRECATION") when (this) {
AndroidJVM, JVM -> Platform.jvm
JS -> Platform.js
Wasm -> Platform.wasm
WasmWasi -> Platform.wasmWasi
WasmJs -> Platform.wasmJs
Native -> Platform.native
Common -> Platform.common
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class KotlinPlatformTest : FunSpec({
"jvm",
"js",
"wasm",
"wasmJs",
"wasmWasi",
"native",
"common",
).shouldForAll {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import io.kotest.inspectors.shouldForAll
import io.kotest.inspectors.shouldForOne
import io.kotest.matchers.nulls.shouldNotBeNull
import io.kotest.matchers.sequences.shouldNotBeEmpty
import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldBeEmpty
import io.kotest.matchers.string.shouldContain
import io.kotest.matchers.string.shouldEndWith
import io.kotest.matchers.string.shouldStartWith
import org.jetbrains.dokka.DokkaConfigurationImpl
import org.jetbrains.dokka.Platform
import org.jetbrains.dokka.gradle.internal.DokkaConstants
import org.jetbrains.dokka.gradle.utils.*
import kotlin.io.path.*
Expand All @@ -34,6 +36,7 @@ class KmpSharedWasmTest : FunSpec({
"--stacktrace",
)
.forwardOutput()
.withDebug(true)
.build {

test("expect project builds successfully") {
Expand Down Expand Up @@ -89,6 +92,12 @@ class KmpSharedWasmTest : FunSpec({
val commonDss = dokkaSourceSets["common"].shouldNotBeNull()
val wasmDss = dokkaSourceSets["wasm"].shouldNotBeNull()

test("expect correct analysisPlatform") {
dokkaSourceSets["common"]?.analysisPlatform.shouldBe(Platform.common)
dokkaSourceSets["wasm"]?.analysisPlatform.shouldBe(Platform.common)
dokkaSourceSets["wasmJs"]?.analysisPlatform.shouldBe(Platform.wasmJs)
dokkaSourceSets["wasmWasi"]?.analysisPlatform.shouldBe(Platform.wasmWasi)
}
test("expect common classpath has kotlin-stdlib") {
commonDss.classpath
.filter { it.isFile }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ public class AnalysisEnvironment(
System.setProperty("idea.io.use.nio2", "true")
System.setProperty("idea.ignore.disabled.plugins", "true")

val configFiles = when (analysisPlatform) {
val configFiles = @Suppress("DEPRECATION") when (analysisPlatform) {
Platform.jvm, Platform.common -> EnvironmentConfigFiles.JVM_CONFIG_FILES
Platform.native -> EnvironmentConfigFiles.NATIVE_CONFIG_FILES
Platform.js, Platform.wasm -> EnvironmentConfigFiles.JS_CONFIG_FILES
Platform.js, Platform.wasm, Platform.wasmWasi, Platform.wasmJs -> EnvironmentConfigFiles.JS_CONFIG_FILES
}

@OptIn(K1Deprecation::class)
Expand Down Expand Up @@ -156,9 +156,9 @@ public class AnalysisEnvironment(
}

private fun createSourceModuleSearchScope(project: Project, sourceFiles: List<KtFile>): GlobalSearchScope =
when (analysisPlatform) {
@Suppress("DEPRECATION") when (analysisPlatform) {
Platform.jvm -> TopDownAnalyzerFacadeForJVM.newModuleSearchScope(project, sourceFiles)
Platform.js, Platform.common, Platform.native, Platform.wasm -> GlobalSearchScope.filesScope(
Platform.js, Platform.common, Platform.native, Platform.wasm, Platform.wasmWasi, Platform.wasmJs -> GlobalSearchScope.filesScope(
project,
sourceFiles.map { it.virtualFile }.toSet()
)
Expand All @@ -172,8 +172,8 @@ public class AnalysisEnvironment(
val projectContext = ProjectContext(environment.project, "Dokka")
val sourceFiles = environment.getSourceFiles()

val targetPlatform = when (analysisPlatform) {
Platform.js, Platform.wasm -> JsPlatforms.defaultJsPlatform
val targetPlatform = @Suppress("DEPRECATION") when (analysisPlatform) {
Platform.js, Platform.wasm, Platform.wasmWasi, Platform.wasmJs -> JsPlatforms.defaultJsPlatform
Platform.common -> CommonPlatforms.defaultCommonPlatform
Platform.native -> NativePlatforms.unspecifiedNativePlatform
Platform.jvm -> JvmPlatforms.defaultJvmPlatform
Expand Down Expand Up @@ -235,7 +235,7 @@ public class AnalysisEnvironment(

var builtIns: JvmBuiltIns? = null

val resolverForProject = when (analysisPlatform) {
val resolverForProject = @Suppress("DEPRECATION") when (analysisPlatform) {
Platform.jvm -> {
builtIns = JvmBuiltIns(
projectContext.storageManager,
Expand All @@ -257,7 +257,7 @@ public class AnalysisEnvironment(
environment,
commonDependencyContainer
)
Platform.js, Platform.wasm -> createJsResolverForProject(projectContext, module, modulesContent)
Platform.js, Platform.wasm, Platform.wasmWasi, Platform.wasmJs -> createJsResolverForProject(projectContext, module, modulesContent)
Platform.native -> createNativeResolverForProject(projectContext, module, modulesContent)

}
Expand All @@ -281,20 +281,29 @@ public class AnalysisEnvironment(
)
}

private fun Platform.analyzerServices() = when (this) {
Platform.js, Platform.wasm -> JsPlatformAnalyzerServices
private fun Platform.analyzerServices() = @Suppress("DEPRECATION") when (this) {
Platform.js, Platform.wasm, Platform.wasmWasi, Platform.wasmJs -> JsPlatformAnalyzerServices
Platform.common -> CommonPlatformAnalyzerServices
Platform.native -> NativePlatformAnalyzerServices
Platform.jvm -> JvmPlatformAnalyzerServices
}

private fun Collection<KotlinLibrary>.registerLibraries(): List<DokkaKlibLibraryInfo> {
if (analysisPlatform != Platform.native && analysisPlatform != Platform.js && analysisPlatform != Platform.wasm) return emptyList()
val supportedPlatforms = setOf(
Platform.native,
Platform.js,
@Suppress("DEPRECATION") Platform.wasm,
Platform.wasmWasi,
Platform.wasmJs
)

if (analysisPlatform !in supportedPlatforms) return emptyList()

val dependencyResolver = DokkaKlibLibraryDependencyResolver()
val analyzerServices = analysisPlatform.analyzerServices()

return map { kotlinLibrary ->
if (analysisPlatform == org.jetbrains.dokka.Platform.native) DokkaNativeKlibLibraryInfo(
if (analysisPlatform == Platform.native) DokkaNativeKlibLibraryInfo(
kotlinLibrary,
analyzerServices,
dependencyResolver
Expand Down Expand Up @@ -533,7 +542,7 @@ public class AnalysisEnvironment(
* $paths: collection of files to add
*/
internal fun addClasspath(paths: List<File>) {
if (analysisPlatform == Platform.js || analysisPlatform == Platform.wasm) {
if (analysisPlatform == Platform.js || analysisPlatform == @Suppress("DEPRECATION") Platform.wasm || analysisPlatform == Platform.wasmWasi || analysisPlatform == Platform.wasmJs) {
configuration.addAll(JSConfigurationKeys.LIBRARIES, paths.map { it.absolutePath })
} else {
configuration.addJvmClasspathRoots(paths)
Expand All @@ -554,7 +563,15 @@ public class AnalysisEnvironment(
* $path: path to add
*/
internal fun addClasspath(path: File) {
if (analysisPlatform == Platform.js || analysisPlatform == Platform.wasm) {
val wasmOrJsPlatforms = setOf(
Platform.js,
@Suppress("DEPRECATION") Platform.wasm,
Platform.wasmWasi,
Platform.wasmJs
)

// Then replace the condition with:
if (analysisPlatform in wasmOrJsPlatforms) {
configuration.add(JSConfigurationKeys.LIBRARIES, path.absolutePath)
} else {
configuration.addJvmClasspathRoot(path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

package org.jetbrains.dokka.analysis.kotlin.symbols.plugin

import com.intellij.diagnostic.LoadingState
import com.intellij.openapi.Disposable
import com.intellij.openapi.util.Disposer
import org.jetbrains.dokka.DokkaConfiguration
Expand All @@ -30,7 +29,9 @@ import org.jetbrains.kotlin.platform.wasm.WasmPlatforms
import java.io.File

internal fun Platform.toTargetPlatform() = when (this) {
Platform.wasm -> WasmPlatforms.unspecifiedWasmPlatform
@Suppress("DEPRECATION") Platform.wasm -> WasmPlatforms.unspecifiedWasmPlatform
Platform.wasmJs -> WasmPlatforms.wasmJs
Platform.wasmWasi -> WasmPlatforms.wasmWasi
Platform.js -> JsPlatforms.defaultJsPlatform
Platform.common -> CommonPlatforms.defaultCommonPlatform
Platform.native -> NativePlatforms.unspecifiedNativePlatform
Expand Down
2 changes: 2 additions & 0 deletions dokka-subprojects/core/api/dokka-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,8 @@ public final class org/jetbrains/dokka/Platform : java/lang/Enum {
public static final field jvm Lorg/jetbrains/dokka/Platform;
public static final field native Lorg/jetbrains/dokka/Platform;
public static final field wasm Lorg/jetbrains/dokka/Platform;
public static final field wasmJs Lorg/jetbrains/dokka/Platform;
public static final field wasmWasi Lorg/jetbrains/dokka/Platform;
public final fun getKey ()Ljava/lang/String;
public static fun valueOf (Ljava/lang/String;)Lorg/jetbrains/dokka/Platform;
public static fun values ()[Lorg/jetbrains/dokka/Platform;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,24 @@ public enum class Platform(
) {
jvm("jvm"),
js("js"),
@Deprecated("Use `wasmWasi` or `wasmJs`")
wasm("wasm"),
wasmWasi("wasmWasi"),
wasmJs("wasmJs"),
native("native"),
common("common");

public companion object {
public val DEFAULT: Platform = jvm

public fun fromString(key: String): Platform {

return when (key.toLowerCase()) {
jvm.key -> jvm
js.key -> js
wasm.key -> wasm
@Suppress("DEPRECATION") wasm.key -> @Suppress("DEPRECATION") wasm
wasmWasi.key.toLowerCase() -> wasmWasi
wasmJs.key.toLowerCase() -> wasmJs
native.key -> native
common.key -> common
"androidjvm", "android" -> jvm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,8 @@ public open class HtmlRenderer(
"jvm" -> classes = classes + "jvm-like"
"js" -> classes = classes + "js-like"
"wasm" -> classes = classes + "wasm-like"
"wasmJs" -> classes = classes + "wasm-like"
"wasmWasi" -> classes = classes + "wasm-like"
}
text(it.name)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import kotlinx.html.*
import kotlinx.html.stream.appendHTML
import kotlinx.html.stream.createHTML
import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.Platform
import org.jetbrains.dokka.base.DokkaBase
import org.jetbrains.dokka.base.DokkaBaseConfiguration
import org.jetbrains.dokka.base.renderers.URIExtension
Expand Down Expand Up @@ -77,7 +78,7 @@ public class DefaultTemplateModelFactory(
.flatMap { it.sourceSets }
.distinct()
.sortedBy { it.comparableKey }
.map { SourceSetModel(it.name, it.platform.key, it.sourceSetIDs.merged.toString()) }
.map { SourceSetModel(it.name, it.platform.modelName, it.sourceSetIDs.merged.toString()) }
.toList()

if (sourceSets.isNotEmpty()) {
Expand All @@ -87,6 +88,17 @@ public class DefaultTemplateModelFactory(
return mapper
}

private val Platform.modelName: String
get() = @Suppress("DEPRECATION") when (this) {
Platform.jvm -> "jvm"
Platform.js -> "js"
Platform.common -> "common"
Platform.native -> "native"
Platform.wasm -> "wasm"
Platform.wasmWasi -> "wasm"
Platform.wasmJs -> "wasm"
}

override fun buildSharedModel(): TemplateMap {
val mapper = mutableMapOf<String, Any>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class KotlinSignatureProvider(
ExtraModifiers.KotlinOnlyModifiers.External
)
private val platformSpecificModifiers: Map<ExtraModifiers, Set<Platform>> = mapOf(
ExtraModifiers.KotlinOnlyModifiers.External to setOf(Platform.js, Platform.wasm)
ExtraModifiers.KotlinOnlyModifiers.External to setOf(Platform.js, @Suppress("DEPRECATION") Platform.wasm, Platform.wasmWasi, Platform.wasmJs)
)

override fun signature(documentable: Documentable): List<ContentNode> = when (documentable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public class SinceKotlinVersion(str: String) : Comparable<SinceKotlinVersion> {
Platform.jvm to SinceKotlinVersion("1.0"),
Platform.js to SinceKotlinVersion("1.1"),
Platform.native to SinceKotlinVersion("1.3"),
Platform.wasm to SinceKotlinVersion("1.8"),
@Suppress("DEPRECATION") Platform.wasm to SinceKotlinVersion("1.8"),
Platform.wasmWasi to SinceKotlinVersion("1.8"),
Platform.wasmJs to SinceKotlinVersion("1.8")
)

fun minVersionOfPlatform(platform: Platform): SinceKotlinVersion {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class SinceKotlinTest : AbstractRenderingTest() {
@Suppress("UNCHECKED_CAST") val funcs = module.children.single { it.name == "test" }
.children.filter { it.name == "ring" && it is DFunction } as List<DFunction>
with(funcs) {
val sinceKotlin = mapOf(
@Suppress("DEPRECATION") val sinceKotlin = mapOf(
Platform.common to SinceKotlinVersion("1.0"),
Platform.jvm to SinceKotlinVersion("1.0"),
Platform.js to SinceKotlinVersion("1.1"),
Expand Down Expand Up @@ -295,7 +295,7 @@ class SinceKotlinTest : AbstractRenderingTest() {
@Suppress("UNCHECKED_CAST") val funcs = module.children.single { it.name == "test" }
.children.filter { it.name == "ring" && it is DFunction } as List<DFunction>
with(funcs) {
val sinceKotlin = mapOf(
@Suppress("DEPRECATION") val sinceKotlin = mapOf(
Platform.common to SinceKotlinVersion("1.3"),
Platform.jvm to SinceKotlinVersion("1.3"),
Platform.js to SinceKotlinVersion("1.3"),
Expand Down
Loading
Loading