Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the compatibility metadata variant check more specific #3103

Merged
merged 3 commits into from
Aug 4, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ repositories {
}

kotlin {
jvm() // artificial empty target to avoid single target project
wasm()
sourceSets {
val wasmMain by getting {
Expand Down Expand Up @@ -45,4 +44,4 @@ configurations.all {
useVersion(project.properties["dokka_it_kotlin_version"] as String)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class WasmGradleIntegrationTest(override val versions: BuildVersions) : Abstract
companion object {
@get:JvmStatic
@get:Parameters(name = "{0}")
val versions = listOf(TestedVersions.LATEST)
val versions = TestedVersions.ALL_SUPPORTED
.filter { it.kotlinVersion >= "1.8.20" } // 1.8.20 is the first public version that can be tested with wasm
}

@BeforeTest
Expand Down
4 changes: 0 additions & 4 deletions runners/gradle-plugin/api/gradle-plugin.api
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,3 @@ public final class org/jetbrains/dokka/gradle/internal/AbstractDokkaTaskExtensio
public static synthetic fun buildJsonConfiguration$default (Lorg/jetbrains/dokka/gradle/AbstractDokkaTask;ZILjava/lang/Object;)Ljava/lang/String;
}

public final class org/jetbrains/dokka/gradle/kotlin/KotlinClasspathUtilsKt {
public static final fun isHMPPEnabled (Lorg/gradle/api/Project;)Z
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,12 @@ import org.gradle.api.file.FileCollection
import org.jetbrains.dokka.gradle.isAndroidTarget
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.jetbrains.kotlin.gradle.plugin.mpp.AbstractKotlinNativeCompilation
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCommonCompilation
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

val Project.isHMPPEnabled
// [KotlinCommonCompilation.isKlibCompilation] is internal, so we use this
get() = (this.findProperty("kotlin.mpp.enableGranularSourceSetsMetadata") as? String)?.toBoolean() ?: false

internal fun Project.classpathOf(sourceSet: KotlinSourceSet): FileCollection {
val compilations = compilationsOf(sourceSet)
return if (compilations.isNotEmpty()) {
compilations
/**
* If the project has enabled Compatibility Metadata Variant (produces legacy variant),
* we don't touch it due to some dependant library
* might be published without Compatibility Metadata Variant.
* Dokka needs only HMPP variant
* Ignore [org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCommonCompilation] for `commonMain` sourceSet with name `main`
*/
.filterNot { compilation -> isHMPPEnabled && compilation is KotlinCommonCompilation && compilation.name == "main" }
.map { compilation -> compilation.compileClasspathOf(project = this) }
.reduce { acc, fileCollection -> acc + fileCollection }
vmishenev marked this conversation as resolved.
Show resolved Hide resolved
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,47 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinSingleTargetExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCommonCompilation

internal typealias KotlinCompilation =
org.jetbrains.kotlin.gradle.plugin.KotlinCompilation<KotlinCommonOptions>

internal fun Project.compilationsOf(sourceSet: KotlinSourceSet): List<KotlinCompilation> {
//KT-45412 Make sure .kotlinSourceSets and .allKotlinSourceSets include the default source set
return allCompilationsOf(sourceSet).filter { compilation ->
val compilations = allCompilationsOf(sourceSet).filter { compilation ->
sourceSet in compilation.kotlinSourceSets || sourceSet == compilation.defaultSourceSet
}

val hasAdditionalCommonCompatibilityMetadataVariant = compilations.size >= 2
&& this.isHmppEnabled()
&& compilations.any { it is KotlinCommonCompilation && it.compilationName == "main" }
&& compilations.any { it is KotlinCommonCompilation && it.compilationName == "commonMain" }

return if (hasAdditionalCommonCompatibilityMetadataVariant) {
// If the project has `kotlin.mpp.enableCompatibilityMetadataVariant` set to `true`
// and it produces a legacy variant for common, we filter it out because one of the dependencies
// might be published without it, and it would lead to the following error:
//
// > Execution failed for task ':project:dokkaHtmlPartial'.
// > Could not resolve all files for configuration ':project:metadataCompileClasspath'.
// > Could not resolve com.example.dependency:0.1.0.
// > The consumer was configured to find a usage of 'kotlin-api' of a library, preferably optimized for
// non-jvm, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common'. However we
// cannot choose between the following variants of com.example.dependency:0.1.0:
//
// This can be reproduced consistently on Ktor of version 2.3.2
compilations.filterNot { it is KotlinCommonCompilation && it.compilationName == "main" }
} else {
compilations
}
}

private fun Project.isHmppEnabled(): Boolean {
// [KotlinCommonCompilation.isKlibCompilation] is internal, so we use this property instead.
// The property name might seem misleading, but it's set by KGP if HMPP is enabled:
// https://github.com/JetBrains/kotlin/blob/1.9.0/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/internal/hierarchicalStructureMigrationHandling.kt#L33
return (this.findProperty("kotlin.mpp.enableGranularSourceSetsMetadata") as? String)?.toBoolean()
?: false
}

internal fun Project.allCompilationsOf(
Expand Down