Skip to content

Commit

Permalink
differentiate between 'all compilations' and 'primary compilations'
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-enko committed Nov 28, 2024
1 parent 0a12fa8 commit fc37735
Showing 1 changed file with 26 additions and 14 deletions.
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

0 comments on commit fc37735

Please sign in to comment.