Skip to content

Commit

Permalink
enabling formatting generated-sources after it processKDocsMain runs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jolanrensen committed Jun 27, 2024
1 parent 2320a28 commit f38b671
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 24 deletions.
66 changes: 42 additions & 24 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,34 @@ fun pathOf(vararg parts: String) = parts.joinToString(File.separator)
val processKDocsMainSources = (kotlinMainSources + kotlinTestSources)
.filterNot { pathOf("build", "generated") in it.path }

// sourceset of the generated sources as a result of `processKDocsMain`, this will create linter tasks
val generatedSources by kotlin.sourceSets.creating {
kotlin {
setSrcDirs(
listOf(
"build/generated/ksp/main/kotlin/",
"core/build/generatedSrc",
"$generatedSourcesFolderName/src/main/kotlin",
"$generatedSourcesFolderName/src/main/java",
),
)
}
}

// Task to generate the processed documentation
val processKDocsMain by creatingProcessDocTask(processKDocsMainSources) {
target = file(generatedSourcesFolderName)
arguments += ARG_DOC_PROCESSOR_LOG_NOT_FOUND to false

// false, so `runKtlintFormatOverGeneratedSourcesSourceSet` can format the output
outputReadOnly = false

exportAsHtml {
dir = file("../docs/StardustDocs/snippets/kdocs")
}
task {
group = "KDocs"
// making sure it always runs, so targets is set
outputs.upToDateWhen { false }
finalizedBy("runKtlintFormatOverGeneratedSourcesSourceSet")
}
}

Expand All @@ -210,37 +227,23 @@ idea {
}
}

// if `processKDocsMain` runs, the Jar tasks must run after it so the generated-sources are there
tasks.withType<Jar> {
mustRunAfter(tasks.generateKeywordsSrc, processKDocsMain)
}

// If `changeJarTask` is run, modify all Jar tasks such that before running the Kotlin sources are set to
// the target of `processKdocMain`, and they are returned to normal afterward.
// This is usually only done when publishing
val changeJarTask by tasks.creating {
outputs.upToDateWhen { false }
doFirst {
tasks.withType<Jar> {
dependsOn(processKDocsMain)
doFirst {
val targets = processKDocsMain.targets
require(targets.toList().isNotEmpty()) {
logger.error("`processKDocsMain.targets` was empty, did it run before this task?")
require(
generatedSources.kotlin.srcDirs
.toList()
.isNotEmpty(),
) {
logger.error("`processKDocsMain`'s outputs are empty, did `processKDocsMain` run before this task?")
}
val srcDirs = targets
.filterNot {
pathOf("src", "test", "kotlin") in it.path ||
pathOf("src", "test", "java") in it.path
} // filter out test sources again
.plus(
kotlinMainSources.filter {
pathOf("build", "generated") in it.path
},
) // Include generated sources (which were excluded above)

kotlin.sourceSets.main {
kotlin.setSrcDirs(srcDirs)
kotlin.setSrcDirs(generatedSources.kotlin.srcDirs)
}
logger.lifecycle("$this is run with modified sources: \"$generatedSourcesFolderName\"")
}
Expand All @@ -254,6 +257,11 @@ val changeJarTask by tasks.creating {
}
}

// if `processKDocsMain` runs, the Jar tasks must run after it so the generated-sources are there
tasks.withType<Jar> {
mustRunAfter(changeJarTask, tasks.generateKeywordsSrc, processKDocsMain)
}

// modify all publishing tasks to depend on `changeJarTask` so the sources are swapped out with generated sources
tasks.named { it.startsWith("publish") }.configureEach {
dependsOn(processKDocsMain, changeJarTask)
Expand Down Expand Up @@ -325,6 +333,11 @@ tasks.runKtlintFormatOverTestSourceSet {
dependsOn("kspTestKotlin")
}

tasks.named("runKtlintFormatOverGeneratedSourcesSourceSet") {
dependsOn(tasks.generateKeywordsSrc)
dependsOn("kspKotlin")
}

tasks.runKtlintCheckOverMainSourceSet {
dependsOn(tasks.generateKeywordsSrc)
dependsOn("kspKotlin")
Expand All @@ -335,6 +348,11 @@ tasks.runKtlintCheckOverTestSourceSet {
dependsOn("kspTestKotlin")
}

tasks.named("runKtlintCheckOverGeneratedSourcesSourceSet") {
dependsOn(tasks.generateKeywordsSrc)
dependsOn("kspKotlin")
}

kotlin {
explicitApi()
}
Expand All @@ -357,7 +375,7 @@ tasks.test {
listOf(
"org.jetbrains.kotlinx.dataframe.jupyter.*",
"org.jetbrains.kotlinx.dataframe.jupyter.SampleNotebooksTests",
)
),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.jetbrains.kotlinx.dataframe.columns.ColumnPath
import org.jetbrains.kotlinx.dataframe.columns.ColumnSet
import org.jetbrains.kotlinx.dataframe.columns.SingleColumn
import org.jetbrains.kotlinx.dataframe.documentation.DslGrammarTemplateColumnsSelectionDsl.DslGrammarTemplate
import org.jetbrains.kotlinx.dataframe.documentation.ExcludeFromSources
import org.jetbrains.kotlinx.dataframe.documentation.Indent
import org.jetbrains.kotlinx.dataframe.documentation.LineBreak
import org.jetbrains.kotlinx.dataframe.impl.columns.TransformableColumnSet
Expand Down Expand Up @@ -112,6 +113,7 @@ public interface ColumnNameFiltersColumnsSelectionDsl {
* @see [nameStartsWith\]
* {@set [ExtraParamsArg]}
*/
@ExcludeFromSources
private interface CommonNameContainsDocs {

/* Example to give */
Expand All @@ -131,6 +133,7 @@ public interface ColumnNameFiltersColumnsSelectionDsl {
* @param [ignoreCase\] `true` to ignore character case when comparing strings. By default `false`.
* }
*/
@ExcludeFromSources
private interface NameContainsTextDocs

/**
Expand Down Expand Up @@ -303,6 +306,7 @@ public interface ColumnNameFiltersColumnsSelectionDsl {
* @return A [ColumnSet] containing
* all columns {@get [CommonNameStartsEndsDocs.NounArg]} with {@get [CommonNameStartsEndsDocs.ArgumentArg]} in their name.
*/
@ExcludeFromSources
private interface CommonNameStartsEndsDocs {

/* "Starts" or "Ends" */
Expand Down Expand Up @@ -340,6 +344,7 @@ public interface ColumnNameFiltersColumnsSelectionDsl {
* @see [nameEndsWith\]
* @see [nameContains\]
*/
@ExcludeFromSources
private interface CommonNameStartsWithDocs

@Deprecated("Use nameStartsWith instead", ReplaceWith("this.nameStartsWith(prefix)"))
Expand Down Expand Up @@ -443,6 +448,7 @@ public interface ColumnNameFiltersColumnsSelectionDsl {
* @see [nameStartsWith\]
* @see [nameContains\]
*/
@ExcludeFromSources
private interface CommonNameEndsWithDocs

@Deprecated("Use nameEndsWith instead", ReplaceWith("this.nameEndsWith(suffix)"))
Expand Down

0 comments on commit f38b671

Please sign in to comment.