refactor event service dispatch
This commit is contained in:
21 files changed
+536
-566
No files matched your search
@@ -173,11 +173,4 @@ open class GolangBindTask : DefaultTask() {
|
||||
if (process.waitFor() != 0)
|
||||
throw GradleException("Run command $this failure")
|
||||
}
|
||||
|
||||
private fun String.exe(): String {
|
||||
return if (Os.isFamily(Os.FAMILY_WINDOWS))
|
||||
"$this.exe"
|
||||
else
|
||||
this
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
import java.io.File
|
||||
|
||||
data class GolangBuildOptions(val sourceDir: File, val outputDir: File, val platform: String)
|
||||
@@ -1,92 +0,0 @@
|
||||
import org.apache.tools.ant.taskdefs.condition.Os
|
||||
import org.gradle.api.GradleException
|
||||
import org.gradle.api.tasks.Exec
|
||||
import java.io.File
|
||||
import java.io.FileReader
|
||||
|
||||
import java.util.Properties
|
||||
|
||||
open class GolangBuildTask : Exec() {
|
||||
private lateinit var options: GolangBuildOptions
|
||||
private lateinit var abi: String
|
||||
|
||||
override fun exec() {
|
||||
val toolchainRoot = findAndroidNdkPath().resolve("toolchains/llvm/prebuilt/${detectOsType()}/bin")
|
||||
val linkerPrefix = toolChainPrefix()
|
||||
val compilerPrefix = linkerPrefix + options.platform
|
||||
|
||||
if ( !toolchainRoot.exists() )
|
||||
throw GradleException("Compiler not found")
|
||||
|
||||
workingDir = options.sourceDir
|
||||
|
||||
environment.put("GOARCH", golangArch())
|
||||
environment.put("GOOS", "android")
|
||||
environment.put("CGO_ENABLED", "1")
|
||||
environment.put("GOPATH", project.buildDir.resolve("intermediates/gopath").absolutePath)
|
||||
environment.put("CXX", toolchainRoot.resolve(compilerPrefix + "-clang++".cmd()).absolutePath)
|
||||
environment.put("CC", toolchainRoot.resolve(compilerPrefix + "-clang".cmd()).absolutePath)
|
||||
environment.put("LD", toolchainRoot.resolve(linkerPrefix + "ld".exe()).absolutePath)
|
||||
|
||||
commandLine = listOf("go".exe(), "build", "-o", options.outputDir.resolve("$abi/libclash.so").absolutePath)
|
||||
|
||||
super.exec()
|
||||
}
|
||||
|
||||
fun setOptions(options: GolangBuildOptions, abi: String) {
|
||||
this.options = options
|
||||
this.abi = abi
|
||||
}
|
||||
|
||||
private fun findAndroidNdkPath(): File {
|
||||
val properties = FileReader(project.rootProject.file("local.properties")).use {
|
||||
Properties().apply { load(it) }
|
||||
}
|
||||
|
||||
return properties.getProperty("ndk.dir")?.let { File(it) }?.takeIf { it.exists() }
|
||||
?: throw GradleException("Android NDK not found.")
|
||||
}
|
||||
|
||||
private fun detectOsType(): String {
|
||||
return when {
|
||||
Os.isFamily(Os.FAMILY_WINDOWS) -> "windows-x86_64"
|
||||
Os.isFamily(Os.FAMILY_MAC) -> "darwin-x86_64"
|
||||
Os.isFamily(Os.FAMILY_UNIX) -> "linux-x86_64"
|
||||
else -> throw GradleException("Unsupported Build OS ${System.getenv("os.name")}")
|
||||
}
|
||||
}
|
||||
|
||||
private fun golangArch(): String {
|
||||
return when (abi) {
|
||||
"armeabi-v7a" -> "arm"
|
||||
"arm64-v8a" -> "arm64"
|
||||
"x86" -> "i686"
|
||||
"x86_64" -> "amd64"
|
||||
else -> throw GradleException("Unsupported arch $abi")
|
||||
}
|
||||
}
|
||||
|
||||
private fun toolChainPrefix(): String {
|
||||
return when (abi) {
|
||||
"armeabi-v7a" -> "arm-linux-androideabi"
|
||||
"arm64-v8a" -> "aarch64-linux-android"
|
||||
"x86" -> "i686-linux-android"
|
||||
"x86_64" -> "x86_64-linux-android"
|
||||
else -> throw GradleException("Unsupported arch $abi")
|
||||
}
|
||||
}
|
||||
|
||||
private fun String.exe(): String {
|
||||
return if ( Os.isFamily(Os.FAMILY_WINDOWS) )
|
||||
"$this.exe"
|
||||
else
|
||||
this
|
||||
}
|
||||
|
||||
private fun String.cmd(): String {
|
||||
return if ( Os.isFamily(Os.FAMILY_WINDOWS) )
|
||||
"$this.cmd"
|
||||
else
|
||||
this
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user