From 633e75acaa616c2427265d96e7338f1204e8395e Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Mon, 15 Jul 2024 14:17:56 +0200 Subject: [PATCH] Added kotlin code generation --- build.gradle.kts | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 8cfc656..e626d1f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -171,12 +171,6 @@ task("fatJarLinux", type = Jar::class) { with(tasks.jar.get() as CopySpec) } -// -//task("rust_generateKotlinFromUdl") { -// println("Generate Kotlin") -// generateKotlinFromUdl() -//} - task("rust_build") { buildRust() } @@ -206,7 +200,7 @@ task("tasksList") { task("rustTasks") { buildRust() copyRustBuild() -// generateKotlinFromUdl() + generateKotlinFromRs() } task("rust_copyBuild") { @@ -214,7 +208,29 @@ task("rust_copyBuild") { } fun generateKotlinFromRs() { + val outDir = "${project.projectDir}/src/main/kotlin/com/jetpackduba/gitnuro/autogenerated/" + println("Out dir is $outDir") + val outDirFile = File(outDir) + if (outDirFile.exists()) { + outDirFile.listFiles()?.forEach { file -> if (file.name != ".gitignore") file.delete() } + } else { + outDirFile.mkdirs() + } + + // cargo-kotars must be preinstalled + val command = listOf( + "cargo-kotars", + "--kotlin-output", + outDir, + ) + + exec { + println("Generating Kotlin source files") + + workingDir = File(project.projectDir, "rs") + commandLine = command + } } fun buildRust() {