[Gradle] kgp-idea-proto: Automate protoc setup

^KT-60053 In Progress
This commit is contained in:
Sebastian Sellmair
2023-07-10 14:41:34 +02:00
committed by Space Team
parent 93c3bcbd74
commit 9732651264
2 changed files with 66 additions and 26 deletions
+6
View File
@@ -1799,6 +1799,12 @@
<sha256 value="50f99a9a77735fb1b0c2c12cb6457c88cd0180b9106190d89cbf311ef8ce675d" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.google.protobuf" name="protoc" version="3.21.9">
<artifact name="protoc-3.21.9-osx-aarch_64.exe">
<md5 value="795b78841e779eceab9ea32acdbaf8fc" origin="Generated by Gradle"/>
<sha256 value="aa75cfcb456ced3784f989b0a90d06c03cc8620d1e8fce893707344eb8689d3b" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.google.testing.platform" name="core-proto" version="0.0.8-alpha01">
<artifact name="core-proto-0.0.8-alpha01.jar">
<md5 value="c4ca15c622b6ecbf566cd8ea28a90a55" origin="Generated by Gradle"/>
@@ -1,6 +1,8 @@
@file:Suppress("HasPlatformType")
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.jetbrains.kotlin.konan.target.HostManager
import org.jetbrains.kotlin.konan.target.KonanTarget.*
plugins {
kotlin("jvm")
@@ -64,35 +66,68 @@ run {
}
}
/* Setup protoc */
tasks.register<Exec>("protoc") {
val protoSources = file("src/main/proto")
val javaOutput = file("src/generated/java/")
val kotlinOutput = file("src/generated/kotlin/")
inputs.dir(protoSources)
outputs.dir(javaOutput)
outputs.dir(kotlinOutput)
doFirst {
javaOutput.deleteRecursively()
kotlinOutput.deleteRecursively()
javaOutput.mkdirs()
kotlinOutput.mkdirs()
run {
val protoc = configurations.create("protoc") {
isCanBeResolved = true
isCanBeConsumed = false
}
workingDir(project.projectDir)
dependencies {
protoc("com.google.protobuf:protoc:3.21.9") {
artifact {
type = "exe"
classifier = when (HostManager.host) {
MACOS_ARM64 -> "osx-aarch_64"
MACOS_X64 -> "osx-x86_64"
MINGW_X64 -> "windows-x86_64"
LINUX_X64 -> "linux-x86_64"
else -> null
}
}
}
}
commandLine(
*arrayOf(
"protoc",
"-I=$protoSources",
"--java_out=${javaOutput.absolutePath}",
"--kotlin_out=${kotlinOutput.absolutePath}"
) + protoSources.listFiles().orEmpty()
.filter { it.extension == "proto" }
.map { it.path },
)
val protocExecutable = buildDir.resolve("protoc/bin")
val setupProtoc = tasks.register("setupProtoc") {
doFirst {
protoc.files.single().copyTo(protocExecutable, overwrite = true)
protocExecutable.setExecutable(true)
}
}
tasks.register<Exec>("protoc") {
dependsOn(setupProtoc)
val protoSources = file("src/main/proto")
val javaOutput = file("src/generated/java/")
val kotlinOutput = file("src/generated/kotlin/")
inputs.dir(protoSources)
outputs.dir(javaOutput)
outputs.dir(kotlinOutput)
doFirst {
javaOutput.deleteRecursively()
kotlinOutput.deleteRecursively()
javaOutput.mkdirs()
kotlinOutput.mkdirs()
}
workingDir(project.projectDir)
commandLine(
*arrayOf(
protocExecutable.absolutePath,
"-I=$protoSources",
"--java_out=${javaOutput.absolutePath}",
"--kotlin_out=${kotlinOutput.absolutePath}"
) + protoSources.listFiles().orEmpty()
.filter { it.extension == "proto" }
.map { it.path },
)
}
}
@@ -118,4 +153,3 @@ run {
}
}
}