downloading proto libs - working!
This commit is contained in:
parent
cbda928141
commit
320bf854db
1 changed files with 93 additions and 67 deletions
|
|
@ -8,6 +8,7 @@ import org.gradle.kotlin.dsl.create
|
||||||
import org.gradle.kotlin.dsl.property
|
import org.gradle.kotlin.dsl.property
|
||||||
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
|
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
|
||||||
import org.gradle.nativeplatform.platform.internal.DefaultOperatingSystem
|
import org.gradle.nativeplatform.platform.internal.DefaultOperatingSystem
|
||||||
|
import org.jetbrains.kotlin.incremental.isJavaFile
|
||||||
import org.jetbrains.kotlin.util.parseSpaceSeparatedArgs
|
import org.jetbrains.kotlin.util.parseSpaceSeparatedArgs
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
|
|
@ -23,79 +24,119 @@ dependencies {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class ProtocPlugin : Plugin<Project> {
|
open class ProtocPlugin : Plugin<Project> {
|
||||||
|
|
||||||
override fun apply(project: Project) {
|
override fun apply(project: Project) {
|
||||||
|
|
||||||
val protocConfig =
|
val protocConfig =
|
||||||
project.extensions.create("protocPluginConfig", ProtocPluginConfig::class, project)
|
project.extensions.create("protocPluginConfig", ProtocPluginConfig::class, project)
|
||||||
|
|
||||||
// val protocDep: Configuration = project.configurations.create("protoc") {
|
val protobufCompiler: Configuration = project.configurations.create("protobufCompiler") {
|
||||||
// isVisible = false
|
isVisible = false
|
||||||
// isCanBeConsumed = false
|
isCanBeConsumed = false
|
||||||
// isCanBeResolved = true
|
isCanBeResolved = true
|
||||||
// isTransitive = false
|
isTransitive = false
|
||||||
//
|
|
||||||
// defaultDependencies {
|
|
||||||
// add(protocConfig.dependencyProvider())
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// project.dependencies.createArtifactResolutionQuery().forComponents()
|
defaultDependencies {
|
||||||
|
add(protocConfig.dependency.get())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val protocPrepare = project.tasks.register<ProtocPrepareTask>("protocPrepare")
|
val protobufLibs: Configuration = project.configurations.create("protobufLib") {
|
||||||
|
isVisible = true
|
||||||
|
isCanBeConsumed = false
|
||||||
|
isCanBeResolved = true
|
||||||
|
isTransitive = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// val protocPrepare = project.tasks.register<ProtocPrepareTask>("protocPrepare")
|
||||||
|
|
||||||
|
project.dependencies {
|
||||||
|
protobufLibs("com.google.protobuf:protobuf-javalite:3.19.1")
|
||||||
|
}
|
||||||
|
|
||||||
|
val libsTask = project.tasks.register<Sync>("protobufLibs") {
|
||||||
|
group = "protobuf"
|
||||||
|
|
||||||
|
includeEmptyDirs = false
|
||||||
|
|
||||||
|
dependsOn(protobufLibs)
|
||||||
|
|
||||||
|
val outDir = project.layout.buildDirectory.dir("proto/libs")
|
||||||
|
|
||||||
|
protobufLibs
|
||||||
|
.map { project.zipTree(it) }
|
||||||
|
.forEach {
|
||||||
|
logger.lifecycle("protoc lib - $it")
|
||||||
|
from(it) {
|
||||||
|
include("**/*.proto")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
into(outDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
project.tasks.register<Exec>("protobufCompile") {
|
||||||
|
group = "protobuf"
|
||||||
|
dependsOn(protobufCompiler, libsTask)
|
||||||
|
executable(protobufCompiler.singleFile)
|
||||||
|
|
||||||
|
|
||||||
|
val protoLibsDir = project.layout.buildDirectory.dir("proto/libs")
|
||||||
|
inputs.dir(protoLibsDir)
|
||||||
|
|
||||||
|
standardOutput = System.out
|
||||||
|
|
||||||
|
val outDir = project.layout.buildDirectory.dir("protoc")
|
||||||
|
// outDir.get().asFile.mkdirs()
|
||||||
|
workingDir(outDir)
|
||||||
|
|
||||||
// project.tasks.register<Exec>("protobufCompile") {
|
|
||||||
//
|
|
||||||
// group = "protoc"
|
|
||||||
// dependsOn(protocPrepare)
|
|
||||||
//
|
|
||||||
// workingDir(temporaryDir)
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// if (protocConfig.operatingSystemProvider.get().get().isWindows) {
|
// if (protocConfig.operatingSystemProvider.get().get().isWindows) {
|
||||||
// args("cmd", "/c")
|
// args("cmd", "/c")
|
||||||
// }
|
// }
|
||||||
//
|
|
||||||
// val srcDir = project.layout.projectDirectory.dir("src")
|
val srcDir = project.layout.projectDirectory.dir("src")
|
||||||
// val javaOut = project.layout.buildDirectory.dir("proto/java")
|
val javaOut = project.layout.buildDirectory.dir("proto/java")
|
||||||
// val kotlinOut = project.layout.buildDirectory.dir("proto/kotlin")
|
val kotlinOut = project.layout.buildDirectory.dir("proto/kotlin")
|
||||||
// val protoFile =
|
val protoFile =
|
||||||
// project.layout.projectDirectory.file("src/main/proto/FactorioServerLogRecord.proto")
|
project.layout.projectDirectory.file("src/main/proto/FactorioServerLogRecord.proto")
|
||||||
//
|
|
||||||
// args(
|
|
||||||
// parseSpaceSeparatedArgs(
|
|
||||||
|
args(
|
||||||
|
parseSpaceSeparatedArgs(
|
||||||
|
"""
|
||||||
|
-I=${srcDir.asFile.canonicalPath}
|
||||||
|
--java_out=${javaOut.get().asFile.canonicalPath}
|
||||||
|
--kotlin_out=${kotlinOut.get().asFile.canonicalPath}
|
||||||
|
${protoFile.asFile.canonicalPath}
|
||||||
|
|
||||||
|
""".trimIndent()
|
||||||
// """
|
// """
|
||||||
// -I=${srcDir.asFile.canonicalPath}
|
// -I=$SRC_DIR
|
||||||
// --java_out=${javaOut.get().asFile.canonicalPath}
|
// --java_out=$DST_DIR
|
||||||
// --kotlin_out=${kotlinOut.get().asFile.canonicalPath}
|
// --kotlin_out=$DST_DIR
|
||||||
// ${protoFile.asFile.canonicalPath}
|
// $SRC_DIR/addressbook.proto"
|
||||||
//
|
//
|
||||||
// """.trimIndent()
|
// """.trimIndent()
|
||||||
//// """
|
)
|
||||||
//// -I=$SRC_DIR
|
)
|
||||||
//// --java_out=$DST_DIR
|
|
||||||
//// --kotlin_out=$DST_DIR
|
|
||||||
//// $SRC_DIR/addressbook.proto"
|
|
||||||
////
|
|
||||||
//// """.trimIndent()
|
|
||||||
// )
|
|
||||||
// )
|
|
||||||
// doLast {
|
// doLast {
|
||||||
// executable = protocPrepare.flatMap { it.protocOutput }.get().asFile.canonicalPath
|
// executable = protocPrepare.flatMap { it.protocOutput }.get().asFile.canonicalPath
|
||||||
// }
|
// }
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class ProtocPluginConfig(private val project: Project) : java.io.Serializable {
|
abstract class ProtocPluginConfig(private val project: Project) : java.io.Serializable { // TODO remove serializable?
|
||||||
|
|
||||||
val protocWorkingDir: DirectoryProperty =
|
val protocWorkingDir: DirectoryProperty =
|
||||||
project.objects.directoryProperty()
|
project.objects.directoryProperty()
|
||||||
.convention(project.rootProject.layout.projectDirectory.dir(".gradle/protoc"))
|
.convention(project.rootProject.layout.projectDirectory.dir(".gradle/protoc"))
|
||||||
|
|
||||||
val protocVersion: Property<String> =
|
val protocVersion: Property<String> =
|
||||||
project.objects.property(String::class).convention("3.9.2")
|
project.objects.property(String::class).convention("3.19.1")
|
||||||
|
|
||||||
val protocGroup: Property<String> =
|
val protocGroup: Property<String> =
|
||||||
project.objects.property(String::class).convention("com.google.protobuf")
|
project.objects.property(String::class).convention("com.google.protobuf")
|
||||||
|
|
@ -177,10 +218,9 @@ abstract class ProtocPluginConfig(private val project: Project) : java.io.Serial
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class ProtocGenerationConfig
|
|
||||||
|
|
||||||
abstract class ProtocPrepareTask : DefaultTask() {
|
abstract class ProtocPrepareTask : DefaultTask() {
|
||||||
|
|
||||||
|
|
||||||
@Internal
|
@Internal
|
||||||
val protocPluginConfig: Provider<ProtocPluginConfig> = project.provider {
|
val protocPluginConfig: Provider<ProtocPluginConfig> = project.provider {
|
||||||
project.extensions.getByType<ProtocPluginConfig>()
|
project.extensions.getByType<ProtocPluginConfig>()
|
||||||
|
|
@ -192,27 +232,18 @@ abstract class ProtocPrepareTask : DefaultTask() {
|
||||||
|
|
||||||
@Internal
|
@Internal
|
||||||
val protocOutput: RegularFileProperty = project.objects.fileProperty()
|
val protocOutput: RegularFileProperty = project.objects.fileProperty()
|
||||||
// @get:OutputFile
|
|
||||||
// val protocOutput: RegularFileProperty = project.objects.fileProperty()
|
|
||||||
// .convention { outputDirectory.asFileTree.singleFile }
|
|
||||||
// .convention(outputDirectory.map { project it.asFileTree.singleFile })
|
|
||||||
|
|
||||||
@Internal
|
@Internal
|
||||||
val protocDependency: Provider<ExternalModuleDependency> =
|
val protocDependency: Provider<ExternalModuleDependency> =
|
||||||
protocPluginConfig.flatMap { it.dependency }
|
protocPluginConfig.flatMap { it.dependency }
|
||||||
|
|
||||||
init {
|
init {
|
||||||
super.setGroup("protoc")
|
super.setGroup("protobuf")
|
||||||
|
outputs.dir(outputDirectory)
|
||||||
// project.dependencies {
|
|
||||||
// protocDep(protocDependency.get())
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// super.dependsOn(protocDep)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@TaskAction
|
@TaskAction
|
||||||
fun prepare() {
|
fun action() {
|
||||||
|
|
||||||
val protocDep: Configuration = project.configurations.create("protoc") {
|
val protocDep: Configuration = project.configurations.create("protoc") {
|
||||||
isVisible = false
|
isVisible = false
|
||||||
|
|
@ -229,16 +260,11 @@ abstract class ProtocPrepareTask : DefaultTask() {
|
||||||
val resolvedProtocDep = protocDep.singleFile
|
val resolvedProtocDep = protocDep.singleFile
|
||||||
logger.lifecycle("Downloaded $resolvedProtocDep")
|
logger.lifecycle("Downloaded $resolvedProtocDep")
|
||||||
|
|
||||||
// require(resolvedProtocDep.singleOrNull() != null) {
|
|
||||||
// "Expected to download a single protoc.exe, but got ${resolvedProtocDep.size}: ${resolvedProtocDep.joinToString()}"
|
|
||||||
// }
|
|
||||||
|
|
||||||
project.sync {
|
project.sync {
|
||||||
from(resolvedProtocDep)
|
from(resolvedProtocDep)
|
||||||
into(outputDirectory)
|
into(outputDirectory)
|
||||||
// doLast {
|
logger.lifecycle("Syncing from $resolvedProtocDep to ${outputDirectory.asFile.get().canonicalPath}")
|
||||||
// logger.lifecycle("Syncing from $resolvedProtocDep to $outputDirectory")
|
protocOutput.set(outputDirectory.asFileTree.singleFile)
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue