Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate kord enums with KSP #686

Merged
merged 53 commits into from
Sep 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
f30f7c3
Add KSP processor for enum generation
lukellmann Jul 9, 2022
c110a92
Add options to deprecate `values` property
lukellmann Jul 14, 2022
35dd217
Generate MessageStickerType
lukellmann Jul 14, 2022
1c768a0
Generate ChannelType
lukellmann Jul 17, 2022
eb2be55
Suppress errors for `HIDDEN` entries
lukellmann Jul 19, 2022
c9e845e
Merge branch '0.8.x' into refactor/enum-generation
lukellmann Jul 20, 2022
4ef0576
Use annotation constructors, small other changes
lukellmann Jul 24, 2022
4f97998
Merge branch '0.8.x' into refactor/enum-generation
lukellmann Aug 26, 2022
56360df
Fix errors after merge
lukellmann Aug 26, 2022
f8b5155
Include generated symbols in dokka output
lukellmann Aug 26, 2022
af13bbb
Check ksp output into vcs
lukellmann Aug 26, 2022
f6f9bb2
Rename `kordJvmOptions()` to `applyKordKotlinOptions()`
lukellmann Aug 26, 2022
22c212c
Hardcode deprecation level for values property
lukellmann Aug 26, 2022
3d5b2d8
Wrapper class for annotation arguments
lukellmann Aug 27, 2022
6e86162
Rollback renames
lukellmann Sep 1, 2022
2271de2
Merge branch '0.8.x' into refactor/enum-generation
lukellmann Sep 1, 2022
e1e741b
Generate `AuditLogEvent`
lukellmann Sep 1, 2022
da27677
Generate `AutoModerationRuleTriggerType`, `AutoModerationRuleKeywordP…
lukellmann Sep 1, 2022
5dfba4f
Generate `OverwriteType` and `VideoQualityMode`
lukellmann Sep 2, 2022
c39aaff
Generate `ComponentType`, `ButtonStyle` and `TextInputStyle`
lukellmann Sep 2, 2022
b2ec643
Generate `DiscordConnectionVisibility`
lukellmann Sep 2, 2022
780113e
Generate `GuildFeature`
lukellmann Sep 2, 2022
df417ed
Generate `DefaultMessageNotificationLevel`, `ExplicitContentFilter`, …
lukellmann Sep 2, 2022
ffe5efd
Generate `GuildScheduledEventPrivacyLevel`, `ScheduledEntityType` and…
lukellmann Sep 2, 2022
914f06f
Generate `IntegrationExpireBehavior`
lukellmann Sep 2, 2022
10ffc50
Generate `InviteTargetType`
lukellmann Sep 2, 2022
77d9ae2
Add missing `GuildFeature.Commerce`
lukellmann Sep 2, 2022
c961a98
Generate `MessageType`
lukellmann Sep 2, 2022
2a01023
Generate `MessageActivityType` and `AllowedMentionType`
lukellmann Sep 2, 2022
a5db3bd
Generate `StageInstancePrivacyLevel`
lukellmann Sep 2, 2022
aa49f9a
Generate `UserPremium`
lukellmann Sep 2, 2022
4a6e5d4
Generate `WebhookType`
lukellmann Sep 2, 2022
5c99c0c
Generate `ApplicationCommandType`, `ApplicationCommandOptionType`, `I…
lukellmann Sep 2, 2022
525dc11
Fix test
lukellmann Sep 2, 2022
a21d5c5
Generate `PresenceStatus` and `TeamMembershipState`
lukellmann Sep 2, 2022
a89afc2
Update dokka config for ksp
lukellmann Sep 3, 2022
68612cc
Gradle config formatting
lukellmann Sep 11, 2022
b768ef7
Merge branch '0.8.x' into refactor/enum-generation
lukellmann Sep 11, 2022
e360522
Binary compatibility for `DiscordGuildApplicationCommandPermission.Type`
lukellmann Sep 11, 2022
b06be40
Add `@DslMarker` for scope control in KotlinPoet DSL
lukellmann Sep 11, 2022
c15e526
Remove comments
lukellmann Sep 11, 2022
4dd5635
Binary compatibility for old public serializers
lukellmann Sep 11, 2022
4ea2a61
New order for KotlinPoet DSL
lukellmann Sep 11, 2022
a60166d
Add `toString` to all kord enums
lukellmann Sep 11, 2022
735c464
Put `KordEnumProcessorProvider` and `KordEnumProcessor` into same file
lukellmann Sep 11, 2022
bb7bf54
Suppress "SpellCheckingInspection" and "GrazieInspection" in generate…
lukellmann Sep 11, 2022
100e9be
Add KDoc for `entries` and `value`
lukellmann Sep 11, 2022
1d7fb28
Generate `EmbedType`
lukellmann Sep 12, 2022
e418baf
Merge branch '0.8.x' into refactor/enum-generation
lukellmann Sep 12, 2022
56804bd
Update dokka config
lukellmann Sep 12, 2022
4750273
Remove double slash in dokka source links
lukellmann Sep 12, 2022
6eb6f0e
Merge branch '0.8.x' into refactor/enum-generation
lukellmann Sep 12, 2022
48fe706
`SOURCE` retention for `@KotlinPoetDsl`
lukellmann Sep 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now I included the generated files by removing them from the .gitignore. I'm not sure if this is the way we should do it, @DRSchlaubi had some other ideas before, what do you say?

# 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