Files
Magisk/buildSrc/src/main/java/BuildSource.kt
topjohnwu ec8fffe61c Merge Magisk install zip into Magisk Manager
Distribute Magisk directly with Magisk Manager APK. The APK will
contain all required binaries and scripts for installation and
uninstallation. App versions will now align with Magisk releases.

Extra effort is spent to make the APK itself also a flashable zip that
can be used in custom recoveries, so those still prefer to install
Magisk with recoveries will not be affected with this change.

As a bonus, this makes the whole installation and uninstallation
process 100% offline. The existing Magisk Manager was not really
functional without an Internet connection, as the installation process
was highly tied to zips hosted on the server.

An additional bonus: since all binaries are now shipped as "native
libraries" of the APK, we can finally bump the target SDK version
higher than 28. The target SDK version was stuck at 28 for a long time
because newer SELinux restricts running executables from internal
storage. More details can be found here: https://github.com/termux/termux-app/issues/1072
The target SDK bump will be addressed in a future commit.

Co-authored with @vvb2060
2021-01-22 02:29:54 -08:00

39 lines
1.3 KiB
Kotlin

import org.eclipse.jgit.api.Git
import org.eclipse.jgit.internal.storage.file.FileRepository
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.provideDelegate
import java.io.File
import java.util.*
private val props = Properties()
private lateinit var commitHash: String
private var commitCount = 0
object Config {
operator fun get(key: String) : String? {
val v = props[key] as? String ?: return null
return if (v.isBlank()) null else v
}
fun contains(key: String) = get(key) != null
val version: String = get("version") ?: commitHash
val versionCode: Int get() = get("magisk.versionCode")!!.toInt()
}
class MagiskPlugin : Plugin<Project> {
override fun apply(project: Project) {
project.rootProject.file("gradle.properties").inputStream().use { props.load(it) }
val configPath: String? by project
val config = configPath?.let { File(it) } ?: project.rootProject.file("config.prop")
if (config.exists())
config.inputStream().use { props.load(it) }
val repo = FileRepository(project.rootProject.file(".git"))
val refId = repo.refDatabase.exactRef("HEAD").objectId
commitHash = repo.newObjectReader().abbreviate(refId, 8).name()
commitCount = Git(repo).log().add(refId).call().count()
}
}