2021-01-27 02:36:32 -08:00
|
|
|
|
2020-12-24 04:46:31 -08:00
|
|
|
import org.eclipse.jgit.internal.storage.file.FileRepository
|
2020-07-04 06:53:31 -07:00
|
|
|
import org.gradle.api.Plugin
|
|
|
|
import org.gradle.api.Project
|
2020-08-15 05:43:28 -07:00
|
|
|
import org.gradle.kotlin.dsl.provideDelegate
|
2020-07-04 06:53:31 -07:00
|
|
|
import java.io.File
|
2024-07-06 01:55:09 -07:00
|
|
|
import java.util.Properties
|
2020-07-04 06:53:31 -07:00
|
|
|
|
|
|
|
private val props = Properties()
|
2021-01-27 02:36:32 -08:00
|
|
|
private var commitHash = ""
|
2024-08-01 14:33:08 -07:00
|
|
|
private val supportAbis = setOf("armeabi-v7a", "x86", "arm64-v8a", "x86_64", "riscv64")
|
|
|
|
private val defaultAbis = setOf("armeabi-v7a", "x86", "arm64-v8a", "x86_64")
|
2020-07-04 06:53:31 -07:00
|
|
|
|
|
|
|
object Config {
|
2021-01-25 23:33:09 +08:00
|
|
|
operator fun get(key: String): String? {
|
2020-12-24 04:46:31 -08:00
|
|
|
val v = props[key] as? String ?: return null
|
|
|
|
return if (v.isBlank()) null else v
|
|
|
|
}
|
2021-01-25 23:33:09 +08:00
|
|
|
|
2020-12-24 04:46:31 -08:00
|
|
|
fun contains(key: String) = get(key) != null
|
|
|
|
|
2021-01-25 23:33:09 +08:00
|
|
|
val version: String get() = get("version") ?: commitHash
|
2021-01-22 02:28:53 -08:00
|
|
|
val versionCode: Int get() = get("magisk.versionCode")!!.toInt()
|
2021-01-22 20:45:37 -08:00
|
|
|
val stubVersion: String get() = get("magisk.stubVersion")!!
|
2024-08-01 14:33:08 -07:00
|
|
|
val abiList: Set<String> get() {
|
|
|
|
val abiList = get("abiList") ?: return defaultAbis
|
|
|
|
return abiList.split(Regex("\\s*,\\s*")).toSet() intersect supportAbis
|
|
|
|
}
|
2020-07-04 06:53:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
class MagiskPlugin : Plugin<Project> {
|
2021-01-27 02:36:32 -08:00
|
|
|
override fun apply(project: Project) = project.applyPlugin()
|
|
|
|
|
|
|
|
private fun Project.applyPlugin() {
|
2024-07-06 01:55:09 -07:00
|
|
|
initRandom(rootProject.file("app/dict.txt"))
|
2021-01-27 02:36:32 -08:00
|
|
|
props.clear()
|
|
|
|
rootProject.file("gradle.properties").inputStream().use { props.load(it) }
|
|
|
|
val configPath: String? by this
|
|
|
|
val config = configPath?.let { File(it) } ?: rootProject.file("config.prop")
|
2020-12-25 13:03:25 -08:00
|
|
|
if (config.exists())
|
|
|
|
config.inputStream().use { props.load(it) }
|
2020-12-25 05:34:15 -08:00
|
|
|
|
2021-01-27 02:36:32 -08:00
|
|
|
val repo = FileRepository(rootProject.file(".git"))
|
2020-12-25 05:34:15 -08:00
|
|
|
val refId = repo.refDatabase.exactRef("HEAD").objectId
|
|
|
|
commitHash = repo.newObjectReader().abbreviate(refId, 8).name()
|
2020-07-04 06:53:31 -07:00
|
|
|
}
|
|
|
|
}
|