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

Add K2 analysis switcher #3152

Merged
merged 7 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -31,22 +31,23 @@ class BasicGradleIntegrationTest : AbstractGradleIntegrationTest() {
}
}

@ParameterizedTest(name = "{0}")
@ArgumentsSource(AllSupportedTestedVersionsArgumentsProvider::class)
fun execute(buildVersions: BuildVersions) {
runAndAssertOutcome(buildVersions, TaskOutcome.SUCCESS)
runAndAssertOutcome(buildVersions, TaskOutcome.UP_TO_DATE)
@ParameterizedTest(name = "{0} {1}")
@ArgumentsSource(AllSupportedTestedVersionsWithK2SwitcherArgumentsProvider::class)
fun execute(buildVersions: BuildVersions, extraParameter: String) {
runAndAssertOutcome(buildVersions, TaskOutcome.SUCCESS, extraParameter)
runAndAssertOutcome(buildVersions, TaskOutcome.UP_TO_DATE, extraParameter)
}

private fun runAndAssertOutcome(buildVersions: BuildVersions, expectedOutcome: TaskOutcome) {
private fun runAndAssertOutcome(buildVersions: BuildVersions, expectedOutcome: TaskOutcome, extraParameter: String) {
val result = createGradleRunner(
buildVersions,
"dokkaHtml",
"dokkaJavadoc",
"dokkaGfm",
"dokkaJekyll",
"-i",
"-s"
"-s",
extraParameter
).buildRelaxed()

assertEquals(expectedOutcome, assertNotNull(result.task(":dokkaHtml")).outcome)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ class MultiModule0IntegrationTest : AbstractGradleIntegrationTest() {
File(templateProjectDir, "moduleA").copyRecursively(File(projectDir, "moduleA"))
}

@ParameterizedTest(name = "{0}")
@ArgumentsSource(AllSupportedTestedVersionsArgumentsProvider::class)
fun execute(buildVersions: BuildVersions) {
@ParameterizedTest(name = "{0} {1}")
@ArgumentsSource(AllSupportedTestedVersionsWithK2SwitcherArgumentsProvider::class)
fun execute(buildVersions: BuildVersions, extraParameter: String) {
val result = createGradleRunner(
buildVersions,
":moduleA:dokkaHtmlMultiModule",
":moduleA:dokkaGfmMultiModule",
":moduleA:dokkaJekyllMultiModule",
"-i", "-s"
"-i", "-s", extraParameter
).buildRelaxed()

assertEquals(TaskOutcome.SUCCESS, assertNotNull(result.task(":moduleA:dokkaHtmlMultiModule")).outcome)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ class MultiModule1IntegrationTest : AbstractGradleIntegrationTest() {
File(templateProjectDir, "second").copyRecursively(File(projectDir, "second"))
}

@ParameterizedTest(name = "{0}")
@ArgumentsSource(AllSupportedTestedVersionsArgumentsProvider::class)
fun execute(buildVersions: BuildVersions) {
@ParameterizedTest(name = "{0} {1}")
@ArgumentsSource(AllSupportedTestedVersionsWithK2SwitcherArgumentsProvider::class)
fun execute(buildVersions: BuildVersions, extraParameter: String) {
val result = createGradleRunner(
buildVersions,
":second:dokkaHtml",
"-i", "-s"
"-i", "-s", extraParameter
).buildRelaxed()

assertEquals(TaskOutcome.SUCCESS, assertNotNull(result.task(":second:dokkaHtml")).outcome)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Multiplatform0GradleIntegrationTest : AbstractGradleIntegrationTest() {
"-i",
"-s",
"-Pkotlin.mpp.enableGranularSourceSetsMetadata=true",
"-Pkotlin.native.enableDependencyPropagation=false"
"-Pkotlin.native.enableDependencyPropagation=false",
).buildRelaxed()
else
createGradleRunner(buildVersions, "dokkaHtml", "-i", "-s").buildRelaxed()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.ArgumentsProvider
import java.util.stream.Stream

const val useK2PropertyCLIArgument = "-Porg.jetbrains.dokka.useK2=true"
internal class LatestTestedVersionsArgumentsProvider : TestedVersionsArgumentsProvider(listOf(TestedVersions.LATEST))
internal open class AllSupportedTestedVersionsArgumentsProvider : TestedVersionsArgumentsProvider(TestedVersions.ALL_SUPPORTED)
internal open class AllSupportedTestedVersionsWithK2SwitcherArgumentsProvider : TestedVersionsWithK2SwitcherArgumentsProvider(TestedVersions.ALL_SUPPORTED)

internal object TestedVersions {

Expand Down Expand Up @@ -70,3 +72,18 @@ abstract class TestedVersionsArgumentsProvider(private val buildVersions: List<B
return buildVersions.stream().map { Arguments.of(it) }
}
}

/**
* The first argument is [BuildVersions], the second one is an extra CLI argument for Gradle
*/
internal abstract class TestedVersionsWithK2SwitcherArgumentsProvider(private val buildVersions: List<BuildVersions>) :
ArgumentsProvider {
override fun provideArguments(context: ExtensionContext?): Stream<out Arguments> {
return (buildVersions.map { Arguments.of(it, "") } + if (TestEnvironment.disableK2Tests) emptyList()
else buildVersions.map {
Arguments.of(
it, useK2PropertyCLIArgument
)
}).stream()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,22 @@ import org.jetbrains.dokka.it.TestOutputCopier
import org.jetbrains.dokka.it.copyAndApplyGitDiff
import org.jetbrains.dokka.it.gradle.AbstractGradleIntegrationTest
import org.jetbrains.dokka.it.gradle.BuildVersions
import org.junit.jupiter.api.extension.ExtensionContext
import org.jetbrains.dokka.it.gradle.TestedVersionsArgumentsProvider
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.ArgumentsProvider
import org.junit.jupiter.params.provider.ArgumentsSource
import java.io.File
import java.util.stream.Stream
import kotlin.test.BeforeTest
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertTrue

class CoroutinesBuildVersionsArgumentsProvider : ArgumentsProvider {
private val buildVersions = BuildVersions.permutations(
gradleVersions = listOf("7.4.2"),
kotlinVersions = listOf("1.8.10")
)

override fun provideArguments(context: ExtensionContext?): Stream<out Arguments> {
return buildVersions.stream().map { Arguments.of(it) }
}
}
private val buildVersions = BuildVersions.permutations(
gradleVersions = listOf("7.4.2"),
kotlinVersions = listOf("1.8.10")
)

internal class CoroutinesBuildVersionsArgumentsProvider :
TestedVersionsArgumentsProvider(buildVersions)
class CoroutinesGradleIntegrationTest : AbstractGradleIntegrationTest(), TestOutputCopier {

override val projectOutputLocation: File by lazy { File(projectDir, "build/dokka/htmlMultiModule") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,22 @@ import org.jetbrains.dokka.it.TestOutputCopier
import org.jetbrains.dokka.it.copyAndApplyGitDiff
import org.jetbrains.dokka.it.gradle.AbstractGradleIntegrationTest
import org.jetbrains.dokka.it.gradle.BuildVersions
import org.junit.jupiter.api.extension.ExtensionContext
import org.jetbrains.dokka.it.gradle.TestedVersionsArgumentsProvider
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.ArgumentsProvider
import org.junit.jupiter.params.provider.ArgumentsSource
import java.io.File
import java.util.stream.Stream
import kotlin.test.BeforeTest
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertTrue

class SerializationBuildVersionsArgumentsProvider : ArgumentsProvider {
private val buildVersions = BuildVersions.permutations(
gradleVersions = listOf("7.6.1"),
kotlinVersions = listOf("1.9.0")
)
private val buildVersions = BuildVersions.permutations(
gradleVersions = listOf("7.6.1"),
kotlinVersions = listOf("1.9.0")
)

override fun provideArguments(context: ExtensionContext?): Stream<out Arguments> {
return buildVersions.stream().map { Arguments.of(it) }
}
}
internal class SerializationBuildVersionsArgumentsProvider :
TestedVersionsArgumentsProvider(buildVersions)

class SerializationGradleIntegrationTest : AbstractGradleIntegrationTest(), TestOutputCopier {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public abstract class AbstractGradleIntegrationTest : AbstractIntegrationTest()
"-Pdokka_it_android_gradle_plugin_version=$androidVersion"
},
* arguments
)
).filter { it.isNotBlank() }
).run { this as DefaultGradleRunner }
.withJvmArguments(jvmArgs)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public object TestEnvironment {
public val isExhaustive: Boolean = checkNotNull(System.getenv("isExhaustive")) {
"Missing `isExhaustive` environment variable"
}.toBoolean()

public val disableK2Tests: Boolean = System.getenv("DISABLE_K2_TESTS").toBoolean()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ internal class DokkaArtifacts(private val project: Project) {

// TODO [beresnev] analysis switcher
val analysisKotlinDescriptors get() = fromModuleName("analysis-kotlin-descriptors")
val analysisKotlinSymbols get() = fromModuleName("analysis-kotlin-symbols")

val allModulesPage get() = fromModuleName("all-modules-page-plugin")
val dokkaCore get() = fromModuleName("dokka-core")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ open class DokkaPlugin : Plugin<Project> {
if (GradleVersion.version(project.gradle.gradleVersion) < GradleVersion.version("5.6")) {
project.logger.warn("Dokka: Build is using unsupported gradle version, expected at least 5.6 but got ${project.gradle.gradleVersion}. This may result in strange errors")
}
if (project.shouldUseK2())
project.logger.warn("K2 Analysis is using. " +
"This feature is experimental and can cause failed Dokka or incorrect documentation. " +
"Feel free report problems in https://github.com/Kotlin/dokka/issues")
IgnatBeresnev marked this conversation as resolved.
Show resolved Hide resolved

project.setupDokkaTasks("dokkaHtml") {
description = "Generates documentation in 'html' format"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import org.gradle.api.artifacts.Dependency
import org.gradle.api.attributes.Usage
import org.gradle.kotlin.dsl.named

internal fun Project.shouldUseK2() =
(findProperty("org.jetbrains.dokka.useK2") as? String)?.toBoolean() ?: false
IgnatBeresnev marked this conversation as resolved.
Show resolved Hide resolved

internal fun Project.maybeCreateDokkaDefaultPluginConfiguration(): Configuration {
return configurations.maybeCreate("dokkaPlugin") {
attributes.attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage.JAVA_RUNTIME))
Expand All @@ -29,7 +32,10 @@ internal fun Project.maybeCreateDokkaPluginConfiguration(dokkaTaskName: String,
extendsFrom(maybeCreateDokkaDefaultPluginConfiguration())
attributes.attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage.JAVA_RUNTIME))
isCanBeConsumed = false
dependencies.add(project.dokkaArtifacts.analysisKotlinDescriptors)
dependencies.add(
if (shouldUseK2()) project.dokkaArtifacts.analysisKotlinSymbols
else project.dokkaArtifacts.analysisKotlinDescriptors
)
dependencies.add(project.dokkaArtifacts.dokkaBase)
dependencies.addAll(additionalDependencies)
}
Expand Down
3 changes: 1 addition & 2 deletions subprojects/analysis-kotlin-symbols/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ plugins {

dependencies {
compileOnly(projects.core)
compileOnly(projects.subprojects.analysisKotlinApi)
implementation(projects.subprojects.analysisKotlinApi)
Copy link
Member

@IgnatBeresnev IgnatBeresnev Nov 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(rhetorical question) I wonder how and why it worked before...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was not merged in scope of this PR - is it correct? Without it, most likely switch to K2 will not work, no?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only one way to find out :) #3333

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was not merged in scope of this PR - is it correct? Without it, most likely switch to K2 will not work, no?

Sorry, I have missed it( Thank you for noticing it. It would be nice to have integration tests in single PR.

(rhetorical question) I wonder how and why it worked before...

Do you mean unit tests? This dependency comes from pluginBaseTestUtils where it is not excluded.


implementation(projects.subprojects.analysisMarkdownJb)
implementation(projects.subprojects.analysisJavaPsi)
Expand Down Expand Up @@ -82,7 +82,6 @@ dependencies {

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

}

tasks {
Expand Down
Loading