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

Fix ksp code generation for non-jvm target #141

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.

---
## master
* Fix ksp code generation for non-jvm target

## 2.13.0
* Refactoring publication and configuration logic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,38 @@ class MockingbirdPluginKspDelegate {
// in commonTest. The plugin will add this the code generated at point 1 as source set for common test so that
// this code will be available for each platform and resolvable by the IDE
target.extensions.configure(KotlinMultiplatformExtension::class.java) {
val firstTargetName = targets.first { it.targetName != "metadata" }.targetName
val selectedTargetName =
targets.firstOrNull { it.targetName == "jvm" }?.targetName ?: firstTargetName
sourceSets.getByName("commonTest") {
kotlin.srcDir("build/generated/ksp/$selectedTargetName/${selectedTargetName}Test/kotlin")
val selectedTarget =
targets.firstOrNull { it.preset?.name == "jvm" }
?: targets.firstOrNull { it.preset?.name == "android" }
?: targets.first { it.preset?.name != "metadata" }
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not rely on metadata without bothering with jvm and/or android?


val srcDir = if (selectedTarget.preset!!.name == "android") {
"build/generated/ksp/${selectedTarget.name}/${selectedTarget.name}UnitTestRelease/kotlin"
} else {
"build/generated/ksp/${selectedTarget.name}/${selectedTarget.name}Test/kotlin"
}

sourceSets.getByName("commonTest") { kotlin.srcDir(srcDir) }

val kspConfiguration = if (selectedTarget.preset!!.name == "android") {
"ksp${selectedTarget.name.capitalized()}TestRelease"
} else {
"ksp${selectedTarget.name.capitalized()}Test"
}

target.dependencies {
"ksp${selectedTargetName.capitalized()}Test"("com.careem.mockingbird:mockingbird-processor:${BuildConfig.VERSION}")
kspConfiguration("com.careem.mockingbird:mockingbird-processor:${BuildConfig.VERSION}")
}

val kspTask = if (selectedTarget.preset!!.name == "android") {
"kspReleaseUnitTestKotlin${selectedTarget.name.capitalized()}"
} else {
"kspTestKotlin${selectedTarget.name.capitalized()}"
}

tasks.forEach { task ->
if (task.name.contains("Test") && (task is KotlinCompile<*>)) {
task.dependsOn("kspTestKotlin${selectedTargetName.capitalized()}")
task.dependsOn(kspTask)
}
}
}
Expand Down