Skip to content

Commit f38b671

Browse files
committed
enabling formatting generated-sources after it processKDocsMain runs
1 parent 2320a28 commit f38b671

File tree

2 files changed

+48
-24
lines changed

2 files changed

+48
-24
lines changed

core/build.gradle.kts

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -189,17 +189,34 @@ fun pathOf(vararg parts: String) = parts.joinToString(File.separator)
189189
val processKDocsMainSources = (kotlinMainSources + kotlinTestSources)
190190
.filterNot { pathOf("build", "generated") in it.path }
191191

192+
// sourceset of the generated sources as a result of `processKDocsMain`, this will create linter tasks
193+
val generatedSources by kotlin.sourceSets.creating {
194+
kotlin {
195+
setSrcDirs(
196+
listOf(
197+
"build/generated/ksp/main/kotlin/",
198+
"core/build/generatedSrc",
199+
"$generatedSourcesFolderName/src/main/kotlin",
200+
"$generatedSourcesFolderName/src/main/java",
201+
),
202+
)
203+
}
204+
}
205+
192206
// Task to generate the processed documentation
193207
val processKDocsMain by creatingProcessDocTask(processKDocsMainSources) {
194208
target = file(generatedSourcesFolderName)
195209
arguments += ARG_DOC_PROCESSOR_LOG_NOT_FOUND to false
210+
211+
// false, so `runKtlintFormatOverGeneratedSourcesSourceSet` can format the output
212+
outputReadOnly = false
213+
196214
exportAsHtml {
197215
dir = file("../docs/StardustDocs/snippets/kdocs")
198216
}
199217
task {
200218
group = "KDocs"
201-
// making sure it always runs, so targets is set
202-
outputs.upToDateWhen { false }
219+
finalizedBy("runKtlintFormatOverGeneratedSourcesSourceSet")
203220
}
204221
}
205222

@@ -210,37 +227,23 @@ idea {
210227
}
211228
}
212229

