Skip to content

Commit

Permalink
Generate kord enums with KSP (#686)
Browse files Browse the repository at this point in the history
* Add KSP processor for enum generation

* Add options to deprecate `values` property

* Generate MessageStickerType

* Generate ChannelType

* Suppress errors for `HIDDEN` entries

* Use annotation constructors, small other changes

* Fix errors after merge

* Include generated symbols in dokka output

* Check ksp output into vcs

* Rename `kordJvmOptions()` to `applyKordKotlinOptions()`

* Hardcode deprecation level for values property

* Wrapper class for annotation arguments

* Rollback renames

* Generate `AuditLogEvent`

* Generate `AutoModerationRuleTriggerType`, `AutoModerationRuleKeywordPresetType`, `AutoModerationRuleEventType` and `AutoModerationActionType`

* Generate `OverwriteType` and `VideoQualityMode`

* Generate `ComponentType`, `ButtonStyle` and `TextInputStyle`

* Generate `DiscordConnectionVisibility`

* Generate `GuildFeature`

* Generate `DefaultMessageNotificationLevel`, `ExplicitContentFilter`, `ExplicitContentFilter`, `VerificationLevel`, `NsfwLevel` and `PremiumTier`

* Generate `GuildScheduledEventPrivacyLevel`, `ScheduledEntityType` and `GuildScheduledEventStatus`

* Generate `IntegrationExpireBehavior`

* Generate `InviteTargetType`

* Add missing `GuildFeature.Commerce`

* Generate `MessageType`

* Generate `MessageActivityType` and `AllowedMentionType`

* Generate `StageInstancePrivacyLevel`

* Generate `UserPremium`

* Generate `WebhookType`

* Generate `ApplicationCommandType`, `ApplicationCommandOptionType`, `InteractionType`, `InteractionResponseType` and `ApplicationCommandPermissionType`

* Fix test

* Generate `PresenceStatus` and `TeamMembershipState`

* Update dokka config for ksp

* Gradle config formatting

* Binary compatibility for `DiscordGuildApplicationCommandPermission.Type`

* Add `@DslMarker` for scope control in KotlinPoet DSL

* Remove comments

* Binary compatibility for old public serializers

* New order for KotlinPoet DSL

* Add `toString` to all kord enums

* Put `KordEnumProcessorProvider` and `KordEnumProcessor` into same file

* Suppress "SpellCheckingInspection" and "GrazieInspection" in generated files

* Add KDoc for `entries` and `value`

* Generate `EmbedType`

* Update dokka config

* Remove double slash in dokka source links

* `SOURCE` retention for `@KotlinPoetDsl`
  • Loading branch information
lukellmann authored Sep 18, 2022
1 parent 946610e commit 10d8fc8
Show file tree
Hide file tree
Showing 81 changed files with 6,423 additions and 1,743 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
.gradle/
.idea/
build/
out/
dokka/

**/build/*
!**/build/generated/
# re-exclude BuildConfigGenerated.kt
common/build/generated/source/buildConfig/main/main/dev/kord/common/BuildConfigGenerated.kt
4 changes: 4 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ tasks {
outputDirectory.set(dokkaOutputDir)
}
}

apiValidation {
ignoredProjects += listOf("ksp-annotations", "ksp-processors")
}
1 change: 1 addition & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ dependencies {
implementation(kotlin("serialization", kotlinVersion))
implementation("org.jetbrains.dokka", "dokka-gradle-plugin", "1.7.10")
implementation("org.jetbrains.kotlinx", "atomicfu-gradle-plugin", "0.18.3")
implementation("com.google.devtools.ksp", "symbol-processing-gradle-plugin", "1.7.10-1.0.6")
implementation(gradleApi())
}
8 changes: 8 additions & 0 deletions buildSrc/src/main/kotlin/Compiler.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions

