|
4 | 4 |
|
5 | 5 | package kotlinx.rpc.protoc |
6 | 6 |
|
| 7 | +import kotlinx.rpc.buf.BufCommentsExtension |
| 8 | +import kotlinx.rpc.buf.BufGenerateExtension |
7 | 9 | import kotlinx.rpc.buf.tasks.BufGenerateTask |
8 | 10 | import kotlinx.rpc.protoc.ProtocPlugin.Companion.GRPC_KOTLIN_MULTIPLATFORM |
9 | 11 | import kotlinx.rpc.protoc.ProtocPlugin.Companion.KOTLIN_MULTIPLATFORM |
| 12 | +import kotlinx.rpc.rpcExtension |
| 13 | +import kotlinx.rpc.rpcExtensionOrNull |
10 | 14 | import kotlinx.rpc.util.findOrCreate |
11 | 15 | import kotlinx.rpc.util.withKotlinJvmExtension |
12 | 16 | import kotlinx.rpc.util.withKotlinKmpExtension |
13 | 17 | import org.gradle.api.* |
14 | 18 | import org.gradle.api.file.SourceDirectorySet |
15 | 19 | import org.gradle.api.provider.ListProperty |
16 | 20 | import org.gradle.api.provider.Property |
| 21 | +import org.gradle.api.provider.Provider |
17 | 22 | import org.gradle.api.tasks.SourceSet |
18 | 23 | import org.gradle.api.tasks.SourceSetContainer |
19 | 24 | import org.gradle.kotlin.dsl.add |
20 | 25 | import org.gradle.kotlin.dsl.listProperty |
| 26 | +import org.gradle.kotlin.dsl.newInstance |
21 | 27 | import org.gradle.kotlin.dsl.property |
22 | 28 | import org.gradle.kotlin.dsl.the |
23 | 29 | import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode |
24 | 30 | import org.jetbrains.kotlin.gradle.dsl.KotlinBaseExtension |
| 31 | +import org.jetbrains.kotlin.gradle.targets.js.npm.includedRange |
25 | 32 | import javax.inject.Inject |
26 | 33 |
|
27 | 34 | @Suppress("UNCHECKED_CAST") |
@@ -58,24 +65,33 @@ internal open class DefaultProtoSourceSet @Inject constructor( |
58 | 65 | javaJar(project.kotlinMultiplatformProtocPluginJarPath) |
59 | 66 | } |
60 | 67 |
|
61 | | - options.put("debugOutput", "protoc-gen-kotlin-multiplatform.log") |
62 | | - |
63 | | - if (this@DefaultProtoSourceSet.name.lowercase().endsWith("main")) { |
64 | | - options.put("explicitApiModeEnabled", explicitApiModeEnabled) |
65 | | - } |
| 68 | + defaultOptions(explicitApiModeEnabled) |
66 | 69 | } |
67 | 70 |
|
68 | 71 | plugins.create(GRPC_KOTLIN_MULTIPLATFORM) { |
69 | 72 | local { |
70 | 73 | javaJar(project.grpcKotlinMultiplatformProtocPluginJarPath) |
71 | 74 | } |
72 | 75 |
|
73 | | - options.put("debugOutput", "protoc-gen-grpc-kotlin-multiplatform.log") |
| 76 | + defaultOptions(explicitApiModeEnabled) |
| 77 | + } |
| 78 | + } |
74 | 79 |
|
75 | | - if (this@DefaultProtoSourceSet.name.lowercase().endsWith("main")) { |
76 | | - options.put("explicitApiModeEnabled", explicitApiModeEnabled) |
77 | | - } |
| 80 | + private fun ProtocPlugin.defaultOptions(explicitApiModeEnabled: Provider<Boolean>) { |
| 81 | + options.put("debugOutput", "protoc-gen-$name.log") |
| 82 | + |
| 83 | + if (this@DefaultProtoSourceSet.name.lowercase().endsWith("main")) { |
| 84 | + options.put("explicitApiModeEnabled", explicitApiModeEnabled) |
| 85 | + } |
| 86 | + |
| 87 | + val comments: Provider<BufGenerateExtension> = project.provider { |
| 88 | + project.rpcExtensionOrNull()?.run { protoc.buf.generate } |
| 89 | + ?: project.objects.newInstance<BufGenerateExtension>() |
78 | 90 | } |
| 91 | + |
| 92 | + options.put("generateComments", comments.flatMap { it.comments.copyComments }) |
| 93 | + options.put("generateFileLevelComments", comments.flatMap { it.comments.includeFileLevelComments }) |
| 94 | + options.put("indentSize", comments.flatMap { it.indentSize }) |
79 | 95 | } |
80 | 96 |
|
81 | 97 | val languageSourceSets: ListProperty<Any> = project.objects.listProperty<Any>() |
|
0 commit comments