213-
// if `processKDocsMain` runs, the Jar tasks must run after it so the generated-sources are there
214-
tasks.withType<Jar> {
215-
mustRunAfter(tasks.generateKeywordsSrc, processKDocsMain)
216-
}
217-
218230
// If `changeJarTask` is run, modify all Jar tasks such that before running the Kotlin sources are set to
219231
// the target of `processKdocMain`, and they are returned to normal afterward.
220232
// This is usually only done when publishing
221233
val changeJarTask by tasks.creating {
222234
outputs.upToDateWhen { false }
223235
doFirst {
224236
tasks.withType<Jar> {
225-
dependsOn(processKDocsMain)
226237
doFirst {
227-
val targets = processKDocsMain.targets
228-
require(targets.toList().isNotEmpty()) {
229-
logger.error("`processKDocsMain.targets` was empty, did it run before this task?")
238+
require(
239+
generatedSources.kotlin.srcDirs
240+
.toList()
241+
.isNotEmpty(),
242+
) {
243+
logger.error("`processKDocsMain`'s outputs are empty, did `processKDocsMain` run before this task?")
230244
}
231-
val srcDirs = targets
232-
.filterNot {
233-
pathOf("src", "test", "kotlin") in it.path ||
234-
pathOf("src", "test", "java") in it.path
235-
} // filter out test sources again
236-
.plus(
237-
kotlinMainSources.filter {
238-
pathOf("build", "generated") in it.path
239-
},
240-
) // Include generated sources (which were excluded above)
241-
242245
kotlin.sourceSets.main {
243-
kotlin.setSrcDirs(srcDirs)
246+
kotlin.setSrcDirs(generatedSources.kotlin.srcDirs)
244247
}
245248
logger.lifecycle("$this is run with modified sources: \"$generatedSourcesFolderName\"")
246249
}
@@ -254,6 +257,11 @@ val changeJarTask by tasks.creating {
254257
}
255258
}
256259

260+
// if `processKDocsMain` runs, the Jar tasks must run after it so the generated-sources are there
261+
tasks.withType<Jar> {
262+
mustRunAfter(changeJarTask, tasks.generateKeywordsSrc, processKDocsMain)
263+
}
264+
257265
// modify all publishing tasks to depend on `changeJarTask` so the sources are swapped out with generated sources
258266
tasks.named { it.startsWith("publish") }.configureEach {
259267
dependsOn(processKDocsMain, changeJarTask)
@@ -325,6 +333,11 @@ tasks.runKtlintFormatOverTestSourceSet {
325333
dependsOn("kspTestKotlin")
326334
}
327335

336+
tasks.named("runKtlintFormatOverGeneratedSourcesSourceSet") {
337+
dependsOn(tasks.generateKeywordsSrc)
338+
dependsOn("kspKotlin")
339+
}
340+
328341
tasks.runKtlintCheckOverMainSourceSet {
329342
dependsOn(tasks.generateKeywordsSrc)
330343
dependsOn("kspKotlin")
@@ -335,6 +348,11 @@ tasks.runKtlintCheckOverTestSourceSet {
335348
dependsOn("kspTestKotlin")
336349
}
337350

351+
tasks.named("runKtlintCheckOverGeneratedSourcesSourceSet") {
352+
dependsOn(tasks.generateKeywordsSrc)
353+
dependsOn("kspKotlin")
354+
}
355+
338356
kotlin {
339357
explicitApi()
340358
}
@@ -357,7 +375,7 @@ tasks.test {
357375
listOf(
358376
"org.jetbrains.kotlinx.dataframe.jupyter.*",
359377
"org.jetbrains.kotlinx.dataframe.jupyter.SampleNotebooksTests",
360-
)
378+
),
361379
)
362380
}
363381
}

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/columnNameFilters.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import org.jetbrains.kotlinx.dataframe.columns.ColumnPath
88
import org.jetbrains.kotlinx.dataframe.columns.ColumnSet
99
import org.jetbrains.kotlinx.dataframe.columns.SingleColumn
1010
import org.jetbrains.kotlinx.dataframe.documentation.DslGrammarTemplateColumnsSelectionDsl.DslGrammarTemplate
11+
import org.jetbrains.kotlinx.dataframe.documentation.ExcludeFromSources
1112
import org.jetbrains.kotlinx.dataframe.documentation.Indent
1213
import org.jetbrains.kotlinx.dataframe.documentation.LineBreak
1314
import org.jetbrains.kotlinx.dataframe.impl.columns.TransformableColumnSet
@@ -112,6 +113,7 @@ public interface ColumnNameFiltersColumnsSelectionDsl {
112113
* @see [nameStartsWith\]
113114
* {@set [ExtraParamsArg]}
114115
*/
116+
@ExcludeFromSources
115117
private interface CommonNameContainsDocs {
116118

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

136139
/**
@@ -303,6 +306,7 @@ public interface ColumnNameFiltersColumnsSelectionDsl {
303306
* @return A [ColumnSet] containing
304307
* all columns {@get [CommonNameStartsEndsDocs.NounArg]} with {@get [CommonNameStartsEndsDocs.ArgumentArg]} in their name.
305308
*/
309+
@ExcludeFromSources
306310
private interface CommonNameStartsEndsDocs {
307311

308312
/* "Starts" or "Ends" */
@@ -340,6 +344,7 @@ public interface ColumnNameFiltersColumnsSelectionDsl {
340344
* @see [nameEndsWith\]
341345
* @see [nameContains\]
342346
*/
347+
@ExcludeFromSources
343348
private interface CommonNameStartsWithDocs
344349

345350
@Deprecated("Use nameStartsWith instead", ReplaceWith("this.nameStartsWith(prefix)"))
@@ -443,6 +448,7 @@ public interface ColumnNameFiltersColumnsSelectionDsl {
443448
* @see [nameStartsWith\]
444449
* @see [nameContains\]
445450
*/
451+
@ExcludeFromSources
446452
private interface CommonNameEndsWithDocs
447453

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

0 commit comments

Comments
 (0)