From 333d57e162b7f19453de9e52ba3e17f6a3dc887d Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Sun, 16 Jul 2023 17:47:48 +0200 Subject: [PATCH] Updated gradle tasks order --- build.gradle.kts | 75 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 24 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index b27da9c..cbbb601 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -109,9 +109,7 @@ compose.desktop { application { mainClass = "com.jetpackduba.gitnuro.MainKt" - this@application.dependsOn("rust_generateKotlinFromUdl") - this@application.dependsOn("rust_build") - this@application.dependsOn("rust_copyBuild") + this@application.dependsOn("rustTasks") sourceSets.forEach { it.java.srcDir(rustGeneratedSource) @@ -161,27 +159,28 @@ task("fatJarLinux", type = Jar::class) { } -task("rust_generateKotlinFromUdl", type = Exec::class) { +task("rust_generateKotlinFromUdl") { println("Generate Kotlin") - workingDir = File(project.projectDir, "rs") - commandLine = listOf( - "cargo", "run", "--features=uniffi/cli", - "--bin", "uniffi-bindgen", "generate", "src/repository_watcher.udl", - "--language", "kotlin", - "--out-dir", rustGeneratedSource - ) + generateKotlinFromUdl() } -task("rust_build", type = Exec::class) { - println("Build rs called") - workingDir = File(project.projectDir, "rs") - commandLine = listOf( - "cargo", "build", "--release", "--features=uniffi/cli", - ) +task("rust_build") { + buildRust() } -tasks.getByName("compileKotlin").dependsOn("rustTasks") -tasks.getByName("compileTestKotlin").dependsOn("rustTasks") +tasks.getByName("compileKotlin").doLast { + println("compileKotlin called") + buildRust() + copyRustBuild() + generateKotlinFromUdl() +} + +tasks.getByName("compileTestKotlin").doLast { + println("compileTestKotlin called") + buildRust() + copyRustBuild() + generateKotlinFromUdl() +} task("tasksList") { @@ -192,14 +191,40 @@ task("tasksList") { } task("rustTasks") { - dependsOn("rust_build") - dependsOn("rust_generateKotlinFromUdl") - dependsOn("rust_copyBuild") + buildRust() + copyRustBuild() + generateKotlinFromUdl() } task("rust_copyBuild") { + copyRustBuild() +} + +fun generateKotlinFromUdl() { + exec { + workingDir = File(project.projectDir, "rs") + commandLine = listOf( + "cargo", "run", "--features=uniffi/cli", + "--bin", "uniffi-bindgen", "generate", "src/repository_watcher.udl", + "--language", "kotlin", + "--out-dir", rustGeneratedSource + ) + } +} + +fun buildRust() { + exec { + println("Build rs called") + workingDir = File(project.projectDir, "rs") + commandLine = listOf( + "cargo", "build", "--release", "--features=uniffi/cli", + ) + } +} + +fun copyRustBuild() { val outputDir = "${buildDir}/classes/kotlin/main" - println("Copy rs called") + println("Copy rs build called") val workingDir = File(project.projectDir, "rs/target/release") val directory = File(outputDir) @@ -221,4 +246,6 @@ task("rust_copyBuild") { val destinyFile = File(directory, destinyLib) com.google.common.io.Files.copy(originFile, destinyFile) -} + + println("Copy rs build completed") +} \ No newline at end of file