Skip to content

Add cargoClean gradle task #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions plugin/src/main/kotlin/com/nishtahir/CargoCleanTask.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.nishtahir;

import com.android.build.gradle.*
import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
import org.gradle.api.Project
import org.gradle.api.logging.LogLevel
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.TaskAction
import java.io.ByteArrayOutputStream
import java.io.File

open class CargoCleanTask : DefaultTask() {

@Suppress("unused")
@TaskAction
fun clean() = with(project) {
extensions[CargoExtension::class].apply {
val theCommandLine = mutableListOf(this.cargoCommand)
theCommandLine.add("clean")
project.exec { spec ->
val cargoExtension = this
with(spec){
val module = File(cargoExtension.module!!)
if (module.isAbsolute) {
workingDir = module
} else {
workingDir = File(project.project.projectDir, module.path)
}

workingDir = workingDir.canonicalFile
standardOutput = System.out
commandLine = theCommandLine
}
}
}
}
}
6 changes: 6 additions & 0 deletions plugin/src/main/kotlin/com/nishtahir/RustAndroidPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -307,5 +307,11 @@ open class RustAndroidPlugin : Plugin<Project> {
targetBuildTask.dependsOn(generateLinkerWrapper)
buildTask.dependsOn(targetBuildTask)
}

val cleanTask = tasks.maybeCreate("cargoClean",
CargoCleanTask::class.java).apply {
group = RUST_TASK_GROUP
description = "Deletes the target directory."
}
}
}