Skip to content

Commit e4db702

Browse files
committed
remove NATIVE_ENABLED path
1 parent 3b14351 commit e4db702

File tree

1 file changed

+55
-50
lines changed

1 file changed

+55
-50
lines changed

hll/dynamodb-mapper/dynamodb-mapper/build.gradle.kts

Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import aws.sdk.kotlin.gradle.kmp.NATIVE_ENABLED
76
import com.amazonaws.services.dynamodbv2.local.main.ServerRunner
87
import com.amazonaws.services.dynamodbv2.local.server.DynamoDBProxyServer
98
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
@@ -66,63 +65,69 @@ ksp {
6665
)
6766
arg("op-allowlist", allowlist.joinToString(";"))
6867
}
68+
// FIXME dynamodb-mapper native compilation never worked?
69+
//if (project.NATIVE_ENABLED) {
70+
// // Configure KSP for multiplatform: https://kotlinlang.org/docs/ksp-multiplatform.html
71+
// // https://github.com/google/ksp/issues/963#issuecomment-1894144639
72+
// // https://github.com/google/ksp/issues/965
73+
// dependencies.kspCommonMainMetadata(project(":hll:dynamodb-mapper:dynamodb-mapper-ops-codegen"))
74+
//
75+
// kotlin.sourceSets.commonMain {
76+
// // Wire up the generated source to the commonMain source set
77+
// kotlin.srcDir("build/generated/ksp/metadata/commonMain/kotlin")
78+
// }
79+
//}
80+
81+
// FIXME This is a dirty hack for JVM-only builds which KSP doesn't consider to be "multiplatform".
82+
// Explanation of hack follows in narrative, minimally-opinionated comments.
83+
84+
// Start by invoking the JVM-only KSP configuration
85+
dependencies.kspJvm(project(":hll:dynamodb-mapper:dynamodb-mapper-ops-codegen"))
86+
87+
// Then we need to move the generated source from jvm to common
88+
val moveGenSrc by tasks.registering {
89+
// Can't move src until the src is generated
90+
dependsOn(tasks.named("kspKotlinJvm"))
91+
92+
// Detecting these paths programmatically is complex; just hardcode them
93+
val srcDir = file("build/generated/ksp/jvm/jvmMain")
94+
val destDir = file("build/generated/ksp/common/commonMain")
95+
96+
inputs.dir(srcDir)
97+
outputs.dirs(srcDir, destDir)
6998

70-
if (project.NATIVE_ENABLED) {
71-
// Configure KSP for multiplatform: https://kotlinlang.org/docs/ksp-multiplatform.html
72-
// https://github.com/google/ksp/issues/963#issuecomment-1894144639
73-
// https://github.com/google/ksp/issues/965
74-
dependencies.kspCommonMainMetadata(project(":hll:dynamodb-mapper:dynamodb-mapper-ops-codegen"))
75-
76-
kotlin.sourceSets.commonMain {
77-
// Wire up the generated source to the commonMain source set
78-
kotlin.srcDir("build/generated/ksp/metadata/commonMain/kotlin")
79-
}
80-
} else {
81-
// FIXME This is a dirty hack for JVM-only builds which KSP doesn't consider to be "multiplatform". Explanation of
82-
// hack follows in narrative, minimally-opinionated comments.
83-
84-
// Start by invoking the JVM-only KSP configuration
85-
dependencies.kspJvm(project(":hll:dynamodb-mapper:dynamodb-mapper-ops-codegen"))
86-
87-
// Then we need to move the generated source from jvm to common
88-
val moveGenSrc by tasks.registering {
89-
// Can't move src until the src is generated
90-
dependsOn(tasks.named("kspKotlinJvm"))
91-
92-
// Detecting these paths programmatically is complex; just hardcode them
93-
val srcDir = file("build/generated/ksp/jvm/jvmMain")
94-
val destDir = file("build/generated/ksp/common/commonMain")
95-
96-
inputs.dir(srcDir)
97-
outputs.dirs(srcDir, destDir)
98-
99-
doLast {
100-
if (destDir.exists()) {
101-
// Clean out the existing destination, otherwise move fails
102-
require(destDir.deleteRecursively()) { "Failed to delete $destDir before moving from $srcDir" }
103-
} else {
104-
// Create the destination directories, otherwise move fails
105-
require(destDir.mkdirs()) { "Failed to create path $destDir" }
106-
}
107-
108-
Files.move(srcDir.toPath(), destDir.toPath(), StandardCopyOption.REPLACE_EXISTING)
99+
doLast {
100+
if (destDir.exists()) {
101+
// Clean out the existing destination, otherwise move fails
102+
require(destDir.deleteRecursively()) { "Failed to delete $destDir before moving from $srcDir" }
103+
} else {
104+
// Create the destination directories, otherwise move fails
105+
require(destDir.mkdirs()) { "Failed to create path $destDir" }
109106
}
110-
}
111107

112-
listOf("jvmSourcesJar", "metadataSourcesJar", "jvmProcessResources").forEach {
113-
tasks.named(it) {
114-
dependsOn(moveGenSrc)
115-
}
108+
Files.move(srcDir.toPath(), destDir.toPath(), StandardCopyOption.REPLACE_EXISTING)
116109
}
110+
}
111+
112+
// Ensure all source jar tasks depend on the generated source move
113+
tasks.matching { it.name.endsWith("SourcesJar") || it.name == "sourcesJar" }.configureEach {
114+
dependsOn(moveGenSrc)
115+
}
117116

118-
tasks.withType<KotlinCompilationTask<*>> {
117+
// Also ensure specific tasks depend on the move
118+
listOf("jvmProcessResources", "metadataSourcesJar").forEach { taskName ->
119+
tasks.matching { it.name == taskName }.configureEach {
119120
dependsOn(moveGenSrc)
120121
}
122+
}
121123

122-
// Finally, wire up the generated source to the commonMain source set
123-
kotlin.sourceSets.commonMain {
124-
kotlin.srcDir("build/generated/ksp/common/commonMain/kotlin")
125-
}
124+
tasks.withType<KotlinCompilationTask<*>> {
125+
dependsOn(moveGenSrc)
126+
}
127+
128+
// Finally, wire up the generated source to the commonMain source set
129+
kotlin.sourceSets.commonMain {
130+
kotlin.srcDir("build/generated/ksp/common/commonMain/kotlin")
126131
}
127132

128133
open class DynamoDbLocalInstance : DefaultTask() {

0 commit comments

Comments
 (0)