[Gradle] Add a check that KGP API has consistent KDoc

^KT-58858 In Progress
This commit is contained in:
Yahor Berdnikau
2023-09-13 17:50:30 +02:00
committed by Space Team
parent 01e9ad1680
commit aeaaf6dd8e
17 changed files with 124 additions and 7 deletions
@@ -47,6 +47,14 @@ private const val OPTIONS_PACKAGE_PREFIX = "org.jetbrains.kotlin.gradle.dsl"
private const val IMPLEMENTATION_SUFFIX = "Default" private const val IMPLEMENTATION_SUFFIX = "Default"
private const val IMPLEMENTATION_HELPERS_SUFFIX = "Helper" private const val IMPLEMENTATION_HELPERS_SUFFIX = "Helper"
private const val TOOL_OPTIONS_KDOC = "Common options for all Kotlin platforms' compilations and tools."
private const val COMMON_COMPILER_OPTIONS_KDOC = "Common compiler options for all Kotlin platforms."
private const val JVM_COMPILER_OPTIONS_KDOC = "Compiler options for Kotlin/JVM."
private const val JS_COMPILER_OPTIONS_KDOC = "Compiler options for Kotlin/JS."
private const val NATIVE_COMPILER_OPTIONS_KDOC = "Compiler options for Kotlin Native."
private const val MULTIPLATFORM_COMPILER_OPTION_KDOC = "Compiler options for the Kotlin common platform."
private const val JS_DCE_TOOL_OPTIONS_KDOC = "Options for the Kotlin JavaScript dead code elimination tool."
fun generateKotlinGradleOptions(withPrinterToFile: (targetFile: File, Printer.() -> Unit) -> Unit) { fun generateKotlinGradleOptions(withPrinterToFile: (targetFile: File, Printer.() -> Unit) -> Unit) {
val apiSrcDir = File(GRADLE_API_SRC_DIR) val apiSrcDir = File(GRADLE_API_SRC_DIR)
val srcDir = File(GRADLE_PLUGIN_SRC_DIR) val srcDir = File(GRADLE_PLUGIN_SRC_DIR)
@@ -158,7 +166,8 @@ private fun generateKotlinCommonToolOptions(
withPrinterToFile(fileFromFqName(apiSrcDir, commonInterfaceFqName)) { withPrinterToFile(fileFromFqName(apiSrcDir, commonInterfaceFqName)) {
generateInterface( generateInterface(
commonInterfaceFqName, commonInterfaceFqName,
commonOptions + additionalOptions commonOptions + additionalOptions,
interfaceKDoc = TOOL_OPTIONS_KDOC,
) )
} }
@@ -169,6 +178,7 @@ private fun generateKotlinCommonToolOptions(
commonInterfaceFqName, commonInterfaceFqName,
commonOptions + additionalOptions, commonOptions + additionalOptions,
parentType = null, parentType = null,
interfaceKDoc = TOOL_OPTIONS_KDOC,
) )
} }
@@ -223,6 +233,7 @@ private fun generateKotlinCommonOptions(
commonCompilerInterfaceFqName, commonCompilerInterfaceFqName,
commonCompilerOptions, commonCompilerOptions,
parentType = commonToolGeneratedOptions.optionsName, parentType = commonToolGeneratedOptions.optionsName,
interfaceKDoc = COMMON_COMPILER_OPTIONS_KDOC,
) )
} }
@@ -232,7 +243,8 @@ private fun generateKotlinCommonOptions(
deprecatedCommonCompilerInterfaceFqName, deprecatedCommonCompilerInterfaceFqName,
commonCompilerInterfaceFqName, commonCompilerInterfaceFqName,
commonCompilerOptions, commonCompilerOptions,
parentType = commonToolGeneratedOptions.deprecatedOptionsName parentType = commonToolGeneratedOptions.deprecatedOptionsName,
interfaceKDoc = COMMON_COMPILER_OPTIONS_KDOC,
) )
} }
@@ -289,6 +301,7 @@ private fun generateKotlinJvmOptions(
jvmInterfaceFqName, jvmInterfaceFqName,
jvmOptions, jvmOptions,
parentType = commonCompilerGeneratedOptions.optionsName, parentType = commonCompilerGeneratedOptions.optionsName,
interfaceKDoc = JVM_COMPILER_OPTIONS_KDOC,
) )
} }
@@ -298,7 +311,8 @@ private fun generateKotlinJvmOptions(
deprecatedJvmInterfaceFqName, deprecatedJvmInterfaceFqName,
jvmInterfaceFqName, jvmInterfaceFqName,
jvmOptions, jvmOptions,
parentType = commonCompilerGeneratedOptions.deprecatedOptionsName parentType = commonCompilerGeneratedOptions.deprecatedOptionsName,
interfaceKDoc = JVM_COMPILER_OPTIONS_KDOC,
) )
} }
@@ -353,6 +367,7 @@ private fun generateKotlinJsOptions(
jsInterfaceFqName, jsInterfaceFqName,
jsOptions, jsOptions,
parentType = commonCompilerOptions.optionsName, parentType = commonCompilerOptions.optionsName,
interfaceKDoc = JS_COMPILER_OPTIONS_KDOC,
) )
} }
@@ -363,6 +378,7 @@ private fun generateKotlinJsOptions(
jsInterfaceFqName, jsInterfaceFqName,
jsOptions, jsOptions,
parentType = commonCompilerOptions.deprecatedOptionsName, parentType = commonCompilerOptions.deprecatedOptionsName,
interfaceKDoc = JS_COMPILER_OPTIONS_KDOC,
) )
} }
@@ -417,6 +433,7 @@ private fun generateKotlinNativeOptions(
nativeInterfaceFqName, nativeInterfaceFqName,
nativeOptions, nativeOptions,
parentType = commonCompilerOptions.optionsName, parentType = commonCompilerOptions.optionsName,
interfaceKDoc = NATIVE_COMPILER_OPTIONS_KDOC
) )
} }
@@ -472,6 +489,7 @@ private fun generateJsDceOptions(
jsDceInterfaceFqName, jsDceInterfaceFqName,
jsDceOptions, jsDceOptions,
parentType = commonToolOptions.optionsName, parentType = commonToolOptions.optionsName,
interfaceKDoc = JS_DCE_TOOL_OPTIONS_KDOC,
) )
} }
@@ -482,6 +500,7 @@ private fun generateJsDceOptions(
jsDceInterfaceFqName, jsDceInterfaceFqName,
jsDceOptions, jsDceOptions,
parentType = commonToolOptions.deprecatedOptionsName, parentType = commonToolOptions.deprecatedOptionsName,
interfaceKDoc = JS_DCE_TOOL_OPTIONS_KDOC,
) )
} }
@@ -536,6 +555,7 @@ private fun generateMultiplatformCommonOptions(
multiplatformCommonInterfaceFqName, multiplatformCommonInterfaceFqName,
multiplatformCommonOptions, multiplatformCommonOptions,
parentType = commonCompilerOptions.optionsName, parentType = commonCompilerOptions.optionsName,
interfaceKDoc = MULTIPLATFORM_COMPILER_OPTION_KDOC,
) )
} }
@@ -545,7 +565,8 @@ private fun generateMultiplatformCommonOptions(
deprecatedMultiplatformCommonInterfaceFqName, deprecatedMultiplatformCommonInterfaceFqName,
multiplatformCommonInterfaceFqName, multiplatformCommonInterfaceFqName,
parentType = commonCompilerOptions.deprecatedOptionsName, parentType = commonCompilerOptions.deprecatedOptionsName,
properties = multiplatformCommonOptions properties = multiplatformCommonOptions,
interfaceKDoc = MULTIPLATFORM_COMPILER_OPTION_KDOC,
) )
} }
@@ -613,9 +634,10 @@ private fun Printer.generateInterface(
type: FqName, type: FqName,
properties: List<KProperty1<*, *>>, properties: List<KProperty1<*, *>>,
parentType: FqName? = null, parentType: FqName? = null,
interfaceKDoc: String? = null,
) { ) {
val afterType = parentType?.let { " : $it" } val afterType = parentType?.let { " : $it" }
generateDeclaration("interface", type, afterType = afterType) { generateDeclaration("interface", type, afterType = afterType, declarationKDoc = interfaceKDoc) {
for (property in properties) { for (property in properties) {
println() println()
generateDoc(property) generateDoc(property)
@@ -629,6 +651,7 @@ private fun Printer.generateDeprecatedInterface(
type: FqName, type: FqName,
compilerOptionType: FqName, compilerOptionType: FqName,
properties: List<KProperty1<*, *>>, properties: List<KProperty1<*, *>>,
interfaceKDoc: String? = null,
parentType: FqName? = null, parentType: FqName? = null,
) { ) {
val afterType = parentType?.let { " : $it" } val afterType = parentType?.let { " : $it" }
@@ -639,8 +662,11 @@ private fun Printer.generateDeprecatedInterface(
val deprecatedProperties = properties.filter { it.generateDeprecatedKotlinOption } val deprecatedProperties = properties.filter { it.generateDeprecatedKotlinOption }
// KotlinMultiplatformCommonOptions doesn't have any options, but it is being kept for backward compatibility // KotlinMultiplatformCommonOptions doesn't have any options, but it is being kept for backward compatibility
if (deprecatedProperties.isNotEmpty() || type.asString().endsWith("KotlinMultiplatformCommonOptions")) { if (deprecatedProperties.isNotEmpty() || type.asString().endsWith("KotlinMultiplatformCommonOptions")) {
generateDeclaration(modifier, type, afterType = afterType) { generateDeclaration(modifier, type, afterType = afterType, declarationKDoc = interfaceKDoc) {
println("/**")
println(" * @suppress")
println(" */")
println("${if (parentType != null) "override " else ""}val options: $compilerOptionType") println("${if (parentType != null) "override " else ""}val options: $compilerOptionType")
deprecatedProperties deprecatedProperties
.forEach { .forEach {
@@ -761,6 +787,7 @@ internal fun Printer.generateDeclaration(
modifiers: String, modifiers: String,
type: FqName, type: FqName,
constructorDeclaration: String? = null, constructorDeclaration: String? = null,
declarationKDoc: String? = null,
afterType: String? = null, afterType: String? = null,
generateBody: Printer.() -> Unit generateBody: Printer.() -> Unit
) { ) {
@@ -778,6 +805,14 @@ internal fun Printer.generateDeclaration(
println("package ${type.parent()}") println("package ${type.parent()}")
println() println()
} }
if (declarationKDoc != null) {
println("/**")
declarationKDoc.split('\n').forEach {
println(" * $it")
}
println(" */")
}
print("$modifiers ${type.shortName()}") print("$modifiers ${type.shortName()}")
constructorDeclaration?.let { print(" $it ") } constructorDeclaration?.let { print(" $it ") }
afterType?.let { print("$afterType") } afterType?.let { print("$afterType") }
@@ -7,7 +7,17 @@ plugins {
configureDokkaPublication( configureDokkaPublication(
shouldLinkGradleApi = true, shouldLinkGradleApi = true,
configurePublishingToKotlinlang = true, configurePublishingToKotlinlang = true,
) ) {
dokkaSourceSets.configureEach {
reportUndocumented.set(true)
failOnWarning.set(true)
perPackageOption {
matchingRegex.set("org\\.jetbrains\\.kotlin\\.gradle\\.plugin.*")
suppress.set(true)
}
}
}
dependencies { dependencies {
commonApi(platform(project(":kotlin-gradle-plugins-bom"))) commonApi(platform(project(":kotlin-gradle-plugins-bom")))
@@ -5,6 +5,9 @@
package org.jetbrains.kotlin.gradle.dsl package org.jetbrains.kotlin.gradle.dsl
/**
* Common compiler options for all Kotlin platforms.
*/
interface KotlinCommonCompilerOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerToolOptions { interface KotlinCommonCompilerOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerToolOptions {
/** /**
@@ -5,6 +5,9 @@
package org.jetbrains.kotlin.gradle.dsl package org.jetbrains.kotlin.gradle.dsl
/**
* Common options for all Kotlin platforms' compilations and tools.
*/
interface KotlinCommonCompilerToolOptions { interface KotlinCommonCompilerToolOptions {
/** /**
@@ -5,7 +5,13 @@
package org.jetbrains.kotlin.gradle.dsl package org.jetbrains.kotlin.gradle.dsl
/**
* Common compiler options for all Kotlin platforms.
*/
interface KotlinCommonOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonToolOptions { interface KotlinCommonOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonToolOptions {
/**
* @suppress
*/
override val options: org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions override val options: org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions
private val kotlin.String?.apiVersionCompilerOption get() = if (this != null) org.jetbrains.kotlin.gradle.dsl.KotlinVersion.fromVersion(this) else null private val kotlin.String?.apiVersionCompilerOption get() = if (this != null) org.jetbrains.kotlin.gradle.dsl.KotlinVersion.fromVersion(this) else null
@@ -5,7 +5,13 @@
package org.jetbrains.kotlin.gradle.dsl package org.jetbrains.kotlin.gradle.dsl
/**
* Common options for all Kotlin platforms' compilations and tools.
*/
interface KotlinCommonToolOptions { interface KotlinCommonToolOptions {
/**
* @suppress
*/
val options: org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerToolOptions val options: org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerToolOptions
/** /**
@@ -5,6 +5,9 @@
package org.jetbrains.kotlin.gradle.dsl package org.jetbrains.kotlin.gradle.dsl
/**
* Compiler options for Kotlin/JS.
*/
interface KotlinJsCompilerOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions { interface KotlinJsCompilerOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions {
/** /**
@@ -5,6 +5,9 @@
package org.jetbrains.kotlin.gradle.dsl package org.jetbrains.kotlin.gradle.dsl
/**
* Options for the Kotlin JavaScript dead code elimination tool.
*/
interface KotlinJsDceCompilerToolOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerToolOptions { interface KotlinJsDceCompilerToolOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerToolOptions {
/** /**
@@ -5,7 +5,13 @@
package org.jetbrains.kotlin.gradle.dsl package org.jetbrains.kotlin.gradle.dsl
/**
* Options for the Kotlin JavaScript dead code elimination tool.
*/
interface KotlinJsDceOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonToolOptions { interface KotlinJsDceOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonToolOptions {
/**
* @suppress
*/
override val options: org.jetbrains.kotlin.gradle.dsl.KotlinJsDceCompilerToolOptions override val options: org.jetbrains.kotlin.gradle.dsl.KotlinJsDceCompilerToolOptions
/** /**
@@ -5,7 +5,13 @@
package org.jetbrains.kotlin.gradle.dsl package org.jetbrains.kotlin.gradle.dsl
/**
* Compiler options for Kotlin/JS.
*/
interface KotlinJsOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions { interface KotlinJsOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions {
/**
* @suppress
*/
override val options: org.jetbrains.kotlin.gradle.dsl.KotlinJsCompilerOptions override val options: org.jetbrains.kotlin.gradle.dsl.KotlinJsCompilerOptions
/** /**
@@ -5,6 +5,9 @@
package org.jetbrains.kotlin.gradle.dsl package org.jetbrains.kotlin.gradle.dsl
/**
* Compiler options for Kotlin/JVM.
*/
interface KotlinJvmCompilerOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions { interface KotlinJvmCompilerOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions {
/** /**
@@ -5,7 +5,13 @@
package org.jetbrains.kotlin.gradle.dsl package org.jetbrains.kotlin.gradle.dsl
/**
* Compiler options for Kotlin/JVM.
*/
interface KotlinJvmOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions { interface KotlinJvmOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions {
/**
* @suppress
*/
override val options: org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions override val options: org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions
/** /**
@@ -5,5 +5,8 @@
package org.jetbrains.kotlin.gradle.dsl package org.jetbrains.kotlin.gradle.dsl
/**
* Compiler options for the Kotlin common platform.
*/
interface KotlinMultiplatformCommonCompilerOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions { interface KotlinMultiplatformCommonCompilerOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions {
} }
@@ -5,6 +5,12 @@
package org.jetbrains.kotlin.gradle.dsl package org.jetbrains.kotlin.gradle.dsl
/**
* Compiler options for the Kotlin common platform.
*/
interface KotlinMultiplatformCommonOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions { interface KotlinMultiplatformCommonOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions {
/**
* @suppress
*/
override val options: org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformCommonCompilerOptions override val options: org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformCommonCompilerOptions
} }
@@ -5,6 +5,9 @@
package org.jetbrains.kotlin.gradle.dsl package org.jetbrains.kotlin.gradle.dsl
/**
* Compiler options for Kotlin Native.
*/
interface KotlinNativeCompilerOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions { interface KotlinNativeCompilerOptions : org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions {
/** /**
@@ -67,9 +67,19 @@ interface KotlinCompileTool : PatternFilterable, Task {
@get:OutputDirectory @get:OutputDirectory
val destinationDirectory: DirectoryProperty val destinationDirectory: DirectoryProperty
/**
* Returns the set of exclude patterns.
*
* @return The exclude patterns. Returns an empty set when there are no exclude patterns.
*/
@Internal @Internal
override fun getExcludes(): MutableSet<String> override fun getExcludes(): MutableSet<String>
/**
* Returns the set of include patterns.
*
* @return The include patterns. Returns an empty set when there are no include patterns.
*/
@Internal @Internal
override fun getIncludes(): MutableSet<String> override fun getIncludes(): MutableSet<String>
} }
@@ -664,6 +664,7 @@ fun Project.addBomCheckTask() {
fun Project.configureDokkaPublication( fun Project.configureDokkaPublication(
shouldLinkGradleApi: Boolean = false, shouldLinkGradleApi: Boolean = false,
configurePublishingToKotlinlang: Boolean = false, configurePublishingToKotlinlang: Boolean = false,
additionalDokkaTaskConfiguration: DokkaTask.() -> Unit = {}
) { ) {
val dokkaVersioningPluginVersion = "1.8.10" val dokkaVersioningPluginVersion = "1.8.10"
@@ -715,6 +716,8 @@ fun Project.configureDokkaPublication(
} }
} }
} }
additionalDokkaTaskConfiguration()
} }
tasks.named<Jar>(variantSourceSet.javadocJarTaskName) { tasks.named<Jar>(variantSourceSet.javadocJarTaskName) {
@@ -764,6 +767,8 @@ fun Project.configureDokkaPublication(
} }
} }
} }
additionalDokkaTaskConfiguration()
} }
} }
} }