|
3 | 3 | * SPDX-License-Identifier: Apache-2.0 |
4 | 4 | */ |
5 | 5 |
|
6 | | -import aws.sdk.kotlin.gradle.kmp.NATIVE_ENABLED |
7 | 6 | import com.amazonaws.services.dynamodbv2.local.main.ServerRunner |
8 | 7 | import com.amazonaws.services.dynamodbv2.local.server.DynamoDBProxyServer |
9 | 8 | import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask |
@@ -66,63 +65,69 @@ ksp { |
66 | 65 | ) |
67 | 66 | arg("op-allowlist", allowlist.joinToString(";")) |
68 | 67 | } |
| 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) |
69 | 98 |
|
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" } |
109 | 106 | } |
110 | | - } |
111 | 107 |
|
112 | | - listOf("jvmSourcesJar", "metadataSourcesJar", "jvmProcessResources").forEach { |
113 | | - tasks.named(it) { |
114 | | - dependsOn(moveGenSrc) |
115 | | - } |
| 108 | + Files.move(srcDir.toPath(), destDir.toPath(), StandardCopyOption.REPLACE_EXISTING) |
116 | 109 | } |
| 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 | +} |
117 | 116 |
|
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 { |
119 | 120 | dependsOn(moveGenSrc) |
120 | 121 | } |
| 122 | +} |
121 | 123 |
|
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") |
126 | 131 | } |
127 | 132 |
|
128 | 133 | open class DynamoDbLocalInstance : DefaultTask() { |
|
0 commit comments