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

KT-71784 Fix classpath for KMP shared source sets #3942

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class AndroidComposeIT {
val expectedFileTree = expectedHtml.toTreeString()
val actualFileTree = actualHtmlDir.toTreeString()
withClue((actualFileTree to expectedFileTree).sideBySide()) {
expectedFileTree shouldBe actualFileTree
actualFileTree shouldBe expectedFileTree

actualHtmlDir shouldBeADirectoryWithSameContentAs expectedHtml
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class AndroidProjectIT {
val expectedFileTree = expectedHtml.toTreeString()
val actualFileTree = actualHtmlDir.toTreeString()
withClue((actualFileTree to expectedFileTree).sideBySide()) {
expectedFileTree shouldBe actualFileTree
actualFileTree shouldBe expectedFileTree

actualHtmlDir shouldBeADirectoryWithSameContentAs expectedHtml
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class ExampleProjectsTest {
withClue("expect file trees are the same") {
val expectedFileTree = expectedDataDir.toTreeString()
val actualFileTree = dokkaOutputDir.toTreeString()
expectedFileTree shouldBe actualFileTree
actualFileTree shouldBe expectedFileTree
}

withClue("expect directories are the same") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ abstract class KotlinAdapter @Inject constructor(
projectPath: String,
details: KotlinSourceSetDetails,
): Provider<KotlinPlatform> {
return details.compilations.map { compilations: List<KotlinCompilationDetails> ->
return details.allCompilations.map { compilations: List<KotlinCompilationDetails> ->
val allPlatforms = compilations
// Exclude metadata compilations: they are always KotlinPlatform.Common, which isn't relevant here.
// Dokka only cares about the compilable KMP targets of a KotlinSourceSet.
Expand All @@ -193,7 +193,7 @@ abstract class KotlinAdapter @Inject constructor(
private fun determineClasspath(
details: KotlinSourceSetDetails
): Provider<FileCollection> {
return details.compilations.map { compilations: List<KotlinCompilationDetails> ->
return details.primaryCompilations.map { compilations: List<KotlinCompilationDetails> ->
val classpath = objects.fileCollection()

if (compilations.isNotEmpty()) {
Expand Down Expand Up @@ -258,7 +258,8 @@ private data class KotlinCompilationDetails(
val isMetadata: Boolean,
/** [KotlinCompilation.platformType] name. */
val kotlinPlatform: KotlinPlatform,
val allKotlinSourceSetsNames: Set<String>,
val primarySourceSetNames: Set<String>,
val allSourceSetNames: Set<String>,
/**
* Whether the compilation is published or not.
*
Expand All @@ -267,7 +268,7 @@ private data class KotlinCompilationDetails(
* (E.g. 'main' compilations are published, 'test' compilations are not.)
*/
val publishedCompilation: Boolean,
/** [KotlinCompilation.defaultSourceSet] → [KotlinSourceSet.dependsOn] names. */
/** [KotlinCompilation.kotlinSourceSets] → [KotlinSourceSet.dependsOn] names. */
val dependentSourceSetNames: Set<String>,
val compilationClasspath: FileCollection,
/** [KotlinCompilation.defaultSourceSet] name. */
Expand Down Expand Up @@ -305,19 +306,19 @@ private class KotlinCompilationDetailsBuilder(
private fun createCompilationDetails(
compilation: KotlinCompilation<*>,
): KotlinCompilationDetails {
val allKotlinSourceSetsNames =
compilation.allKotlinSourceSets.map { it.name } + compilation.defaultSourceSet.name

val dependentSourceSetNames =
compilation.defaultSourceSet.dependsOn.map { it.name }
val primarySourceSetNames = compilation.kotlinSourceSets.map { it.name }
val allSourceSetNames = compilation.allKotlinSourceSets.map { it.name }
val dependentSourceSetNames = compilation.kotlinSourceSets.flatMap { it.dependsOn }.map { it.name }

val compilationClasspath: FileCollection =
collectKotlinCompilationClasspath(compilation = compilation)

return KotlinCompilationDetails(
target = compilation.target.name,
kotlinPlatform = KotlinPlatform.fromString(compilation.platformType.name),
allKotlinSourceSetsNames = allKotlinSourceSetsNames.toSet(),
primarySourceSetNames = primarySourceSetNames.toSet(),
allSourceSetNames = allSourceSetNames.toSet(),
publishedCompilation = compilation.isPublished(),
dependentSourceSetNames = dependentSourceSetNames.toSet(),
compilationClasspath = compilationClasspath,
Expand Down Expand Up @@ -476,11 +477,14 @@ private abstract class KotlinSourceSetDetails @Inject constructor(
abstract val sourceDirectoriesOfDependents: ConfigurableFileCollection

/** The specific compilations used to build this source set. */
abstract val compilations: ListProperty<KotlinCompilationDetails>
abstract val primaryCompilations: ListProperty<KotlinCompilationDetails>

/** Associated compilations that this [KotlinSourceSet] participates in. */
abstract val allCompilations: ListProperty<KotlinCompilationDetails>

/** Estimate if this Kotlin source set contains 'published' sources. */
fun isPublishedSourceSet(): Provider<Boolean> =
compilations.map { values ->
allCompilations.map { values ->
values.any { it.publishedCompilation }
}

Expand Down Expand Up @@ -518,6 +522,7 @@ private class KotlinSourceSetDetailsBuilder(
return sourceSetDetails
}

/** Register a [DokkaSourceSetSpec]. */
private fun NamedDomainObjectContainer<KotlinSourceSetDetails>.register(
kotlinSourceSet: KotlinSourceSet,
allKotlinCompilationDetails: ListProperty<KotlinCompilationDetails>,
Expand All @@ -530,9 +535,15 @@ private class KotlinSourceSetDetailsBuilder(
kotlinSourceSet.kotlin.sourceDirectories.filter { it.exists() }
}

val compilations = allKotlinCompilationDetails.map { allCompilations ->
val primaryCompilations = allKotlinCompilationDetails.map { primaryCompilations ->
primaryCompilations.filter { compilation ->
kotlinSourceSet.name in compilation.primarySourceSetNames
}
}

val allCompilations = allKotlinCompilationDetails.map { allCompilations ->
allCompilations.filter { compilation ->
kotlinSourceSet.name in compilation.allKotlinSourceSetsNames
kotlinSourceSet.name in compilation.allSourceSetNames
}
}

Expand Down Expand Up @@ -565,7 +576,8 @@ private class KotlinSourceSetDetailsBuilder(
this.dependentSourceSetIds.addAll(dependentSourceSetIds)
this.sourceDirectories.from(extantSourceDirectories)
this.sourceDirectoriesOfDependents.from(sourceDirectoriesOfDependents)
this.compilations.addAll(compilations)
this.primaryCompilations.addAll(primaryCompilations)
this.allCompilations.addAll(allCompilations)
}
}

Expand Down
Loading