Skip to content

Commit

Permalink
Ignore BuiltIns for StdLib (#2658)
Browse files Browse the repository at this point in the history
  • Loading branch information
vmishenev authored Oct 13, 2022
1 parent 9fe1228 commit c065412
Show file tree
Hide file tree
Showing 14 changed files with 362 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ repositories {
}

dependencies {
implementation "org.jetbrains.dokka:dokka-base:${dokka_it_kotlin_version}"
compileOnly "org.jetbrains.dokka:dokka-core:${dokka_it_kotlin_version}"
implementation "org.jetbrains.dokka:dokka-base:${dokka_it_version}"
compileOnly "org.jetbrains.dokka:dokka-core:${dokka_it_version}"
compileOnly "org.jetbrains.dokka:dokka-analysis:${dokka_it_version}"
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.jvmTarget = "1.8"
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
plugins {
id 'org.jetbrains.kotlin.jvm'
}
description "Dokka Plugin to configure Dokka for stdlib"

repositories {
mavenLocal()
mavenCentral()
}

dependencies {
implementation "org.jetbrains.dokka:dokka-base:${dokka_it_version}"
compileOnly "org.jetbrains.dokka:dokka-core:${dokka_it_version}"
compileOnly "org.jetbrains.dokka:dokka-analysis:${dokka_it_version}"
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
kotlinOptions.jvmTarget = "1.8"
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.jetbrains.dokka.kotlinlang

import org.jetbrains.dokka.base.DokkaBase
import org.jetbrains.dokka.plugability.DokkaPlugin
//import org.jetbrains.dokka.analysis.DokkaAnalysisConfiguration
import org.jetbrains.dokka.analysis.KotlinAnalysis

class StdLibConfigurationPlugin : DokkaPlugin() {
private val dokkaBase by lazy { plugin<DokkaBase>() }
/**
* Uncomment after updating of StdLib in tests
*/
/*val stdLibKotlinAnalysis by extending {
dokkaBase.kotlinAnalysis providing { ctx ->
KotlinAnalysis(
sourceSets = ctx.configuration.sourceSets,
logger = ctx.logger,
analysisConfiguration = DokkaAnalysisConfiguration(ignoreCommonBuiltIns = true)
)
} override dokkaBase.defaultKotlinAnalysis
}*/
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.jetbrains.dokka.kotlinlang.StdLibConfigurationPlugin
10 changes: 6 additions & 4 deletions integration-tests/gradle/projects/stdlib/stdlib.diff
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ diff --git a/build.gradle b/build.gradle
index aa8f21b..dd6a2ae 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,80 +1,444 @@
@@ -1,80 +1,445 @@
+import org.jetbrains.dokka.Platform
+
plugins {
Expand Down Expand Up @@ -76,7 +76,8 @@ index aa8f21b..dd6a2ae 100644

dependencies {
- dokka "org.jetbrains.dokka:dokka-fatjar:$dokka_version"
+ dokkaPlugin project(":dokka-samples-transformer-plugin")
+ dokkaPlugin project(":plugins:dokka-samples-transformer-plugin")
+ dokkaPlugin project(":plugins:dokka-stdlib-configuration-plugin")
}

-final File dokkaHome = new File(buildDir, "dokka-home")
Expand Down Expand Up @@ -559,7 +560,7 @@ diff --git a/settings.gradle b/settings.gradle
index 5209245..bd38b18 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -1,5 +1,19 @@
@@ -1,5 +1,20 @@
+pluginManagement {
+ resolutionStrategy {
+ eachPlugin {
Expand All @@ -579,4 +580,5 @@ index 5209245..bd38b18 100644
include 'kotlin_native'
include 'kotlin_big'
-include 'ant'
+include 'dokka-samples-transformer-plugin'
+include 'plugins:dokka-samples-transformer-plugin'
+include 'plugins:dokka-stdlib-configuration-plugin'
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,20 @@ class StdlibGradleIntegrationTest(override val versions: BuildVersions) : Abstra

override val projectOutputLocation: File by lazy { File(projectDir, "build/dokka/kotlin-stdlib") }

private val currentDokkaVersion: String = "1.5.0"//checkNotNull(System.getenv("DOKKA_VERSION")) // uncomment after updating of StdLib

@BeforeTest
fun prepareProjectFiles() {
val templateProjectDir = File("projects", "stdlib/kotlin-dokka-stdlib")
templateProjectDir.listFiles().orEmpty()
.forEach { topLevelFile -> topLevelFile.copyRecursively(File(projectDir, topLevelFile.name)) }

val pluginDir = File("projects", "stdlib/dokka-samples-transformer-plugin")
val pluginDir = File("projects", "stdlib/plugins")
pluginDir.listFiles().orEmpty()
.forEach { topLevelFile ->
topLevelFile.copyRecursively(
File(
projectDir.resolve("dokka-samples-transformer-plugin").also { it.mkdir() }, topLevelFile.name
projectDir.resolve("plugins").also { it.mkdir() }, topLevelFile.name
)
)
}
Expand All @@ -45,7 +47,7 @@ class StdlibGradleIntegrationTest(override val versions: BuildVersions) : Abstra

@Test
fun execute() {
val result = createGradleRunner("callDokka", "-i", "-s").buildRelaxed()
val result = createGradleRunner("callDokka", "-Pdokka_it_version=$currentDokkaVersion", "-i", "-s").buildRelaxed()

assertEquals(TaskOutcome.SUCCESS, assertNotNull(result.task(":callDokka")).outcome)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ import com.intellij.psi.search.GlobalSearchScope
import org.jetbrains.dokka.Platform
import org.jetbrains.dokka.analysis.resolve.*
import org.jetbrains.kotlin.analyzer.*
import org.jetbrains.kotlin.analyzer.common.CommonAnalysisParameters
import org.jetbrains.kotlin.analyzer.common.CommonDependenciesContainer
import org.jetbrains.kotlin.analyzer.common.CommonPlatformAnalyzerServices
import org.jetbrains.kotlin.analyzer.common.CommonResolverForModuleFactory
import org.jetbrains.kotlin.analyzer.common.*
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.jvm.JvmBuiltIns
Expand Down Expand Up @@ -179,7 +176,7 @@ class AnalysisEnvironment(val messageCollector: MessageCollector, val analysisPl
)
}

fun createResolutionFacade(environment: KotlinCoreEnvironment): Pair<DokkaResolutionFacade, DokkaResolutionFacade> {
fun createResolutionFacade(environment: KotlinCoreEnvironment, ignoreCommonBuiltIns: Boolean = false): Pair<DokkaResolutionFacade, DokkaResolutionFacade> {
val projectContext = ProjectContext(environment.project, "Dokka")
val sourceFiles = environment.getSourceFiles()

Expand Down Expand Up @@ -218,6 +215,15 @@ class AnalysisEnvironment(val messageCollector: MessageCollector, val analysisPl
override val platform: TargetPlatform = targetPlatform
override fun dependencies(): List<ModuleInfo> =
listOf(this, library) + extraModuleDependencies

/**
* Only for common platform ignore BuiltIns for StdLib since it can cause a conflict
* between BuiltIns from a compiler and ones from source code.
*/
override fun dependencyOnBuiltIns(): ModuleInfo.DependencyOnBuiltIns {
return if (analysisPlatform == Platform.common && ignoreCommonBuiltIns) ModuleInfo.DependencyOnBuiltIns.NONE
else super.dependencyOnBuiltIns()
}
}

val sourcesScope = createSourceModuleSearchScope(environment.project, sourceFiles)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.utils.PathUtil

internal fun createEnvironmentAndFacade(
logger: DokkaLogger,
sourceSets: List<DokkaConfiguration.DokkaSourceSet>,
sourceSet: DokkaConfiguration.DokkaSourceSet
sourceSet: DokkaConfiguration.DokkaSourceSet,
analysisConfiguration: DokkaAnalysisConfiguration
): EnvironmentAndFacade =
AnalysisEnvironment(DokkaMessageCollector(logger), sourceSet.analysisPlatform).run {
if (analysisPlatform == Platform.jvm) {
Expand All @@ -28,7 +28,8 @@ internal fun createEnvironmentAndFacade(
loadLanguageVersionSettings(sourceSet.languageVersion, sourceSet.apiVersion)

val environment = createCoreEnvironment()
val (facade, _) = createResolutionFacade(environment)

val (facade, _) = createResolutionFacade(environment, analysisConfiguration.ignoreCommonBuiltIns)
EnvironmentAndFacade(environment, facade)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,27 @@ import org.jetbrains.dokka.model.SourceSetDependent
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.utilities.DokkaLogger

fun KotlinAnalysis(sourceSets: List<DokkaSourceSet>, logger: DokkaLogger): KotlinAnalysis {
fun KotlinAnalysis(sourceSets: List<DokkaSourceSet>, logger: DokkaLogger, analysisConfiguration: DokkaAnalysisConfiguration = DokkaAnalysisConfiguration()): KotlinAnalysis {
val environments = sourceSets.associateWith { sourceSet ->
createEnvironmentAndFacade(
logger = logger,
sourceSets = sourceSets,
sourceSet = sourceSet
sourceSet = sourceSet,
analysisConfiguration = analysisConfiguration
)
}

return KotlinAnalysisImpl(environments)
}

class DokkaAnalysisConfiguration(
/**
* Only for common platform ignore BuiltIns for StdLib since it can cause a conflict
* between BuiltIns from a compiler and ones from source code.
*/
val ignoreCommonBuiltIns: Boolean = false
)

@Deprecated(message = "Construct using list of DokkaSourceSets and logger",
replaceWith = ReplaceWith("KotlinAnalysis(context.configuration.sourceSets, context.logger)")
)
Expand Down
8 changes: 7 additions & 1 deletion plugins/base/src/main/kotlin/DokkaBase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import org.jetbrains.dokka.base.translators.descriptors.ExternalClasslikesTransl
import org.jetbrains.dokka.base.translators.descriptors.ExternalDocumentablesProvider
import org.jetbrains.dokka.base.utils.NoopIntellijLoggerFactory
import org.jetbrains.dokka.plugability.DokkaPlugin
import org.jetbrains.dokka.plugability.configuration
import org.jetbrains.dokka.transformers.documentation.PreMergeDocumentableTransformer
import org.jetbrains.dokka.transformers.pages.PageTransformer

Expand Down Expand Up @@ -186,7 +187,12 @@ class DokkaBase : DokkaPlugin() {
}

val defaultKotlinAnalysis by extending {
kotlinAnalysis providing { ctx -> KotlinAnalysis(ctx.configuration.sourceSets, ctx.logger) }
kotlinAnalysis providing { ctx ->
KotlinAnalysis(
sourceSets = ctx.configuration.sourceSets,
logger = ctx.logger
)
}
}

val locationProvider by extending {
Expand Down
Loading

0 comments on commit c065412

Please sign in to comment.