object CompilerArguments {
const val time = "-opt-in=kotlin.time.ExperimentalTime"
const val contracts = "-opt-in=kotlin.contracts.ExperimentalContracts"
Expand All @@ -14,3 +16,9 @@ object Jvm {
const val targetString = "1.8"
const val targetInt = 8
}

fun KotlinJvmOptions.applyKordKotlinOptions() {
jvmTarget = Jvm.targetString
allWarningsAsErrors = true
freeCompilerArgs += CompilerArguments.progressive
}
22 changes: 22 additions & 0 deletions buildSrc/src/main/kotlin/kord-internal-module.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm")
}

repositories {
mavenCentral()
}

tasks {
withType<JavaCompile> {
sourceCompatibility = Jvm.targetString
targetCompatibility = Jvm.targetString
}

withType<KotlinCompile> {
kotlinOptions {
applyKordKotlinOptions()
}
}
}
36 changes: 26 additions & 10 deletions buildSrc/src/main/kotlin/kord-module.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ plugins {
kotlin("plugin.serialization")
id("org.jetbrains.dokka")
id("kotlinx-atomicfu")
id("com.google.devtools.ksp")
`maven-publish`
}

Expand All @@ -24,8 +25,13 @@ dependencies {
kotlin {
explicitApi()

// allow ExperimentalCoroutinesApi for `runTest {}`
sourceSets["test"].languageSettings.optIn("kotlinx.coroutines.ExperimentalCoroutinesApi")
sourceSets {
// mark ksp src dir
main { kotlin.srcDir("build/generated/ksp/main/kotlin") }

// allow `ExperimentalCoroutinesApi` for `runTest {}`
test { languageSettings.optIn("kotlinx.coroutines.ExperimentalCoroutinesApi") }
}
}

tasks {
Expand All @@ -36,17 +42,14 @@ tasks {

withType<KotlinCompile> {
kotlinOptions {
jvmTarget = Jvm.targetString
allWarningsAsErrors = true
freeCompilerArgs = listOf(
applyKordKotlinOptions()
freeCompilerArgs += listOf(
CompilerArguments.time,
CompilerArguments.contracts,

CompilerArguments.kordPreview,
CompilerArguments.kordExperimental,
CompilerArguments.kordVoice,

CompilerArguments.progressive,
)
}
}
Expand All @@ -60,15 +63,30 @@ tasks {
withType<AbstractDokkaLeafTask> {
// see https://kotlin.github.io/dokka/<dokka version>/user_guide/gradle/usage/#configuration-options

// make sure ksp generates files before building docs
dependsOn(compileKotlin)

failOnWarning.set(true)

dokkaSourceSets.configureEach {

jdkVersion.set(Jvm.targetInt)

val baseRemoteUrl =
"https://github.com/kordlib/kord/blob/${Library.commitHashOrDefault("0.8.x")}/${project.name}"

sourceLink {
localDirectory.set(file("src/main/kotlin"))
remoteUrl.set(URL("https://github.com/kordlib/kord/blob/${Library.commitHashOrDefault("0.8.x")}/${project.name}/src/main/kotlin/"))
remoteUrl.set(URL("$baseRemoteUrl/src/main/kotlin"))
remoteLineSuffix.set("#L")
}

// config for files generated by ksp
suppressGeneratedFiles.set(false)
sourceLink {
// will fail if dir doesn't exist -> always create it, won't harm if not needed
localDirectory.set(file("build/generated/ksp/main/kotlin").apply { mkdirs() })
remoteUrl.set(URL("$baseRemoteUrl/build/generated/ksp/main/kotlin"))
remoteLineSuffix.set("#L")
}

Expand All @@ -89,8 +107,6 @@ tasks {
from(sourceSets.main.get().allSource)
}

val dokkaHtml by getting

val dokkaJar by registering(Jar::class) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = "Assembles Kotlin docs with Dokka"
Expand Down
Loading

0 comments on commit 10d8fc8

Please sign in to comment.