Skip to content

Commit beb9b35

Browse files
committed
Fixed full KMP + Android support
1 parent 40352ec commit beb9b35

File tree

10 files changed

+302
-272
lines changed

10 files changed

+302
-272
lines changed

gradle-plugin/build.gradle.kts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ dependencies {
4747
}
4848

4949
tasks.test {
50-
val forwardOutput: Boolean = (properties.getOrDefault("gradle.test.forward.output", "false")
51-
as String).toBooleanStrictOrNull() ?: false
52-
53-
systemProperty("gradle.test.forward.output", forwardOutput)
54-
5550
useJUnitPlatform()
5651

5752
val protocGen = gradle.includedBuild("protoc-gen")

gradle-plugin/src/main/kotlin/kotlinx/rpc/buf/tasks/BufGenerateTask.kt

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ import java.io.File
1818
import kotlinx.rpc.buf.BufGenerateExtension
1919
import kotlinx.rpc.protoc.DefaultProtoSourceSet
2020
import kotlinx.rpc.protoc.ProtoTask
21-
import kotlinx.rpc.protoc.protoTaskProperties
2221
import org.gradle.api.file.SourceDirectorySet
2322
import org.gradle.api.provider.Provider
2423
import org.gradle.api.tasks.InputFiles
2524
import org.gradle.api.tasks.OutputDirectories
26-
import org.gradle.kotlin.dsl.listProperty
2725
import javax.inject.Inject
2826

2927
/**
@@ -92,15 +90,16 @@ public abstract class BufGenerateTask @Inject internal constructor(
9290
@get:OutputDirectory
9391
public abstract val outputDirectory: Property<File>
9492

95-
private val outputSourceDirectoriesInternal: ListProperty<File> = project.objects.listProperty()
96-
9793
/**
9894
* Generated source directories by plugin name.
9995
*
100-
* Can be used in [SourceDirectorySet.srcDirs].
96+
* Can be used in [SourceDirectorySet.srcDir] or similar `srcDir` functions from other source set directories.
10197
*/
10298
@get:OutputDirectories
103-
public val outputSourceDirectories: Provider<List<File>> = outputSourceDirectoriesInternal
99+
public val outputSourceDirectories: Provider<List<File>> = pluginNames.map { plugins ->
100+
val out = outputDirectory.get()
101+
plugins.map { out.resolve(it) }
102+
}
104103

105104
init {
106105
command.set("generate")
@@ -125,11 +124,6 @@ public abstract class BufGenerateTask @Inject internal constructor(
125124
}
126125

127126
this.args.set(args)
128-
129-
outputSourceDirectoriesInternal.set(pluginNames.map { plugins ->
130-
val out = outputDirectory.get()
131-
plugins.map { out.resolve(it) }
132-
})
133127
}
134128

135129
internal companion object {

gradle-plugin/src/main/kotlin/kotlinx/rpc/protoc/DefaultProtoSourceSet.kt

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ package kotlinx.rpc.protoc
66

77
import kotlinx.rpc.buf.tasks.BufGenerateTask
88
import kotlinx.rpc.rpcExtension
9-
import kotlinx.rpc.util.KotlinPluginId
109
import kotlinx.rpc.util.findOrCreate
11-
import kotlinx.rpc.util.withAndroid
10+
import kotlinx.rpc.util.withLegacyAndroid
1211
import kotlinx.rpc.util.withAndroidSourceSets
1312
import kotlinx.rpc.util.withKotlin
1413
import kotlinx.rpc.util.withLazyJavaPluginExtension
@@ -51,7 +50,7 @@ internal class ProtoSourceSetFactory(
5150
}
5251

5352
internal fun Project.findOrCreateProtoSourceSets(): NamedDomainObjectContainer<ProtoSourceSet> =
54-
project.findOrCreate(PROTO_SOURCE_SETS) {
53+
findOrCreate(PROTO_SOURCE_SETS) {
5554
val container = objects.domainObjectContainer(
5655
ProtoSourceSet::class.java,
5756
ProtoSourceSetFactory(project)
@@ -119,6 +118,9 @@ internal open class DefaultProtoSourceSet(
119118
}
120119
}
121120

121+
val tasksConfigured: Property<Boolean> = project.objects.property<Boolean>()
122+
.convention(false)
123+
122124
// Collection of AndroidSourceSet, KotlinSourceSet, SourceSet (java) associated with this proto source set
123125
val languageSourceSets: ListProperty<Any> = project.objects.listProperty<Any>()
124126
val generateTask: Property<BufGenerateTask?> = project.objects.property<BufGenerateTask?>()
@@ -133,18 +135,6 @@ internal open class DefaultProtoSourceSet(
133135
internal val isLegacyAndroid: Property<Boolean> = project.objects.property<Boolean>()
134136
.convention(false)
135137

136-
// when com.android.* (not kotlin.multiplatform.library) is applied - kotlin has proxy source sets:
137-
// | AndroidSourceSet | KotlinSourceSet |
138-
// | main | androidMain |
139-
// | test | androidUnitTest |
140-
// | debug | androidDebug |
141-
// ...
142-
//
143-
// these kotlin 'proxy' source sets have propper dependsOn values, but should not have tasks configures,
144-
// as tasks are configured once for the android source sets
145-
internal val isKotlinProxyLegacyAndroid: Property<Boolean> = project.objects.property<Boolean>()
146-
.convention(false)
147-
148138
// used to track tasks' dependencies for main/commonMain/commonTest tasks, e.g.:
149139
// - bufGenerateTestDebug depends on bufGenerateDebug
150140
// - bufGenerateTestDebug depends on bufGenerateCommonTest and bufGenerateDebug for KMP
@@ -250,19 +240,15 @@ internal fun Project.createProtoExtensions() {
250240

251241
// CCE free check for kotlin
252242
withKotlin {
253-
withKotlinSourceSets { id, extension ->
243+
withKotlinSourceSets { extension ->
254244
extension.sourceSets.all {
255245
findOrCreateAndConfigure(name, this)
256246
}
257-
258-
if (id != KotlinPluginId.MULTIPLATFORM) {
259-
return@withKotlinSourceSets
260-
}
261247
}
262248
}
263249

264250
// CCE free check for android
265-
withAndroid {
251+
withLegacyAndroid {
266252
withAndroidSourceSets { sourceSets ->
267253
sourceSets.all {
268254
findOrCreateAndConfigure(name, this)
@@ -284,6 +270,6 @@ internal fun Project.createProtoExtensions() {
284270
internal fun DefaultProtoSourceSet.protoTaskProperties(): ProtoTask.Properties {
285271
return androidProperties.orNull ?: ProtoTask.Properties(
286272
isTest = name.lowercase().endsWith("test"),
287-
sourceSetName = name,
273+
sourceSetNames = setOf(name),
288274
)
289275
}

0 commit comments

Comments
 (0)