Improve: clean tun2socket build on tasks["clean"]

This commit is contained in:
Kr328 2021-05-25 02:24:50 +08:00
parent ca85a688cc
commit 12220789a3
3 changed files with 32 additions and 6 deletions

View File

@ -11,14 +11,12 @@ data class BuildConfig(
val minSdkVersion: Int,
) : Serializable {
companion object {
fun of(extension: BaseExtension, variant: BaseVariant): BuildConfig {
fun of(abis: List<NativeAbi>, minSdkVersion: Int, variant: BaseVariant): BuildConfig {
return BuildConfig(
debug = variant.buildType.isDebuggable,
premium = variant.flavorName == "premium",
abis = extension.defaultConfig.externalNativeBuild.cmake.abiFilters
.map { NativeAbi.parse(it) }
.distinct(),
minSdkVersion = extension.defaultConfig.minSdkVersion!!.apiLevel
abis = abis,
minSdkVersion = minSdkVersion
)
}
}

View File

@ -11,8 +11,19 @@ class ClashBuildPlugin : Plugin<Project> {
override fun apply(target: Project) {
target.afterEvaluate {
target.extensions.getByType(LibraryExtension::class.java).apply {
val abis = defaultConfig.externalNativeBuild.cmake.abiFilters
.map { NativeAbi.parse(it) }
.distinct()
val minSdkVersion = defaultConfig.minSdkVersion!!.apiLevel
target.tasks.register("cleanGolang", ClashCleanTask::class.java) {
it.applyFrom(target, abis)
target.tasks.getByName("clean").dependsOn(it)
}
libraryVariants.forEach { variant ->
val config = BuildConfig.of(this, variant)
val config = BuildConfig.of(abis, minSdkVersion, variant)
val buildDir = target.golangBuild.resolve(variant.name)
val capitalize = variant.name.capitalize(Locale.getDefault())

View File

@ -0,0 +1,17 @@
package com.github.kr328.clash.tools
import org.gradle.api.Project
import org.gradle.api.tasks.Delete
import golangSource
abstract class ClashCleanTask : Delete() {
fun applyFrom(project: Project, abis: List<NativeAbi>) {
val bridge = project.golangSource.resolve("tun2socket/bridge")
delete(bridge.resolve("build"))
abis.forEach {
delete(bridge.resolve("build_android_${it.goArch}.go"))
}
}
}